]> git.mdlowis.com Git - projs/opts.git/commitdiff
Updated makefile to allow project specific overrides and features
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 30 Dec 2015 03:00:08 +0000 (22:00 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 30 Dec 2015 03:00:08 +0000 (22:00 -0500)
.gitignore
Makefile
config.mk [new file with mode: 0644]

index a8d198849eb5baa7900f7d7bcd226307b8d091ef..fc212327dd0832b36baf2cba8102812b7a870b37 100644 (file)
@@ -3,8 +3,13 @@ tags
 cscope.out
 project.vim
 *.o
+*.d
+*.gcno
+*.gcda
 *.exe
 *.a
 *.lib
 *~
 *.d
+config.mk
+testopts
index 466e757875a456dd2abd2384f439bdb9819c0019..1b7d52152481972d5b2d60f6b7507169200007aa 100644 (file)
--- 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 (file)
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