1*b0c40a00SSimon J. Gerraty# $NetBSD: directive-export.mk,v 1.8 2021/02/16 19:01:18 rillig Exp $ 22c3632d1SSimon J. Gerraty# 32c3632d1SSimon J. Gerraty# Tests for the .export directive. 406b9b3e0SSimon J. Gerraty# 506b9b3e0SSimon J. Gerraty# See also: 606b9b3e0SSimon J. Gerraty# directive-misspellings.mk 72c3632d1SSimon J. Gerraty 82c3632d1SSimon J. Gerraty# TODO: Implementation 92c3632d1SSimon J. Gerraty 10956e45f6SSimon J. GerratyINDIRECT= indirect 11956e45f6SSimon J. GerratyVAR= value $$ ${INDIRECT} 12956e45f6SSimon J. Gerraty 1306b9b3e0SSimon J. Gerraty# Before 2020-12-13, this unusual expression invoked undefined behavior since 1406b9b3e0SSimon J. Gerraty# it accessed out-of-bounds memory via Var_Export -> ExportVar -> MayExport. 1506b9b3e0SSimon J. Gerraty.export ${:U } 1606b9b3e0SSimon J. Gerraty 17956e45f6SSimon J. Gerraty# A variable is exported using the .export directive. 18956e45f6SSimon J. Gerraty# During that, its value is expanded, just like almost everywhere else. 19956e45f6SSimon J. Gerraty.export VAR 20956e45f6SSimon J. Gerraty.if ${:!env | grep '^VAR'!} != "VAR=value \$ indirect" 21956e45f6SSimon J. Gerraty. error 22956e45f6SSimon J. Gerraty.endif 23956e45f6SSimon J. Gerraty 24956e45f6SSimon J. Gerraty# Undefining a variable that has been exported implicitly removes it from 25956e45f6SSimon J. Gerraty# the environment of all child processes. 26956e45f6SSimon J. Gerraty.undef VAR 27956e45f6SSimon J. Gerraty.if ${:!env | grep '^VAR' || true!} != "" 28956e45f6SSimon J. Gerraty. error 29956e45f6SSimon J. Gerraty.endif 30956e45f6SSimon J. Gerraty 31*b0c40a00SSimon J. Gerraty# No syntactical argument means to export all variables. 3206b9b3e0SSimon J. Gerraty.export 33e2eeea75SSimon J. Gerraty 34*b0c40a00SSimon J. Gerraty# An empty argument means no additional variables to export. 35*b0c40a00SSimon J. Gerraty.export ${:U} 36*b0c40a00SSimon J. Gerraty 37*b0c40a00SSimon J. Gerraty 38*b0c40a00SSimon J. Gerraty# Trigger the "This isn't going to end well" in ExportVarEnv. 39*b0c40a00SSimon J. GerratyEMPTY_SHELL= ${:sh} 40*b0c40a00SSimon J. Gerraty.export EMPTY_SHELL # only marked for export at this point 41*b0c40a00SSimon J. Gerraty_!= :;: # Force the variable to be actually exported. 42*b0c40a00SSimon J. Gerraty 43*b0c40a00SSimon J. Gerraty 442c3632d1SSimon J. Gerratyall: 45