Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
509 views
in Technique[技术] by (71.8m points)

gnu make - Show the output of a $(shell xx ) command also on stdout

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?

question from:https://stackoverflow.com/questions/65881794/show-the-output-of-a-shell-xx-command-also-on-stdout

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 included 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...