manpagez: man pages & more
info make
Home | html | info | man

File: make.info,  Node: Origin Function,  Next: Flavor Function,  Prev: Eval Function,  Up: Functions

8.11 The 'origin' Function
==========================

The 'origin' function is unlike most other functions in that it does not
operate on the values of variables; it tells you something _about_ a
variable.  Specifically, it tells you where it came from.

   The syntax of the 'origin' function is:

     $(origin VARIABLE)

   Note that VARIABLE is the _name_ of a variable to inquire about, not
a _reference_ to that variable.  Therefore you would not normally use a
'$' or parentheses when writing it.  (You can, however, use a variable
reference in the name if you want the name not to be a constant.)

   The result of this function is a string telling you how the variable
VARIABLE was defined:

'undefined'

     if VARIABLE was never defined.

'default'

     if VARIABLE has a default definition, as is usual with 'CC' and so
     on.  *Note Variables Used by Implicit Rules: Implicit Variables.
     Note that if you have redefined a default variable, the 'origin'
     function will return the origin of the later definition.

'environment'

     if VARIABLE was inherited from the environment provided to 'make'.

'environment override'

     if VARIABLE was inherited from the environment provided to 'make',
     and is overriding a setting for VARIABLE in the makefile as a
     result of the '-e' option (*note Summary of Options: Options
     Summary.).

'file'

     if VARIABLE was defined in a makefile.

'command line'

     if VARIABLE was defined on the command line.

'override'

     if VARIABLE was defined with an 'override' directive in a makefile
     (*note The 'override' Directive: Override Directive.).

'automatic'

     if VARIABLE is an automatic variable defined for the execution of
     the recipe for each rule (*note Automatic Variables::).

   This information is primarily useful (other than for your curiosity)
to determine if you want to believe the value of a variable.  For
example, suppose you have a makefile 'foo' that includes another
makefile 'bar'.  You want a variable 'bletch' to be defined in 'bar' if
you run the command 'make -f bar', even if the environment contains a
definition of 'bletch'.  However, if 'foo' defined 'bletch' before
including 'bar', you do not want to override that definition.  This
could be done by using an 'override' directive in 'foo', giving that
definition precedence over the later definition in 'bar'; unfortunately,
the 'override' directive would also override any command line
definitions.  So, 'bar' could include:

     ifdef bletch
     ifeq "$(origin bletch)" "environment"
     bletch = barf, gag, etc.
     endif
     endif

If 'bletch' has been defined from the environment, this will redefine
it.

   If you want to override a previous definition of 'bletch' if it came
from the environment, even under '-e', you could instead write:

     ifneq "$(findstring environment,$(origin bletch))" ""
     bletch = barf, gag, etc.
     endif

   Here the redefinition takes place if '$(origin bletch)' returns
either 'environment' or 'environment override'.  *Note Functions for
String Substitution and Analysis: Text Functions.

© manpagez.com 2000-2025
Individual documents may contain additional copyright information.