From 2d7a8c3c571bcc5335437e9db074c75af00408ce Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 21 Jun 2021 14:47:42 -0700 Subject: [PATCH 1/5] Makefile: use shell commands to read in Sourcefile File function is not supported < Make 4.2. --- src/Makefile | 11 ++++++----- src/Makefile.d/platform.mk | 2 ++ src/Makefile.d/util.mk | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Makefile b/src/Makefile index 18ab524b8..7104a91cf 100644 --- a/src/Makefile +++ b/src/Makefile @@ -176,11 +176,7 @@ include Makefile.d/detect.mk # make would try to remove the implicitly made directories .PRECIOUS : %/ comptime.c -# very sophisticated dependency -sources:=\ - $(call List,Sourcefile)\ - $(call List,blua/Sourcefile)\ - +sources:= makedir:=../make # -DCOMPVERSION: flag to use comptime.h @@ -204,6 +200,11 @@ endif depdir:=$(makedir)/deps objdir:=$(makedir)/objs +# very sophisticated dependency +sources+=\ + $(call List,Sourcefile)\ + $(call List,blua/Sourcefile)\ + depends:=$(basename $(filter %.c %.s,$(sources))) objects:=$(basename $(filter %.c %.s %.nas,$(sources))) diff --git a/src/Makefile.d/platform.mk b/src/Makefile.d/platform.mk index 531d073e9..fad4be191 100644 --- a/src/Makefile.d/platform.mk +++ b/src/Makefile.d/platform.mk @@ -7,9 +7,11 @@ PKG_CONFIG?=pkg-config ifdef WINDOWSHELL rmrf=-2>NUL DEL /S /Q mkdir=-2>NUL MD +cat=TYPE else rmrf=rm -rf mkdir=mkdir -p +cat=cat endif ifdef LINUX64 diff --git a/src/Makefile.d/util.mk b/src/Makefile.d/util.mk index e76e32422..bda68df13 100644 --- a/src/Makefile.d/util.mk +++ b/src/Makefile.d/util.mk @@ -10,7 +10,8 @@ Wildvar=$(foreach v,$(filter $(1),$(.VARIABLES)),$($(v))) # Read a list of words from file and prepend each with the # directory of the file. -List=$(addprefix $(dir $(1)),$(file < $(1))) +_cat=$(shell $(cat) $(call Windows_path,$(1))) +List=$(addprefix $(dir $(1)),$(call _cat,$(1))) # Convert path separators to backslash on Windows. Windows_path=$(if $(WINDOWSHELL),$(subst /,\,$(1)),$(1)) From d5146945a69ebf30e6fc1fbb64558e456e0b7459 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 21 Jun 2021 16:10:13 -0700 Subject: [PATCH 2/5] Makefile: don't automatically set WINDOWSHELL unless PATH matches Windows norms This is for MSYS2, which requires unix shell commands. --- src/Makefile.d/detect.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Makefile.d/detect.mk b/src/Makefile.d/detect.mk index f576bcf78..89c193a32 100644 --- a/src/Makefile.d/detect.mk +++ b/src/Makefile.d/detect.mk @@ -29,7 +29,10 @@ $(call Print,$(_m)) # go for a 32-bit sdl mingw exe by default MINGW:=1 +# cmd.exe uses native Windows semicolon delimited PATH +ifneq (,$(findstring ;,$(PATH))) WINDOWSHELL:=1 +endif else # if you on the *nix From 5f4d7e3c5b013afe03ae2a441c82ad79bae7c66c Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 22 Jun 2021 15:14:42 -0700 Subject: [PATCH 3/5] Makefile: fail if old build directories exist After a checkout from before revision, old directories such as bin/Linux64 only remain if untracked files exist within. This may be confusing to the user. They may even use an outdated executable if it is one of those untracked files. --- src/Makefile | 6 +++++- src/Makefile.d/old.mk | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/Makefile.d/old.mk diff --git a/src/Makefile b/src/Makefile index 7104a91cf..61a4c5e34 100644 --- a/src/Makefile +++ b/src/Makefile @@ -132,6 +132,10 @@ goals:=$(or $(MAKECMDGOALS),all) cleanonly:=$(filter $(clean_targets),$(goals)) destructive:=$(filter-out info,$(cleanonly)) +ifndef cleanonly +include Makefile.d/old.mk +endif + include Makefile.d/util.mk ifdef PREFIX @@ -399,7 +403,7 @@ clean : $(call _rm,$(exe) $(dbg) $(dbg).txt $(objects)) distclean : - $(call _rm,../bin ../objs ../deps comptime.h) + $(call _rm,../bin ../objs ../deps ../make comptime.h) info: ifdef WINDOWSHELL diff --git a/src/Makefile.d/old.mk b/src/Makefile.d/old.mk new file mode 100644 index 000000000..e5890eedd --- /dev/null +++ b/src/Makefile.d/old.mk @@ -0,0 +1,16 @@ +# +# Warn about old build directories and offer to purge. +# + +_old:=$(wildcard $(addprefix ../bin/,FreeBSD Linux \ + Linux64 Mingw Mingw64 SDL dummy) ../objs ../deps) + +ifdef _old +$(foreach v,$(_old),$(info $(abspath $(v)))) +$(info ) +$(info These directories are no longer\ + required and should be removed.) +$(info You may remove them manually or\ + by using 'make distclean') +$(error ) +endif From c3ad5de912fccfdd64c510f5684883afceaa7d36 Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 22 Jun 2021 15:47:48 -0700 Subject: [PATCH 4/5] Makefile: let variables be defined on Make line If a variable is defined as in 'make CC=gcc-10', then that definition overrides anything other definition in the Makefile. --- src/Makefile | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/Makefile b/src/Makefile index 61a4c5e34..90776b812 100644 --- a/src/Makefile +++ b/src/Makefile @@ -145,7 +145,7 @@ endif OBJDUMP_OPTS?=--wide --source --line-numbers OBJCOPY:=$(call Prefix,objcopy) -OBJDUMP:=$(call Prefix,objdump) $(OBJDUMP_OPTS) +OBJDUMP:=$(call Prefix,objdump) WINDRES:=$(call Prefix,windres) ifdef YASM @@ -273,16 +273,18 @@ opts+=$(debug_opts) opts+=$(foreach v,$(passthru_opts),$(if $($(v)),-D$(v))) -CFLAGS:=$(opts) $(WFLAGS) $(CPPFLAGS) $(CFLAGS) -LDFLAGS:=$(libs) $(LDFLAGS) -ASFLAGS+=-x assembler-with-cpp +opts+=$(WFLAGS) $(CPPFLAGS) $(CFLAGS) +libs+=$(LDFLAGS) +asflags:=$(ASFLAGS) -x assembler-with-cpp + +cc=$(CC) ifdef DISTCC -CC:=distcc $(CC) +cc=distcc $(CC) endif ifdef CCACHE -CC:=ccache $(CC) +cc=ccache $(CC) endif ifndef SILENT @@ -293,11 +295,11 @@ ifndef destructive $(shell $(CC) -v) define flags = -CC ........ $(CC) +CC ........ $(cc) -CFLAGS .... $(CFLAGS) +CFLAGS .... $(opts) -LDFLAGS ... $(LDFLAGS) +LDFLAGS ... $(libs) endef $(info $(flags)) @@ -311,13 +313,12 @@ endif endif LD:=$(CC) -CC:=$(CC) $(CFLAGS) -NASM:=$(NASM) $(NASMOPTS) -f $(nasm_format) -GZIP:=$(GZIP) $(GZIP_OPTS) +cc:=$(cc) $(opts) +nasm=$(NASM) $(NASMOPTS) -f $(nasm_format) ifdef UPX -UPX:=$(UPX) $(UPX_OPTS) +upx=$(UPX) $(UPX_OPTS) endif -WINDRES:=$(WINDRES) $(WINDRESFLAGS)\ +windres=$(WINDRES) $(WINDRESFLAGS)\ $(debug_opts) --include-dir=win32 -O coff %/ : @@ -327,7 +328,7 @@ WINDRES:=$(WINDRES) $(WINDRESFLAGS)\ # prerequisites .SECONDEXPANSION : -# 'UPX' is also recognized in the enviornment by upx +# 'UPX' is also recognized in the environment by upx unexport UPX # executable stripped of debugging symbols @@ -336,19 +337,19 @@ $(exe) : $(dbg) | $$(@D)/ $(.)-$(OBJCOPY) --add-gnu-debuglink=$< $@ ifdef UPX $(call Echo,Compressing final executable...) - $(.)-$(UPX) $@ + $(.)-$(upx) $@ endif # original executable with debugging symbols $(dbg) : $(objects) | $$(@D)/ $(call Echo,Linking $(@F)...) - $(.)$(LD) -o $@ $^ $(LDFLAGS) + $(.)$(LD) -o $@ $^ $(libs) # disassembly of executable $(dbg).txt : $(dbg) $(call Echo,Dumping debugging info...) - $(.)$(OBJDUMP) $< > $@ - $(.)$(GZIP) $@ + $(.)$(OBJDUMP) $(OBJDUMP_OPTS) $< > $@ + $(.)$(GZIP) $(GZIP_OPTS) $@ # '::' means run unconditionally # this really updates comptime.h @@ -373,11 +374,11 @@ ifdef Echo_name @printf '%-20.20s\r' $$< endif endif - $(.)$(CC) -MM -MF $$@ -MT $(objdir)/$$(*F).o $(2) $$< + $(.)$(cc) -MM -MF $$@ -MT $(objdir)/$$(*F).o $(2) $$< endef $(eval $(call _recipe,c)) -$(eval $(call _recipe,s,$(ASFLAGS))) +$(eval $(call _recipe,s,$(asflags))) # compiling recipe template # 1: target file suffix @@ -389,10 +390,10 @@ $(objdir)/%.$(1) : %.$(2) | $$$$(@D)/ $(.)$(3) endef -$(eval $(call _recipe,o,c,$(CC) -c -o $$@ $$<)) -$(eval $(call _recipe,o,nas,$(NASM) -o $$@ $$<)) -$(eval $(call _recipe,o,s,$(CC) $(ASFLAGS) -c -o $$@ $$<)) -$(eval $(call _recipe,res,rc,$(WINDRES) -i $$< -o $$@)) +$(eval $(call _recipe,o,c,$(cc) -c -o $$@ $$<)) +$(eval $(call _recipe,o,nas,$(nasm) -o $$@ $$<)) +$(eval $(call _recipe,o,s,$(cc) $(asflags) -c -o $$@ $$<)) +$(eval $(call _recipe,res,rc,$(windres) -i $$< -o $$@)) _rm=$(.)$(rmrf) $(call Windows_path,$(1)) From ed85e994a46ace07cf022b38a9abac1698a8667e Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 22 Jun 2021 15:49:59 -0700 Subject: [PATCH 5/5] Remove misplaced parentheses --- src/Makefile.d/detect.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.d/detect.mk b/src/Makefile.d/detect.mk index 89c193a32..3edf0dad4 100644 --- a/src/Makefile.d/detect.mk +++ b/src/Makefile.d/detect.mk @@ -94,7 +94,7 @@ ifeq (,$(filter $(v),$(gcc_versions))) define line = Your compiler version, GCC $(version), \ is not supported by the Makefile. -The Makefile will assume GCC $(latest_gcc_version).)) +The Makefile will assume GCC $(latest_gcc_version). endef $(call Print,$(line)) GCC$(subst .,,$(latest_gcc_version)):=1