11.23Slukem# $NetBSD: Makefile.params,v 1.23 2023/06/11 10:43:51 lukem Exp $ 21.1Sapb# 31.1Sapb# Makefile fragment for printing build parameters. 41.1Sapb# 51.1Sapb# Public variables: 61.1Sapb# RELEASEVARS 71.1Sapb# List of variables whose value should be printed. 81.1Sapb# 91.1Sapb# PRINT_PARAMS 101.4Sapb# A command to print the desired variables and values 111.4Sapb# to stdout, without any additional debugging information. 121.1Sapb# Values are printed as single-quoted strings, with 131.1Sapb# embedded quotes and newlines escaped in a way that's 141.1Sapb# acceptable to sh(1). Undefined values are printed 151.1Sapb# as "(undefined)" (without quotation marks). 161.1Sapb# 171.1Sapb# Internal targets: 181.1Sapb# _params: 191.4Sapb# Prints the names and values of all the variables 201.4Sapb# listed in ${RELEASEVARS}. The desired results may be 211.4Sapb# redirected somewhere other than stdout, for example by 221.4Sapb# setting _params_redirect='>&3'. stdout and stderr may 231.4Sapb# contain unwanted debugging information, from make and 241.4Sapb# the shell. 251.1Sapb# 261.1Sapb# Internal variables: 271.4Sapb# _params_redirect: 281.4Sapb# If set, this should be a shell redirection specification, such 291.4Sapb# as '>&3', controlling where the output from "make _params" will 301.4Sapb# be sent. 311.1Sapb# 321.1Sapb# Example: 331.1Sapb# . ${NETBSDSRCDIR}/etc/Makefile.params 341.1Sapb# show-params: .MAKE .PHONY # print params to stdout 351.1Sapb# @${PRINT_PARAMS} 361.1Sapb# 371.1Sapb 381.7Sapb.include <bsd.own.mk> # for some variables 391.5Sapb 401.14SchristosRELEASEVARS= DISTRIBVER EXTERNAL_TOOLCHAIN HAVE_GCC HAVE_GDB \ 411.3Snjoly HAVE_LLVM HAVE_PCC INSTALLWORLDDIR \ 421.20Smartin MACHINE MACHINE_ARCH \ 431.21Smartin NETBSD_OFFICIAL_RELEASE NOCLEANDIR NODISTRIBDIRS NOINCLUDES \ 441.14Schristos TOOLCHAIN_MISSING \ 451.1Sapb USE_HESIOD USE_INET6 USE_JEMALLOC USE_KERBEROS USE_LDAP \ 461.1Sapb USE_PAM USE_SKEY USE_YP \ 471.14Schristos USETOOLS 481.14Schristos 491.14Schristos.if ${MKREPRO:Uno} != "yes" 501.14SchristosRELEASEVARS+= BSDOBJDIR BSDSRCDIR BUILDID BUILDINFO BUILDSEED \ 511.17Schristos DESTDIR KERNARCHDIR KERNCONFDIR KERNOBJDIR KERNSRCDIR MAKE \ 521.22Spgoyette KERNEL_DIR MAKECONF MAKEFLAGS MAKEOBJDIR MAKEOBJDIRPREFIX \ 531.23Slukem MAKEVERBOSE NETBSDSRCDIR OBJMACHINE OBJMACHINE_ARCH \ 541.14Schristos RELEASEDIR RELEASEMACHINEDIR TOOLDIR USR_OBJMACHINE X11SRCDIR 551.14Schristos.endif 561.1Sapb 571.16SchristosRELEASEVARS+= ${_MKVARS.yes} ${_MKVARS.no} 581.5Sapb 591.5Sapb# 601.5Sapb# Duplicate the DISTRIBVER setting from src/etc/Makefile. 611.5Sapb# 621.5Sapb.ifndef DISTRIBVER 631.7SapbDISTRIBVER!= ${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh 641.5Sapb.endif 651.5Sapb 661.5Sapb# 671.5Sapb# _params does the printing. 681.5Sapb# 691.4Sapb_params_redirect?= # empty 701.1Sapb 711.1Sapb_params: .PHONY 721.14Schristos.for var in ${RELEASEVARS:O} 731.1Sapb.if defined(${var}) 741.4Sapb @printf "%20s = '%-s'\n" ${var} ${${var}:C/'/'\\\\''/gW:Q} \ 751.4Sapb ${_params_redirect} 761.1Sapb.else 771.5Sapb @printf "%20s = (undefined)\n" ${var} \ 781.4Sapb ${_params_redirect} 791.1Sapb.endif 801.1Sapb.endfor 811.1Sapb 821.4Sapb# PRINT_PARAMS: 831.1Sapb# 841.1Sapb# The output from the "make _params" can include the following types of 851.1Sapb# unwanted lines: 861.1Sapb# 871.4Sapb# make -j prints "--- _params ---"; 881.1Sapb# 891.1Sapb# if MAKEVERBOSE is set to 3 or more then make prints each "printf" 901.1Sapb# command in addition to executing it; 911.1Sapb# 921.1Sapb# if MAKEVERBOSE is set to 4 then the shell prints each command 931.1Sapb# (prefixed with "+"). 941.1Sapb# 951.1Sapb# So the resulting output can look like this: 961.1Sapb# 971.4Sapb# --- _params --- 981.1Sapb# + echo 'printf "%20s = '\''%-s'\''\n" BSDOBJDIR /usr/obj' 991.1Sapb# printf "%20s = '%-s'\n" BSDOBJDIR /usr/obj 1001.1Sapb# + printf '%20s = '\''%-s'\''\n' BSDOBJDIR /usr/obj 1011.1Sapb# BSDOBJDIR = '/usr/obj' 1021.1Sapb# + echo 'printf "%20s = '\''%-s'\''\n" BSDSRCDIR /usr/src' 1031.1Sapb# printf "%20s = '%-s'\n" BSDSRCDIR /usr/src 1041.1Sapb# + printf '%20s = '\''%-s'\''\n' BSDSRCDIR /usr/src 1051.1Sapb# BSDSRCDIR = '/usr/src' 1061.1Sapb# [...] 1071.1Sapb# 1081.1Sapb# where what we want is just this: 1091.1Sapb# 1101.1Sapb# BSDOBJDIR = '/usr/obj' 1111.1Sapb# BSDSRCDIR = '/usr/src' 1121.1Sapb# [...] 1131.1Sapb# 1141.4Sapb# The shell redirections in ${PRINT_PARAMS} ensure that the unwanted 1151.4Sapb# noise is discarded (via ">/dev/null"), while the desired information 1161.4Sapb# ends up on the subshell's stdout (via ">&3" and "3>&1"). The value 1171.4Sapb# of _params_redirect is passed in the environment instead of on the 1181.4Sapb# command line, to prevent it from appearing in MAKEFLAGS (which would 1191.4Sapb# appear in the output). 1201.4Sapb# 1211.4SapbPRINT_PARAMS:= (_params_redirect='>&3' ${MAKE} -f ${.PARSEDIR:Q}/${.PARSEFILE:Q} _params 3>&1 >/dev/null) 122