Makefile (1741B)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | # Include the configuration -include config.mk # Directories needed for build DIRS = bin bin/release bin/debug # Main source code, objects, and dependencies SRCS = $(shell ls *.c) OBJS = $(shell ls *.c | \ sed -e '/test.c/d' -e 's/.c$$/.o/' | \ awk '{print "bin/$(MODE)/" $$0}') DEPS = $(shell ls *.c | \ sed -e '/test.c/d' -e 's/.c$$/.d/' | \ awk '{print "bin/$(MODE)/" $$0}') # PCH source PCH_SRC = pch.h PCH = bin/$(MODE)/pch.h.gch PCH_DEPS = bin/$(MODE)/pch.h.d TEST_TARGET = test TEST_OBJS = $(shell ls *.c | sed -e '/main.c/d' -e 's/.c$$/.o/' | awk '{print "bin/$(MODE)/" $$0}') all: dirs bin/$(PROGRAM_TARGET) test: dirs bin/$(TEST_TARGET) runtest: test @bin/$(TEST_TARGET) debugtest: test @gdb bin/$(TEST_TARGET) clean: $(RM) $(PROGRAM_TARGET) $(OBJS) $(TEST_OBJS) $(TEST_TARGET) run: all @bin/$(PROGRAM_TARGET) debug: all @gdb bin/$(PROGRAM_TARGET) mem: all @valgrind $(VALGRIND_ARGS) --log-file=$(VALGRIND_LOG) bin/$(PROGRAM_TARGET) mem_nolog: @valgrind $(VALGRIND_ARGS) bin/$(PROGRAM_TARGET) # Link the executable bin/$(PROGRAM_TARGET): $(OBJS) @echo " [link] $@" @$(CC) $(OBJS) -o $@ $(CFLAGS) $(LDFLAGS) # Include dependency files -include $(DEPS) -include $(PCH_DEPS) # Compile C sources with dependencies bin/$(MODE)/%.o: %.c $(PCH) @echo " [cc] $<" @$(CC) -MMD -MP -c $< -o $@ $(CFLAGS) # Compile precompiled header $(PCH): $(PCH_SRC) @echo " [pch] $<" @$(CC) -MMD -MP -x c-header -c $< -o $@ $(CFLAGS) # Link test executable bin/$(TEST_TARGET): $(TEST_OBJS) @echo " [link] $@" @$(CC) $(TEST_OBJS) -o $@ $(CFLAGS) $(LDFLAGS) dirs: $(DIRS) # Create prerequisite directories $(DIRS): @$(MKDIR) $(DIRS) .PHONY: all dirs clean run debug mem mem_nolog test |