xref: /netbsd-src/etc/Makefile.params (revision 922f5e2588a58574818fef37264163f244d789f1)
1*922f5e25Slukem#	$NetBSD: Makefile.params,v 1.23 2023/06/11 10:43:51 lukem Exp $
23e31590fSapb#
33e31590fSapb# Makefile fragment for printing build parameters.
43e31590fSapb#
53e31590fSapb# Public variables:
63e31590fSapb#	RELEASEVARS
73e31590fSapb#		List of variables whose value should be printed.
83e31590fSapb#
93e31590fSapb#	PRINT_PARAMS
10b56cbda8Sapb#		A command to print the desired variables and values
11b56cbda8Sapb#		to stdout, without any additional debugging information.
123e31590fSapb#		Values are printed as single-quoted strings, with
133e31590fSapb#		embedded quotes and newlines escaped in a way that's
143e31590fSapb#		acceptable to sh(1).  Undefined values are printed
153e31590fSapb#		as "(undefined)" (without quotation marks).
163e31590fSapb#
173e31590fSapb# Internal targets:
183e31590fSapb# 	_params:
193e31590fSapb#		Prints the names and values of all the variables
20b56cbda8Sapb#		listed in ${RELEASEVARS}.  The desired results may be
21b56cbda8Sapb#		redirected somewhere other than stdout, for example by
22b56cbda8Sapb#		setting _params_redirect='>&3'.	 stdout and stderr may
23b56cbda8Sapb#		contain unwanted debugging information, from make and
24b56cbda8Sapb#		the shell.
253e31590fSapb#
263e31590fSapb# Internal variables:
27b56cbda8Sapb#	_params_redirect:
28b56cbda8Sapb#		If set, this should be a shell redirection specification, such
29b56cbda8Sapb#		as '>&3', controlling where the output from "make _params" will
30b56cbda8Sapb#		be sent.
313e31590fSapb#
323e31590fSapb# Example:
333e31590fSapb#	. ${NETBSDSRCDIR}/etc/Makefile.params
343e31590fSapb#	show-params: .MAKE .PHONY # print params to stdout
353e31590fSapb#		@${PRINT_PARAMS}
363e31590fSapb#
373e31590fSapb
3844f40b00Sapb.include <bsd.own.mk>	# for some variables
39f644e879Sapb
40700b0bb1SchristosRELEASEVARS=	DISTRIBVER EXTERNAL_TOOLCHAIN HAVE_GCC HAVE_GDB \
419329703bSnjoly		HAVE_LLVM HAVE_PCC INSTALLWORLDDIR \
4216afadc5Smartin		MACHINE MACHINE_ARCH \
439d445e07Smartin		NETBSD_OFFICIAL_RELEASE NOCLEANDIR NODISTRIBDIRS NOINCLUDES \
44700b0bb1Schristos		TOOLCHAIN_MISSING \
453e31590fSapb		USE_HESIOD USE_INET6 USE_JEMALLOC USE_KERBEROS USE_LDAP \
463e31590fSapb		USE_PAM USE_SKEY USE_YP \
47700b0bb1Schristos		USETOOLS
48700b0bb1Schristos
49700b0bb1Schristos.if ${MKREPRO:Uno} != "yes"
50700b0bb1SchristosRELEASEVARS+= 	BSDOBJDIR BSDSRCDIR BUILDID BUILDINFO BUILDSEED \
513d09c58aSchristos		DESTDIR KERNARCHDIR KERNCONFDIR KERNOBJDIR KERNSRCDIR MAKE \
520d15fa02Spgoyette		KERNEL_DIR MAKECONF MAKEFLAGS MAKEOBJDIR MAKEOBJDIRPREFIX \
53*922f5e25Slukem		MAKEVERBOSE NETBSDSRCDIR OBJMACHINE OBJMACHINE_ARCH \
54700b0bb1Schristos		RELEASEDIR RELEASEMACHINEDIR TOOLDIR USR_OBJMACHINE X11SRCDIR
55700b0bb1Schristos.endif
563e31590fSapb
57b575a423SchristosRELEASEVARS+= ${_MKVARS.yes} ${_MKVARS.no}
58f644e879Sapb
59f644e879Sapb#
60f644e879Sapb# Duplicate the DISTRIBVER setting from src/etc/Makefile.
61f644e879Sapb#
62f644e879Sapb.ifndef DISTRIBVER
6344f40b00SapbDISTRIBVER!=	${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh
64f644e879Sapb.endif
65f644e879Sapb
66f644e879Sapb#
67f644e879Sapb# _params does the printing.
68f644e879Sapb#
69b56cbda8Sapb_params_redirect?= # empty
703e31590fSapb
713e31590fSapb_params: .PHONY
72700b0bb1Schristos.for var in ${RELEASEVARS:O}
733e31590fSapb.if defined(${var})
74b56cbda8Sapb	@printf "%20s = '%-s'\n" ${var} ${${var}:C/'/'\\\\''/gW:Q} \
75b56cbda8Sapb	    ${_params_redirect}
763e31590fSapb.else
77f644e879Sapb	@printf "%20s = (undefined)\n" ${var} \
78b56cbda8Sapb	    ${_params_redirect}
793e31590fSapb.endif
803e31590fSapb.endfor
813e31590fSapb
82b56cbda8Sapb# PRINT_PARAMS:
833e31590fSapb#
843e31590fSapb# The output from the "make _params" can include the following types of
853e31590fSapb# unwanted lines:
863e31590fSapb#
87b56cbda8Sapb#     make -j prints "--- _params ---";
883e31590fSapb#
893e31590fSapb#     if MAKEVERBOSE is set to 3 or more then make prints each "printf"
903e31590fSapb#     command in addition to executing it;
913e31590fSapb#
923e31590fSapb#     if MAKEVERBOSE is set to 4 then the shell prints each command
933e31590fSapb#     (prefixed with "+").
943e31590fSapb#
953e31590fSapb# So the resulting output can look like this:
963e31590fSapb#
97b56cbda8Sapb#	--- _params ---
983e31590fSapb#	+ echo 'printf "%20s = '\''%-s'\''\n" BSDOBJDIR /usr/obj'
993e31590fSapb#	printf "%20s = '%-s'\n" BSDOBJDIR /usr/obj
1003e31590fSapb#	+ printf '%20s = '\''%-s'\''\n' BSDOBJDIR /usr/obj
1013e31590fSapb#	           BSDOBJDIR = '/usr/obj'
1023e31590fSapb#	+ echo 'printf "%20s = '\''%-s'\''\n" BSDSRCDIR /usr/src'
1033e31590fSapb#	printf "%20s = '%-s'\n" BSDSRCDIR /usr/src
1043e31590fSapb#	+ printf '%20s = '\''%-s'\''\n' BSDSRCDIR /usr/src
1053e31590fSapb#	           BSDSRCDIR = '/usr/src'
1063e31590fSapb#	[...]
1073e31590fSapb#
1083e31590fSapb# where what we want is just this:
1093e31590fSapb#
1103e31590fSapb#	           BSDOBJDIR = '/usr/obj'
1113e31590fSapb#	           BSDSRCDIR = '/usr/src'
1123e31590fSapb#	           [...]
1133e31590fSapb#
114b56cbda8Sapb# The shell redirections in ${PRINT_PARAMS} ensure that the unwanted
115b56cbda8Sapb# noise is discarded (via ">/dev/null"), while the desired information
116b56cbda8Sapb# ends up on the subshell's stdout (via ">&3" and "3>&1").  The value
117b56cbda8Sapb# of _params_redirect is passed in the environment instead of on the
118b56cbda8Sapb# command line, to prevent it from appearing in MAKEFLAGS (which would
119b56cbda8Sapb# appear in the output).
1203e31590fSapb#
121b56cbda8SapbPRINT_PARAMS:=	(_params_redirect='>&3' ${MAKE} -f ${.PARSEDIR:Q}/${.PARSEFILE:Q} _params 3>&1 >/dev/null)
122