2008-04-30 17:10:46 +04:00
|
|
|
# $NetBSD: parselist.awk,v 1.15 2008/04/30 13:10:48 martin Exp $
|
2002-02-03 18:24:43 +03:00
|
|
|
#
|
|
|
|
# Copyright (c) 2002 The NetBSD Foundation, Inc.
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
# by Luke Mewburn of Wasabi Systems.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#
|
2002-02-07 14:39:17 +03:00
|
|
|
|
|
|
|
#
|
|
|
|
# awk -f parselist.awk -v mode=MODE [var=val ...] file1 [...]
|
2002-02-03 18:24:43 +03:00
|
|
|
#
|
|
|
|
# Parse list files file1 [...], generating different output,
|
2002-03-14 04:07:27 +03:00
|
|
|
# depending upon the value of MODE:
|
2002-03-15 01:26:08 +03:00
|
|
|
#
|
2002-02-03 18:24:43 +03:00
|
|
|
# crunch crunchgen(1) config
|
2002-03-15 01:26:08 +03:00
|
|
|
#
|
2002-08-18 18:03:42 +04:00
|
|
|
# install make(1) Makefile to install commands into ${TARGETDIR},
|
|
|
|
# with an `install' target.
|
|
|
|
# The following environment variables need to be set:
|
|
|
|
# TARGETDIR Directory to populate
|
|
|
|
#
|
2002-02-03 18:24:43 +03:00
|
|
|
# mtree mtree(8) specfile
|
2002-03-15 01:26:08 +03:00
|
|
|
#
|
|
|
|
# populate sh(1) commands to populate ${TARGETDIR} from ${CURDIR}
|
|
|
|
# The following environment variables need to be set:
|
|
|
|
# CURDIR Source directory; make(1)'s ${.CURDIR}
|
|
|
|
# TARGETDIR Directory to populate
|
|
|
|
#
|
2002-08-18 18:03:42 +04:00
|
|
|
# The following environment variables need to be set for all modes:
|
|
|
|
# CRUNCHBIN Name of crunchgen(1) target binary
|
|
|
|
# OBJDIR Object directory; make(1)'s ${.OBJDIR}
|
2002-02-03 18:24:43 +03:00
|
|
|
#
|
|
|
|
# Each line of the input is either a comment (starts with `#'),
|
|
|
|
# or contains one of the following keywords and arguments.
|
2002-02-07 14:39:17 +03:00
|
|
|
#
|
2002-03-15 01:26:08 +03:00
|
|
|
# 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"].
|
2002-02-07 14:39:17 +03:00
|
|
|
#
|
2002-02-03 18:24:43 +03:00
|
|
|
# mode key operation
|
|
|
|
# -------- ---------
|
|
|
|
# C crunch
|
2002-08-18 18:03:42 +04:00
|
|
|
# I install
|
2002-02-03 18:24:43 +03:00
|
|
|
# M mtree
|
|
|
|
# P populate
|
|
|
|
#
|
|
|
|
# mode keyword arg1 [...] description
|
|
|
|
# ---- ------------------ -----------
|
|
|
|
#
|
|
|
|
# C ARGVLN prog link as per crunchgen(1) `ln'
|
|
|
|
#
|
|
|
|
# P CMD arg1 [...] run CMD as a shell command
|
|
|
|
#
|
2002-08-18 18:03:42 +04:00
|
|
|
# IMP COPY src dest [perm] copy src to dest. perm defaults to 0444
|
2002-03-05 03:19:43 +03:00
|
|
|
#
|
2002-08-18 18:03:42 +04:00
|
|
|
# IMP COPYDIR src dest recursively copy files under src to
|
2002-04-10 06:01:43 +04:00
|
|
|
# dest. for M, dest is listed first,
|
|
|
|
# followed by the subdirectories in src.
|
2002-05-29 07:01:55 +04:00
|
|
|
# copied directories have mode 0755.
|
|
|
|
# copied files have mode 0444.
|
2002-02-03 18:24:43 +03:00
|
|
|
#
|
|
|
|
# C LIBS libspec ... as per crunchgen(1) `libs'
|
|
|
|
#
|
2002-08-18 18:03:42 +04:00
|
|
|
# IMP LINK src d1 [d2 ...] hard link src to d1, d2, ...
|
2002-02-03 18:24:43 +03:00
|
|
|
#
|
2002-03-07 04:36:34 +03:00
|
|
|
# M MTREE arg1 [...] output arguments `as-is' to specfile
|
|
|
|
#
|
2002-08-18 18:03:42 +04:00
|
|
|
# CIMP PROG prog [links...] program(s) to crunch/mtree/populate.
|
|
|
|
# for I, M & P, the first prog listed
|
2002-02-03 18:24:43 +03:00
|
|
|
# is copied from ${OBJDIR}/${CRUNCHBIN}
|
|
|
|
# and then used as the name to link
|
|
|
|
# all other PROG entries to.
|
|
|
|
#
|
|
|
|
# C SPECIAL prog cmd ... as per crunchgen(1) `special'
|
|
|
|
#
|
|
|
|
# C SRCDIRS dirname ... as per crunchgen(1) `srcdirs'
|
|
|
|
#
|
2002-08-18 18:03:42 +04:00
|
|
|
# IMP SYMLINK src dest [...] symlink src to dest, [...]
|
2002-02-03 18:24:43 +03:00
|
|
|
#
|
|
|
|
|
|
|
|
BEGIN \
|
|
|
|
{
|
|
|
|
crunchprog = "";
|
|
|
|
|
2002-08-18 18:03:42 +04:00
|
|
|
if (mode != "crunch" && mode != "install" &&
|
|
|
|
mode != "mtree" && mode != "populate")
|
2002-03-15 01:26:08 +03:00
|
|
|
errx("Unknown parselist mode '" mode "'");
|
|
|
|
|
2002-08-18 18:03:42 +04:00
|
|
|
needvars["CRUNCHBIN"]++
|
|
|
|
needvars["OBJDIR"]++
|
|
|
|
if (mode == "install") {
|
|
|
|
needvars["TARGETDIR"]++
|
|
|
|
}
|
|
|
|
else if (mode == "populate") {
|
|
|
|
needvars["CURDIR"]++
|
|
|
|
}
|
|
|
|
for (nv in needvars) {
|
|
|
|
if (! (nv in ENVIRON))
|
|
|
|
errx("Environment variable " nv " not defined");
|
2002-03-15 01:26:08 +03:00
|
|
|
}
|
|
|
|
|
2002-02-03 18:24:43 +03:00
|
|
|
print "#";
|
|
|
|
print "# This file is automatically generated by";
|
|
|
|
print "#\tparselist mode=" mode;
|
|
|
|
print "#";
|
|
|
|
print "";
|
2002-08-18 18:03:42 +04:00
|
|
|
if (mode == "install") {
|
|
|
|
print ".include <bsd.own.mk>"
|
|
|
|
print "install:"
|
2002-02-03 18:24:43 +03:00
|
|
|
} else if (mode == "mtree") {
|
2002-02-06 02:16:51 +03:00
|
|
|
print "/unset\tall";
|
2002-02-03 18:24:43 +03:00
|
|
|
print "/set\ttype=file uname=root gname=wheel";
|
|
|
|
print;
|
2002-08-18 18:03:42 +04:00
|
|
|
} else if (mode == "populate") {
|
|
|
|
print "cd " ENVIRON["CURDIR"];
|
|
|
|
print;
|
2002-02-03 18:24:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/^$/ || /^#/ \
|
|
|
|
{
|
|
|
|
print;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2002-03-15 01:26:08 +03:00
|
|
|
# replace ${FOO} with ENVIRON["FOO"]
|
|
|
|
#
|
2002-09-15 20:15:40 +04:00
|
|
|
/\$\{[A-Za-z0-9_]+\}/ \
|
2002-02-07 14:39:17 +03:00
|
|
|
{
|
2002-09-15 20:15:40 +04:00
|
|
|
while (match($0, /\$\{[A-Za-z0-9_]+\}/) > 0) {
|
2002-03-15 01:26:08 +03:00
|
|
|
v = substr($0, RSTART + 2, RLENGTH - 3);
|
|
|
|
if (! (v in ENVIRON))
|
|
|
|
err("Variable " v " is not in the environment");
|
|
|
|
else
|
2002-09-15 20:15:40 +04:00
|
|
|
sub(/\$\{[A-Za-z0-9_]+\}/, ENVIRON[v]);
|
2002-03-15 01:26:08 +03:00
|
|
|
}
|
2002-02-07 14:39:17 +03:00
|
|
|
}
|
|
|
|
|
2002-02-03 18:24:43 +03:00
|
|
|
$1 == "COPY" \
|
|
|
|
{
|
2002-02-07 14:39:17 +03:00
|
|
|
if (NF < 3 || NF > 4)
|
2002-05-29 07:01:55 +04:00
|
|
|
err("Usage: COPY src dest [perm]");
|
2002-08-18 18:03:42 +04:00
|
|
|
if (mode == "install" || mode == "mtree" || mode == "populate")
|
2002-02-07 14:39:17 +03:00
|
|
|
copy($2, $3, $4);
|
2002-02-03 18:24:43 +03:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2002-03-05 03:19:43 +03:00
|
|
|
$1 == "COPYDIR" \
|
|
|
|
{
|
|
|
|
if (NF != 3)
|
|
|
|
err("Usage: COPYDIR src dest");
|
2002-03-06 07:47:58 +03:00
|
|
|
srcdir=$2;
|
|
|
|
destdir=$3;
|
2002-03-05 03:19:43 +03:00
|
|
|
if (mode == "mtree") {
|
2002-03-06 07:47:58 +03:00
|
|
|
printf("./%s type=dir mode=755\n", destdir);
|
2002-03-14 04:24:35 +03:00
|
|
|
command="cd " srcdir " && find . -type d -print"
|
2002-03-05 03:19:43 +03:00
|
|
|
while (command | getline dir) {
|
|
|
|
gsub(/^\.\//, "", dir);
|
2002-03-06 07:47:58 +03:00
|
|
|
if (dir == ".")
|
|
|
|
continue;
|
|
|
|
printf("./%s/%s type=dir mode=755\n", destdir, dir);
|
2002-03-05 03:19:43 +03:00
|
|
|
}
|
|
|
|
close(command);
|
|
|
|
}
|
2002-08-18 18:03:42 +04:00
|
|
|
if (mode == "install" || mode == "mtree" || mode == "populate") {
|
2002-03-14 04:24:35 +03:00
|
|
|
command="cd " srcdir " && find . -type f -print"
|
2002-03-05 03:19:43 +03:00
|
|
|
while (command | getline srcfile) {
|
|
|
|
gsub(/^\.\//, "", srcfile);
|
|
|
|
copy(srcdir "/" srcfile, destdir "/" srcfile, "");
|
|
|
|
}
|
|
|
|
close(command);
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2002-02-03 18:24:43 +03:00
|
|
|
$1 == "LIBS" || $1 == "SPECIAL" || $1 == "SRCDIRS" \
|
|
|
|
{
|
2002-02-07 14:39:17 +03:00
|
|
|
if (NF < 2)
|
|
|
|
err("Usage: " $1 " args...");
|
2002-02-03 18:24:43 +03:00
|
|
|
if (mode == "crunch") {
|
|
|
|
$1 = tolower($1);
|
|
|
|
print;
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
$1 == "PROG" \
|
|
|
|
{
|
2002-02-07 14:39:17 +03:00
|
|
|
if (NF < 2)
|
|
|
|
err("Usage: PROG prog [link ...]");
|
2002-02-03 18:24:43 +03:00
|
|
|
if (mode == "crunch") {
|
|
|
|
prog = basename($2);
|
|
|
|
print "progs " prog;
|
|
|
|
for (i = 3; i <= NF; i++)
|
|
|
|
print "ln " prog " " basename($i);
|
|
|
|
} else {
|
|
|
|
for (i = 2; i <= NF; i++) {
|
|
|
|
if (crunchprog == "") {
|
|
|
|
crunchprog = $i;
|
2002-03-15 01:26:08 +03:00
|
|
|
copy(ENVIRON["OBJDIR"] "/" ENVIRON["CRUNCHBIN"],
|
2002-05-29 07:01:55 +04:00
|
|
|
crunchprog, 555);
|
2002-02-03 18:24:43 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
link(crunchprog, $i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
$1 == "ARGVLN" \
|
|
|
|
{
|
2002-02-07 14:39:17 +03:00
|
|
|
if (NF != 3)
|
|
|
|
err("Usage: ARGVLN prog link");
|
2002-02-03 18:24:43 +03:00
|
|
|
if (mode == "crunch") {
|
|
|
|
$1 = "ln";
|
|
|
|
print;
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
$1 == "LINK" \
|
|
|
|
{
|
2002-02-07 14:39:17 +03:00
|
|
|
if (NF < 3)
|
|
|
|
err("Usage: LINK prog link [...]");
|
2002-08-18 18:03:42 +04:00
|
|
|
if (mode == "install" || mode == "mtree" || mode == "populate") {
|
2002-02-03 18:24:43 +03:00
|
|
|
for (i = 3; i <= NF; i++)
|
|
|
|
link($2, $i);
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
$1 == "SYMLINK" \
|
|
|
|
{
|
2002-02-07 14:39:17 +03:00
|
|
|
if (NF < 3)
|
|
|
|
err("Usage: SYMLINK prog link [...]");
|
2002-08-18 18:03:42 +04:00
|
|
|
if (mode == "install" || mode == "mtree" || mode == "populate") {
|
2002-02-03 18:24:43 +03:00
|
|
|
for (i = 3; i <= NF; i++)
|
|
|
|
symlink($2, $i);
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
$1 == "CMD" \
|
|
|
|
{
|
2002-02-07 14:39:17 +03:00
|
|
|
if (NF < 2)
|
|
|
|
err("Usage: CMD ...");
|
2002-02-03 18:24:43 +03:00
|
|
|
if (mode == "populate") {
|
2002-03-15 01:26:08 +03:00
|
|
|
printf("(cd %s;", ENVIRON["TARGETDIR"]);
|
2002-02-03 18:24:43 +03:00
|
|
|
for (i = 2; i <= NF; i++)
|
|
|
|
printf(" %s", $i);
|
2002-05-29 07:01:55 +04:00
|
|
|
print ") || exit 1";
|
2002-02-03 18:24:43 +03:00
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2002-03-07 04:36:34 +03:00
|
|
|
$1 == "MTREE" \
|
|
|
|
{
|
|
|
|
if (NF < 2)
|
|
|
|
err("Usage: MTREE ...");
|
|
|
|
if (mode == "mtree") {
|
|
|
|
sub(/^[^ \t]+[ \t]+/, ""); # strip first word ("MTREE")
|
|
|
|
print;
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-03 18:24:43 +03:00
|
|
|
{
|
2002-02-07 14:39:17 +03:00
|
|
|
err("Unknown keyword '" $1 "'");
|
2002-02-03 18:24:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function basename (file) \
|
|
|
|
{
|
|
|
|
gsub(/[^\/]+\//, "", file);
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2002-02-07 14:39:17 +03:00
|
|
|
function copy (src, dest, perm) \
|
2002-02-03 18:24:43 +03:00
|
|
|
{
|
2002-05-29 07:01:55 +04:00
|
|
|
if (perm == "")
|
|
|
|
perm = 444;
|
2002-08-18 18:03:42 +04:00
|
|
|
if (mode == "install") {
|
2002-09-16 06:13:16 +04:00
|
|
|
printf("\t${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m %s %s %s/%s\n",
|
2002-08-18 18:03:42 +04:00
|
|
|
perm, src, ENVIRON["TARGETDIR"], dest)
|
|
|
|
} else if (mode == "mtree") {
|
2002-05-29 07:01:55 +04:00
|
|
|
printf("./%s mode=%s\n", dest, perm);
|
2002-02-03 18:24:43 +03:00
|
|
|
} else {
|
2002-03-15 01:26:08 +03:00
|
|
|
printf("rm -rf %s/%s\n", ENVIRON["TARGETDIR"], dest);
|
|
|
|
printf("cp %s %s/%s\n", src, ENVIRON["TARGETDIR"], dest);
|
2002-05-29 07:01:55 +04:00
|
|
|
printf("chmod %s %s/%s\n", perm, ENVIRON["TARGETDIR"], dest);
|
2002-02-03 18:24:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function link (src, dest) \
|
|
|
|
{
|
2002-08-18 18:03:42 +04:00
|
|
|
if (mode == "install") {
|
2002-09-16 06:13:16 +04:00
|
|
|
printf("\t${INSTALL_LINK} %s/%s %s/%s\n",
|
2002-08-18 18:03:42 +04:00
|
|
|
ENVIRON["TARGETDIR"], src, ENVIRON["TARGETDIR"], dest)
|
|
|
|
} else if (mode == "mtree") {
|
2002-02-03 18:24:43 +03:00
|
|
|
printf("./%s\n", dest);
|
|
|
|
} else {
|
2002-03-15 01:26:08 +03:00
|
|
|
printf("rm -rf %s/%s\n", ENVIRON["TARGETDIR"], dest);
|
2002-05-29 07:01:55 +04:00
|
|
|
printf("(cd %s; ln %s %s) || exit 1\n",
|
|
|
|
ENVIRON["TARGETDIR"], src, dest);
|
2002-02-03 18:24:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function symlink (src, dest) \
|
|
|
|
{
|
2002-08-18 18:03:42 +04:00
|
|
|
if (mode == "install") {
|
2002-09-16 06:13:16 +04:00
|
|
|
printf("\t${INSTALL_SYMLINK} %s/%s %s/%s\n",
|
2002-08-18 18:03:42 +04:00
|
|
|
ENVIRON["TARGETDIR"], src, ENVIRON["TARGETDIR"], dest)
|
|
|
|
} else if (mode == "mtree") {
|
2002-02-03 18:24:43 +03:00
|
|
|
printf("./%s type=link link=%s\n", dest, src);
|
|
|
|
} else {
|
2002-03-15 01:26:08 +03:00
|
|
|
printf("rm -rf %s/%s\n", ENVIRON["TARGETDIR"], dest);
|
2002-05-29 07:01:55 +04:00
|
|
|
printf("(cd %s; ln -s %s %s) || exit 1\n",
|
|
|
|
ENVIRON["TARGETDIR"], src, dest);
|
2002-02-03 18:24:43 +03:00
|
|
|
}
|
|
|
|
}
|
2002-02-07 14:39:17 +03:00
|
|
|
|
|
|
|
function err(msg) \
|
|
|
|
{
|
2002-03-15 01:26:08 +03:00
|
|
|
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";
|
2002-02-07 14:39:17 +03:00
|
|
|
exit 1;
|
|
|
|
}
|