Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/etc Instead of stupid postprocessor tricks, use redirect tricks
details: https://anonhg.NetBSD.org/src/rev/6077521506da
branches: trunk
changeset: 791007:6077521506da
user: apb <apb%NetBSD.org@localhost>
date: Wed Oct 30 15:15:12 2013 +0000
description:
Instead of stupid postprocessor tricks, use redirect tricks
to ensure that the output from ${PRINT_PARAMS} contains only
the desired information without any debugging noise.
diffstat:
etc/Makefile.params | 90 ++++++++++++++++------------------------------------
1 files changed, 28 insertions(+), 62 deletions(-)
diffs (151 lines):
diff -r 277d505e39a3 -r 6077521506da etc/Makefile.params
--- a/etc/Makefile.params Wed Oct 30 14:25:47 2013 +0000
+++ b/etc/Makefile.params Wed Oct 30 15:15:12 2013 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.params,v 1.3 2013/10/18 11:42:59 njoly Exp $
+# $NetBSD: Makefile.params,v 1.4 2013/10/30 15:15:12 apb Exp $
#
# Makefile fragment for printing build parameters.
#
@@ -7,7 +7,8 @@
# List of variables whose value should be printed.
#
# PRINT_PARAMS
-# A command to print the desired variables and values.
+# A command to print the desired variables and values
+# to stdout, without any additional debugging information.
# 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
@@ -15,15 +16,18 @@
#
# 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.
+# Prints the names and values of all the variables
+# listed in ${RELEASEVARS}. The desired results may be
+# redirected somewhere other than stdout, for example by
+# setting _params_redirect='>&3'. stdout and stderr may
+# contain unwanted debugging information, from make and
+# the shell.
#
# Internal variables:
-# _PARAMS_POSTPROCESS
-# A command to postprocess the output from "make _params",
-# to remove debugging information and other noise.
+# _params_redirect:
+# If set, this should be a shell redirection specification, such
+# as '>&3', controlling where the output from "make _params" will
+# be sent.
#
# Example:
# . ${NETBSDSRCDIR}/etc/Makefile.params
@@ -31,8 +35,6 @@
# @${PRINT_PARAMS}
#
-.include <bsd.sys.mk> # for TOOL_AWK, ...
-
RELEASEVARS= BSDOBJDIR BSDSRCDIR BUILDID \
DESTDIR DISTRIBVER EXTERNAL_TOOLCHAIN HAVE_GCC HAVE_GDB \
HAVE_LLVM HAVE_PCC INSTALLWORLDDIR \
@@ -59,23 +61,25 @@
USETOOLS USR_OBJMACHINE \
X11SRCDIR X11FLAVOUR
-PRINT_PARAMS= (cd ${.CURDIR}; ${MAKE} _params) | ${_PARAMS_POSTPROCESS}
+_params_redirect?= # empty
_params: .PHONY
.for var in ${RELEASEVARS}
.if defined(${var})
- @printf "%20s = '%-s'\n" ${var} ${${var}:C/'/'\\\\''/gW:Q}
+ @printf "%20s = '%-s'\n" ${var} ${${var}:C/'/'\\\\''/gW:Q} \
+ ${_params_redirect}
.else
- @printf "%20s = (undefined)\n" ${var}
+ @printf >&3 "%20s = (undefined)\n" ${var} \
+ ${_params_redirect}
.endif
.endfor
-# _PARAMS_POSTPROCESS:
+# PRINT_PARAMS:
#
# The output from the "make _params" can include the following types of
# unwanted lines:
#
-# make -j prints "--- params ---";
+# make -j prints "--- _params ---";
#
# if MAKEVERBOSE is set to 3 or more then make prints each "printf"
# command in addition to executing it;
@@ -85,7 +89,7 @@
#
# So the resulting output can look like this:
#
-# --- params ---
+# --- _params ---
# + echo 'printf "%20s = '\''%-s'\''\n" BSDOBJDIR /usr/obj'
# printf "%20s = '%-s'\n" BSDOBJDIR /usr/obj
# + printf '%20s = '\''%-s'\''\n' BSDOBJDIR /usr/obj
@@ -102,49 +106,11 @@
# 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).
+# The shell redirections in ${PRINT_PARAMS} ensure that the unwanted
+# noise is discarded (via ">/dev/null"), while the desired information
+# ends up on the subshell's stdout (via ">&3" and "3>&1"). The value
+# of _params_redirect is passed in the environment instead of on the
+# command line, to prevent it from appearing in MAKEFLAGS (which would
+# appear in the output).
#
-_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; \
- } \
- '
+PRINT_PARAMS:= (_params_redirect='>&3' ${MAKE} -f ${.PARSEDIR:Q}/${.PARSEFILE:Q} _params 3>&1 >/dev/null)
Home |
Main Index |
Thread Index |
Old Index