# 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
# 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 $(or $(MISSING_TRG), $(and $(BUILDGOALS),$(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
$(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
$(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