1# $NetBSD: directive-export-impl.mk,v 1.1 2020/12/29 01:45:06 rillig Exp $ 2# 3# Test for the implementation of exporting variables to child processes. 4# This involves marking variables for export, actually exporting them, 5# or marking them for being re-exported. 6# 7# See also: 8# Var_Export 9# ExportVar 10# VarExportedMode (global) 11# VAR_EXPORTED (per variable) 12# VAR_REEXPORT (per variable) 13# VarExportMode (per call of Var_Export and ExportVar) 14 15: ${:U:sh} # side effect: initialize .SHELL 16 17.MAKEFLAGS: -dcpv 18 19# This is a variable that references another variable. At this point, the 20# other variable is still undefined. 21UT_VAR= <${REF}> 22 23# At this point, ExportVar("UT_VAR", VEM_PLAIN) is called. Since the 24# variable value refers to another variable, ExportVar does not actually 25# export the variable but only marks it as VAR_EXPORTED and VAR_REEXPORT. 26# After that, ExportVars registers the variable name in .MAKE.EXPORTED. 27# That's all for now. 28.export UT_VAR 29 30# Evaluating this expression shows the variable flags in the debug log, 31# which are VAR_EXPORTED|VAR_REEXPORT. 32: ${UT_VAR:N*} 33 34# At the last moment before actually forking off the child process for the 35# :!...! modifier, Cmd_Exec calls Var_ReexportVars to have all relevant 36# variables exported. Since this variable has both of the above-mentioned 37# flags set, it is actually exported to the environment. The variable flags 38# are not modified though, since the next time the :!...! modifier is 39# evaluated, the referenced variables could have changed, therefore the 40# variable will be exported anew for each ':sh' modifier, ':!...!' modifier, 41# '!=' variable assignment. 42.if ${:!echo "\$UT_VAR"!} != "<>" 43. error 44.endif 45 46# Evaluating this expression shows the variable flags in the debug log, 47# which are still VAR_EXPORTED|VAR_REEXPORT, which means that the variable 48# is still marked as being re-exported for each child process. 49: ${UT_VAR:N*} 50 51# Now the referenced variable gets defined. This does not influence anything 52# in the process of exporting the variable value, though. 53REF= defined 54 55# Nothing surprising here. The variable UT_VAR gets exported, and this time, 56# REF is defined and gets expanded into the exported environment variable. 57.if ${:!echo "\$UT_VAR"!} != "<defined>" 58. error 59.endif 60 61all: 62.MAKEFLAGS: -d0 63