parselist.awk

- improve comments
- provide a general purpose variable replacement; replace contents of ${FOO}
  with ENVIRON["FOO"].
- deprecate @MACHINE@ and @MACHINE_ARCH@ in favour of using ${MACHINE}
  and ${MACHINE_ARCH} instead
- add errx() function; like err(), but doesn't print the line number
- invoke this script with various variables defined via PARSELISTENV

*/Makefile*
- use PARSELISTENV instead of POPULATEENV, and add variables like DESTDIR
- other minor tweaks

*/list*
- replace @MACHINE@ with ${MACHINE}
This commit is contained in:
lukem 2002-03-14 22:26:08 +00:00
parent 58d564bc8c
commit deffb66504
11 changed files with 99 additions and 73 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.7 2002/03/12 12:44:19 reinoud Exp $
# $NetBSD: Makefile,v 1.8 2002/03/14 22:26:08 lukem Exp $
.include "${.CURDIR}/../../Makefile.inc"
.include <bsd.own.mk>
@ -14,7 +14,7 @@ LISTS= ${.CURDIR}/list ${DISTRIBDIR}/common/list.sysinst
MTREECONF= ${DISTRIBDIR}/common/mtree.common
IMAGEENDIAN= le
MAKEDEVTARGETS= ramdisk
POPULATEENV= PWD_MKDB=${PWD_MKDB:Q}
PARSELISTENV= PWD_MKDB=${PWD_MKDB:Q}
IMAGEDEPENDS= ${CRUNCHBIN} \
disktab.preinstall dot.hdprofile dot.profile termcap.vt100 \
${_SRC_TOP_}/etc/group ${_SRC_TOP_}/etc/master.passwd \

View File

@ -1,10 +1,10 @@
# $NetBSD: Makefile,v 1.15 2002/03/07 23:51:48 lukem Exp $
# $NetBSD: Makefile,v 1.16 2002/03/14 22:26:08 lukem Exp $
.include "${.CURDIR}/../../../Makefile.inc"
.include <bsd.own.mk>
IMAGE= ramdisk.fs
IMAGESIZE= 9000b
IMAGESIZE= 4480k
MAKEFS_FLAGS= -o density=5k
WARNS= 1
@ -14,7 +14,7 @@ LISTS= ${.CURDIR}/list ${DISTRIBDIR}/common/list.sysinst
MTREECONF= ${DISTRIBDIR}/common/mtree.common #${.CURDIR}/mtree.conf
IMAGEENDIAN= le
MAKEDEVTARGETS= minimal
IMAGEDEPENDS+= ${CRUNCHBIN} \
IMAGEDEPENDS= ${CRUNCHBIN} \
disktab.preinstall dot.hdprofile dot.profile \
${.CURDIR}/../src/install.sh ${.CURDIR}/../src/upgrade.sh \
${DESTDIR}/usr/mdec/boot ${DESTDIR}/usr/mdec/bootxx_ffs \
@ -27,7 +27,7 @@ IMAGEDEPENDS+= ${CRUNCHBIN} \
INSTALLNOTES!= cd ${DISTRIBDIR}/notes/alpha && ${MAKE} echomore
IMAGEDEPENDS+= ${INSTALLNOTES}
POPULATEENV+= INSTALLNOTES=${INSTALLNOTES:Q} PWD_MKDB=${PWD_MKDB:Q}
PARSELISTENV= INSTALLNOTES=${INSTALLNOTES:Q} PWD_MKDB=${PWD_MKDB:Q}
realall: ${IMAGE}

View File

