From f7a9ec702596778172e279c24ed2f1121500e187 Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Sat, 30 Dec 2023 07:53:03 +0100 Subject: [PATCH] best makefile --- makefile | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/makefile b/makefile index 239c64d..355e64f 100644 --- a/makefile +++ b/makefile @@ -10,9 +10,10 @@ OFLAGS = -O4 -Os #OFLAGS += -minline-all-stringops -fsingle-precision-constant #OFLAGS += -malign-double CFLAGS += -W -Wall -Wextra -g -CFLAGS += -std=c99 -D_XOPEN_SOURCE=500 -CFLAGS += $(OFLAGS) $(INCLUDES) $(GCOV) -LDFLAGS += -g $(GCOV) +#CFLAGS += -std=c99 -D_XOPEN_SOURCE=500 +CFLAGS += $(OFLAGS) $(INCLUDES) $(OPTIONS) +LDFLAGS += -g $(OPTIONS) + ifeq ($(OS),Windows_NT) LDLIBS += -lws2_32 endif @@ -53,7 +54,7 @@ count: clean: $(call TITLE, "Cleaning") touch clean - rm -f clean $(wildcard *.d *.ld *.log *.o *.test *~ .exec_*) + rm -f clean $(wildcard *.d *.ld *.log *.o *.test *~ .exec_* gmon.out) $(call PASS, SUCCESS) depends: $(patsubst %.c, %.d, $(wildcard *.c)) $(patsubst %, %.ld, $(ALLEXE)) @@ -61,6 +62,9 @@ depends: $(patsubst %.c, %.d, $(wildcard *.c)) $(patsubst %, %.ld, $(ALLEXE)) gcovs: $(MAKE) $(addprefix gcov_,$(ALLEXE)) +gprofs: + $(MAKE) $(addprefix gprof_,$(ALLEXE)) + purge: clean $(call TITLE, "Purging") touch purge @@ -73,7 +77,7 @@ valgrinds: all wipe: purge $(call TITLE, "Wiping") touch wipe - rm -f wipe $(wildcard *.gcda *.gcno *.gcov) + rm -f wipe $(wildcard *.gcda *.gcno *.gcov *.glog) $(call PASS, SUCCESS) tests: all @@ -86,7 +90,7 @@ include $(wildcard *.ld) gcov_%: $(MAKE) purge - GCOV="-coverage -O0" $(MAKE) + OPTIONS="-coverage -O0" $(MAKE) $(MAKE) test_$(@:gcov_%=%) gcov `sed -e 's/\.exe:/.c/;s/\.o/.c/g' $(@:gcov_%=%.ld)` touch gcov @@ -94,6 +98,25 @@ gcov_%: $(MAKE) purge grep '#####' *.c.gcov || true +gprof_%: + $(MAKE) purge + $(MAKE) depends + OPTIONS="-pg" $(MAKE) ${@:gprof_%=%}.exe + $(MAKE) ${@:gprof_%=%}.test + IFS=$$'\n'; id=1; \ + for test in `cat ${@:gprof_%=%}.test | sed 's,${@:gprof_%=%}.exe,./${@:gprof_%=%}.exe,g'`; do \ + log=${@:gprof_%=%}.prof-$$id.glog; \ + $(call TITLE, test: $$test); \ + echo $$test > $$log; \ + eval $$test >> $$log; \ + [ $$? -eq 0 ] \ + && echo -e "\033[1;32mSUCCESS\033[0;0m" \ + || echo -e "\033[1;31mFAILED\033[0;0m"; \ + [ -f gmon.out ] && { gprof ${@:gprof_%=%}.exe gmon.out >> $$log; rm gmon.out; }; \ + let id++; \ + done; + $(MAKE) purge + %.test: %.c $(call TITLE, "Building $@") # awk '/\/\* *test:.*\*\// { sub(/^.*\/\* *test: */, ""); sub(/ *\*\/.*$$/, ""); print }' $< > $@ -- 2.30.2