Makefile.params revision 1.1.2.2
1#	$NetBSD: Makefile.params,v 1.1.2.2 2013/01/16 05:26:13 yamt 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#		Values are printed as single-quoted strings, with
12#		embedded quotes and newlines escaped in a way that's
13#		acceptable to sh(1).  Undefined values are printed
14#		as "(undefined)" (without quotation marks).
15#
16# Internal targets:
17# 	_params:
18# 		Prints the names and values of all the variables
19# 		listed in ${RELEASEVARS}.  The output may be intermixed
20# 		with debugging information, which can be removed by the
21# 		${_PARAMS_POSTPROCESS} command.
22#
23# Internal variables:
24#	_PARAMS_POSTPROCESS
25#		A command to postprocess the output from "make _params",
26#		to remove debugging information and other noise.
27#
28# Example:
29#	. ${NETBSDSRCDIR}/etc/Makefile.params
30#	show-params: .MAKE .PHONY # print params to stdout
31#		@${PRINT_PARAMS}
32#
33
34.include <bsd.sys.mk>		# for TOOL_AWK, ...
35
36RELEASEVARS=	BSDOBJDIR BSDSRCDIR BUILDID \
37		DESTDIR DISTRIBVER EXTERNAL_TOOLCHAIN HAVE_GCC HAVE_GDB \
38		INSTALLWORLDDIR \
39		KERNARCHDIR KERNCONFDIR KERNOBJDIR KERNSRCDIR \
40		MACHINE MACHINE_ARCH MAKE MAKECONF MAKEFLAGS \
41		MAKEOBJDIR MAKEOBJDIRPREFIX MAKEVERBOSE \
42		MKBFD MKBINUTILS MKCATPAGES \
43		MKCRYPTO MKCRYPTO_RC5 MKCVS \
44		MKDEBUG MKDEBUGLIB MKDOC MKDTRACE MKDYNAMICROOT \
45		MKGCC MKGCCCMDS MKGDB \
46		MKHESIOD MKHTML MKIEEEFP MKINET6 MKINFO MKIPFILTER \
47		MKKERBEROS MKLDAP MKLINKLIB MKLINT \
48		MKMAN MKMANZ MKMDNS MKNLS MKNPF MKOBJ MKOBJDIRS \
49		MKPAM MKPF MKPIC MKPICINSTALL MKPICLIB MKPOSTFIX MKPROFILE \
50		MKSHARE MKSKEY MKSOFTFLOAT MKSTATICLIB \
51		MKUNPRIVED MKUPDATE MKX11 MKYP \
52		NBUILDJOBS NETBSDSRCDIR \
53		NOCLEANDIR NODISTRIBDIRS NOINCLUDES \
54		OBJMACHINE \
55		RELEASEDIR RELEASEMACHINEDIR TOOLCHAIN_MISSING TOOLDIR \
56		USE_HESIOD USE_INET6 USE_JEMALLOC USE_KERBEROS USE_LDAP \
57		USE_PAM USE_SKEY USE_YP \
58		USETOOLS USR_OBJMACHINE \
59		X11SRCDIR X11FLAVOUR
60
61PRINT_PARAMS= (cd ${.CURDIR}; ${MAKE} _params) | ${_PARAMS_POSTPROCESS}
62
63_params: .PHONY
64.for var in ${RELEASEVARS}
65.if defined(${var})
66	@printf "%20s = '%-s'\n" ${var} ${${var}:C/'/'\\\\''/gW:Q}
67.else
68	@printf "%20s = (undefined)\n" ${var}
69.endif
70.endfor
71
72# _PARAMS_POSTPROCESS:
73#
74# The output from the "make _params" can include the following types of
75# unwanted lines:
76#
77#     make -j prints "--- params ---";
78#
79#     if MAKEVERBOSE is set to 3 or more then make prints each "printf"
80#     command in addition to executing it;
81#
82#     if MAKEVERBOSE is set to 4 then the shell prints each command
83#     (prefixed with "+").
84#
85# So the resulting output can look like this:
86#
87#	--- params ---
88#	+ echo 'printf "%20s = '\''%-s'\''\n" BSDOBJDIR /usr/obj'
89#	printf "%20s = '%-s'\n" BSDOBJDIR /usr/obj
90#	+ printf '%20s = '\''%-s'\''\n' BSDOBJDIR /usr/obj
91#	           BSDOBJDIR = '/usr/obj'
92#	+ echo 'printf "%20s = '\''%-s'\''\n" BSDSRCDIR /usr/src'
93#	printf "%20s = '%-s'\n" BSDSRCDIR /usr/src
94#	+ printf '%20s = '\''%-s'\''\n' BSDSRCDIR /usr/src
95#	           BSDSRCDIR = '/usr/src'
96#	[...]
97#
98# where what we want is just this:
99#
100#	           BSDOBJDIR = '/usr/obj'
101#	           BSDSRCDIR = '/usr/src'
102#	           [...]
103#
104# The awk program in ${PARAMS_POSTPROCESS} removes the unwanted noise,
105# taking care with variables whose values contain embedded newlines
106# (assuming that embedded newlines appear only inside single quotes).
107#
108_PARAMS_POSTPROCESS= ${TOOL_AWK} '\
109	BEGIN { single_quote = "'\''"; \
110		NORMAL = 0; \
111		SKIP_HEADING = 1; \
112		SKIP_MULTILINE = 2; \
113		PRINT_MULTILINE = 3; \
114		state = SKIP_HEADING; \
115	} \
116	function quotes_balanced_p(line) { \
117		return (line ~ /^([^\\"'\'']|\\.|'\''[^'\'']*'\''|"(\\.|[^\\"])*")*$$/); \
118	} \
119	state == SKIP_MULTILINE { \
120		if (quotes_balanced_p(single_quote $$0)) { \
121			state = NORMAL; \
122		} \
123		next; \
124	} \
125	state == PRINT_MULTILINE { \
126		if (quotes_balanced_p(single_quote $$0)) { \
127			state = NORMAL; \
128		} \
129		print; next; \
130	} \
131	state == SKIP_HEADING && $$0 ~ /^--- .* ---$$/ { next; } \
132	state == SKIP_HEADING && $$0 ~ / ===> / { next; } \
133	/^(\+ )?(echo ["'\''])?printf.* = / { \
134		if (quotes_balanced_p($$0)) { \
135			state = NORMAL; \
136		} else { \
137			state = SKIP_MULTILINE; \
138		} \
139		next; \
140	} \
141	// { \
142		if (quotes_balanced_p($$0)) { \
143			state = NORMAL; \
144		} else { \
145			state = PRINT_MULTILINE; \
146		} \
147		print; next; \
148	} \
149	'
150