Skip to content
Snippets Groups Projects
Commit c3ad5de9 authored by James R.'s avatar James R.
Browse files

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.
parent 5f4d7e3c
No related branches found
No related tags found
1 merge request!1553Some issues with the Makefile
...@@ -145,7 +145,7 @@ endif ...@@ -145,7 +145,7 @@ endif
OBJDUMP_OPTS?=--wide --source --line-numbers OBJDUMP_OPTS?=--wide --source --line-numbers
OBJCOPY:=$(call Prefix,objcopy) OBJCOPY:=$(call Prefix,objcopy)
OBJDUMP:=$(call Prefix,objdump) $(OBJDUMP_OPTS) OBJDUMP:=$(call Prefix,objdump)
WINDRES:=$(call Prefix,windres) WINDRES:=$(call Prefix,windres)
ifdef YASM ifdef YASM
...@@ -273,16 +273,18 @@ opts+=$(debug_opts) ...@@ -273,16 +273,18 @@ opts+=$(debug_opts)
opts+=$(foreach v,$(passthru_opts),$(if $($(v)),-D$(v))) opts+=$(foreach v,$(passthru_opts),$(if $($(v)),-D$(v)))
CFLAGS:=$(opts) $(WFLAGS) $(CPPFLAGS) $(CFLAGS) opts+=$(WFLAGS) $(CPPFLAGS) $(CFLAGS)
LDFLAGS:=$(libs) $(LDFLAGS) libs+=$(LDFLAGS)
ASFLAGS+=-x assembler-with-cpp asflags:=$(ASFLAGS) -x assembler-with-cpp
cc=$(CC)
ifdef DISTCC ifdef DISTCC
CC:=distcc $(CC) cc=distcc $(CC)
endif endif
ifdef CCACHE ifdef CCACHE
CC:=ccache $(CC) cc=ccache $(CC)
endif endif
ifndef SILENT ifndef SILENT
...@@ -293,11 +295,11 @@ ifndef destructive ...@@ -293,11 +295,11 @@ ifndef destructive
$(shell $(CC) -v) $(shell $(CC) -v)
define flags = define flags =
CC ........ $(CC) CC ........ $(cc)
CFLAGS .... $(CFLAGS) CFLAGS .... $(opts)
LDFLAGS ... $(LDFLAGS) LDFLAGS ... $(libs)
endef endef
$(info $(flags)) $(info $(flags))
...@@ -311,13 +313,12 @@ endif ...@@ -311,13 +313,12 @@ endif
endif endif
LD:=$(CC) LD:=$(CC)
CC:=$(CC) $(CFLAGS) cc:=$(cc) $(opts)
NASM:=$(NASM) $(NASMOPTS) -f $(nasm_format) nasm=$(NASM) $(NASMOPTS) -f $(nasm_format)
GZIP:=$(GZIP) $(GZIP_OPTS)
ifdef UPX ifdef UPX
UPX:=$(UPX) $(UPX_OPTS) upx=$(UPX) $(UPX_OPTS)
endif endif
WINDRES:=$(WINDRES) $(WINDRESFLAGS)\ windres=$(WINDRES) $(WINDRESFLAGS)\
$(debug_opts) --include-dir=win32 -O coff $(debug_opts) --include-dir=win32 -O coff
%/ : %/ :
...@@ -327,7 +328,7 @@ WINDRES:=$(WINDRES) $(WINDRESFLAGS)\ ...@@ -327,7 +328,7 @@ WINDRES:=$(WINDRES) $(WINDRESFLAGS)\
# prerequisites # prerequisites
.SECONDEXPANSION : .SECONDEXPANSION :
# 'UPX' is also recognized in the enviornment by upx # 'UPX' is also recognized in the environment by upx
unexport UPX unexport UPX
# executable stripped of debugging symbols # executable stripped of debugging symbols
...@@ -336,19 +337,19 @@ $(exe) : $(dbg) | $$(@D)/ ...@@ -336,19 +337,19 @@ $(exe) : $(dbg) | $$(@D)/
$(.)-$(OBJCOPY) --add-gnu-debuglink=$< $@ $(.)-$(OBJCOPY) --add-gnu-debuglink=$< $@
ifdef UPX ifdef UPX
$(call Echo,Compressing final executable...) $(call Echo,Compressing final executable...)
$(.)-$(UPX) $@ $(.)-$(upx) $@
endif endif
# original executable with debugging symbols # original executable with debugging symbols
$(dbg) : $(objects) | $$(@D)/ $(dbg) : $(objects) | $$(@D)/
$(call Echo,Linking $(@F)...) $(call Echo,Linking $(@F)...)
$(.)$(LD) -o $@ $^ $(LDFLAGS) $(.)$(LD) -o $@ $^ $(libs)
# disassembly of executable # disassembly of executable
$(dbg).txt : $(dbg) $(dbg).txt : $(dbg)
$(call Echo,Dumping debugging info...) $(call Echo,Dumping debugging info...)
$(.)$(OBJDUMP) $< > $@ $(.)$(OBJDUMP) $(OBJDUMP_OPTS) $< > $@
$(.)$(GZIP) $@ $(.)$(GZIP) $(GZIP_OPTS) $@
# '::' means run unconditionally # '::' means run unconditionally
# this really updates comptime.h # this really updates comptime.h
...@@ -373,11 +374,11 @@ ifdef Echo_name ...@@ -373,11 +374,11 @@ ifdef Echo_name
@printf '%-20.20s\r' $$< @printf '%-20.20s\r' $$<
endif endif
endif endif
$(.)$(CC) -MM -MF $$@ -MT $(objdir)/$$(*F).o $(2) $$< $(.)$(cc) -MM -MF $$@ -MT $(objdir)/$$(*F).o $(2) $$<
endef endef
$(eval $(call _recipe,c)) $(eval $(call _recipe,c))
$(eval $(call _recipe,s,$(ASFLAGS))) $(eval $(call _recipe,s,$(asflags)))
# compiling recipe template # compiling recipe template
# 1: target file suffix # 1: target file suffix
...@@ -389,10 +390,10 @@ $(objdir)/%.$(1) : %.$(2) | $$$$(@D)/ ...@@ -389,10 +390,10 @@ $(objdir)/%.$(1) : %.$(2) | $$$$(@D)/
$(.)$(3) $(.)$(3)
endef endef
$(eval $(call _recipe,o,c,$(CC) -c -o $$@ $$<)) $(eval $(call _recipe,o,c,$(cc) -c -o $$@ $$<))
$(eval $(call _recipe,o,nas,$(NASM) -o $$@ $$<)) $(eval $(call _recipe,o,nas,$(nasm) -o $$@ $$<))
$(eval $(call _recipe,o,s,$(CC) $(ASFLAGS) -c -o $$@ $$<)) $(eval $(call _recipe,o,s,$(cc) $(asflags) -c -o $$@ $$<))
$(eval $(call _recipe,res,rc,$(WINDRES) -i $$< -o $$@)) $(eval $(call _recipe,res,rc,$(windres) -i $$< -o $$@))
_rm=$(.)$(rmrf) $(call Windows_path,$(1)) _rm=$(.)$(rmrf) $(call Windows_path,$(1))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment