aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile36
1 files changed, 26 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index bd4eb4f..0413454 100644
--- a/Makefile
+++ b/Makefile
@@ -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