@ -1,7 +1,7 @@
# $NetBSD: list,v 1.13 2002/03/07 23:51:48 lukem Exp $
# $NetBSD: list,v 1.14 2002/03/14 22:26:08 lukem Exp $
SRCDIRS bin sbin usr.bin/less usr.bin usr.sbin gnu/usr.bin
SRCDIRS sys/arch/@MACHINE@/stand
SRCDIRS sys/arch/${MACHINE}/stand
PROG bin/cat usr/bin/strings

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.crunch,v 1.3 2002/02/07 11:39:17 lukem Exp $
# $NetBSD: Makefile.crunch,v 1.4 2002/03/14 22:26:09 lukem Exp $
#
# Makefile snippet to build a crunchgen(1)ed binary from the provided lists
#
@ -9,6 +9,18 @@
# CRUNCHBIN name of crunchgen(1)ed binary
# LISTS list file(s) to use
#
# Optional variables:
# DESTDIR destination directory
# PARSELISTENV environment variables to set for parselist.awk
#
PARSELISTENV+= _SRC_TOP_=${_SRC_TOP_:Q} \
CRUNCHBIN=${CRUNCHBIN:Q} \
CURDIR=${.CURDIR:Q} \
DESTDIR=${DESTDIR:Q} \
MACHINE=${MACHINE:Q} \
MACHINE_ARCH=${MACHINE_ARCH:Q} \
OBJDIR=${.OBJDIR:Q}
_PARSELIST= ${_SRC_TOP_}/distrib/common/parselist.awk
@ -21,8 +33,7 @@ ${CRUNCHBIN}.mk ${CRUNCHBIN}.cache ${CRUNCHBIN}.c: ${CRUNCHBIN}.conf
${CRUNCHBIN}.conf: ${LISTS} ${_PARSELIST}
-rm -f ${.TARGET} ${.TARGET}.tmp
awk -f ${_PARSELIST} -v mode=crunch \
MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE_ARCH} \
${PARSELISTENV} awk -f ${_PARSELIST} -v mode=crunch \
${LISTS} > ${.TARGET}.tmp
&& mv ${.TARGET}.tmp ${.TARGET}

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.image,v 1.5 2002/03/14 01:07:27 lukem Exp $
# $NetBSD: Makefile.image,v 1.6 2002/03/14 22:26:09 lukem Exp $
#
# Makefile snippet to build a tree from the provided lists,
# and make an ffs file system image from that tree
@ -18,8 +18,7 @@
# Optional variables:
# DESTDIR destination directory
# MAKEFS_FLAGS extra options to ${MAKEFS}
# POPULATEENV environment variables to pass to the output of
# parselist.awk -v mode=populate
# PARSELISTENV environment variables to set for parselist.awk
# WORKDIR directory to build image in to
#
@ -27,12 +26,14 @@ WORKDIR?= work
WORKSPEC?= work.spec
WORKBUILT?= work.built
POPULATEENV+= _SRC_TOP_=${_SRC_TOP_:Q} \
DESTDIR=${DESTDIR:Q} \
PARSELISTENV+= _SRC_TOP_=${_SRC_TOP_:Q} \
CRUNCHBIN=${CRUNCHBIN:Q} \
CURDIR=${.CURDIR:Q} \
DESTDIR=${DESTDIR:Q} \
MACHINE=${MACHINE:Q} \
MACHINE_ARCH=${MACHINE_ARCH:Q} \
OBJDIR=${.OBJDIR:Q} \
TARGDIR=${.OBJDIR}/${WORKDIR:Q}
TARGETDIR=${.OBJDIR}/${WORKDIR:Q}
_PARSELIST= ${_SRC_TOP_}/distrib/common/parselist.awk
@ -42,9 +43,8 @@ ${WORKBUILT}: ${IMAGEDEPENDS} ${WORKSPEC} ${_PARSELIST} ${LISTS}
-rm -rf ${WORKDIR} ${WORKBUILT}
mkdir -m 755 ${WORKDIR}
${MTREE} -def ${WORKSPEC} -p ${WORKDIR}/ -UW
awk -f ${_PARSELIST} -v mode=populate \
MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE_ARCH} \
${LISTS} | ${POPULATEENV} sh -e \
${PARSELISTENV} awk -f ${_PARSELIST} -v mode=populate \
${LISTS} | sh -e ${POPULATE_DEBUG} \
&& touch ${WORKBUILT}
${WORKSPEC}: ${MTREECONF} ${LISTS} ${_PARSELIST}
@ -53,8 +53,7 @@ ${WORKSPEC}: ${MTREECONF} ${LISTS} ${_PARSELIST}
cat $$i ; \
echo "/unset all" ; \
done ) >> ${.TARGET}.tmp
awk -f ${_PARSELIST} -v mode=mtree \
MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE_ARCH} \
${PARSELISTENV} awk -f ${_PARSELIST} -v mode=mtree \
${LISTS} >> ${.TARGET}.tmp \
&& mv ${.TARGET}.tmp ${.TARGET}

View File

@ -1,3 +1,3 @@
# $NetBSD: list.makedev,v 1.1 2002/02/08 02:18:53 lukem Exp $
# $NetBSD: list.makedev,v 1.2 2002/03/14 22:26:09 lukem Exp $
COPY ${_SRC_TOP_}/etc/etc.@MACHINE@/MAKEDEV dev/MAKEDEV 555
COPY ${_SRC_TOP_}/etc/etc.${MACHINE}/MAKEDEV dev/MAKEDEV 555

View File

