help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: curious behaviour of $MAKEFLAGS and leading hyphen


From: Paul D. Smith
Subject: Re: curious behaviour of $MAKEFLAGS and leading hyphen
Date: Fri, 22 Apr 2005 10:46:25 -0400

%% "Robert P. J. Day" <address@hidden> writes:

  rpjd> ok, that makes sense, so let me ask one more followup question.
  rpjd> is there a reason i can't use ${MAKEFLAGS} in a make directive
  rpjd> to *examine* the values of the command-line options with which
  rpjd> i, the makefile, was invoked?

No, no reason.

  rpjd> as a trivial example,

  rpjd>   $(warning Hi, my MAKEFLAGS value is ${MAKEFLAGS}.)

  rpjd> if you do that in a makefile, it won't represent the
  rpjd> command-line options you were invoked with but, if you make a
  rpjd> recursive call, then the command-line options will be added to
  rpjd> MAKEFLAGS for the purpose of that recursive call.

The reason it doesn't represent the full set in that example is that the
contents of that variable are not completely constructed until after all
the makefiles are read in; a $(warning ...) function like this is
expanded when it is seen, during the parsing of the makefile.

  rpjd> in short, if a makefile is invoked with, say, "-I /tmp/fred",
  rpjd> that information will certainly affect the behaviour of the
  rpjd> makefile but won't be reflected in that current MAKEFLAGS
  rpjd> variable.  (i'm not sure *why* i'd want to look at it, but i'm
  rpjd> just curious.)

It will be reflected in the MAKEFLAGS variable passed to sub-shells, but
not during read-in, you're right.  Consider this makefile:

  $ cat Makefile
  $(warning MAKEFLAGS = '$(MAKEFLAGS)')
  all: ; @echo "MAKEFLAGS = '$(MAKEFLAGS)'"

  $ make
  Makefile:1: MAKEFLAGS = ''
  MAKEFLAGS = ''

  $ make -k
  Makefile:1: MAKEFLAGS = 'k'
  MAKEFLAGS = 'k'

  $ make -f x.mk -k -I/usr/include
  Makefile:1: MAKEFLAGS = 'k'
  MAKEFLAGS = 'kI /usr/include'

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]