X-Git-Url: https://www.kengrimes.com/gitweb/?p=henge%2Fwebcc.git;a=blobdiff_plain;f=src%2FMakefile;h=b4c8225f63ee3947010f64490400292d4c1b21a1;hp=1f9950fd0fdb6fbbaa2f58adc034e2ea6a98bf31;hb=522656e8b68f7189d1c221e19211946ba7774ab5;hpb=b1da5106b8db9e5ff0113106d32779cdef43408f diff --git a/src/Makefile b/src/Makefile index 1f9950f..b4c8225 100644 --- a/src/Makefile +++ b/src/Makefile @@ -109,14 +109,20 @@ endef define PREMAKE_SOURCE_COMPILER = # Find the sources for each source-to-source language $(foreach slang,$(SLANGS), -$(eval SLANG_SRC := $(patsubst ./%, %,$(shell find -name "*.$(slang)"))) +$(eval SLANG_SRC := $(patsubst ./%, %,$(shell find -name "*.$(slang)" -not -name ".*"))) # Foreach target type in the source-to-source language, add this source's # targets to the list of the current source-to-source language targets $(eval undefine SLANG_TRG) -$(eval $(foreach trg,$($(slang)_TRG), -$(eval SLANG_TRG += $(SLANG_SRC:%.$(slang)=%.$(if $($(slang)_STEM),$($(slang)_STEM).)$(trg))))) +$(foreach trg,$($(slang)_TRG), +$(eval SLANG_TRG += $(SLANG_SRC:%.$(slang)=%.$(if $($(slang)_STEM),$($(slang)_STEM).)$(trg)))) # Stat the source file's last-modified time to the var SRC_TIME $(foreach src,$(SLANG_SRC), +# Establish a command to run for compiling this file +$(eval SHELL_CMD := cd $(dir $(src)) && $($(slang)_C) $($(slang)_FLAGS) $(notdir $(src))) +# Evaluate missing targets +$(eval FOUND_TRG := $(shell find $(dir $(src)) -name "$(basename $(notdir $(src))).*" -not -name ".*")) +$(eval MISSING_TRG := $(filter-out $(FOUND_TRG), $(SLANG_TRG))) +# Check timings of existing files $(eval SRC_TIME := $(shell stat -c %Y $(src))) # For each of the targets created by this source language, evaluate the # last-modified times of each potential target. If the file does not exist, set @@ -132,17 +138,23 @@ $(eval NEWEST_TRG_TIME := $(word 1,$(subst ==, ,$(TRG_TIMES)))) # Find the older of the two times (between SRC_TIME and NEWEST_TRG_TIME) $(eval OLDER_TIME := $(firstword $(sort $(NEWEST_TRG_TIME) $(SRC_TIME)))) # If the older of the two times is the newest target time found, then we need to -# rebuild, but only if our build rule intends to actually make something +# rebuild, but only if our build rule intends to actually make something. If it +# does not intend to make something, drop a functional rule to actually make the +# target $(if $(MAKECMDGOALS), $(eval BUILDGOALS := $(filter-out clean scrub purge uninstall,$(MAKECMDGOALS))), $(eval BUILDGOALS := all)) -$(if $(and $(BUILDGOALS),$(filter $(OLDER_TIME),$(NEWEST_TRG_TIME))), -$(eval SHELL_CMD := cd $(dir $(src)) && $($(slang)_C) $($(slang)_FLAGS) $(notdir $(src))) -$(info $(SHELL_CMD) $(shell $(SHELL_CMD))) -))) +$(if $(and $(BUILDGOALS),$(or $(MISSING_TRG), $(filter $(OLDER_TIME),$(NEWEST_TRG_TIME)))), +$(if $(findstring n,$(MAKEFLAGS)), +$(SLANG_TRG): + $(SHELL_CMD) +, +$(info $(SHELL_CMD) $(eval $(shell $(SHELL_CMD))))) +)) # Put these targets on the MAKE_TARGETS list to be removed during "clean", # regardless of whether or not they were built just now. $(eval MAKE_TARGETS += $(SLANG_TRG)) +) #/PREMAKE_SOURCE_COMPILER######################################################## endef # Compile a source language to a language that compiles to binary, but only if @@ -183,7 +195,10 @@ $(eval MDEPS := $(shell echo $(MDEPS) | sed -e 's@[a-zA-Z0-9\-\+/]*\.\./include@ $(eval ALLDEPS := $(MDEPS) $(DEPS)),\ $(error Cannot generate deps for: $1, file not found))\ $(eval SRC_OBJ := $(basename $1).$($2_OBJ))\ -$(eval MAKE_TARGETS+= $(SRC_OBJ)) +$(eval MAKE_TARGETS += $(SRC_OBJ)) +# Assume that lost dependencies are in the folder with the source +$(foreach lost,$(LOST), +$(eval ALLDEPS := $(subst $(lost), $(dir $1)$(lost),$(ALLDEPS)))) # Find any deps that aren't built yet, which the compiler has flagged # as missing, but which we know the expected location of libs for @@ -197,6 +212,7 @@ $(if $($2_DBG),\ $(eval DBG_OBJ := $(dir $1).$($2_DBG)/$(basename $(notdir $1)).$($2_OBJ))\ $(if $(findstring $(dir $(DBG_OBJ)),$(MAKE_DIRS)),,\ $(eval MAKE_DIRS += $(dir $(DBG_OBJ)))) +$(eval MAKE_TARGETS += $(DBG_OBJ)) # Object for $1 with $($2_DBG) symbols $(DBG_OBJ): $(ALLDEPS) | $(dir $(DBG_OBJ)) $($2_C) $$($2_FLAGS) $(FLG) -Og -g$($2_DBG) -c -o $$@ $1 @@ -226,7 +242,9 @@ $(eval DRIVER_MODULES := $(filter-out $(DRIVER_DIR) ..,$(sort $(DRIVER_MODULES)) # any internal modules, the developer may instead create a file with the same # basename as the driver, but with the '.ld' suffix, which contains a space # separated list of internal modules to link together during compilation -$(eval DRIVER_MODULES += $(file <$(1:%.$2=%.ld))) +$(eval DRIVER_LDVALS := $(file <$(1:%.$2=%.ld))) +$(eval DRIVER_LFLAGS := $(filter -l%,$(DRIVER_LDVALS))) +$(eval DRIVER_MODULES += $(filter-out -l%,$(DRIVER_LDVALS))) # List of module archives to link together during compilation $(eval DRIVER_ARCHIVES := $(DRIVER_MODULES:%=%.$($2_AROBJ))) @@ -255,8 +273,8 @@ $(if $($2_DBG),$(eval MAKE_DIRS += $(DRIVER_TARG_DIR).$($2_DBG))) # '_start'). This driver object is then simply linked to its libraries and # module archives to create an executable binary in the output folder. # ORDER MATTERS HERE, this is for the linker: -$(eval DRIVER_SRC := $(DRIVER_DEPS)) -$(eval DRIVER_DBGSRC := $(DRIVER_DBGDEPS)) +$(eval DRIVER_SRC := $(DRIVER_LFLAGS) $(DRIVER_DEPS)) +$(eval DRIVER_DBGSRC := $(DRIVER_LFLAGS) $(DRIVER_DBGDEPS)) # Iterate through the list of libraries in our language and stack commands from # left to right in the "sources" section of the LD command (or LD section of the # commandline for the compiler), to preserve ordering and also ensure that it is