From: Michael D. Lowis Date: Wed, 30 Dec 2015 03:00:08 +0000 (-0500) Subject: Updated makefile to allow project specific overrides and features X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=79dd2cd363d2312dd117849bed96f29f9e408fe1;p=projs%2Fopts.git Updated makefile to allow project specific overrides and features --- diff --git a/.gitignore b/.gitignore index a8d1988..fc21232 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,13 @@ tags cscope.out project.vim *.o +*.d +*.gcno +*.gcda *.exe *.a *.lib *~ *.d +config.mk +testopts diff --git a/Makefile b/Makefile index 466e757..1b7d521 100644 --- a/Makefile +++ b/Makefile @@ -11,19 +11,36 @@ AR = ar # flags INCS = -Isource/ -Itests/ CPPFLAGS = -D_XOPEN_SOURCE=700 -CFLAGS += -g ${INCS} ${CPPFLAGS} +CFLAGS += ${INCS} ${CPPFLAGS} LDFLAGS += ${LIBS} ARFLAGS = rcs +# commands +COMPILE = @echo CC $@; ${CC} ${CFLAGS} -c -o $@ $< +LINK = @echo LD $@; ${LD} -o $@ $^ ${LDFLAGS} +ARCHIVE = @echo AR $@; ${AR} ${ARFLAGS} $@ $^ +CLEAN = @rm -f + #------------------------------------------------------------------------------ # Build Targets and Rules #------------------------------------------------------------------------------ -SRCS = source/opts.c -OBJS = ${SRCS:.c=.o} -TEST_SRCS = tests/atf.c tests/main.c tests/test_opts.c tests/test_opt.c -TEST_OBJS = ${TEST_SRCS:.c=.o} +LIBNAME = opts +LIB = lib${LIBNAME}.a + +DEPS = ${OBJS:.o=.d} +OBJS = source/opts.o + +TEST_BIN = test${LIBNAME} +TEST_DEPS = ${TEST_OBJS:.o=.d} +TEST_OBJS = tests/atf.o \ + tests/main.o \ + tests/test_opts.o \ + tests/test_opt.o -all: options libopts.a testopts +# load user-specific settings +-include config.mk + +all: options ${LIB} tests options: @echo "Toolchain Configuration:" @@ -34,21 +51,27 @@ options: @echo " AR = ${AR}" @echo " ARFLAGS = ${ARFLAGS}" -libopts.a: ${OBJS} - @echo AR $@ - @${AR} ${ARFLAGS} $@ ${OBJS} +tests: ${TEST_BIN} + +${LIB}: ${OBJS} + ${ARCHIVE} -testopts: ${TEST_OBJS} libopts.a - @echo LD $@ - @${LD} -o $@ ${TEST_OBJS} libopts.a ${LDFLAGS} - -./$@ +${TEST_BIN}: ${TEST_OBJS} ${LIB} + ${LINK} + @./$@ .c.o: - @echo CC $< - @${CC} ${CFLAGS} -c -o $@ $< + ${COMPILE} clean: - @rm -f libopts.a testopts ${OBJS} ${TEST_OBJS} + ${CLEAN} ${LIB} ${TEST_BIN} ${OBJS} ${TEST_OBJS} + ${CLEAN} ${OBJS:.o=.gcno} ${OBJS:.o=.gcda} + ${CLEAN} ${TEST_OBJS:.o=.gcno} ${TEST_OBJS:.o=.gcda} + ${CLEAN} ${DEPS} ${TEST_DEPS} + +# load dependency files +-include ${DEPS} +-include ${TEST_DEPS} -.PHONY: all options +.PHONY: all options tests diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..b4b59ae --- /dev/null +++ b/config.mk @@ -0,0 +1,17 @@ +#------------------------------------------------------------------------------ +# User and Platform Specific Configuration Options +#------------------------------------------------------------------------------ +# Override the tools used with platform specific ones +#CC = cc +#LD = ${CC} +#AR = ar + +# GCC dependency generation +#COMPILE += && ${CC} ${INCS} -MM -MT $@ -MF ${@:.o=.d} ${<:.o=.c} + +# Enable output of debug symbols +#CFLAGS += -g + +# Enable output of coverage information +#CFLAGS += --coverage +#LDFLAGS += --coverage