diff options
| author | Pavel Vymetálek <pavel@vym.cz> | 2026-11-04 09:28:23 +0100 |
|---|---|---|
| committer | Pavel Vymetálek <pavel@vym.cz> | 2026-11-04 09:28:23 +0100 |
| commit | 16121ff4db151c72049e96734f1e592c4e283514 (patch) | |
| tree | 8a2a3e59954a991437ee10ba80b447f8564a5379 /Makefile | |
| parent | adb2e06a2cc480d6d9218d8784be91221fbe6783 (diff) | |
| download | sercp-pc-16121ff4db151c72049e96734f1e592c4e283514.tar.gz | |
Makefile: centralize compiler flags, add DEBUG=1 and .PHONY
- Move common flags to CFLAGS_COMMON; allow CFLAGS_EXTRA and LDFLAGS
- Replace the debug target with `make DEBUG=1` (-g -O0)
- Add .PHONY and include generated .d dependency file
- Use the default CC so macOS builds with clang
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 36 |
1 files changed, 26 insertions, 10 deletions
@@ -1,15 +1,31 @@ PROJECT=sercp PREFIX=/usr/local -CC=gcc +# CC is left to make's default (cc), so it also works with clang on macOS; override with make CC=gcc WINCC_PREFIX=i686-w64-mingw32 WINCC64_PREFIX=x86_64-w64-mingw32ucrt +# compiler flags are defined only here; extra ones can be added from outside: +# make CFLAGS_EXTRA=... LDFLAGS=... +CFLAGS_COMMON=-Wall -pedantic -MP -MD -std=gnu99 -Werror=format-security -Wformat -fno-common $(CFLAGS_EXTRA) + +WIN_WINDRES_COMMON=--input-format=rc --codepage=65001 -O coff +WIN_CFLAGS_COMMON=$(PROJECT).res $(CFLAGS_COMMON) -O2 $(LDFLAGS) + +# make DEBUG=1 builds without optimization and with debug info +ifeq ($(DEBUG),1) +OPTFLAGS=-g -O0 +else +OPTFLAGS=-O2 +endif + +.PHONY: all windows install clean sercp.w32 sercp.w64 + all: $(PROJECT) -windows: $(PROJECT).w32 $(PROJECT).w64 +windows: $(PROJECT).w64 $(PROJECT).w32 sercp: $(PROJECT).c - $(CC) $(PROJECT).c -o $(PROJECT) -Wall -pedantic -MP -MD -std=gnu99 -Werror=format-security -O2 -Wformat + $(CC) $(PROJECT).c -o $(PROJECT) $(CFLAGS_COMMON) $(OPTFLAGS) $(LDFLAGS) install: $(PROJECT) install -d $(DESTDIR)$(PREFIX)/bin/ @@ -17,18 +33,18 @@ install: $(PROJECT) sercp.w64: $(PROJECT).c rm -f $(PROJECT).res - $(WINCC64_PREFIX)-windres -i $(PROJECT).rc --input-format=rc --codepage=65001 -o $(PROJECT).res -O coff - $(WINCC64_PREFIX)-gcc $(PROJECT).c $(PROJECT).res -o $(PROJECT).exe -Wall -pedantic -MP -MD -std=gnu99 -Werror=format-security -Wformat -O2 + $(WINCC64_PREFIX)-windres -i $(PROJECT).rc $(WIN_WINDRES_COMMON) -o $(PROJECT).res + $(WINCC64_PREFIX)-gcc $(PROJECT).c $(WIN_CFLAGS_COMMON) -o $(PROJECT).exe $(WINCC64_PREFIX)-strip $(PROJECT).exe sercp.w32: $(PROJECT).c rm -f $(PROJECT).res - $(WINCC_PREFIX)-windres -i $(PROJECT).rc --input-format=rc --codepage=65001 -o $(PROJECT).res -O coff - $(WINCC_PREFIX)-gcc $(PROJECT).res $(PROJECT).c -o $(PROJECT)32.exe -Wall -pedantic -MP -MD -std=gnu99 -Werror=format-security -Wformat -O2 + $(WINCC_PREFIX)-windres -i $(PROJECT).rc $(WIN_WINDRES_COMMON) -o $(PROJECT).res + $(WINCC_PREFIX)-gcc $(PROJECT).c $(WIN_CFLAGS_COMMON) -o $(PROJECT)32.exe $(WINCC_PREFIX)-strip $(PROJECT)32.exe -debug: $(PROJECT).c - $(CC) $(PROJECT).c -o $(PROJECT) -Wall -pedantic -MP -MD -std=gnu99 -Werror=format-security -g -O0 -Wformat - clean: rm -f $(PROJECT) $(PROJECT).d $(PROJECT).o $(PROJECT).res $(PROJECT)*.d $(PROJECT)*.exe + +# header dependencies generated by -MD +-include $(PROJECT).d |
