generic makefile
authorLaurent Mazet <mazet@softndesign.org>
Sun, 13 Apr 2025 12:08:45 +0000 (14:08 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Sun, 13 Apr 2025 12:08:45 +0000 (14:08 +0200)
makefile

index 2f126ba8b2df9d5a7b248d2c97d24d05cb94fb0a..09ecb8bc309abe5c9bba31812b7dfecc3743bcb9 100644 (file)
--- a/makefile
+++ b/makefile
@@ -5,6 +5,7 @@ CC = gcc
 #INCLUDES = -I../debug -D__MEMORY_ALLOCATION__
 INCLUDES =
 OFLAGS  = -O4 -Os
+#OFLAGS  = -O0
 #OFLAGS  = -O4 -ffast-math -finline-functions
 #OFLAGS  = -O4 -finline-functions
 #OFLAGS += -mtune=pentium3 -mmmx -msse -msse2 -m3dnow
@@ -21,9 +22,11 @@ ifneq (, $(findstring linux, $(MAKE_HOST)))
 # Linux
 else ifneq (, $(findstring mingw, $(MAKE_HOST)))
 # Windows MinGw
+CFLAGS += -DWIN32
 #LDLIBS += -lws2_32
 LDOPT = winlnk
 else ifneq (, $(findstring cygwin, $(MAKE_HOST)))
+CFLAGS += -DWIN32
 # Windows CygWin
 LDOPT = winlnk
 else ifneq (, $(findstring msdos, $(MAKE_HOST)))
@@ -34,8 +37,7 @@ endif
 
 # Targets
 
-ALLEXE  =
-ALLEXE += tetris
+ALLEXE  = $(shell for f in *.c; do grep -q '/\*\slinker:' $$f && echo $${f/.c}; done)
 
 SHELL = bash
 
@@ -64,6 +66,11 @@ GETCOMMENTS = awk '/\/\*\s*$(1):/,/\*\// { sub(/.*\/\*\s*$(1):/, ""); sub (/\s*\
 all: depends
        $(MAKE) $(ALLEXE:%=%.exe)
 
+analyze:
+       make purge
+       scan-build make
+       #scan-build -stats make
+
 count:
        wc $(wildcard *.c *.h) $(MAKEFILE_LIST)
 
@@ -116,7 +123,7 @@ gcov_%:
        touch gcov
        rm -f gcov $(wildcard *.gcda *.gcno)
        $(MAKE) purge
-       grep '#####' *.c.gcov || true
+       grep '^ *#####' *.c.gcov || true
 
 gprof_%:
        $(MAKE) purge
@@ -150,6 +157,7 @@ test_%: %.test %.exe
          eval $$test; \
          [ $$? -eq 0 ] && echo -e "\033[1;32mSUCCESS\033[0;0m" \
                        || { echo -e "\033[1;31mFAILED\033[0;0m"; RC=1; }; \
+         test "$$RC" = 1 -a "$(STOP)" = 1 && break; \
        done; \
        test "$$RC" -ne 1
 
@@ -183,7 +191,7 @@ valgrind_%: %.exe
 
 ## Phony
 
-.PHONY: all clean count depends gcovs purge tests
+.PHONY: all analyze clean count depends gcovs purge tests
 
 ## Precious