gnu-make

GNU Make silent by default

核能气质少年 提交于 2019-11-29 06:02:01
问题 Is it possible to suppress command echoing by default from within the Makefile ? I know that running make in --silent mode will do it, as will prefixing every command with @ . I'm looking for a command or stanza I can include inside the Makefile, saving the trouble of littering everything with @ or having the user silence everything manually. 回答1: If you define the target .SILENT: , then make will not echo anything. It's usually best to guard the definition, so you can easily turn it off:

making all rules depend on the Makefile itself

耗尽温柔 提交于 2019-11-29 05:38:33
When I change a Makefile, its rules may have changed, so they should be reevaluated, but make doesn't seem to think so. Is there any way to say, in a Makefile, that all of its targets, no matter which, depend on the Makefile itself? (Regardless of its name.) I'm using GNU make. This looks like one more simple, useful, logical thing that Make should be able to do, but isn't. Here is a workaround. If the clean rule is set up correctly, Make can execute it whenever the makefile has been altered, using an empty dummy file as a marker. -include dummy dummy: Makefile @touch $@ @$(MAKE) -s clean This

GNU make: Extracting argument to -j within Makefile

馋奶兔 提交于 2019-11-29 05:35:32
问题 I've been searching for an hour, and this information appears to be nowhere... I'd like to be able to extract (and possibly use) the number of requested make "jobs," as passed via the -j option, or by Make itself in the case of sub-makes, in the Makefile. The most promising thing I've seen so far is the $(MAKEFLAGS) variable, but on my system (if I do, say, make -j2) the contents of this variable are only "--jobserver-fds=3,4 -j". Is there any way to get the actual number of jobs passed with

Remove prefix with make

血红的双手。 提交于 2019-11-29 04:55:43
问题 Is there a way to remove a prefix from a string (a pathname in my case) in make ? As an example, suppose I had the string: FILES = a/b/c.d a/b/e.f I want to remove the a/ , and be left with b/c.d b/e.f I have tried using various combinations of dir , notdir and basename from the GNU make manual, but none seem to provide a nice solution. $(dir $(FILE)) # a/b a/b $(notdir $(FILE)) # c.d e.f $(basename $(FILE)) # a/b/c a/b/e The only way I've found to do this so far is: $( join $(basename $(dir

How to get the invoking target of makefile?

和自甴很熟 提交于 2019-11-29 02:06:51
问题 How to get the invoking target of the GNU make Makefile? for example, I invoke make with the following command line: make a-target How can I get the invoking target "a-target" in the Makefile and assign it to a variable? Further more, if more than one target is specified on the command line: make target1 target2 ... How do I get all of them? 回答1: The variable MAKECMDGOALS contains the list of targets that were specified on the command line, no matter how many (it's empty if there were none).

Order of processing components in makefile

南笙酒味 提交于 2019-11-29 01:00:55
In a makefile, the dependency line is of the form - abc: x y z All three of the components (x,y,z) are themselves targets in dependency lines further down in the makefile. If make abc is invoked, in what order will the three targets x,y,z be executed? Eldar Abusalimov By default, the order of execution is the same as specified in the prerequisites list, unless there are any dependencies defined between these prerequisites. abc: x y z The order is x y z . abc: x y z y : z The order would be x z y . But ideally, you should design your Makefiles so that it wouldn't rely on the order in which

How to trace Makefile targets for troubleshooting?

故事扮演 提交于 2019-11-28 21:21:16
We have a long and complicated Makefile in our build system. Is there a good way to trace exactly which targets get executed for a given make invocation? Use make -d or make --debug[=flags] options : ‘-d’ Print debugging information in addition to normal processing. The debugging information says which files are being considered for remaking, which file-times are being compared and with what results, which files actually need to be remade, which implicit rules are considered and which are applied—everything interesting about how make decides what to do. The -d option is equivalent to ‘--debug

Makefile profiling

徘徊边缘 提交于 2019-11-28 21:18:07
问题 So I have this Makefile based build system that my users feel is working too slowly. For the sake of this question lets define performance as the time it takes make to figure out what it should actually do. I can see some avenues for optimization -- Reducing the number of times Makefile is parsed and the DAG recalculated due to including a Makefile fragment. Reducing the number of going to an external Makefile with make -C Reducing variable expansions etc. -- however I want to know first

Makefile improvements, dependency generation not functioning

僤鯓⒐⒋嵵緔 提交于 2019-11-28 20:58:22
I'm currently trying to build a proper Makefile. What I want is full control of what's happening, so I don't want any third party software. My current attempt seems logic to me, but since the dependency generation is not valid, I'm kind of stuck. For better readabilty, the full Makefile is broken into little pieces. I would appreciate any comment on any section if there's something to improve. First of all, I have the following static definitions CXX = g++ CXXFLAGS = -Wall \ -Wextra \ -Wuninitialized \ -Wmissing-declarations \ -pedantic \ -O3 \ -p -g -pg LDFLAGS = -p -g -pg DEPFLAGS = -MM

Measure (profile) time spent in each target of a Makefile

牧云@^-^@ 提交于 2019-11-28 20:36:59
Is there a way to echo the (system, user, real) time spent in each target of a Makefile recursively when I do make all ? I'd like to benchmark the compilation of a project in a more granular way than just time make all . Ideally, it would echo a tree of the executed target, each one with the time spent in all its dependencies. It'd be great also if it could work with -j (parallel make). And by the way my Makefile is non-recursive (doesn't spawn another make instance for each main targets). Thanks! Gnu Make uses the $(SHELL) variable to execute commands in the targets. By default it is set to