[BACK]Return to Makefile.params CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / etc

File: [cvs.NetBSD.org] / src / etc / Makefile.params (download)

Revision 1.1, Mon Dec 3 13:53:28 2012 UTC (11 years, 4 months ago) by apb
Branch: MAIN
CVS Tags: yamt-pagecache-base8, yamt-pagecache-base7
Branch point for: yamt-pagecache, tls-maxphys

Add src/etc/Makefile.params, containing the definition of the
RELEASEVARS variable, and commands related to printing the values of
the variables whose names are in RELEASEVARS.

Add an awk script to remove noise printed by "make -j" or high levels
of MAKEVERBOSE, so we get only the variables names and values.  The
values are escaped so that variables containing embedded newlines,
quotation marks, and backslashes, are passed through safely.

Adapt src/etc/Makefile and src/Makefile to use the new ${PRINT_PARAMS}
command defined in src/etc/Makefile.params.

Now ${DESTDIR}/etc/release and the params file in the top-level
.OBJDIR should never contain unwanted noise, even after a build with
MAKEVERBOSE=4.

#	$NetBSD: Makefile.params,v 1.1 2012/12/03 13:53:28 apb Exp $
#
# Makefile fragment for printing build parameters.
#
# Public variables:
#	RELEASEVARS
#		List of variables whose value should be printed.
#
#	PRINT_PARAMS
#		A command to print the desired variables and values.
#		Values are printed as single-quoted strings, with
#		embedded quotes and newlines escaped in a way that's
#		acceptable to sh(1).  Undefined values are printed
#		as "(undefined)" (without quotation marks).
#
# Internal targets:
# 	_params:
# 		Prints the names and values of all the variables
# 		listed in ${RELEASEVARS}.  The output may be intermixed
# 		with debugging information, which can be removed by the
# 		${_PARAMS_POSTPROCESS} command.
#
# Internal variables:
#	_PARAMS_POSTPROCESS
#		A command to postprocess the output from "make _params",
#		to remove debugging information and other noise.
#
# Example:
#	. ${NETBSDSRCDIR}/etc/Makefile.params
#	show-params: .MAKE .PHONY # print params to stdout
#		@${PRINT_PARAMS}
#

.include <bsd.sys.mk>		# for TOOL_AWK, ...

RELEASEVARS=	BSDOBJDIR BSDSRCDIR BUILDID \
		DESTDIR DISTRIBVER EXTERNAL_TOOLCHAIN HAVE_GCC HAVE_GDB \
		INSTALLWORLDDIR \
		KERNARCHDIR KERNCONFDIR KERNOBJDIR KERNSRCDIR \
		MACHINE MACHINE_ARCH MAKE MAKECONF MAKEFLAGS \
		MAKEOBJDIR MAKEOBJDIRPREFIX MAKEVERBOSE \
		MKBFD MKBINUTILS MKCATPAGES \
		MKCRYPTO MKCRYPTO_RC5 MKCVS \
		MKDEBUG MKDEBUGLIB MKDOC MKDTRACE MKDYNAMICROOT \
		MKGCC MKGCCCMDS MKGDB \
		MKHESIOD MKHTML MKIEEEFP MKINET6 MKINFO MKIPFILTER \
		MKKERBEROS MKLDAP MKLINKLIB MKLINT \
		MKMAN MKMANZ MKMDNS MKNLS MKNPF MKOBJ MKOBJDIRS \
		MKPAM MKPF MKPIC MKPICINSTALL MKPICLIB MKPOSTFIX MKPROFILE \
		MKSHARE MKSKEY MKSOFTFLOAT MKSTATICLIB \
		MKUNPRIVED MKUPDATE MKX11 MKYP \
		NBUILDJOBS NETBSDSRCDIR \
		NOCLEANDIR NODISTRIBDIRS NOINCLUDES \
		OBJMACHINE \
		RELEASEDIR RELEASEMACHINEDIR TOOLCHAIN_MISSING TOOLDIR \
		USE_HESIOD USE_INET6 USE_JEMALLOC USE_KERBEROS USE_LDAP \
		USE_PAM USE_SKEY USE_YP \
		USETOOLS USR_OBJMACHINE \
		X11SRCDIR X11FLAVOUR

PRINT_PARAMS= (cd ${.CURDIR}; ${MAKE} _params) | ${_PARAMS_POSTPROCESS}

_params: .PHONY
.for var in ${RELEASEVARS}
.if defined(${var})
	@printf "%20s = '%-s'\n" ${var} ${${var}:C/'/'\\\\''/gW:Q}
.else
	@printf "%20s = (undefined)\n" ${var}
.endif
.endfor

# _PARAMS_POSTPROCESS:
#
# The output from the "make _params" can include the following types of
# unwanted lines:
#
#     make -j prints "--- params ---";
#
#     if MAKEVERBOSE is set to 3 or more then make prints each "printf"
#     command in addition to executing it;
#
#     if MAKEVERBOSE is set to 4 then the shell prints each command
#     (prefixed with "+").
#
# So the resulting output can look like this:
#
#	--- params ---
#	+ echo 'printf "%20s = '\''%-s'\''\n" BSDOBJDIR /usr/obj'
#	printf "%20s = '%-s'\n" BSDOBJDIR /usr/obj
#	+ printf '%20s = '\''%-s'\''\n' BSDOBJDIR /usr/obj
#	           BSDOBJDIR = '/usr/obj'
#	+ echo 'printf "%20s = '\''%-s'\''\n" BSDSRCDIR /usr/src'
#	printf "%20s = '%-s'\n" BSDSRCDIR /usr/src
#	+ printf '%20s = '\''%-s'\''\n' BSDSRCDIR /usr/src
#	           BSDSRCDIR = '/usr/src'
#	[...]
#
# where what we want is just this:
#
#	           BSDOBJDIR = '/usr/obj'
#	           BSDSRCDIR = '/usr/src'
#	           [...]
#
# The awk program in ${PARAMS_POSTPROCESS} removes the unwanted noise,
# taking care with variables whose values contain embedded newlines
# (assuming that embedded newlines appear only inside single quotes).
#
_PARAMS_POSTPROCESS= ${TOOL_AWK} '\
	BEGIN { single_quote = "'\''"; \
		NORMAL = 0; \
		SKIP_HEADING = 1; \
		SKIP_MULTILINE = 2; \
		PRINT_MULTILINE = 3; \
		state = SKIP_HEADING; \
	} \
	function quotes_balanced_p(line) { \
		return (line ~ /^([^\\"'\'']|\\.|'\''[^'\'']*'\''|"(\\.|[^\\"])*")*$$/); \
	} \
	state == SKIP_MULTILINE { \
		if (quotes_balanced_p(single_quote $$0)) { \
			state = NORMAL; \
		} \
		next; \
	} \
	state == PRINT_MULTILINE { \
		if (quotes_balanced_p(single_quote $$0)) { \
			state = NORMAL; \
		} \
		print; next; \
	} \
	state == SKIP_HEADING && $$0 ~ /^--- .* ---$$/ { next; } \
	state == SKIP_HEADING && $$0 ~ / ===> / { next; } \
	/^(\+ )?(echo ["'\''])?printf.* = / { \
		if (quotes_balanced_p($$0)) { \
			state = NORMAL; \
		} else { \
			state = SKIP_MULTILINE; \
		} \
		next; \
	} \
	// { \
		if (quotes_balanced_p($$0)) { \
			state = NORMAL; \
		} else { \
			state = PRINT_MULTILINE; \
		} \
		print; next; \
	} \
	'