
######################################################################
# Makefile template for simple projects.  Just fill in the blanks and
# add or adjust variables as needed.  Remove unnecessary lines if
# desired.
#
# To override any variables conditionally set (with ?=), run
#
#       make VAR=value
# e.g.
#       make PREFIX=/opt/local CC=gcc CFLAGS=-O2 LFLAGS1="-L/usr/X11R6 -lX11"
#
# Author: Jason W. Bacon
#         Medical College of Wisconsin
######################################################################

################################
# Files to be installed by make

BIN1    = legoctl
BINS    = ${BIN1}

MANS    = legoctl.1
SCRIPTS =


###################################################
# List object files that comprise BIN1, BIN2, etc.

OBJS1   = legoctl.o
OBJS    = ${OBJS1}

#####################################
# Compile, link, and install options

PREFIX          ?= /usr/local
LOCALBASE       ?= /usr/local
MANPREFIX       ?= /usr/local

CC      ?= cc
CFLAGS  ?= -O -pipe
INCLUDES?= -I../../Libs/C -I${LOCALBASE}/include
CFLAGS  += -Wall ${INCLUDES}

LFLAGS1 += -L../../Libs/C -lroboctl -L${LOCALBASE}/lib -lusb -lbluetooth

INSTALL ?= install
LN      ?= ln
RM      ?= rm
PRINTF  ?= printf


#####################################
# Standard targets required by ports

all:    ${BINS} ${LIBS}

# Link rules
${BIN1}:        ${OBJS1}
	${CC} -o ${BIN1} ${OBJS1} ${LFLAGS1}

############################################################################
# Include dependencies generated by "make depend", if they exist.
# These rules explicitly list dependencies for each object file.
# See "depend" target below.  If Makefile.depend does not exist, use
# generic source compile rules.  These have some limitations, so you
# may prefer to create explicit rules for each target file.  This can
# be done automatically using "cpp -M" or "cpp -MM".  Run "man cpp"
# for more information, or see the "depend" target below.

include Makefile.depend

############################################################################
# Self-generate dependencies the old-fashioned way

depend:
	rm -f Makefile.depend
	for file in *.c; do \
		${CPP} ${INCLUDES} -MM $${file} >> Makefile.depend; \
		${PRINTF} "\t\$${CC} -c \$${CFLAGS} $${file}\n\n" >> Makefile.depend; \
	done


############################################################################
# Generate a header containing prototypes for C files.  Requires
# the cproto command, which is freely available on the WEB.

protos:
	(cproto ${INCLUDES} *.c > temp_protos.h && mv -f temp_protos.h protos.h)

# Remove generated files (objs and nroff output from man pages)
clean:
	rm -f ${OBJS} ${BINS} ${LIBS} *.nr *.exe *.EXE

# Keep backup files during normal clean, but provide an option to remove them
realclean: clean
	rm -f .*.bak *.bak *.BAK

install: all
	mkdir -p ${PREFIX}/bin ${PREFIX}/lib ${PREFIX}/include ${MANPREFIX}/man/man1
	@for file in ${BINS}; do \
		${INSTALL} -s -c -m 0555 $${file} ${PREFIX}/bin; \
	done
	@for file in ${MANS}; do \
		${INSTALL} -c -m 0444 $${file} ${MANPREFIX}/man/man1; \
	done

uninstall:
	@for file in ${BINS}; do \
		${RM} ${PREFIX}/bin/$${file}; \
	done
	@for file in ${MANS}; do \
		${RM} ${MANPREFIX}/man/man1/$${file}; \
	done
