5 #INCLUDES = -I../debug -D__MEMORY_ALLOCATION__
9 #OFLAGS = -O4 -ffast-math -finline-functions
10 #OFLAGS = -O4 -finline-functions
11 #OFLAGS += -mtune=pentium3 -mmmx -msse -msse2 -m3dnow
12 #OFLAGS += -minline-all-stringops -fsingle-precision-constant
13 #OFLAGS += -malign-double
14 CFLAGS += -W -Wall -Wextra -g
15 #CFLAGS += -std=c99 -D_XOPEN_SOURCE=500
16 CFLAGS += $(OFLAGS) $(INCLUDES) $(OPTIONS)
17 LDFLAGS += -g $(LDOPTS) $(OPTIONS)
21 ifneq (, $(findstring linux, $(MAKE_HOST)))
23 else ifneq (, $(findstring mingw, $(MAKE_HOST)))
28 else ifneq (, $(findstring cygwin, $(MAKE_HOST)))
32 else ifneq (, $(findstring msdos, $(MAKE_HOST)))
40 ALLEXE = $(shell for f in *.c; do grep -q '/\*\slinker:' $$f && echo $${f/.c}; done)
46 include $(wildcard .makefile)
50 TITLE = echo -en "\033[0;1m$(strip $(1))\033[0;0m:\t"
51 PASS = echo -e "\033[1;32m$(strip $(1))\033[0;0m"
52 WARN = echo -e "\033[1;33m$(strip $(1))\033[0;0m"
53 FAIL = echo -e "\033[1;31m$(strip $(1))\033[0;0m"
55 MKDIR = mkdir -p $(1) && chmod a+rx,go-w $(1)
57 INSTALL = test -d `dirname $(2)` || $(call MKDIR, `dirname $(2)`) && cp -pa $(1) $(2) && chmod a+rX,go-w $(2)
59 VALID = $(call TITLE, $(1)) && $(2) && $(call PASS, SUCCESS) || { $(call FAIL, FAILED); test; }
61 GETCOMMENTS = awk '/\/\*\s*$(1):/,/\*\// { sub(/.*\/\*\s*$(1):/, ""); sub (/\s*\*\/.*/, ""); print } /\/\/\s*$(1):/ {sub (/.*\/\/\s*$(1):/, ""); print }' $(2)
62 #GETCOMMENTS = perl -- getcomments.pl -p='$(1):\s' -f='%' $(2)
67 $(MAKE) $(ALLEXE:%=%.exe)
72 #scan-build -stats make
75 wc $(wildcard *.c *.h) $(MAKEFILE_LIST)
78 $(call TITLE, "Cleaning")
80 rm -f clean $(wildcard *.d *.ld *.log *.o *.test *~ .exec_* gmon.out _)
83 depends: $(patsubst %.c, %.d, $(wildcard *.c)) $(patsubst %, %.ld, $(ALLEXE))
86 $(MAKE) $(addprefix gcov_,$(ALLEXE))
89 $(MAKE) $(addprefix gprof_,$(ALLEXE))
92 $(call TITLE, "Purging")
94 rm -f purge $(ALLEXE:%=%.exe)
99 $(MAKE) $(addprefix valgrind_,$(ALLEXE))
102 $(call TITLE, "Wiping")
104 rm -f wipe $(wildcard *.gcda *.gcno *.gcov *.glog)
105 $(call PASS, SUCCESS)
110 $(MAKE) $(addprefix test_,$(ALLEXE))
114 include $(wildcard *.d)
115 include $(wildcard *.ld)
120 OPTIONS="-coverage -O0" $(MAKE) ${@:gcov_%=%}.exe
121 $(MAKE) test_$(@:gcov_%=%)
122 gcov `sed -e 's/\.exe:/.c/;s/\.o/.c/g' $(@:gcov_%=%.ld)`
124 rm -f gcov $(wildcard *.gcda *.gcno)
126 grep '^ *#####' *.c.gcov || true
131 OPTIONS="-pg" $(MAKE) ${@:gprof_%=%}.exe
132 $(MAKE) ${@:gprof_%=%}.test
134 for test in `cat ${@:gprof_%=%}.test | sed 's,${@:gprof_%=%}.exe,./${@:gprof_%=%}.exe,g'`; do \
135 log=${@:gprof_%=%}.prof-$$id.glog; \
136 $(call TITLE, test: $$test); \
137 echo $$test > $$log; \
138 eval $$test >> $$log; \
140 && echo -e "\033[1;32mSUCCESS\033[0;0m" \
141 || echo -e "\033[1;31mFAILED\033[0;0m"; \
142 [ -f gmon.out ] && { gprof ${@:gprof_%=%}.exe gmon.out >> $$log; rm gmon.out; }; \
148 $(call TITLE, "Building $@")
149 $(call GETCOMMENTS,test, $<) > $@
150 $(call PASS, SUCCESS)
155 for test in `cat $< | sed 's,${<:.test=.exe},$(VALGRIND) ./${<:.test=.exe},g'`; do \
156 echo "=== $$test ==="; \
158 [ $$? -eq 0 ] && echo -e "\033[1;32mSUCCESS\033[0;0m" \
159 || { echo -e "\033[1;31mFAILED\033[0;0m"; RC=1; }; \
160 test "$$RC" = 1 -a "$(STOP)" = 1 && break; \
165 VALGRIND="valgrind -v --leak-check=full --log-fd=3"; \
167 $(MAKE) $(@:valgrind_%=test_%) 3>$@.log
170 $(call TITLE, "Building $@")
171 $(CC) $(INCLUDES) -MM $< -o $@~
172 echo ${<:.c=.o}: $(shell $(call GETCOMMENTS,depends, $<)) >> $@~
174 $(call PASS, SUCCESS)
177 $(call TITLE, "Building $@")
178 echo ${<:.c=.exe}: $(shell $(call GETCOMMENTS,$(LDOPT), $<) | awk '{for (i=1;i<=NF;i++) if ($$(i) ~ /.o$$/) printf " %s", $$(i)}') > $@
179 $(call PASS, SUCCESS)
182 $(call TITLE, "Building $@")
183 $(CC) $(CFLAGS) $(INCLUDES) $(shell $(call GETCOMMENTS,cflags, $<)) -c $< -o $@
184 $(call PASS, SUCCESS)
188 $(call TITLE, "Building $@")
189 $(CC) $(LDFLAGS) $< $(shell $(call GETCOMMENTS,$(LDOPT), ${<:.o=.c})) $(LDLIBS) -o $@
190 $(call PASS, SUCCESS)
194 .PHONY: all analyze clean count depends gcovs purge tests