Discussion:
MAKEFLAGS var does not show "-j" param ???
Fabrice GIRARDOT
2008-03-11 14:26:28 UTC
Permalink
Hi all.

It seems that the MAKEFLAGS variable does not always
show the "-j" option given to make on its command line.

I'm using GNU make 3.81 built for Win32.
For information, the result is the same with GNU make 3.81
for i486-pc-linux-gnu.


Here is a tiny Makefile example that shows the problem :

-------------Makefile-------------------

$(info MAKEFLAGS=$(MAKEFLAGS))

.PHONY: all

all:
@echo $(info MAKEFLAGS_in_cmd=$(MAKEFLAGS)) \
This is command for $@

------------/Makefile-------------------


Some tests with this simple Makefile :


-----------------------------
C:\some_dir> make
MAKEFLAGS=
MAKEFLAGS_in_cmd=
This is command for all
-----------------------------
C:\some_dir> make -w
MAKEFLAGS=w
MAKEFLAGS_in_cmd=w
make: Entering directory `<dir>'
This is command for all
make: Leaving directory `<dir>'
-----------------------------
C:\some_dir> make -j8
MAKEFLAGS=
MAKEFLAGS_in_cmd=j 1
This is command for all
-----------------------------
C:\some_dir> make -w -j8
MAKEFLAGS=w
MAKEFLAGS_in_cmd=wj 1
gnumake: Entering directory `<dir>'
This is command for all
gnumake: Leaving directory `<dir>'
-----------------------------
And also a test on Ubuntu 7.10 :
$ make -j8
MAKEFLAGS=
MAKEFLAGS_in_cmd= --jobserver-fds=3,4 -j
This is command for all
-----------------------------


I've gone through all make's online documentation,
but I can't find why I get this result !

Any idea ?
Should I submit a bug ?


Regards.
--
Fabrice GIRARDOT
Paul Smith
2008-03-11 14:35:25 UTC
Permalink
Post by Fabrice GIRARDOT
It seems that the MAKEFLAGS variable does not always
show the "-j" option given to make on its command line.
I'm using GNU make 3.81 built for Win32.
As far as I recall, parallel make is not supported on MS Windows
systems. You should ask on the make-***@gnu.org mailing list for more
explicit details: those folks know much more about the MS Windows port
of GNU make.
Post by Fabrice GIRARDOT
C:\some_dir> make -j8
MAKEFLAGS=
MAKEFLAGS_in_cmd=j 1
This is command for all
This is because the MS Windows port doesn't support parallel jobs. So,
it explicitly sets the -j flag argument to 1.
Post by Fabrice GIRARDOT
$ make -j8
MAKEFLAGS=
MAKEFLAGS_in_cmd= --jobserver-fds=3,4 -j
This is command for all
This is the expected result on a system that does support parallel jobs
via the jobserver. The special --jobserver-fds option is an
internal-only option that parent makes pass to child makes so they can
participate in the jobserver. For details on the jobserver see my site
below.

For a bit more info see this other recent thread:

http://lists.gnu.org/archive/html/help-make/2008-01/msg00087.html
--
-----------------------------------------------------------------------------
Paul D. Smith <***@gnu.org> http://make.mad-scientist.us
"Please remain calm--I may be mad, but I am a professional."--Mad Scientist
Eli Zaretskii
2008-03-11 19:40:17 UTC
Permalink
Date: Tue, 11 Mar 2008 10:35:25 -0400
Post by Fabrice GIRARDOT
It seems that the MAKEFLAGS variable does not always
show the "-j" option given to make on its command line.
I'm using GNU make 3.81 built for Win32.
As far as I recall, parallel make is not supported on MS Windows
systems.
Not entirely true: the MS-Windows port does support parallel
execution, but it does not support the "job server" method.
Therefore, Make invokes sub-Make's with the "-j 1" switch.

To work around, invoke the sub-Make's with an explicit "-j N" switch
(you will need to figure out the argument N yourself).

Alternatively, volunteer to make the job server work on Windows ;-)
David Wuertele
2008-03-12 19:27:26 UTC
Permalink
Post by Paul Smith
This is the expected result on a system that does support parallel jobs
via the jobserver. The special --jobserver-fds option is an
internal-only option that parent makes pass to child makes so they can
participate in the jobserver. For details on the jobserver see my site
below.
http://lists.gnu.org/archive/html/help-make/2008-01/msg00087.html
I was the OP for that recent thread. I went and read your article about
jobserver, it was very instructive. Thank you for that.

I still have a problem. My makefile builds cross-compiling toolchains. Lots of
them. But when my "make -j LARGENUMBER" does a submake in glibc ("$(MAKE) -C
/path/to/glibc-build"), the glibc build fails to parallelize, even though there
are definitely jobs available.

The glibc makefiles have a variable called PARALLELMFLAGS. When I call $(MAKE)
-C /path/to/glibc-build PARALLELMFLAGS="-j X", glibc parallelizes as I wish.

I want my makefile to behave as follows:
1. if I type "make" with no "-j", I want all builds to be sequential, including
the glibc submake

2. if I type "make -j N", I want the total number of parallel jobs to be at
least N, but I can tolerate it being larger than N.

My idea is to do something like this in my recursive call to glibc build:

build-glibc:
$(MAKE) -C /path/to/glibc/build $($(if $(filter -j,$(info
MAKEFLAGS_in_cmd=$(MAKEFLAGS))),PARALLELMFLAGS="-j 4")

That will get me most of the way there. It hardcodes the glibc parallelism to
either one or four, according to whether the top-level make was parallel or not.

Any better suggestions?

Dave
Fabrice GIRARDOT
2008-03-14 09:24:21 UTC
Permalink
Post by David Wuertele
1. if I type "make" with no "-j", I want all builds to be sequential, including
the glibc submake
2. if I type "make -j N", I want the total number of parallel jobs to be at
least N, but I can tolerate it being larger than N.
I had exactly the same wish, and here is how I did it.

I have a "top-level" Makefile, which is able to build "modules"
(= library or executable). It can scan for dependencies, and
recursively calls itself to build dependencies, and dependencies's
dependencies.
This top-level Makefile doesn't support yet parallel building itself,
but each module does.
I wanted to be able to run the top level Makefile with "-j N"
(despite the fact that it does not support parallel build !),
and if this option is present, then all modules would be built
with "-j N".


In the top-level Makefile, I have an empty ".NOTPARALLEL:" target,
so that it disables parrallel build for top-level.

Each time it has to call a sub-make, it calls :
$(MAKE) $(if $(findstring j,$(MAKEFLAGS)),-j8,) -C /path/to/Makefile

a) if /path/to/Makefile is the top-level Makefile, then it ensures that
parallel build information is kept between all recursive calls
of the top-level Makefile
b) if /path/to/Makefile is a module, then it is build with parallel
option.

Note that the "N" value of the initial invokation of Make is lost
because as far as I know, a Makefile can't read it (unless you use
some trick like "make JOBS=8 -j8", which I don't want).


The tricky part was here : when you dump $(MAKEFLAGS) somewhere *NOT*
in a command, then it *NEVER* shows the "-j" otpion.
If you dump it *IN A COMMAND* for some target, then it shows the
"-j" option (forced to "-j 1" on win32").


Regards,
--
Fabrice GIRARDOT
Loading...