@ -1,9 +1,9 @@
# $NetBSD: list.sysinst,v 1.2 2002/02/08 02:18:54 lukem Exp $
# $NetBSD: list.sysinst,v 1.3 2002/03/14 22:26:09 lukem Exp $
#
PROG sysinst
SPECIAL sysinst srcdir distrib/utils/sysinst/arch/@MACHINE@
SPECIAL sysinst srcdir distrib/utils/sysinst/arch/${MACHINE}
# generate the lists of obsolete files used by sysinst
CMD sh ${_SRC_TOP_}/distrib/sets/makeobsolete -b -s ${_SRC_TOP_}/distrib/sets -t ./dist

View File

@ -1,4 +1,4 @@
# $NetBSD: parselist.awk,v 1.8 2002/03/14 01:24:35 lukem Exp $
# $NetBSD: parselist.awk,v 1.9 2002/03/14 22:26:09 lukem Exp $
#
# Copyright (c) 2002 The NetBSD Foundation, Inc.
# All rights reserved.
@ -40,22 +40,27 @@
#
# Parse list files file1 [...], generating different output,
# depending upon the value of MODE:
#
# crunch crunchgen(1) config
#
# mtree mtree(8) specfile
# populate sh(1) commands to populate ${TARGDIR} from ${CURDIR}
#
# populate sh(1) commands to populate ${TARGETDIR} from ${CURDIR}
# The following environment variables need to be set:
# CRUNCHBIN Name of crunchgen(1) target binary
# CURDIR Source directory; make(1)'s ${.CURDIR}
# OBJDIR Object directory; make(1)'s ${.OBJDIR}
# TARGETDIR Directory to populate
#
#
# Each line of the input is either a comment (starts with `#'),
# or contains one of the following keywords and arguments.
# In general, keywords in lowercase are crunchgen(1) keywords which
# might be also supported for the other operations.
#
# Before each line is parsed, the following strings are replaced with
# the appropriate value which is passed in on the command line:
#
# string value
# ------ -----
# @MACHINE_ARCH@ MACHINE_ARCH
# @MACHINE@ MACHINE
# Before each line is parsed for a keyword, words surrounded by
# "${" and "}", and containing only letters, numbers, and `_'
# will be replaced by the value of the environment variable of
# the same name. I.e., "${MACHINE_ARCH}" will be replaced with the
# value of ENVIRON["MACHINE_ARCH"].
#
# mode key operation
# -------- ---------
@ -97,31 +102,27 @@
BEGIN \
{
errexit = 0;
crunchprog = "";
if (mode != "crunch" && mode != "mtree" && mode != "populate")
err("Unknown parselist mode '" mode "'");
errx("Unknown parselist mode '" mode "'");
if (mode == "populate") {
split("CRUNCHBIN CURDIR OBJDIR TARGETDIR", needvars);
for (nv in needvars) {
if (! (needvars[nv] in ENVIRON))
errx("Environment variable " \
needvars[nv] " not defined");
}
}
print "#";
print "# This file is automatically generated by";
print "#\tparselist mode=" mode;
print "#";
print "";
if (mode == "populate") {
print "checkvarisset()";
print "{";
print " eval _v=\\$${1}";
print " if [ -z \"$_v\" ]; then";
print " echo 1>&2 \"Error: $1 is not defined\"";
print " exit 1";
print " fi";
print "}";
print;
print "checkvarisset CRUNCHBIN";
print "checkvarisset CURDIR";
print "checkvarisset OBJDIR";
print "checkvarisset TARGDIR";
print "cd ${CURDIR}";
print "cd " ENVIRON["CURDIR"];
print;
} else if (mode == "mtree") {
print "/unset\tall";
@ -136,10 +137,17 @@ BEGIN \
next;
}
/@MACHINE(_ARCH)?@/ \
# replace ${FOO} with ENVIRON["FOO"]
#
/\${[A-Za-z0-9_]+}/ \
{
gsub(/@MACHINE_ARCH@/, MACHINE_ARCH);
gsub(/@MACHINE@/, MACHINE);
while (match($0, /\${[A-Za-z0-9_]+}/) > 0) {
v = substr($0, RSTART + 2, RLENGTH - 3);
if (! (v in ENVIRON))
err("Variable " v " is not in the environment");
else
sub(/\${[A-Za-z0-9_]+}/, ENVIRON[v]);
}
}
$1 == "COPY" \
@ -203,7 +211,8 @@ $1 == "PROG" \
for (i = 2; i <= NF; i++) {
if (crunchprog == "") {
crunchprog = $i;
copy("${OBJDIR}/${CRUNCHBIN}", crunchprog);
copy(ENVIRON["OBJDIR"] "/" ENVIRON["CRUNCHBIN"],
crunchprog);
continue;
}
link(crunchprog, $i);
@ -250,7 +259,7 @@ $1 == "CMD" \
if (NF < 2)
err("Usage: CMD ...");
if (mode == "populate") {
printf("(cd ${TARGDIR};");
printf("(cd %s;", ENVIRON["TARGETDIR"]);
for (i = 2; i <= NF; i++)
printf(" %s", $i);
print ")";
@ -286,10 +295,11 @@ function copy (src, dest, perm) \
if (mode == "mtree") {
printf("./%s%s\n", dest, perm != "" ? " mode=" perm : "");
} else {
printf("rm -rf ${TARGDIR}/%s\n", dest);
printf("cp %s ${TARGDIR}/%s\n", src, dest);
printf("rm -rf %s/%s\n", ENVIRON["TARGETDIR"], dest);
printf("cp %s %s/%s\n", src, ENVIRON["TARGETDIR"], dest);
if (perm != "")
printf("chmod %s ${TARGDIR}/%s\n", perm, dest);
printf("chmod %s %s/%s\n", perm,
ENVIRON["TARGETDIR"], dest);
}
}
@ -298,8 +308,8 @@ function link (src, dest) \
if (mode == "mtree") {
printf("./%s\n", dest);
} else {
printf("rm -rf ${TARGDIR}/%s\n", dest);
printf("(cd ${TARGDIR}; ln %s %s)\n", src, dest);
printf("rm -rf %s/%s\n", ENVIRON["TARGETDIR"], dest);
printf("(cd %s; ln %s %s)\n", ENVIRON["TARGETDIR"], src, dest);
}
}
@ -308,14 +318,20 @@ function symlink (src, dest) \
if (mode == "mtree") {
printf("./%s type=link link=%s\n", dest, src);
} else {
printf("rm -rf ${TARGDIR}/%s\n", dest);
printf("(cd ${TARGDIR}; ln -s %s %s)\n", src, dest);
printf("rm -rf %s/%s\n", ENVIRON["TARGETDIR"], dest);
printf("(cd %s; ln -s %s %s)\n", ENVIRON["TARGETDIR"],
src, dest);
}
}
function err(msg) \
{
printf("%s at line %d of input.\n", msg, NR) >"/dev/stderr";
errexit=1;
printf("parselist: %s at line %d of input.\n", msg, NR) >"/dev/stderr";
exit 1;
}
function errx(msg) \
{
printf("parselist: %s.\n", msg) >"/dev/stderr";
exit 1;
}

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.ramdisk,v 1.9 2002/03/07 01:41:48 lukem Exp $
# $NetBSD: Makefile.ramdisk,v 1.10 2002/03/14 22:26:09 lukem Exp $
TOP= ${.CURDIR}/..
@ -18,7 +18,7 @@ IMAGEDEPENDS+= ${CRUNCHBIN} dot.profile termcap.mini \
${_SRC_TOP_}/etc/netconfig ${_SRC_TOP_}/etc/protocols \
${_SRC_TOP_}/etc/services ${DESTDIR}/usr/mdec/biosboot.sym \
${DESTDIR}/usr/mdec/mbr ${DESTDIR}/usr/mdec/mbr_bootsel
POPULATEENV+= BOOTMODEL=${BOOTMODEL:Q}
PARSELISTENV+= BOOTMODEL=${BOOTMODEL:Q}
.if defined(USE_SYSINST)

