summaryrefslogtreecommitdiff
path: root/devdocs/gnu_make/origin-function.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/gnu_make/origin-function.html')
-rw-r--r--devdocs/gnu_make/origin-function.html19
1 files changed, 19 insertions, 0 deletions
diff --git a/devdocs/gnu_make/origin-function.html b/devdocs/gnu_make/origin-function.html
new file mode 100644
index 00000000..cb7aaa06
--- /dev/null
+++ b/devdocs/gnu_make/origin-function.html
@@ -0,0 +1,19 @@
+ <h1 class="section">The origin Function</h1> <p>The <code>origin</code> function is unlike most other functions in that it does not operate on the values of variables; it tells you something <em>about</em> a variable. Specifically, it tells you where it came from. </p> <p>The syntax of the <code>origin</code> function is: </p> <div class="example"> <pre class="example">$(origin <var>variable</var>)
+</pre>
+</div> <p>Note that <var>variable</var> is the <em>name</em> of a variable to inquire about, not a <em>reference</em> to that variable. Therefore you would not normally use a ‘<samp>$</samp>’ 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.) </p> <p>The result of this function is a string telling you how the variable <var>variable</var> was defined: </p> <dl compact> <dt id="undefined">‘<samp>undefined</samp>’</dt> <dd> <p>if <var>variable</var> was never defined. </p> </dd> <dt id="default">‘<samp>default</samp>’</dt> <dd> <p>if <var>variable</var> has a default definition, as is usual with <code>CC</code> and so on. See <a href="implicit-variables">Variables Used by Implicit Rules</a>. Note that if you have redefined a default variable, the <code>origin</code> function will return the origin of the later definition. </p> </dd> <dt id="environment">‘<samp>environment</samp>’</dt> <dd> <p>if <var>variable</var> was inherited from the environment provided to <code>make</code>. </p> </dd> <dt id="environment override">‘<samp>environment override</samp>’</dt> <dd> <p>if <var>variable</var> was inherited from the environment provided to <code>make</code>, and is overriding a setting for <var>variable</var> in the makefile as a result of the ‘<samp><span class="nolinebreak">-e</span></samp>’ option (see <a href="options-summary">Summary of Options</a>). </p> </dd> <dt id="file">‘<samp>file</samp>’</dt> <dd> <p>if <var>variable</var> was defined in a makefile. </p> </dd> <dt id="command line">‘<samp>command line</samp>’</dt> <dd> <p>if <var>variable</var> was defined on the command line. </p> </dd> <dt id="override">‘<samp>override</samp>’</dt> <dd> <p>if <var>variable</var> was defined with an <code>override</code> directive in a makefile (see <a href="override-directive">The <code>override</code> Directive</a>). </p> </dd> <dt id="automatic">‘<samp>automatic</samp>’</dt> <dd> <p>if <var>variable</var> is an automatic variable defined for the execution of the recipe for each rule (see <a href="automatic-variables">Automatic Variables</a>). </p>
+</dd> </dl> <p>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 <samp>foo</samp> that includes another makefile <samp>bar</samp>. You want a variable <code>bletch</code> to be defined in <samp>bar</samp> if you run the command ‘<samp>make <span class="nolinebreak">-f</span> bar</samp>’, even if the environment contains a definition of <code>bletch</code>. However, if <samp>foo</samp> defined <code>bletch</code> before including <samp>bar</samp>, you do not want to override that definition. This could be done by using an <code>override</code> directive in <samp>foo</samp>, giving that definition precedence over the later definition in <samp>bar</samp>; unfortunately, the <code>override</code> directive would also override any command line definitions. So, <samp>bar</samp> could include: </p> <div class="example"> <pre class="example">ifdef bletch
+ifeq "$(origin bletch)" "environment"
+bletch = barf, gag, etc.
+endif
+endif
+</pre>
+</div> <p>If <code>bletch</code> has been defined from the environment, this will redefine it. </p> <p>If you want to override a previous definition of <code>bletch</code> if it came from the environment, even under ‘<samp>-e</samp>’, you could instead write: </p> <div class="example"> <pre class="example">ifneq "$(findstring environment,$(origin bletch))" ""
+bletch = barf, gag, etc.
+endif
+</pre>
+</div> <p>Here the redefinition takes place if ‘<samp>$(origin bletch)</samp>’ returns either ‘<samp>environment</samp>’ or ‘<samp>environment override</samp>’. See <a href="text-functions">Functions for String Substitution and Analysis</a>. </p><div class="_attribution">
+ <p class="_attribution-p">
+ Copyright © 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Free Software Foundation, Inc. <br>Licensed under the GNU Free Documentation License.<br>
+ <a href="https://www.gnu.org/software/make/manual/html_node/Origin-Function.html" class="_attribution-link">https://www.gnu.org/software/make/manual/html_node/Origin-Function.html</a>
+ </p>
+</div>