Makefile.params revision 1.3
1#	$NetBSD: Makefile.params,v 1.3 2013/10/18 11:42:59 njoly 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		HAVE_LLVM HAVE_PCC INSTALLWORLDDIR \
39		KERNARCHDIR KERNCONFDIR KERNOBJDIR KERNSRCDIR \
40		MACHINE MACHINE_ARCH MAKE MAKECONF MAKEFLAGS \
41		MAKEOBJDIR MAKEOBJDIRPREFIX MAKEVERBOSE \
42		MKATF 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 MKKYUA MKLDAP MKLINKLIB MKLINT MKLLVM \
48		MKMAN MKMANZ MKMDNS MKNLS MKNPF MKOBJ MKOBJDIRS \
49		MKPAM MKPCC MKPF MKPIC MKPICINSTALL MKPICLIB MKPOSTFIX \
50		MKPROFILE \
51		MKSHARE MKSKEY MKSOFTFLOAT MKSTATICLIB \
52		MKUNPRIVED MKUPDATE MKX11 MKYP \
53		NBUILDJOBS NETBSDSRCDIR \
54		NOCLEANDIR NODISTRIBDIRS NOINCLUDES \
55		OBJMACHINE \
56		RELEASEDIR RELEASEMACHINEDIR TOOLCHAIN_MISSING TOOLDIR \
57		USE_HESIOD USE_INET6 USE_JEMALLOC USE_KERBEROS USE_LDAP \
58		USE_PAM USE_SKEY USE_YP \
59		USETOOLS USR_OBJMACHINE \
60		X11SRCDIR X11FLAVOUR
61
62PRINT_PARAMS= (cd ${.CURDIR}; ${MAKE} _params) | ${_PARAMS_POSTPROCESS}
63
64_params: .PHONY
65.for var in ${RELEASEVARS}
66.if defined(${var})
67	@printf "%20s = '%-s'\n" ${var} ${${var}:C/'/'\\\\''/gW:Q}
68.else
69	@printf "%20s = (undefined)\n" ${var}
70.endif
71.endfor
72
73# _PARAMS_POSTPROCESS:
74#
75# The output from the "make _params" can include the following types of
76# unwanted lines:
77#
78#     make -j prints "--- params ---";
79#
80#     if MAKEVERBOSE is set to 3 or more then make prints each "printf"
81#     command in addition to executing it;
82#
83#     if MAKEVERBOSE is set to 4 then the shell prints each command
84#     (prefixed with "+").
85#
86# So the resulting output can look like this:
87#
88#	--- params ---
89#	+ echo 'printf "%20s = '\''%-s'\''\n" BSDOBJDIR /usr/obj'
90#	printf "%20s = '%-s'\n" BSDOBJDIR /usr/obj
91#	+ printf '%20s = '\''%-s'\''\n' BSDOBJDIR /usr/obj
92#	           BSDOBJDIR = '/usr/obj'
93#	+ echo 'printf "%20s = '\''%-s'\''\n" BSDSRCDIR /usr/src'
94#	printf "%20s = '%-s'\n" BSDSRCDIR /usr/src
95#	+ printf '%20s = '\''%-s'\''\n' BSDSRCDIR /usr/src
96#	           BSDSRCDIR = '/usr/src'
97#	[...]
98#
99# where what we want is just this:
100#
101#	           BSDOBJDIR = '/usr/obj'
102#	           BSDSRCDIR = '/usr/src'
103#	           [...]
104#
105# The awk program in ${PARAMS_POSTPROCESS} removes the unwanted noise,
106# taking care with variables whose values contain embedded newlines
107# (assuming that embedded newlines appear only inside single quotes).
108#
109_PARAMS_POSTPROCESS= ${TOOL_AWK} '\
110	BEGIN { single_quote = "'\''"; \
111		NORMAL = 0; \
112		SKIP_HEADING = 1; \
113		SKIP_MULTILINE = 2; \
114		PRINT_MULTILINE = 3; \
115		state = SKIP_HEADING; \
116	} \
117	function quotes_balanced_p(line) { \
118		return (line ~ /^([^\\"'\'']|\\.|'\''[^'\'']*'\''|"(\\.|[^\\"])*")*$$/); \
119	} \
120	state == SKIP_MULTILINE { \
121		if (quotes_balanced_p(single_quote $$0)) { \
122			state = NORMAL; \
123		} \
124		next; \
125	} \
126	state == PRINT_MULTILINE { \
127		if (quotes_balanced_p(single_quote $$0)) { \
128			state = NORMAL; \
129		} \
130		print; next; \
131	} \
132	state == SKIP_HEADING && $$0 ~ /^--- .* ---$$/ { next; } \
133	state == SKIP_HEADING && $$0 ~ / ===> / { next; } \
134	/^(\+ )?(echo ["'\''])?printf.* = / { \
135		if (quotes_balanced_p($$0)) { \
136			state = NORMAL; \
137		} else { \
138			state = SKIP_MULTILINE; \
139		} \
140		next; \
141	} \
142	// { \
143		if (quotes_balanced_p($$0)) { \
144			state = NORMAL; \
145		} else { \
146			state = PRINT_MULTILINE; \
147		} \
148		print; next; \
149	} \
150	'
151