This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fwd: Re: Question about substituting $(MAKE) and recursive makes.


FYI: Here is the answer I received from help-make.

----- Message Forwarded on Tue, 09 Sep 2003 08:03:26 -0500 -----
From: "Paul D. Smith" <psmith@gnu.org>
To: Kelley Cook <kelleycook@wideopenwest.com>
Cc: help-make@gnu.org
Subject: Re: Question about substituting $(MAKE) and recursive makes.
Date: Tue, 9 Sep 2003 08:23:40 -0400

%% Kelley Cook <kcook34@ford.com> writes:

kc> For the GCC project, there are numberous places where we have something
kc> similar to


kc> dep:
kc> $(MAKE) LANGUAGES="$(LANGUAGES)" BOOT_CFLAGS="$(BOOT_CFLAGS)" newstage
kc> which proved to be prone to mistakes in maintenance of the Makefile.
kc> So, I attempted to define a


  kc> REMAKE=$(MAKE) LANGUAGES="$(LANGUAGES)" BOOT_CFLAGS="$(BOOT_CFLAGS)"
  kc> and then replace those constructs with

  kc> dep:
  kc>   $(REMAKE) newstage

kc> but any parallel build ended up being serialized once it recursed.

Didn't you get any warnings? You should have received a warning, and if you look up the warning in the error messages section of the GNU make manual you'd find some info there about this.
kc> It was suggested to try


  kc> dep:
  kc>   +$(REMAKE) newstage

You can put the + inside the REMAKE variable as well; that's probably less work and safer as people won't forget it:

REMAKE = +$(MAKE) LANGUAGES="$(LANGUAGES)" BOOT_CFLAGS="$(BOOT_CFLAGS)"

The one downside to this style is that you can't use this form of $(REMAKE) anywhere except the beginning of a command script. For example this will not work if you include the "+" in the variable:

  foo:
        cd foo && $(REMAKE)

  kc> which does *seem* to work, but I cannot see where in the manual
  kc> that this construct is supposed to allow parallel builds to work
  kc> again.  From what I can tell the '+' should only affect '-n',
  kc> '-t', and '-q'.  Though the 'MAKE' variable page does mention that
  kc> the special variable '$(MAKE)' acts like it was specified with
  kc> '+$(MAKE)'.

  kc> Can you please shed some light on this?  Is it valid, and if not
  kc> is their a better way to do this.

It is valid. In order for the make "jobserver" feature (that controls the total number of jobs being invoked across all the different possible instances of make and sub-makes) to work, make needs to know which commands are sub-makes and which aren't.
It determines that by the "usual" method as described in the manual: either by $(MAKE) or ${MAKE} appearing verbatim in the script (before expansion), or by having the script begin with the "+" special character.


Any command that is marked in this way will eligible to participate in the jobserver feature; any command that is not marked in this way will not be eligible. If a make is invoked and finds that it's a submake of a parallel build, but is not eligible for jobserver, it will print a warning about needing to add "+" to the parent makefile and it will continue as a serial build.

As for "a better way to do this", I'm not sure what "this" you're talking about. I guess you mean the whole idea of providing flags to submakes.

The simplest thing to do is append your variables to the MAKEFLAGS variable:

MAKEFLAGS += LANGUAGES="$(LANGUAGES)" BOOT_CFLAGS="$(BOOT_CFLAGS)"

I believe that will work fine. I suppose you might want to check to make sure those variables are not already present first. See the GNU make manual for more info on MAKEFLAGS.

--
-------------------------------------------------------------------------------
Paul D. Smith <psmith@gnu.org> Find some GNU make tips at:
http://www.gnu.org http://make.paulandlesley.org
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]