# ******************************************************************************
# Makefile: Builds the "set SeaMAC" test app (setseamac)
# Sealevel Systems, Inc.
# Dec 2025
# ******************************************************************************

APPDIR  ?= /usr/bin
MAN1DIR ?= /usr/share/man/man1
INCLUDE ?= $(shell pwd)/../../driver/inc

CC      ?= /usr/bin/gcc
MKDIR   ?= /bin/mkdir
CP      ?= /bin/cp
RM      ?= /bin/rm
CHMOD   ?= /bin/chmod

## ============================================================================

APPNAME  = setseamac
APPDESC  = "setseamac Configuration/Test Utility"
HEADER   = $(INCLUDE)/seamac.h

OBJS     = setseamac.o
MAN1     = setseamac.1.gz

CFLAGS = -Wall -O3 -I$(INCLUDE)


## ============================================================================
all: $(APPNAME)

$(HEADER):
	@echo
	@echo "  ERROR!  Include file missing! " $(HEADER)
	@echo
	@echo "       You may need to fetch another copy of this distribution."
	@echo
	@exit 1

$(OBJS): %.o: %.c $(HEADER)
	@echo "   Compiling $(APPNAME) source: $*.o"
	@$(CC) $(CFLAGS) -c $< -o $@

$(APPNAME): %: %.o
	@echo "   Linking $^"
	@$(CC) $(CFLAGS) $^ -o $@

objs: $(OBJS)
	@echo " *$(APPDESC) prepared"
	@echo

install: $(APPNAME)
	@echo "   Installing ${APPNAME} in ${APPDIR}"
	@for n in $(APPNAME); do $(CP) -r $$n ${APPDIR}; done
	@for n in $(APPNAME); do $(CHMOD) 755 ${APPDIR}/$$n; done
	@for n in $(MAN1); do $(CP) -r $$n ${MAN1DIR}; done
	@echo " *${APPNAME} installed"
	@echo

uninstall:
	@echo "   Uninstalling ${APPNAME} from ${APPDIR}"
	@for n in $(APPNAME); do $(RM) -f ${APPDIR}/$$n; done
	@for n in $(MAN1); do $(RM) -f ${MAN1DIR}/$$n; done
	@echo " *${APPNAME} uninstalled"
	@echo 

clean: 
	@echo "   Removing ${APPNAME} temp build files"
	@$(RM) -rf $(OBJS)
	@echo

clobber: 
	@echo "   Removing ${APPNAME} build output plus executable"
	@$(RM) -rf $(OBJS) $(APPNAME)
	@echo " *${APPNAME} build files removed"
	@echo
