I have Makefiles for several custom domain specific languages. One of them require weird paths for the input/output files passed to the compiler, So I had to use some gnumake tricks. Now they are not playing nice with variable overloading, even using the always-re-parse-variable (=
).
# Makefile.main
SOURCE_FILES=forgot_to_set_source_files.ksp
# Paths
SRCDIR=src
OBJDIR=Resources/scripts
.SUFFIXES: # Delete the default suffixes
.SUFFIXES: .txt .ksp # Define our suffix list
VPATH =
VPATH = $(SRCDIR)
OBJECT_FILES = $(addprefix $(OBJDIR)/, $(SOURCE_FILES:.ksp=.txt))
# src/abc.ksp -> Resources/script/abc.txt
$(OBJECT_FILES): $(OBJDIR)/%.txt: %.ksp
$(info Compiling $<)
@mkdir -p $(@D)
"$(CC)" $(CC_FLAGS) $< $@
build: $(VMPID) $(OBJECT_FILES)
$(info $(OBJECT_FILES))
$(info $(SOURCE_FILES))
Now each project have:
# projA/Makefile
include ../Makefile.main
SOURCE_FILES=
one.ksp
two.ksp
Now when i try to make:
$ make
make: *** No rule to make target 'forgot_to_set_source_files.ksp', needed by 'Resources/scripts/forgot_to_set_source_files.txt'. Stop.
tried to remove the default value
$ git diff ../Makefile.main
- SOURCE_FILES=forgot_to_set_source_files.ksp
+ #SOURCE_FILES
$ make
Resources/scripts/one.txt Resources/scripts/two.txt
one.ksp two.ksp
make: Nothing to be done for 'default'.
From the output of the two $(info ...)
we confirm make “sees” an empty variable for the rules targets, but see the correct value inside the rule.
I then tried to reset all values that are used to construct the rule target into the project Makefile, and added some exports for good measure.
# projA/Makefile
include ../Makefile.main
export SOURCE_FILES=
one.ksp
two.ksp
export OBJECT_FILES=$(addprefix $(OBJDIR)/, $(SOURCE_FILES:.ksp=.txt))
export
No change. Still exact same failures.
I tried to re-declare the sulfix rule ($(OBJECT_FILES): $(OBJDIR)/%.txt: %.ksp
) in the project makefile. Still fails!
I tried to use ?=
on the main makefile’s assignment of SOURCE_FILES, and I still get No rule to make target 'forgot_to_set_source_files.ksp'...
What is preventing that rule from getting the updated value of SOURCE_FILES? Is there anything special about $(addprefix ...)
?