[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 4.4.1 breaks recursive invocation with --print-directory [when addin
From: |
Satish Balay |
Subject: |
Re: 4.4.1 breaks recursive invocation with --print-directory [when adding to MAKEFLAGS] |
Date: |
Sun, 5 Mar 2023 13:12:42 -0600 (CST) |
Thanks for all the suggestions.
The code is not attempting to "change -j" - but have a "default" when the
top-level is not invoked with '-j'. i.e:
-'make' should use the default set in the makefile
- make -j3' should use this value specified here [and ignore the default].
I'm reworking the code to avoid modifying MAKEFLAGS (as suggested in this
thread). And using shell here [as currently this makefile can also be processed
by non-gnu-make]. i.e something like:
if '-j' in $(MAKEFLAGS):
usej=''
else:
usej='-j$(DEFAULT_NP)'
${CONFIGURED_MAKE} -f makefile $$(usej)
thanks,
Satish
On Sun, 5 Mar 2023, Paul Smith wrote:
> On Tue, 2023-02-28 at 19:02 -0600, Satish Balay via Bug reports and
> discussion for GNU make wrote:
> > This usage works with make-4.4 [and older versions] - but not 4.4.1
> >
> > balay@p1 /home/balay/tmp
> > $ cat makefile
> > all:
> > @MAKEFLAGS="-j1 ${MAKEFLAGS}" ${MAKE} -f makefile hello
> > hello:
> > @echo Hello
>
> Sorry for the delay. I wanted to say that, in addition to not doing
> what you intended (changing the number of parallel jobs in a recursive
> make), which I discussed last week, the above is actually wrong
> (including in older versions of GNU make).
>
> It will work, UNLESS you provide certain options. I think that's what
> Dmitry was getting at with the --print-options thing but it might be
> easier to see with a different flag, like "-s" (silent mode).
>
> It has always been true (not changed in 4.x) that the MAKEFLAGS
> variable has a first word which is either empty, or contains the
> single-letter options with no arguments, AND NO PRECEDING "-".
>
> So if you run "make" then MAKEFLAGS has an empty value. If you run
> "make --no-print-directory" then MAKEFLAGS has the value
> " --no-print-directory" (note very carefully the leading space here!)
> If you run "make -s" then MAKEFLAGS has the value "s" (note, no leading
> space AND no leading "-"!)
>
> In your makefile above, if you run "make -s" then the sub-make is
> invoked with MAKEFLAGS="-j1 s". That "s" is not treated as an option:
> it's ignored (probably make should warn about this) so now you've lost
> your "silent" option. You can see this with your makefile above, and
> ANY version of GNU make, by removing the "@" from the echo line and
> running it like this:
>
> $ make
> MAKEFLAGS="-j1 " make -f makefile hello
> make[1]: Entering directory '/tmp'
> echo Hello
> Hello
> make[1]: Leaving directory '/tmp'
>
> Note how we make prints the recipe "echo hello". Now if we ran
> "make -s" instead we would expect to see that line NOT printed because
> we run in silent mode; here's what we get:
>
> $ make -s
> make[1]: Entering directory '/tmp'
> echo Hello
> Hello
> make[1]: Leaving directory '/tmp'
>
> Note here, the top-level makefile is silent because the "-s" option was
> in effect, BUT the sub-make was not silent: we lost the "-s" option as
> I described above.
>
> Andreas is correct, if you want to add options to MAKEFLAGS you MUST
> add the "-". Luckily, make ignores a single "-" in MAKEFLAGS so you
> don't have to get more complicated:
>
> all:
> @MAKEFLAGS="-j1 -${MAKEFLAGS}" ${MAKE} -f makefile hello
>
> I believe this works in all versions of GNU make.
>
> But as I said in my previous email, you can't change the value of N in
> -jN using this method (or any other method).
>