Makefile.params revision 1.18
1#	$NetBSD: Makefile.params,v 1.18 2018/07/05 15:52:27 martin 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
38.include <bsd.own.mk>	# for some variables
39
40RELEASEVARS=	DISTRIBVER EXTERNAL_TOOLCHAIN HAVE_GCC HAVE_GDB \
41		HAVE_LLVM HAVE_PCC INSTALLWORLDDIR \
42		MACHINE MACHINE_ARCH MAKECONF \
43		MAKEOBJDIR MAKEOBJDIRPREFIX MAKEVERBOSE \
44		NOCLEANDIR NODISTRIBDIRS NOINCLUDES \
45		TOOLCHAIN_MISSING \
46		USE_HESIOD USE_INET6 USE_JEMALLOC USE_KERBEROS USE_LDAP \
47		USE_PAM USE_SKEY USE_YP \
48		USETOOLS
49
50.if ${MKREPRO:Uno} != "yes"
51RELEASEVARS+= 	BSDOBJDIR BSDSRCDIR BUILDID BUILDINFO BUILDSEED \
52		DESTDIR KERNARCHDIR KERNCONFDIR KERNOBJDIR KERNSRCDIR MAKE \
53		MAKEFLAGS NBUILDJOBS NETBSDSRCDIR OBJMACHINE OBJMACHINE_ARCH \
54		RELEASEDIR RELEASEMACHINEDIR TOOLDIR USR_OBJMACHINE X11SRCDIR
55.else
56		# temporary debugging for MKREPRO builds
57RELEASEVARS+=	BUILDSEED _CXXSEED __BUILDSEED
58.endif
59
60RELEASEVARS+= ${_MKVARS.yes} ${_MKVARS.no}
61
62#
63# Duplicate the DISTRIBVER setting from src/etc/Makefile.
64#
65.ifndef DISTRIBVER
66DISTRIBVER!=	${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh
67.endif
68
69#
70# _params does the printing.
71#
72_params_redirect?= # empty
73
74_params: .PHONY
75.for var in ${RELEASEVARS:O}
76.if defined(${var})
77	@printf "%20s = '%-s'\n" ${var} ${${var}:C/'/'\\\\''/gW:Q} \
78	    ${_params_redirect}
79.else
80	@printf "%20s = (undefined)\n" ${var} \
81	    ${_params_redirect}
82.endif
83.endfor
84
85# PRINT_PARAMS:
86#
87# The output from the "make _params" can include the following types of
88# unwanted lines:
89#
90#     make -j prints "--- _params ---";
91#
92#     if MAKEVERBOSE is set to 3 or more then make prints each "printf"
93#     command in addition to executing it;
94#
95#     if MAKEVERBOSE is set to 4 then the shell prints each command
96#     (prefixed with "+").
97#
98# So the resulting output can look like this:
99#
100#	--- _params ---
101#	+ echo 'printf "%20s = '\''%-s'\''\n" BSDOBJDIR /usr/obj'
102#	printf "%20s = '%-s'\n" BSDOBJDIR /usr/obj
103#	+ printf '%20s = '\''%-s'\''\n' BSDOBJDIR /usr/obj
104#	           BSDOBJDIR = '/usr/obj'
105#	+ echo 'printf "%20s = '\''%-s'\''\n" BSDSRCDIR /usr/src'
106#	printf "%20s = '%-s'\n" BSDSRCDIR /usr/src
107#	+ printf '%20s = '\''%-s'\''\n' BSDSRCDIR /usr/src
108#	           BSDSRCDIR = '/usr/src'
109#	[...]
110#
111# where what we want is just this:
112#
113#	           BSDOBJDIR = '/usr/obj'
114#	           BSDSRCDIR = '/usr/src'
115#	           [...]
116#
117# The shell redirections in ${PRINT_PARAMS} ensure that the unwanted
118# noise is discarded (via ">/dev/null"), while the desired information
119# ends up on the subshell's stdout (via ">&3" and "3>&1").  The value
120# of _params_redirect is passed in the environment instead of on the
121# command line, to prevent it from appearing in MAKEFLAGS (which would
122# appear in the output).
123#
124PRINT_PARAMS:=	(_params_redirect='>&3' ${MAKE} -f ${.PARSEDIR:Q}/${.PARSEFILE:Q} _params 3>&1 >/dev/null)
125