5 #INCLUDES = -I../debug -D__MEMORY_ALLOCATION__
8 #OFLAGS = -O4 -ffast-math -finline-functions
9 #OFLAGS = -O4 -finline-functions
10 #OFLAGS += -mtune=pentium3 -mmmx -msse -msse2 -m3dnow
11 #OFLAGS += -minline-all-stringops -fsingle-precision-constant
12 #OFLAGS += -malign-double
13 CFLAGS += -W -Wall -Wextra -g
14 #CFLAGS += -std=c99 -D_XOPEN_SOURCE=500
15 CFLAGS += $(OFLAGS) $(INCLUDES) $(OPTIONS)
16 LDFLAGS += -g $(OPTIONS)
18 ifeq ($(OS),Windows_NT)
32 include $(wildcard .makefile)
36 TITLE = echo -en "\033[0;1m$(strip $(1))\033[0;0m:\t"
37 PASS = echo -e "\033[1;32m$(strip $(1))\033[0;0m"
38 WARN = echo -e "\033[1;33m$(strip $(1))\033[0;0m"
39 FAIL = echo -e "\033[1;31m$(strip $(1))\033[0;0m"
41 MKDIR = mkdir -p $(1) && chmod a+rx,go-w $(1)
43 INSTALL = test -d `dirname $(2)` || $(call MKDIR, `dirname $(2)`) && cp -pa $(1) $(2) && chmod a+rX,go-w $(2)
45 VALID = $(call TITLE, $(1)) && $(2) && $(call PASS, SUCCESS) || { $(call FAIL, FAILED); test; }
50 $(MAKE) $(ALLEXE:%=%.exe)
53 wc $(wildcard *.c *.h) $(MAKEFILE_LIST)
56 $(call TITLE, "Cleaning")
58 rm -f clean $(wildcard *.d *.ld *.log *.o *.test *~ .exec_* gmon.out)
61 depends: $(patsubst %.c, %.d, $(wildcard *.c)) $(patsubst %, %.ld, $(ALLEXE))
64 $(MAKE) $(addprefix gcov_,$(ALLEXE))
67 $(MAKE) $(addprefix gprof_,$(ALLEXE))
70 $(call TITLE, "Purging")
72 rm -f purge $(ALLEXE:%=%.exe)
76 $(MAKE) $(addprefix valgrind_,$(ALLEXE))
79 $(call TITLE, "Wiping")
81 rm -f wipe $(wildcard *.gcda *.gcno *.gcov *.glog)
85 $(MAKE) $(addprefix test_,$(ALLEXE))
89 include $(wildcard *.d)
90 include $(wildcard *.ld)
94 OPTIONS="-coverage -O0" $(MAKE)
95 $(MAKE) test_$(@:gcov_%=%)
96 gcov `sed -e 's/\.exe:/.c/;s/\.o/.c/g' $(@:gcov_%=%.ld)`
98 rm -f gcov $(wildcard *.gcda *.gcno)
100 grep '#####' *.c.gcov || true
105 OPTIONS="-pg" $(MAKE) ${@:gprof_%=%}.exe
106 $(MAKE) ${@:gprof_%=%}.test
108 for test in `cat ${@:gprof_%=%}.test | sed 's,${@:gprof_%=%}.exe,./${@:gprof_%=%}.exe,g'`; do \
109 log=${@:gprof_%=%}.prof-$$id.glog; \
110 $(call TITLE, test: $$test); \
111 echo $$test > $$log; \
112 eval $$test >> $$log; \
114 && echo -e "\033[1;32mSUCCESS\033[0;0m" \
115 || echo -e "\033[1;31mFAILED\033[0;0m"; \
116 [ -f gmon.out ] && { gprof ${@:gprof_%=%}.exe gmon.out >> $$log; rm gmon.out; }; \
122 $(call TITLE, "Building $@")
123 # awk '/\/\* *test:.*\*\// { sub(/^.*\/\* *test: */, ""); sub(/ *\*\/.*$$/, ""); print }' $< > $@
124 perl -- getcomments.pl -p='test:\s' -f='%' $< > $@
125 $(call PASS, SUCCESS)
129 for test in `cat $< | sed 's,${<:.test=.exe},$(VALGRIND) ./${<:.test=.exe},g'`; do \
130 echo "=== $$test ==="; \
132 [ $$? -eq 0 ] && echo -e "\033[1;32mSUCCESS\033[0;0m" \
133 || { echo -e "\033[1;31mFAILED\033[0;0m"; RC=1; }; \
138 VALGRIND="valgrind -v --leak-check=full --log-fd=3"; \
140 $(MAKE) $(@:valgrind_%=test_%) 3>$@.log
143 $(call TITLE, "Building $@")
144 $(CC) $(INCLUDES) -MM $< -o $@~
145 echo ${<:.c=.o}: $(shell perl -- getcomments.pl -p='depend:\s' -f='%' $<) >> $@~
147 $(call PASS, SUCCESS)
150 $(call TITLE, "Building $@")
151 echo ${<:.c=.exe}: $(shell perl -- getcomments.pl -p='linker:\s' -f='%' $< | awk '{for (i=1;i<=NF;i++) if ($$(i) ~ /.o$$/) printf " %s", $$(i)}') > $@
152 $(call PASS, SUCCESS)
155 $(call TITLE, "Building $@")
156 $(CC) $(CFLAGS) $(INCLUDES) $(shell perl -- getcomments.pl -p='cflags:\s' -f='%' $<) -c $< -o $@
157 $(call PASS, SUCCESS)
161 $(call TITLE, "Building $@")
162 $(CC) $(LDFLAGS) $< $(shell perl -- getcomments.pl -p='linker:\s' -f='%' ${<:.o=.c}) $(LDLIBS) -o $@
163 $(call PASS, SUCCESS)
167 .PHONY: all clean count depends gcovs purge tests