Makefile.params revision 1.4
1#	$NetBSD: Makefile.params,v 1.4 2013/10/30 15:15:12 apb Exp $
2#
3# Makefile fragment for printing build parameters.
4#
5# Public variables:
6#	RELEASEVARS
7#		List of variables whose value should be printed.
8#
9#	PRINT_PARAMS
10#		A command to print the desired variables and values
11#		to stdout, without any additional debugging information.
12#		Values are printed as single-quoted strings, with
13#		embedded quotes and newlines escaped in a way that's
14#		acceptable to sh(1).  Undefined values are printed
15#		as "(undefined)" (without quotation marks).
16#
17# Internal targets:
18# 	_params:
19#		Prints the names and values of all the variables
20#		listed in ${RELEASEVARS}.  The desired results may be
21#		redirected somewhere other than stdout, for example by
22#		setting _params_redirect='>&3'.	 stdout and stderr may
23#		contain unwanted debugging information, from make and
24#		the shell.
25#
26# Internal variables:
27#	_params_redirect:
28#		If set, this should be a shell redirection specification, such
29#		as '>&3', controlling where the output from "make _params" will
30#		be sent.
31#
32# Example:
33#	. ${NETBSDSRCDIR}/etc/Makefile.params
34#	show-params: .MAKE .PHONY # print params to stdout
35#		@${PRINT_PARAMS}
36#
37
38RELEASEVARS=	BSDOBJDIR BSDSRCDIR BUILDID \
39		DESTDIR DISTRIBVER EXTERNAL_TOOLCHAIN HAVE_GCC HAVE_GDB \
40		HAVE_LLVM HAVE_PCC INSTALLWORLDDIR \
41		KERNARCHDIR KERNCONFDIR KERNOBJDIR KERNSRCDIR \
42		MACHINE MACHINE_ARCH MAKE MAKECONF MAKEFLAGS \
43		MAKEOBJDIR MAKEOBJDIRPREFIX MAKEVERBOSE \
44		MKATF MKBFD MKBINUTILS MKCATPAGES \
45		MKCRYPTO MKCRYPTO_RC5 MKCVS \
46		MKDEBUG MKDEBUGLIB MKDOC MKDTRACE MKDYNAMICROOT \
47		MKGCC MKGCCCMDS MKGDB \
48		MKHESIOD MKHTML MKIEEEFP MKINET6 MKINFO MKIPFILTER \
49		MKKERBEROS MKKYUA MKLDAP MKLINKLIB MKLINT MKLLVM \
50		MKMAN MKMANZ MKMDNS MKNLS MKNPF MKOBJ MKOBJDIRS \
51		MKPAM MKPCC MKPF MKPIC MKPICINSTALL MKPICLIB MKPOSTFIX \
52		MKPROFILE \
53		MKSHARE MKSKEY MKSOFTFLOAT MKSTATICLIB \
54		MKUNPRIVED MKUPDATE MKX11 MKYP \
55		NBUILDJOBS NETBSDSRCDIR \
56		NOCLEANDIR NODISTRIBDIRS NOINCLUDES \
57		OBJMACHINE \
58		RELEASEDIR RELEASEMACHINEDIR TOOLCHAIN_MISSING TOOLDIR \
59		USE_HESIOD USE_INET6 USE_JEMALLOC USE_KERBEROS USE_LDAP \
60		USE_PAM USE_SKEY USE_YP \
61		USETOOLS USR_OBJMACHINE \
62		X11SRCDIR X11FLAVOUR
63
64_params_redirect?= # empty
65
66_params: .PHONY
67.for var in ${RELEASEVARS}
68.if defined(${var})
69	@printf "%20s = '%-s'\n" ${var} ${${var}:C/'/'\\\\''/gW:Q} \
70	    ${_params_redirect}
71.else
72	@printf >&3 "%20s = (undefined)\n" ${var} \
73	    ${_params_redirect}
74.endif
75.endfor
76
77# PRINT_PARAMS:
78#
79# The output from the "make _params" can include the following types of
80# unwanted lines:
81#
82#     make -j prints "--- _params ---";
83#
84#     if MAKEVERBOSE is set to 3 or more then make prints each "printf"
85#     command in addition to executing it;
86#
87#     if MAKEVERBOSE is set to 4 then the shell prints each command
88#     (prefixed with "+").
89#
90# So the resulting output can look like this:
91#
92#	--- _params ---
93#	+ echo 'printf "%20s = '\''%-s'\''\n" BSDOBJDIR /usr/obj'
94#	printf "%20s = '%-s'\n" BSDOBJDIR /usr/obj
95#	+ printf '%20s = '\''%-s'\''\n' BSDOBJDIR /usr/obj
96#	           BSDOBJDIR = '/usr/obj'
97#	+ echo 'printf "%20s = '\''%-s'\''\n" BSDSRCDIR /usr/src'
98#	printf "%20s = '%-s'\n" BSDSRCDIR /usr/src
99#	+ printf '%20s = '\''%-s'\''\n' BSDSRCDIR /usr/src
100#	           BSDSRCDIR = '/usr/src'
101#	[...]
102#
103# where what we want is just this:
104#
105#	           BSDOBJDIR = '/usr/obj'
106#	           BSDSRCDIR = '/usr/src'
107#	           [...]
108#
109# The shell redirections in ${PRINT_PARAMS} ensure that the unwanted
110# noise is discarded (via ">/dev/null"), while the desired information
111# ends up on the subshell's stdout (via ">&3" and "3>&1").  The value
112# of _params_redirect is passed in the environment instead of on the
113# command line, to prevent it from appearing in MAKEFLAGS (which would
114# appear in the output).
115#
116PRINT_PARAMS:=	(_params_redirect='>&3' ${MAKE} -f ${.PARSEDIR:Q}/${.PARSEFILE:Q} _params 3>&1 >/dev/null)
117