On Fri, 31 Dec 2021 12:49:46 +0600
NRK <nrk_AT_disroot.org> wrote:
Dear NRK,
> Hmm, I was under the impression that `?=` was accepted into POSIX.
> But I cannot find any mention of it in the posix manpage (man 1p
> make) so I guess I was wrong.
>
> What would be a posix replacement for `?=` ? I assume something like:
>
> VAR = $$(if test -n "$$VAR"; then printf "%s" "$$VAR"; else
> printf "fallback"; fi)
>
> - NRK
that is exactly what I meant earlier on that the POSIX-intended good
practices get destroyed by the retarded GNU extensions.
"?=" sets a variable only if it doesn't have a value. However, you
really don't need that and should go the other way around by specifying
override variables (those following after "make" in the command line)
instead. They will override any variable within the Makefile.
Alternatively pass the "-e" flag to set all environment variables as
overrides, but this is less clean.
GNU of course complicated it again by _then_ offering an "override"
directive which really really overrides even override variables[0]. I
hate GNU so much.
So what is the replacement? Usually you have a context where e.g. in a
config.mk you have
PREFIX=/usr/local
and want to "dynamically" override it (e.g. in a build system context)
when the environment already specifies PREFIX, you either do
make -e
or explicitly set
make PREFIX=/usr/local
and are bloody done. What more do you want?
It was ingenious by POSIX to really not give in to any stupid
extensions which poison this beautifully simple environment handling.
With best regards
Laslo
[0]:
https://www.gnu.org/software/make/manual/html_node/Override-Directive.html
Received on Fri Dec 31 2021 - 09:29:52 CET