5 INCLUDES = -I../debug -D__MEMORY_ALLOCATION__
7 #OFLAGS = -O4 -ffast-math -finline-functions
8 #OFLAGS = -O4 -finline-functions
9 #OFLAGS += -mtune=pentium3 -mmmx -msse -msse2 -m3dnow
10 #OFLAGS += -minline-all-stringops -fsingle-precision-constant
11 #OFLAGS += -malign-double
12 CFLAGS += -W -Wall -Wextra -g
13 #CFLAGS += -std=c99 -D_XOPEN_SOURCE=500
14 CFLAGS += $(OFLAGS) $(INCLUDES) $(OPTIONS)
15 LDFLAGS += -g $(OPTIONS)
17 ifeq ($(OS),Windows_NT)
31 include $(wildcard .makefile)
35 TITLE = echo -en "\033[0;1m$(strip $(1))\033[0;0m:\t"
36 PASS = echo -e "\033[1;32m$(strip $(1))\033[0;0m"
37 WARN = echo -e "\033[1;33m$(strip $(1))\033[0;0m"
38 FAIL = echo -e "\033[1;31m$(strip $(1))\033[0;0m"
40 MKDIR = mkdir -p $(1) && chmod a+rx,go-w $(1)
42 INSTALL = test -d `dirname $(2)` || $(call MKDIR, `dirname $(2)`) && cp -pa $(1) $(2) && chmod a+rX,go-w $(2)
44 VALID = $(call TITLE, $(1)) && $(2) && $(call PASS, SUCCESS) || { $(call FAIL, FAILED); test; }
49 $(MAKE) $(ALLEXE:%=%.exe)
52 wc $(wildcard *.c *.h) $(MAKEFILE_LIST)
55 $(call TITLE, "Cleaning")
57 rm -f clean $(wildcard *.d *.ld *.log *.o *.test *~ .exec_* gmon.out)
60 depends: $(patsubst %.c, %.d, $(wildcard *.c)) $(patsubst %, %.ld, $(ALLEXE))
63 $(MAKE) $(addprefix gcov_,$(ALLEXE))
66 $(MAKE) $(addprefix gprof_,$(ALLEXE))
69 $(call TITLE, "Purging")
71 rm -f purge $(ALLEXE:%=%.exe)
75 $(MAKE) $(addprefix valgrind_,$(ALLEXE))
78 $(call TITLE, "Wiping")
80 rm -f wipe $(wildcard *.gcda *.gcno *.gcov *.glog)
84 $(MAKE) $(addprefix test_,$(ALLEXE))
88 include $(wildcard *.d)
89 include $(wildcard *.ld)
93 OPTIONS="-coverage -O0" $(MAKE)
94 $(MAKE) test_$(@:gcov_%=%)
95 gcov `sed -e 's/\.exe:/.c/;s/\.o/.c/g' $(@:gcov_%=%.ld)`
97 rm -f gcov $(wildcard *.gcda *.gcno)
99 grep '#####' *.c.gcov || true
104 OPTIONS="-pg" $(MAKE) ${@:gprof_%=%}.exe
105 $(MAKE) ${@:gprof_%=%}.test
107 for test in `cat ${@:gprof_%=%}.test | sed 's,${@:gprof_%=%}.exe,./${@:gprof_%=%}.exe,g'`; do \
108 log=${@:gprof_%=%}.prof-$$id.glog; \
109 $(call TITLE, test: $$test); \
110 echo $$test > $$log; \
111 eval $$test >> $$log; \
113 && echo -e "\033[1;32mSUCCESS\033[0;0m" \
114 || echo -e "\033[1;31mFAILED\033[0;0m"; \
115 [ -f gmon.out ] && { gprof ${@:gprof_%=%}.exe gmon.out >> $$log; rm gmon.out; }; \
121 $(call TITLE, "Building $@")
122 # awk '/\/\* *test:.*\*\// { sub(/^.*\/\* *test: */, ""); sub(/ *\*\/.*$$/, ""); print }' $< > $@
123 perl -- getcomments.pl -p='test:\s' -f='%' $< > $@
124 $(call PASS, SUCCESS)
128 for test in `cat $< | sed 's,${<:.test=.exe},$(VALGRIND) ./${<:.test=.exe},g'`; do \
129 echo "=== $$test ==="; \
131 [ $$? -eq 0 ] && echo -e "\033[1;32mSUCCESS\033[0;0m" \
132 || { echo -e "\033[1;31mFAILED\033[0;0m"; RC=1; }; \
137 VALGRIND="valgrind -v --leak-check=full --log-fd=3"; \
139 $(MAKE) $(@:valgrind_%=test_%) 3>$@.log
142 $(call TITLE, "Building $@")
143 $(CC) $(INCLUDES) -MM $< -o $@~
144 echo ${<:.c=.o}: $(shell perl -- getcomments.pl -p='depend:\s' -f='%' $<) >> $@~
146 $(call PASS, SUCCESS)
149 $(call TITLE, "Building $@")
150 echo ${<:.c=.exe}: $(shell perl -- getcomments.pl -p='linker:\s' -f='%' $< | awk '{for (i=1;i<=NF;i++) if ($$(i) ~ /.o$$/) printf " %s", $$(i)}') > $@
151 $(call PASS, SUCCESS)
154 $(call TITLE, "Building $@")
155 $(CC) $(CFLAGS) $(INCLUDES) $(shell perl -- getcomments.pl -p='cflags:\s' -f='%' $<) -c $< -o $@
156 $(call PASS, SUCCESS)
160 $(call TITLE, "Building $@")
161 $(CC) $(LDFLAGS) $< $(shell perl -- getcomments.pl -p='linker:\s' -f='%' ${<:.o=.c}) $(LDLIBS) -o $@
162 $(call PASS, SUCCESS)
166 .PHONY: all clean count depends gcovs purge tests