correct makefile
authorLaurent Mazet <mazet@softndesign.org>
Tue, 16 Jul 2024 06:07:05 +0000 (08:07 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Tue, 16 Jul 2024 06:07:05 +0000 (08:07 +0200)
makefile

index 7329ad3bc2f7fb467c6c3f0a72e8e018c2d160f6..3f2fd9558c752cd6614b0e48ab6acfbc43dc1096 100644 (file)
--- a/makefile
+++ b/makefile
@@ -13,7 +13,7 @@ OFLAGS  = -O4 -Os
 CFLAGS += -W -Wall -Wextra -g
 #CFLAGS += -std=c99 -D_XOPEN_SOURCE=500
 CFLAGS += $(OFLAGS) $(INCLUDES) $(OPTIONS)
-LDFLAGS += -g $(OPTIONS)
+LDFLAGS += -g $(LDOPTS) $(OPTIONS)
 
 LDOPT = linker
 ifeq ($(OS),Windows_NT)
@@ -62,7 +62,7 @@ count:
 clean:
        $(call TITLE, "Cleaning")
        touch clean
-       rm -f clean $(wildcard *.d *.ld *.log *.o *.test *~ .exec_* gmon.out)
+       rm -f clean $(wildcard *.d *.ld *.log *.o *.test *~ .exec_* gmon.out) _
        $(call PASS, SUCCESS)
 
 depends: $(patsubst %.c, %.d, $(wildcard *.c)) $(patsubst %, %.ld, $(ALLEXE))
@@ -90,7 +90,7 @@ wipe: purge
 
 tests: test.o
        -rm -f $(ALLEXE)
-       LDFLAGS="$$LDFLAGS test.o" $(MAKE) all
+       LDOPTS="test.o" $(MAKE) all
        $(MAKE) $(addprefix test_,$(ALLEXE))
 
 ## Main rules
@@ -100,7 +100,9 @@ include $(wildcard *.ld)
 
 gcov_%:
        $(MAKE) purge
-       OPTIONS="-coverage -O0" $(MAKE)
+       $(MAKE) depends
+       $(MAKE) test.o
+       LDOPTS="test.o" OPTIONS="-coverage -O0" $(MAKE) ${@:gcov_%=%}.exe
        $(MAKE) test_$(@:gcov_%=%)
        gcov `sed -e 's/\.exe:/.c/;s/\.o/.c/g' $(@:gcov_%=%.ld)`
        touch gcov
@@ -111,7 +113,8 @@ gcov_%:
 gprof_%:
        $(MAKE) purge
        $(MAKE) depends
-       OPTIONS="-pg" $(MAKE) ${@:gprof_%=%}.exe
+       $(MAKE) test.o
+       LDOPTS="test.o" 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 \
@@ -131,6 +134,7 @@ gprof_%:
        $(call TITLE, "Building $@")
        $(call GETCOMMENTS,test, $<) > $@
        $(call PASS, SUCCESS)
+       -rm -f _
 
 test_%: %.test %.exe
        IFS=$$'\n'; RC=0; \