View File

@ -1,6 +1,6 @@
# $NetBSD: list.ramdisk,v 1.4 2002/03/07 01:41:48 lukem Exp $
# $NetBSD: list.ramdisk,v 1.5 2002/03/14 22:26:09 lukem Exp $
SRCDIRS bin sbin usr.bin usr.sbin gnu/usr.bin sys/arch/@MACHINE@/stand
SRCDIRS bin sbin usr.bin usr.sbin gnu/usr.bin sys/arch/${MACHINE}/stand
# init invokes the shell as -sh
ARGVLN sh -sh

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.49 2002/03/06 12:04:48 lukem Exp $
# $NetBSD: Makefile,v 1.50 2002/03/14 22:26:10 lukem Exp $
.include "${.CURDIR}/../Makefile.inc"
.include <bsd.own.mk>
@ -14,7 +14,7 @@ IMAGEDEPENDS= ${CRUNCHBIN} install.sub install.sh upgrade.sh \
${_SRC_TOP_}/etc/group ${_SRC_TOP_}/etc/master.passwd \
${_SRC_TOP_}/etc/netconfig ${_SRC_TOP_}/etc/protocols \
${_SRC_TOP_}/etc/services
POPULATEENV+= ARCHDIR=${ARCHDIR:Q} KERNOBJDIR=${KERNOBJDIR:Q}
PARSELISTENV= ARCHDIR=${ARCHDIR:Q} KERNOBJDIR=${KERNOBJDIR:Q}
.include "${ARCHDIR}/Makefile.inc"