help-make
[Top][All Lists]
Advanced

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

Re: Exported vs command line variables


From: Brian Vandenberg
Subject: Re: Exported vs command line variables
Date: Tue, 20 Sep 2016 09:13:35 -0600

This makefile example should help clear things up:

$ cat makefile
SHELL := bash
.RECIPEPREFIX := >
blah1 := test1
blah2 := test2
export blah2
# blah2 & blah3 should have identical results
export blah3 := test3

default:
>@$(foreach x,blah1 blah2 blah3 blah4 blah5,echo "${x}: (origin = $(origin
${x}), flavor = $(flavor ${x}), make value = ${${x}}, shell value:
$${${x}:-not set})";)

$ make --version
GNU Make 4.1
(...)

$ blah5=test5 make -f makefile blah4=test4
blah1: (origin = file, flavor = simple, make value = test1, shell value:
not set)
blah2: (origin = file, flavor = simple, make value = test2, shell value:
test2)
blah3: (origin = file, flavor = simple, make value = test3, shell value:
test3)
blah4: (origin = command line, flavor = recursive, make value = test4,
shell value: test4)
blah5: (origin = environment, flavor = recursive, make value = test5, shell
value: test5)

This is identical to:

$ export blah5=test5
$ make -f makefile blah4=test4
blah1: (origin = file, flavor = simple, make value = test1, shell value:
not set)
blah2: (origin = file, flavor = simple, make value = test2, shell value:
test2)
blah3: (origin = file, flavor = simple, make value = test3, shell value:
test3)
blah4: (origin = command line, flavor = recursive, make value = test4,
shell value: test4)
blah5: (origin = environment, flavor = recursive, make value = test5, shell
value: test5)

I was a little surprised to discover that variables passed on the
command-line to make get marked for export.

-brian


reply via email to

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