1*759b177aSSimon J. Gerraty# $NetBSD: posix-varassign.mk,v 1.1 2025/04/13 09:29:33 rillig Exp $ 2*759b177aSSimon J. Gerraty# 3*759b177aSSimon J. Gerraty# https://pubs.opengroup.org/onlinepubs/9799919799/utilities/make.html#tag_20_76_13_05 4*759b177aSSimon J. Gerraty# 5*759b177aSSimon J. Gerraty# Test that variable assignments work in the same way as in default mode. 6*759b177aSSimon J. Gerraty# 7*759b177aSSimon J. Gerraty# The assignment operators "::=" and ":::=" are intentionally not supported, 8*759b177aSSimon J. Gerraty# as they would introduce the distinction between eagerly and lazily evaluated 9*759b177aSSimon J. Gerraty# macros, in addition to the eagerly and lazily evaluated assignments, and 10*759b177aSSimon J. Gerraty# this would add too much complexity to the user's mental model, for too 11*759b177aSSimon J. Gerraty# little benefit. 12*759b177aSSimon J. Gerraty 13*759b177aSSimon J. Gerraty.POSIX: 14*759b177aSSimon J. Gerraty 15*759b177aSSimon J. Gerraty 16*759b177aSSimon J. GerratyVAR= value 17*759b177aSSimon J. Gerraty.if ${VAR} != "value" 18*759b177aSSimon J. Gerraty. error 19*759b177aSSimon J. Gerraty.endif 20*759b177aSSimon J. Gerraty 21*759b177aSSimon J. Gerraty 22*759b177aSSimon J. Gerraty# Deviation from POSIX: The "::=" assignment operator is not supported, 23*759b177aSSimon J. Gerraty# instead, the variable named "VAR:" is defined. 24*759b177aSSimon J. GerratyVAR= before 25*759b177aSSimon J. GerratyVAR::= posix-immediate-expansion 26*759b177aSSimon J. Gerraty.if ${VAR} != "before" 27*759b177aSSimon J. Gerraty. error 28*759b177aSSimon J. Gerraty.elif ${${:UVAR\:}} != "posix-immediate-expansion" 29*759b177aSSimon J. Gerraty. error 30*759b177aSSimon J. Gerraty.endif 31*759b177aSSimon J. Gerraty 32*759b177aSSimon J. Gerraty 33*759b177aSSimon J. Gerraty# Deviation from POSIX: The ":::=" assignment operator is not supported, 34*759b177aSSimon J. Gerraty# instead, the variable named "VAR::" is defined. 35*759b177aSSimon J. GerratyVAR:::= posix-delayed-expansion 36*759b177aSSimon J. Gerraty.if ${VAR} != "before" 37*759b177aSSimon J. Gerraty. error 38*759b177aSSimon J. Gerraty.elif ${${:UVAR\:\:}} != "posix-delayed-expansion" 39*759b177aSSimon J. Gerraty. error 40*759b177aSSimon J. Gerraty.endif 41*759b177aSSimon J. Gerraty 42*759b177aSSimon J. Gerraty 43*759b177aSSimon J. GerratyVAR!= echo from shell command 44*759b177aSSimon J. Gerraty.if ${VAR} != "from shell command" 45*759b177aSSimon J. Gerraty. error 46*759b177aSSimon J. Gerraty.endif 47*759b177aSSimon J. Gerraty 48*759b177aSSimon J. Gerraty 49*759b177aSSimon J. GerratyVAR= value 50*759b177aSSimon J. GerratyVAR?= fallback 51*759b177aSSimon J. Gerraty.if ${VAR} != "value" 52*759b177aSSimon J. Gerraty. error 53*759b177aSSimon J. Gerraty.endif 54*759b177aSSimon J. Gerraty.undef VAR 55*759b177aSSimon J. GerratyVAR?= fallback 56*759b177aSSimon J. Gerraty.if ${VAR} != "fallback" 57*759b177aSSimon J. Gerraty. error 58*759b177aSSimon J. Gerraty.endif 59*759b177aSSimon J. Gerraty 60*759b177aSSimon J. Gerraty 61*759b177aSSimon J. GerratyVAR= value 62*759b177aSSimon J. GerratyVAR+= appended 63*759b177aSSimon J. Gerraty.if ${VAR} != "value appended" 64*759b177aSSimon J. Gerraty. error 65*759b177aSSimon J. Gerraty.endif 66*759b177aSSimon J. Gerraty 67*759b177aSSimon J. Gerraty 68*759b177aSSimon J. Gerraty# In POSIX mode, the ":=" assignment operator is available as well, even 69*759b177aSSimon J. Gerraty# though it is not specified by POSIX, due to the differences in existing 70*759b177aSSimon J. Gerraty# make implementations. 71*759b177aSSimon J. GerratyREF= before 72*759b177aSSimon J. GerratyVAR:= immediate ${REF} 73*759b177aSSimon J. GerratyREF= after 74*759b177aSSimon J. Gerraty.if ${VAR} != "immediate before" 75*759b177aSSimon J. Gerraty. error 76*759b177aSSimon J. Gerraty.endif 77*759b177aSSimon J. Gerraty 78*759b177aSSimon J. Gerraty 79*759b177aSSimon J. Gerratyall: 80