Reputation: 163
I have an external program creating the a bunch of files. These files are prerequisites to my targets. At the moment I call it as follows:
# build the external resouce and create a the file filelist.txt
VHDL_SOURCES += $(shell make -C $(SCRIPT_PATH) > $(SCRIPT_PATH)/log; cat $(BUILD_PATH)/filelist.txt)
This works fine. My variable VHDL_SOURCES contains all source files mentioned in filelist.txt. The drawback of this approach is that I can not see the output of the called script. As it takes a long time to run, it would be great to see on the stdout whats going on.
Is there a way to show what is moved (and therefore hidden) to $(SCRIPT_PATH)/log at the moment?
Upvotes: 0
Views: 140
Reputation: 13475
Everything from $(shell ...)
stdout goes into its result. You cannot let it go to stdout, and then take some other stdout as a function result.
You can redirect the script's output to stderr. This may or may not be suitable, depending on how you use your makefile.
Let me suggest a more dramatic change.
Calling recursive make
from $(shell)
is a sign of an overcomplicated process. Let's at least make it idiomatic: let's generate an include
d makefile with a proper value. This will rebuild it if it's not present.
include $(BUILD_PATH)/filelist.mk
$(BUILD_PATH)/filelist.mk:
# A normal recursive call. Its output goes to stdout.
make -C $(SCRIPT_PATH)
# Assuming that filelist.txt can only include a list of
# existing files, and no malicious injected code.
echo "define VHDL_SOURCES" > $@
cat $(BUILD_PATH)/filelist.txt >> $@
echo "endef" >> $@
Bonus: if you can set a proper dependencies for filelist.mk
, it will only be rebuilt when these dependencies change.
If you want it to always rebuild (which is probably not necessary), make it phony:
.PHONY: $(BUILD_PATH)/filelist.mk
After the file is generated, make
will restart its run with the new included file.
Upvotes: 1