Makefile.params revision 1.11
11.11Sozaki#	$NetBSD: Makefile.params,v 1.11 2014/03/25 09:52:55 ozaki-r 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.10SapbRELEASEVARS=	BSDOBJDIR BSDSRCDIR BUILDID BUILDSEED \
411.1Sapb		DESTDIR DISTRIBVER EXTERNAL_TOOLCHAIN HAVE_GCC HAVE_GDB \
421.3Snjoly		HAVE_LLVM HAVE_PCC INSTALLWORLDDIR \
431.1Sapb		KERNARCHDIR KERNCONFDIR KERNOBJDIR KERNSRCDIR \
441.1Sapb		MACHINE MACHINE_ARCH MAKE MAKECONF MAKEFLAGS \
451.1Sapb		MAKEOBJDIR MAKEOBJDIRPREFIX MAKEVERBOSE \
461.9Sapb		MKARZERO MKATF MKBFD MKBINUTILS MKCATPAGES \
471.11Sozaki		MKCRYPTO MKCRYPTO_RC5 MKCTF MKCVS \
481.1Sapb		MKDEBUG MKDEBUGLIB MKDOC MKDTRACE MKDYNAMICROOT \
491.1Sapb		MKGCC MKGCCCMDS MKGDB \
501.1Sapb		MKHESIOD MKHTML MKIEEEFP MKINET6 MKINFO MKIPFILTER \
511.3Snjoly		MKKERBEROS MKKYUA MKLDAP MKLINKLIB MKLINT MKLLVM \
521.1Sapb		MKMAN MKMANZ MKMDNS MKNLS MKNPF MKOBJ MKOBJDIRS \
531.3Snjoly		MKPAM MKPCC MKPF MKPIC MKPICINSTALL MKPICLIB MKPOSTFIX \
541.9Sapb		MKPROFILE MKREPRO \
551.1Sapb		MKSHARE MKSKEY MKSOFTFLOAT MKSTATICLIB \
561.1Sapb		MKUNPRIVED MKUPDATE MKX11 MKYP \
571.1Sapb		NBUILDJOBS NETBSDSRCDIR \
581.1Sapb		NOCLEANDIR NODISTRIBDIRS NOINCLUDES \
591.1Sapb		OBJMACHINE \
601.1Sapb		RELEASEDIR RELEASEMACHINEDIR TOOLCHAIN_MISSING TOOLDIR \
611.1Sapb		USE_HESIOD USE_INET6 USE_JEMALLOC USE_KERBEROS USE_LDAP \
621.1Sapb		USE_PAM USE_SKEY USE_YP \
631.1Sapb		USETOOLS USR_OBJMACHINE \
641.1Sapb		X11SRCDIR X11FLAVOUR
651.1Sapb
661.5Sapb
671.5Sapb#
681.5Sapb# Duplicate the DISTRIBVER setting from src/etc/Makefile.
691.5Sapb#
701.5Sapb.ifndef DISTRIBVER
711.7SapbDISTRIBVER!=	${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh
721.5Sapb.endif
731.5Sapb
741.5Sapb#
751.5Sapb# _params does the printing.
761.5Sapb#
771.4Sapb_params_redirect?= # empty
781.1Sapb
791.1Sapb_params: .PHONY
801.1Sapb.for var in ${RELEASEVARS}
811.1Sapb.if defined(${var})
821.4Sapb	@printf "%20s = '%-s'\n" ${var} ${${var}:C/'/'\\\\''/gW:Q} \
831.4Sapb	    ${_params_redirect}
841.1Sapb.else
851.5Sapb	@printf "%20s = (undefined)\n" ${var} \
861.4Sapb	    ${_params_redirect}
871.1Sapb.endif
881.1Sapb.endfor
891.1Sapb
901.4Sapb# PRINT_PARAMS:
911.1Sapb#
921.1Sapb# The output from the "make _params" can include the following types of
931.1Sapb# unwanted lines:
941.1Sapb#
951.4Sapb#     make -j prints "--- _params ---";
961.1Sapb#
971.1Sapb#     if MAKEVERBOSE is set to 3 or more then make prints each "printf"
981.1Sapb#     command in addition to executing it;
991.1Sapb#
1001.1Sapb#     if MAKEVERBOSE is set to 4 then the shell prints each command
1011.1Sapb#     (prefixed with "+").
1021.1Sapb#
1031.1Sapb# So the resulting output can look like this:
1041.1Sapb#
1051.4Sapb#	--- _params ---
1061.1Sapb#	+ echo 'printf "%20s = '\''%-s'\''\n" BSDOBJDIR /usr/obj'
1071.1Sapb#	printf "%20s = '%-s'\n" BSDOBJDIR /usr/obj
1081.1Sapb#	+ printf '%20s = '\''%-s'\''\n' BSDOBJDIR /usr/obj
1091.1Sapb#	           BSDOBJDIR = '/usr/obj'
1101.1Sapb#	+ echo 'printf "%20s = '\''%-s'\''\n" BSDSRCDIR /usr/src'
1111.1Sapb#	printf "%20s = '%-s'\n" BSDSRCDIR /usr/src
1121.1Sapb#	+ printf '%20s = '\''%-s'\''\n' BSDSRCDIR /usr/src
1131.1Sapb#	           BSDSRCDIR = '/usr/src'
1141.1Sapb#	[...]
1151.1Sapb#
1161.1Sapb# where what we want is just this:
1171.1Sapb#
1181.1Sapb#	           BSDOBJDIR = '/usr/obj'
1191.1Sapb#	           BSDSRCDIR = '/usr/src'
1201.1Sapb#	           [...]
1211.1Sapb#
1221.4Sapb# The shell redirections in ${PRINT_PARAMS} ensure that the unwanted
1231.4Sapb# noise is discarded (via ">/dev/null"), while the desired information
1241.4Sapb# ends up on the subshell's stdout (via ">&3" and "3>&1").  The value
1251.4Sapb# of _params_redirect is passed in the environment instead of on the
1261.4Sapb# command line, to prevent it from appearing in MAKEFLAGS (which would
1271.4Sapb# appear in the output).
1281.4Sapb#
1291.4SapbPRINT_PARAMS:=	(_params_redirect='>&3' ${MAKE} -f ${.PARSEDIR:Q}/${.PARSEFILE:Q} _params 3>&1 >/dev/null)
130