[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to privately export a variable?
From: |
Masahiro Yamada |
Subject: |
How to privately export a variable? |
Date: |
Sun, 8 Jan 2023 21:14:50 +0900 |
Hi.
I want to export a variable to recipe commands of
a particular target, but not to its prerequisites.
The manual [1] says:
"Target-specific variable assignments can be prefixed with
any or all of the special keywords export, unexport, override,
or private; these apply their normal behavior to this instance
of the variable only."
So, I wrote code like this:
foo: private export FOR_FOO := 1
foo: bar baz
command-1
command-2
command-3
I expected "private export" would mean
"privately export", but it is the same as "export".
The variable is exported not only to 'foo',
but also to 'bar' and 'baz'.
"private" and "export" are OR'ed instead of AND'ed.
This implementation is unfortunate because there is no
use-case where "private export" makes sense.
So, what is the best practice to export a variable only to
a particular target?
foo: private FOR_FOO := 1
foo: bar baz
FOR_FOO="$(FOR_FOO)" command-1
FOR_FOO="$(FOR_FOO)" command-2
FOR_FOO="$(FOR_FOO)" command-3
or
If we can require GNU Make 4.4,
foo: export FOR_FOO := 1
foo: bar baz
command-1
command-2
command-3
bar baz: unexport FOR_FOO :=
or anything else?
--
Best Regards
Masahiro Yamada
- How to privately export a variable?,
Masahiro Yamada <=