Makefile - pass param job to sub makefiles

I have a makefile that calls several other makefiles.

I would like to pass the -j option along with other calls to the makefile.

Something like (make -j8):

all: make -f libpng_linux.mk -j$(J) 

Where $ (J) is the value 8 of -j8. I absolutely swear that I did this before, but I can not find my example.

$ (MAKEFLAGS) seems to contain -jobserver-fds = 3,4 -j no matter what -j2 or -j8

Edit: Possible solution:

Copy this as an answer soon.

It seems one solution is not to worry about it. Turn on -j8 when you invoke the main makefile. Sub-calls should look like this:

  all: +make -f libpng_linux.mk -j$(J) 

Note the "+" before make. I noticed that I was throwing a warning when trying to build in parallel: make [1]: warning: jobserver not available: using -j1. Add `+ 'to the parent make rule.

+6
source share
2 answers

Only certain flags are included in $(MAKEFLAGS) . -j not enabled because sub-brands communicate with each other to ensure that the appropriate number of tasks is completed

In addition, you should use $(MAKE) instead of make , since $(MAKE) will always have the correct executable name (which may not be make ).

+6
source

โ€œDon't do thisโ€ is not always the answer, but in this case, at least for GNU make .

The GNU make parent process has an internal job server . If the top-level Makefile starts with -j , the make subprocess will communicate with the job server and read the level of parallelism from it, without explicit -j .

Continuous coordination with the parent job server is much better for using the kernel. For example, during the same build with -j6 parent can do 2 tasks, and the child can do 4 more, at the next moment both can start 3 tasks each, then the parent will do 1, and the child will do 5.

+1
source

Source: https://habr.com/ru/post/1394835/


All Articles