From: Laurent Mazet Date: Sun, 13 Apr 2025 11:35:41 +0000 (+0200) Subject: generic makefile X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=9844758537aa597bb7ad745b5fe76722a82641e7;p=scrabble.git generic makefile --- diff --git a/makefile b/makefile index dcc3a3b..09ecb8b 100644 --- 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 @@ -13,21 +14,30 @@ 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) +MV = mv +ifneq (, $(findstring linux, $(MAKE_HOST))) +# Linux +else ifneq (, $(findstring mingw, $(MAKE_HOST))) +# Windows MinGw +CFLAGS += -DWIN32 #LDLIBS += -lws2_32 LDOPT = winlnk -endif -ifeq ($(OS),Dos) +else ifneq (, $(findstring cygwin, $(MAKE_HOST))) +CFLAGS += -DWIN32 +# Windows CygWin +LDOPT = winlnk +else ifneq (, $(findstring msdos, $(MAKE_HOST))) +# MSDOS LDOPT = doslnk +MV = move endif # Targets -ALLEXE = -ALLEXE += scrabble +ALLEXE = $(shell for f in *.c; do grep -q '/\*\slinker:' $$f && echo $${f/.c}; done) SHELL = bash @@ -59,6 +69,7 @@ all: depends analyze: make purge scan-build make + #scan-build -stats make count: wc $(wildcard *.c *.h) $(MAKEFILE_LIST) @@ -66,7 +77,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)) @@ -83,7 +94,8 @@ purge: clean rm -f purge $(ALLEXE:%=%.exe) $(call PASS, SUCCESS) -valgrinds: all +valgrinds: + $(MAKE) all $(MAKE) $(addprefix valgrind_,$(ALLEXE)) wipe: purge @@ -92,7 +104,9 @@ wipe: purge rm -f wipe $(wildcard *.gcda *.gcno *.gcov *.glog) $(call PASS, SUCCESS) -tests: all +tests: + -rm -f $(ALLEXE) + $(MAKE) all $(MAKE) $(addprefix test_,$(ALLEXE)) ## Main rules @@ -102,13 +116,14 @@ include $(wildcard *.ld) gcov_%: $(MAKE) purge - OPTIONS="-coverage -O0" $(MAKE) + $(MAKE) depends + OPTIONS="-coverage -O0" $(MAKE) ${@:gcov_%=%}.exe $(MAKE) test_$(@:gcov_%=%) gcov `sed -e 's/\.exe:/.c/;s/\.o/.c/g' $(@:gcov_%=%.ld)` touch gcov rm -f gcov $(wildcard *.gcda *.gcno) $(MAKE) purge - grep '#####' *.c.gcov || true + grep '^ *#####' *.c.gcov || true gprof_%: $(MAKE) purge @@ -133,6 +148,7 @@ gprof_%: $(call TITLE, "Building $@") $(call GETCOMMENTS,test, $<) > $@ $(call PASS, SUCCESS) + -rm -f _ test_%: %.test %.exe IFS=$$'\n'; RC=0; \ @@ -141,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 @@ -153,7 +170,7 @@ valgrind_%: %.exe $(call TITLE, "Building $@") $(CC) $(INCLUDES) -MM $< -o $@~ echo ${<:.c=.o}: $(shell $(call GETCOMMENTS,depends, $<)) >> $@~ - mv $@~ $@ + $(MV) $@~ $@ $(call PASS, SUCCESS) %.ld: %.c