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)
31 TITLE = echo -en "\033[0;1m$(strip $(1))\033[0;0m:\t"
32 PASS = echo -e "\033[1;32m$(strip $(1))\033[0;0m"
33 WARN = echo -e "\033[1;33m$(strip $(1))\033[0;0m"
34 FAIL = echo -e "\033[1;31m$(strip $(1))\033[0;0m"
36 MKDIR = mkdir -p $(1) && chmod a+rx,go-w $(1)
38 INSTALL = test -d `dirname $(2)` || $(call MKDIR, `dirname $(2)`) && cp -pa $(1) $(2) && chmod a+rX,go-w $(2)
40 VALID = $(call TITLE, $(1)) && $(2) && $(call PASS, SUCCESS) || { $(call FAIL, FAILED); test; }
45 $(MAKE) $(ALLEXE:%=%.exe)
48 $(MAKE) $(addprefix test_,$(ALLEXE:%.exe=%))
50 depends: $(patsubst %.c, %.d, $(wildcard *.c)) $(patsubst %, %.ld, $(ALLEXE))
53 wc $(wildcard *.c *.h) $(MAKEFILE_LIST)
56 $(call TITLE, "Cleaning")
58 rm -f clean $(wildcard *.d *.ld *.log *.o *.test *~ .exec_*)
62 $(call TITLE, "Purging")
64 rm -f purge $(ALLEXE) $(shell [ -f .targets ] && { cat .targets | sort | uniq; echo .targets; })
69 include $(wildcard *.d)
70 include $(wildcard *.ld)
73 $(call TITLE, "Building $@")
74 # awk '/\/\* *test:.*\*\// { sub(/^.*\/\* *test: */, ""); sub(/ *\*\/.*$$/, ""); print }' $< > $@
75 ./getcomments.pl -p='test:\s' -f='%' $< > $@
80 for test in `cat $< | sed 's,${<:.test=.exe},./${<:.test=.exe},g'`; do \
81 echo "=== $$test ==="; \
82 eval $(VALGRIND) $$test; \
83 [ $$? -eq 0 ] && echo -e "\033[1;32mSUCCESS\033[0;0m" \
84 || { echo -e "\033[1;31mFAILED\033[0;0m"; RC=1; }; \
89 VALGRIND="valgrind -v --leak-check=full --show-reachable=yes --log-fd=2"; \
94 $(call TITLE, "Building $@")
95 $(CC) $(INCLUDES) -MM $< -o $@~
96 echo ${<:.c=.o}: $(shell ./getcomments.pl -p='depend:\s' -f='%' $<) >> $@~
101 $(call TITLE, "Building $@")
102 echo ${<:.c=.exe}: $(shell ./getcomments.pl -p='linker:\s' -f='%' $< | awk '{for (i=1;i<=NF;i++) if ($$(i) ~ /.o$$/) printf " %s", $$(i)}') > $@
103 $(call PASS, SUCCESS)
106 $(call TITLE, "Building $@")
107 $(CC) $(CFLAGS) $(INCLUDES) $(shell ./getcomments.pl -p='cflags:\s' -f='%' $<) -c $< -o $@
108 $(call PASS, SUCCESS)
112 $(call TITLE, "Building $@")
113 $(CC) $(LDFLAGS) $(shell ./getcomments.pl -p='linker:\s' -f='%' ${<:.o=.c}) $< -o $@
114 $(call PASS, SUCCESS)
118 .PHONY: clean count purge