-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrigin-Function.html
More file actions
116 lines (94 loc) · 4.7 KB
/
Origin-Function.html
File metadata and controls
116 lines (94 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<html lang="en">
<head>
<title>GNU `make'</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="GNU `make'">
<meta name="generator" content="makeinfo 4.3">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">
</head>
<body>
<div class="node">
<p>
Node:<a name="Origin%20Function">Origin Function</a>,
Next:<a rel="next" accesskey="n" href="Shell-Function.html#Shell%20Function">Shell Function</a>,
Previous:<a rel="previous" accesskey="p" href="Eval-Function.html#Eval%20Function">Eval Function</a>,
Up:<a rel="up" accesskey="u" href="Functions.html#Functions">Functions</a>
<hr><br>
</div>
<h3 class="section">The <code>origin</code> Function</h3>
<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>The syntax of the <code>origin</code> function is:
<pre class="example"> $(origin <var>variable</var>)
</pre>
<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 <code>$</code> 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>The result of this function is a string telling you how the variable
<var>variable</var> was defined:
<dl>
<dt><code>undefined</code>
<dd>
if <var>variable</var> was never defined.
<br><dt><code>default</code>
<dd>
if <var>variable</var> has a default definition, as is usual with <code>CC</code>
and so on. See <a href="Implicit-Variables.html#Implicit%20Variables">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.
<br><dt><code>environment</code>
<dd>
if <var>variable</var> was defined as an environment variable and the
<code>-e</code> option is <em>not</em> turned on (see <a href="Options-Summary.html#Options%20Summary">Summary of Options</a>).
<br><dt><code>environment override</code>
<dd>
if <var>variable</var> was defined as an environment variable and the
<code>-e</code> option <em>is</em> turned on (see <a href="Options-Summary.html#Options%20Summary">Summary of Options</a>).
<br><dt><code>file</code>
<dd>
if <var>variable</var> was defined in a makefile.
<br><dt><code>command line</code>
<dd>
if <var>variable</var> was defined on the command line.
<br><dt><code>override</code>
<dd>
if <var>variable</var> was defined with an <code>override</code> directive in a
makefile (see <a href="Override-Directive.html#Override%20Directive">The <code>override</code> Directive</a>).
<br><dt><code>automatic</code>
<dd>
if <var>variable</var> is an automatic variable defined for the
execution of the commands for each rule
(see <a href="Automatic.html#Automatic">Automatic Variables</a>).
</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 <code>foo</code> that includes another makefile
<code>bar</code>. You want a variable <code>bletch</code> to be defined in <code>bar</code>
if you run the command <code>make -f bar</code>, even if the environment contains
a definition of <code>bletch</code>. However, if <code>foo</code> defined
<code>bletch</code> before including <code>bar</code>, you do not want to override that
definition. This could be done by using an <code>override</code> directive in
<code>foo</code>, giving that definition precedence over the later definition in
<code>bar</code>; unfortunately, the <code>override</code> directive would also
override any command line definitions. So, <code>bar</code> could
include:
<pre class="example"> ifdef bletch
ifeq "$(origin bletch)" "environment"
bletch = barf, gag, etc.
endif
endif
</pre>
<p>If <code>bletch</code> has been defined from the environment, this will redefine
it.
<p>If you want to override a previous definition of <code>bletch</code> if it came
from the environment, even under <code>-e</code>, you could instead write:
<pre class="example"> ifneq "$(findstring environment,$(origin bletch))" ""
bletch = barf, gag, etc.
endif
</pre>
<p>Here the redefinition takes place if <code>$(origin bletch)</code> returns either
<code>environment</code> or <code>environment override</code>.
See <a href="Text-Functions.html#Text%20Functions">Functions for String Substitution and Analysis</a>.
</body></html>