问题
I have a gnu Makefile that collects version information through environment variables. Now, I want to do "something" globally before any target is built using the gnumake syntax. As pseudo code, this means:
- when a specified file exists, delete it
- run through an array of strings and put their value into a specified file
I tried this:
$(shell if exist $(subst /,\,$(products)filenames.h) del /F/Q $(subst /,\,$(products)filenames.h))
$(foreach Item, $(EnvFilenames), @echo $(Item) >> $(subst /,\,$(products)filenames.h))
this gives me an error:
C:\temp\Makefile.mak:72: *** missing separator. Stop.
where Line 72 is the $(shell ... line. If I put this in a define section:
define foobar
$(shell if exist $(subst /,\,$(products)filenames.h) del /F/Q $(subst /,\,$(products)filenames.h))
$(foreach Item, $(EnvFilenames), @echo $(Item) >> $(subst /,\,$(products)filenames.h))
endef
and call this for a target, it runs fine:
$(products)$test.o : test.c $(commons)
$(call foobar)
$(cc) $(cflags_m) test.c -o$@
and does what it should... but as soon as I want to call it from inside of another define, it fails again with a missing seperator.
What does it mean and how can I fix it?
Compilation takes place on a Win32 platform and does not have to be multi-platform.
回答1:
If once per Make invocation is sufficient, you could put it in a global assignment.
# Ignore the value, calling for side effects
IGNORE := $(shell commands with side effects)
I would recommend against this hack, but I can imagine situations where it might come in handy.
来源:https://stackoverflow.com/questions/9064577/how-to-run-some-commands-globally-in-a-gnu-make-file