Import of pkgsrc-2013Q2

This commit is contained in:
2013-09-26 17:14:40 +02:00
commit 785076ae39
74991 changed files with 4380255 additions and 0 deletions

444
mk/scripts/binpkg-cache Executable file
View File

@@ -0,0 +1,444 @@
#!/bin/sh
#
# $NetBSD: binpkg-cache,v 1.21 2010/07/21 12:29:46 spz Exp $
#
# Script for generating a cache file with information about
# all binary packages contained in a directory.
#
# Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Dan McMahill.
#
# 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.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the NetBSD
# Foundation, Inc. and its contributors.
# 4. Neither the name of The NetBSD Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# 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.
#
TMPDIR=${TMPDIR:-/tmp}
PACKAGES=${PACKAGES:-/usr/pkgsrc/packages/}
AWK=${AWK:-awk}
CMP=${CMP:-cmp}
FIND=${FIND:-find}
GREP=${GREP:-grep}
GZIP_CMD=${GZIP_CMD:-gzip}
BZIP2=${BZIP2:-bzip2}
PKG_INFO=${PKG_INFO:-pkg_info}
PKG_SUFX=${PKG_SUFX:-.tgz}
SED=${SED:-sed}
SORT=${SORT:-sort}
STAT=${STAT:-stat}
cachefile=.pkgcache
summaryfile=pkg_summary
cacheversion=20050428
prompt="----> "
tab=" "
tmpd=${TMPDIR}/pkg-cache.$$
mkdir -m 0700 ${tmpd}
if test $? -ne 0 ; then
echo "ERROR: Could not create temporary directory ${tmpd}"
echo "Either you do not have write permission to ${tmpd} or"
echo "${tmpd} already exists"
exit 1
fi
all_dirs=${tmpd}/all_dirs
prog=$0
usage(){
echo "$prog - Generates cache files for each directory containing binary"
echo " packages. This cache file can then be used by the README.html"
echo " generation code to avoid having to call pkg_info(1) over and over"
echo " on the same binary package. In addition, pkg_summary.gz files for"
echo " use by the pkgtools/pkg_chk pacakge may be generated."
echo " "
echo "Usage: $prog [-d|--debug] [-v|--verbose] [-s|--summary] [-p|--packages <dir>]"
echo " "
echo " $prog -h|--help"
echo " "
echo " $prog -V|--version"
echo " "
echo "The options supported by $prog are: "
echo " "
echo " -d|--debug Enables debugging output"
echo " "
echo " -F|--force Forces a rebuild of the cache files even if they are"
echo " otherwise up to date."
echo " "
echo " -h|--help Displays this help message"
echo " "
echo " -p|--packages <dir> Specifies the top level directory to be searched"
echo " for binary packages."
echo " "
echo " -s|--summary Enables the creation of pkg_summary.gz files in each"
echo " directory containing binary packages. The pkg_summary.gz"
echo " file is used by the pkgtools/pkg_chk package."
echo " "
echo " -v|--verbose Enables verbose output from the script."
echo " "
echo " -V|--version Displays the version of this script and exits."
echo " "
echo "Returns 0 on success, 1 on errors, 2 if the packages"
echo "directory does not exist."
echo " "
echo "Example: $prog -v --packages /usr/pkgsrc/packages"
echo " "
}
clean_and_exit0(){
rm -fr ${tmpd}
exit 0
}
clean_and_exit1(){
rm -fr ${tmpd}
exit 1
}
clean_and_exit2(){
rm -fr ${tmpd}
exit 2
}
all_cache_files=""
#############################################################################
#
# process_binpkg_dir()
#
# Process a directory by checking to see if a cache file exists. If the
# cache file exists, make sure it is up to date. If the file does not
# exist, create one.
#
# also keep track of this directory so it can be added to the master
# cache.
#
process_binpkg_dir(){
rdir=`${GREP} "^${d} " ${all_dirs} | ${AWK} '{print $2}'`
need_update=no
if test -f ${d}/${cachefile} ; then
stale_entries=`${FIND} ${d} -type f -name \*${PKG_SUFX} -newer ${d}/${cachefile} -print`
# FIX_ME
#
# We also should find cache entries for files which no longer exist
# and nuke them. Right now we simply declare the entire cache out
# of date. Once we implement incremental updates to the cache,
# we need to remove the entries but not mark the entire cache as
# bad.
$if_debug echo " Checking for cache entries with no corresponding pkg."
# get the list of what pkgs belong in the cache
rm -f ${tmpd}/pkg_list ${tmpd}/cache_pkg_list
${FIND} ${d}/ -name \*${PKG_SUFX} -print | \
${SED} -e "s;^${d}/*;${rdir}/;g" -e 's;//;/;g' | \
${SORT} > ${tmpd}/pkg_list
# and get the list of what is in the cache
${AWK} '/pkgcache_begin/ {gsub(/pkgcache_begin[ \t]*/, ""); print}' \
${d}/${cachefile} | ${SORT} > ${tmpd}/cache_pkg_list
if ${CMP} -s ${tmpd}/pkg_list ${tmpd}/cache_pkg_list ; then
$if_debug echo " No extra cache entries in ${d}/${cachefile}"
else
$if_debug echo "Package list:"
$if_debug cat ${tmpd}/pkg_list
$if_debug echo "Cache list:"
$if_debug cat ${tmpd}/cache_pkg_list
echo " Entries found in ${d}/${cachefile} but no packages found"
need_update=yes
fi
else
stale_entries=""
fi
if test "X${force}" = "Xyes" -o "X${need_update}" = "Xyes" ; then
need_update=yes
echo "${tab}Forcing rebuild of cache ${d}/${cachefile}."
elif test ! -f ${d}/${cachefile} ; then
need_update=yes
echo "${tab}Missing cache file. ${d}/${cachefile} will be generated."
elif test -n "${stale_entries}" ; then
need_update=yes
echo "${tab}Stale cache file. ${d}/${cachefile} will be regenerated."
else
${GREP} "pkgcache_version ${cacheversion}" ${d}/${cachefile} >/dev/null 2>&1
if test $? -ne 0 ; then
need_update=yes
echo "${tab}Invalid version cache file. ${d}/${cachefile} will be regenerated."
echo "Need version ${cacheversion} but the file has"
${GREP} "^pkgcache_version " ${d}/${cachefile}
else
$if_verbose echo "${tab}Cache file ${d}/${cachefile} is up to date."
fi
fi
if test "${build_summary}" = "yes" -a ! -f ${d}/${summaryfile}.gz ; then
echo "${tab}Summary file ${d}/${summaryfile}.gz is missing and will be created."
need_update=yes
fi
if test "${build_summary}" = "yes" -a ${d}/${summaryfile}.gz -ot ${d}/${cachefile} ; then
echo "${tab}Summary file ${d}/${summaryfile}.gz is out of date and will be regenerated."
need_update=yes
fi
# FIX_ME
# We should use stale_entries in a way where we only update the
# cache file entries corresponding to these if we're rebuilding
# due to stale entries. That should save a good bit of time.
#
if test "X${need_update}" = "Xyes" ; then
echo "pkgcache_version ${cacheversion}" > ${tmpd}/${cachefile}
rm -f ${tmpd}/${summaryfile}
touch ${tmpd}/${summaryfile}
for f in ${d}/*${PKG_SUFX} ; do
fn=`grep "^${d} " ${all_dirs} | ${AWK} '{print $2}'`"/"`basename ${f}`
$if_debug echo " Adding ${fn} (${f}) to the cache"
echo " " >> ${tmpd}/${cachefile}
# stat(1) needs to be added to the bootstrap kit
# first if we want to use it here
#eval $(${STAT} -s ${f} 2>/dev/null)
echo "pkgcache_begin ${fn}" >> ${tmpd}/${cachefile}
#echo "pkgcache_mtime=${st_mtime}" >> ${tmpd}/${cachefile}
$if_debug echo "${PKG_INFO} -q -B ${f}"
${PKG_INFO} -q -B ${f} >> ${tmpd}/${cachefile}
if test "${build_summary}" = "yes" ; then
$if_debug echo "${PKG_INFO} -X ${f}"
${PKG_INFO} -X ${f} >> ${tmpd}/${summaryfile}
fi
echo "pkgcache_end ${fn}" >> ${tmpd}/${cachefile}
done
if test -f ${d}/${cachefile} ; then
rm -f ${d}/${cachefile}
fi
mv -f ${tmpd}/${cachefile} ${d}/${cachefile}
if test $? -ne 0 ; then
echo "********** WARNING **********"
echo "move of ${tmpd}/${cachefile} to ${d}/${cachefile} failed!"
echo "Perhaps you do not have write permissions to ${d}?"
echo "This directory will be dropped from the master cache file."
echo "********** WARNING **********"
return
fi
if test "${build_summary}" = "yes" ; then
if test -f ${d}/${summaryfile}.gz ; then
rm -f ${d}/${summaryfile}.gz
fi
cat ${tmpd}/${summaryfile} | ${GZIP_CMD} > ${d}/${summaryfile}.gz
if test $? -ne 0 ; then
echo "********** WARNING **********"
echo "${GZIP_CMD} of ${tmpd}/${summaryfile} to ${d}/${summaryfile}.gz failed!"
echo "Perhaps you do not have write permissions to ${d}?"
echo "********** WARNING **********"
return
fi
# if it's there, update it, otherwise don't bother
if test -f ${d}/${summaryfile}.bz2 ; then
rm -f ${d}/${summaryfile}.bz2
cat ${tmpd}/${summaryfile} | ${BZIP2} > ${d}/${summaryfile}.bz2
if test $? -ne 0 ; then
echo "********** WARNING **********"
echo "${BZIP2} of ${tmpd}/${summaryfile} to ${d}/${summaryfile}.bz2 failed!"
echo "Perhaps you do not have write permissions to ${d}?"
echo "********** WARNING **********"
return
fi
fi
fi
fi
# if we got here, then this directory should have a good cache file in
# it and we should be able to add it to the master cache file
all_cache_files="${all_cache_files} ${d}/${cachefile}"
}
process_cache_files(){
echo "${prompt}Checking master cache file ${PACKAGES}/${cachefile}"
echo "pkgcache_version ${cacheversion}" > ${tmpd}/${cachefile}
if test -n "${all_cache_files}" ; then
for c in ${all_cache_files} ; do
echo "pkgcache_cachefile ${c}" >> ${tmpd}/${cachefile}
done
fi
if test ! -f ${PACKAGES}/${cachefile} ; then
echo "${tab}Creating master cache file ${PACKAGES}/${cachefile}"
mv -f ${tmpd}/${cachefile} ${PACKAGES}/${cachefile}
if test $? -ne 0 ; then
echo "********** ERROR **********"
echo "move of ${tmpd}/${cachefile} to ${PACKAGES}/${cachefile} failed!"
echo "Perhaps you do not have write permissions to ${PACKAGES}?"
echo "********** ERROR **********"
clean_and_exit1
fi
elif ${CMP} -s ${tmpd}/${cachefile} ${PACKAGES}/${cachefile} ; then
echo "${tab}Master cache file ${PACKAGES}/${cachefile} is up to date"
else
echo "${tab}Updating master cache file ${PACKAGES}/${cachefile}"
mv -f ${tmpd}/${cachefile} ${PACKAGES}/${cachefile}
if test $? -ne 0 ; then
echo "********** ERROR **********"
echo "move of ${tmpd}/${cachefile} to ${PACKAGES}/${cachefile} failed!"
echo "Perhaps you do not have write permissions to ${PACKAGES}?"
echo "********** ERROR **********"
clean_and_exit1
fi
fi
}
######################################################################
#
# Handle command line options
#
######################################################################
if_debug=: # either ":" or ""
if_verbose=: # either ":" or ""
force=no
build_summary=no
while
test -n "$1"
do
case "$1" in
# Turn on debugging
-d|--debug)
if_debug=""
if_verbose=""
shift
;;
# Force a rebuilde of the cache
-F|--force)
force=yes
shift
;;
# Help
-h|--help)
usage
exit 0
;;
# Use the specified packages directory
-p|--packages)
PACKAGES=$2
shift 2
;;
# Build the pkg_summary.gz files
-s|--summary)
build_summary=yes
shift
;;
# Version
-V|--version)
${AWK} '/^#[ \t]*\$NetBSD/ {gsub(/,v/,"",$3);printf("%s: Version %s, %s\n",$3,$4,$5); exit 0;}' $prog
exit 0
;;
# Turn on verbose output, but not as noisy as debug
-v|--verbose)
if_verbose=""
shift
;;
-*) echo "$prog: ERROR: $1 is not a valid option"
usage
clean_and_exit1
;;
*)
break
;;
esac
done
if test $# -ne 0 ; then
echo "$0: $* is invalid"
usage
clean_and_exit1
fi
if test ! -d ${PACKAGES} ; then
echo "Packages directory ${PACKAGES} seems to be missing"
clean_and_exit2
fi
# put a trailing / after ${PACKAGES} in case ${PACKAGES} is
# a link.
# pass 1, we find all directories under PACKAGES. Note that this
# may contain some directories more than once depending on what sort
# of soft links may be in place
rm -f ${all_dirs}.tmp
for d in `${FIND} ${PACKAGES}/ -type d -follow -print` ; do
cname=`(cd ${d} && pwd -P)`
rname=`echo ${d} | ${SED} "s;^${PACKAGES}/*;;g"`
echo "${cname} ${rname}" >> ${all_dirs}.tmp
done
${SORT} -u -k1,1 ${all_dirs}.tmp > ${all_dirs}
$if_debug echo "Full directory list:"
$if_debug cat ${all_dirs}.tmp
$if_debug echo "Unique directory list:"
$if_debug cat ${all_dirs}
for d in `${AWK} '{print $1}' ${all_dirs}` ; do
$if_debug echo "${prompt}Processing directory ${d}"
is_pkg_dir=no
for f in ${d}/*${PKG_SUFX} ; do
if test -f "${f}" -a ! -h "${f}" ; then
${PKG_INFO} ${f} >/dev/null 2>&1
if test $? -eq 0 ; then
is_pkg_dir=yes
break
fi
fi
done
if test "X${is_pkg_dir}" = "Xyes" ; then
$if_verbose echo "${prompt}Checking cache in ${d}"
process_binpkg_dir
else
$if_debug echo "${prompt}no binary packages in ${d}"
fi
done
process_cache_files
clean_and_exit0

161
mk/scripts/binpkg-scan Executable file
View File

@@ -0,0 +1,161 @@
#!/usr/bin/awk -f
# $NetBSD: binpkg-scan,v 1.4 2007/10/09 14:33:25 rillig Exp $
#
# Copyright (c) 2006 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Dan McMahill.
#
# 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.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the NetBSD
# Foundation, Inc. and its contributors.
# 4. Neither the name of The NetBSD Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# 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.
#
# Scans for packages with NO_BIN_ON_FTP set. This script makes use of the
# cache files generated as part of the README.html generation. This makes
# this scan run quite fast when you have a very large binary packages collection.
#
# Usage:
#
# binpkg-scan PACKAGES=/usr/pkgsrc/packages /dev/null
#
# Global variables
#-----------------
#
# notify - if set to 1, something will be set in the output script to make it
# easy to detect and an automatic email can be sent to notify a person
# that some cleanup is required.
#
#
BEGIN {
printf("#!/bin/sh\n#\n\n");
printf("# Starting scan for NO_BIN_ON_FTP packages\n\n");
notify = 0;
}
END {
# printf("Making sure binary package cache file is up to date...\n");
# cmd = sprintf("%s AWK=%s CMP=%s FIND=%s GREP=%s PKG_INFO=\"%s\" PKG_SUFX=%s SED=%s SORT=%s %s/mk/scripts/binpkg-cache --packages %s",
# SETENV, AWK, CMP, FIND, GREP, PKG_INFO, PKG_SUFX, SED, SORT, PKGSRCDIR, PACKAGES);
# if (debug) printf("\nExecute: %s\n",cmd);
# rc = system(cmd);
rc = 0;
if (rc != 0 && rc != 2) {
printf("\n**** WARNING ****\n") > "/dev/stderr";
printf("Command: %s\nfailed.", cmd) > "/dev/stderr";
printf("**** ------- ****\n") > "/dev/stderr";
exit(1);
}
if (rc == 2) {
printf("\n**** WARNING ****\n") > "/dev/stderr";
printf("* No binary packages directory found\n") > "/dev/stderr";
printf("* List of binary packages will not be generated\n") > "/dev/stderr";
printf("**** ------- ****\n") > "/dev/stderr";
exit(0);
}
printf("# Loading binary package cache file...\n\n");
load_cache_file( PACKAGES "/.pkgcache" );
printf("\n");
for(pkg in noftp_list) {
printf("# NO_BIN_ON_FTP (%s) = %s\nrm %s/%s\n\n",
pkgpath_list[pkg], noftp_list[pkg], PACKAGES, pkg);
}
if( notify ) {
printf("\n# NOTIFY a person that this script should be run\n\n");
}
}
function fatal_check_file(file, cmd){
cmd="test -f " file ;
if (debug) printf("Execute: %s\n",cmd);
if (system(cmd) != 0) {
printf("**** FATAL ****\nRequired file %s does not exist\n",
file) > "/dev/stderr";
printf("**** ------- ****\n") > "/dev/stderr";
close("/dev/stderr");
exit(1);
}
}
function load_cache_file( file, pkgfile, noftp, pkgpath, wk, rx ) {
printf("# * %s\n", file);
fatal_check_file( file );
# read the cache file
while( getline < file ) {
# if this line points to another cache file, then recursively
# load it
if( $0 ~ /^pkgcache_cachefile/ ) {
if( debug ) printf("# Found pkgcache_cachefile line.\n");
load_cache_file( $2 );
} else if( $0 ~/^pkgcache_begin /) {
pkgfile = $2;
if( debug ) printf("# Starting %s\n", pkgfile);
pkgpath = "unknown";
noftp = "unknown";
} else if( $0 ~/^PKGPATH=/ ) {
pkgpath = $0;
gsub(/PKGPATH=[ \t]*/, "", pkgpath);
} else if( $0 ~/^NO_BIN_ON_FTP=/ ) {
noftp = $0;
gsub(/NO_BIN_ON_FTP=[ \t]*/, "", noftp);
} else if( $0 ~/^pkgcache_end /) {
if( debug ) printf("# %s, NO_BIN_ON_FTP=%s, PKGPATH=%s\n",
pkgfile, noftp, pkpath);
if(noftp == "") {
if( debug ) printf("# %s, NOT restricted\n", pkgfile);
} else if( noftp == "unknown" ) {
printf("# UNKNOWN value for NO_BIN_ON_FTP: %s/%s\n", PACKAGES, pkgfile);
notify = 1;
} else {
noftp_list[pkgfile] = noftp;
pkgpath_list[pkgfile] = pkgpath;
notify = 1;
}
} else {
# skip this line
}
}
# close the cache file
close( file );
}

115
mk/scripts/chkdatabase.awk Executable file
View File

@@ -0,0 +1,115 @@
#!/usr/bin/awk -f
#
# $NetBSD: chkdatabase.awk,v 1.3 2006/12/15 12:46:24 martti Exp $
#
# Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Dan McMahill.
#
# 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.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the NetBSD
# Foundation, Inc. and its contributors.
# 4. Neither the name of The NetBSD Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# 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.
#
# This script reads a pkgsrc database created with the 'print-summary-data'
# target and returns a lists of packages which are listed as DEPENDS and/or
# BUILD_DEPENDS but do not have their own dependencies recorded yet.
# This can be used as part of a loop which makes several passes to record
# the complete dependency tree for a package in the database
#
BEGIN {
if(debug) {
printf("Reading database file\n") > "/dev/stderr";
fflush("/dev/stderr");
}
}
/^(build_)?depends / {
#
# Read in the entire depends tree
# These lines look like:
#
#depends /usr/pkgsrc/math/scilab xless-[0-9]*:../../x11/xless pvm-3.4.3:../../parallel/pvm3
#build_depends /usr/pkgsrc/math/scilab libtool-base>=1.4.20010614nb9:../../devel/libtool-base
#
pkg = $2;
# mark this package as having its depencencies listed
depended_pkgs[pkg] = 1;
# now go through the dependency lists and pull out all pkg directories that
# we will need to examine to ensure they have been depended.
for(i=3; i<=NF; i++) {
split($i,a,":");
pkgpat=a[1];
pkgdir=a[2];
sub(/[\.\/]*/,"",pkgdir);
if(pkgdir !~ /\//) {
pkgcat=pkg;
gsub(/\/.*/,"",pkgcat);
pkgdir=pkgcat "/" pkgdir;
if(debug) printf("Corrected missing category directory to get \"%s\"\n",pkgdir) > "/dev/stderr";
}
if(debug){
printf("package in directory %s %s on:\n",pkg,deptype) > "/dev/stderr";
printf("\tpkgpat = %s\n",pkgpat) > "/dev/stderr";
printf("\tpkgdir = %s\n",pkgdir) > "/dev/stderr";
}
# mark this package directory as being one which is depended upon
depended_on_pkgs[pkgdir] = 1;
}
next;
}
END {
i=0;
for(pkg in depended_on_pkgs) {
if(pkg in depended_pkgs) {
if(debug) printf("Package: %s is already depended\n",pkg) > "/dev/stderr";
}
else {
if(debug)printf("Package: %s is NOT depended\n",pkg) > "/dev/stderr";
not_depended[i]=pkg;
i++;
}
}
i=0;
while(i in not_depended) {
printf("%s\n",not_depended[i]);
i++;
}
close("/dev/stderr");
exit(0);
}

View File

@@ -0,0 +1,290 @@
#!/usr/bin/awk -f
#
# $NetBSD: depends-depth-first.awk,v 1.6 2009/01/05 02:37:05 dbj Exp $
#
# Copyright (c) 2006 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Johnny C. Lam.
#
# 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.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the NetBSD
# Foundation, Inc. and its contributors.
# 4. Neither the name of The NetBSD Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# 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.
#
######################################################################
#
# NAME
# depends-depth-first.awk -- traverse the dependency graph
#
# SYNOPSIS
# depends-depth-first.awk -- [options] pkgpath ...
#
# DESCRIPTION
# depends-depth-first.awk performs a depth-first traversal of the
# dependency graph associated with the package directories specified
# on the command line, and provides a hook to allow a shell command
# line to be executed within each package directory during traversal.
#
# OPTIONS
# The following command line arguments are supported.
#
# -- This is a mandatory option and must always be the
# first option specified.
#
# -c cmdline Execute the specified command line when visiting
# a package directory during traversal. If the -c
# option is not given, then the default action is
# to output the package directory name.
#
# -d depends-type
# When searching for a package's dependencies, use
# the named "depends-type". This is passed as the
# DEPENDS_TYPE argument of the "show-depends-pkgpaths"
# target. By default, the dependency type is "all".
#
# -o order The dependencies are visited during the dependency
# graph traversal in the named order, which is either
# "prefix" or "postfix". By default, dependencies
# are visited in "postfix" order.
#
# -r If the -r option is specified, then the package
# directories specified on the command-line are
# also visited.
#
# -s pkgsrcdir Use the specified directory as the path to the
# pkgsrc directory tree. By default, this is the
# value stored in the PKGSRCDIR environment variable.
#
# ENVIRONMENT
# MAKEFLAGS This contains the shell environment in the format
# required by make(1) that is passed to the process
# that outputs a package's dependencies.
#
# PKGSRCDIR This is the location of the pkgsrc directory tree,
# which defaults to "/usr/pkgsrc".
#
######################################################################
######################################################################
#
# Initialize global variables, parse the command-line arguments, and
# invoke the main() function
#
######################################################################
BEGIN {
ECHO = ENVIRON["ECHO"] ? ENVIRON["ECHO"] : "echo"
MAKE = ENVIRON["MAKE"] ? ENVIRON["MAKE"] : "make"
PKGSRCDIR = ENVIRON["PKGSRCDIR"] ? ENVIRON["PKGSRCDIR"] : "/usr/pkgsrc"
TEST = ENVIRON["TEST"] ? ENVIRON["TEST"] : "test"
self = "depends-depth-first.awk"
cmd_hook = ""
depends_type = "all"
do_root = 0
walk_order = "postfix"
ARGSTART = 1
parse_options()
main()
}
######################################################################
#
# usage()
# Output the usage message to standard error.
#
######################################################################
function usage() {
print "usage: " self " [-- [-c cmdline] [-d depends-type] [-o order] [-r] [-s pkgsrcdir]] [pkgpath ...]" > "/dev/stderr"
}
######################################################################
#
# parse_options()
# Adjust global variables based on the options passed on the
# command line. After this function exists, ARGSTART is set
# to the index in the ARGV array of the first package directory
# in which to begin the traversal.
#
######################################################################
function parse_options( option) {
if (ARGV[ARGSTART] == "--") {
ARGSTART++
}
while (ARGSTART < ARGC) {
option = ARGV[ARGSTART]
if (option == "-c") {
cmd_hook = ARGV[ARGSTART + 1]
ARGSTART += 2
} else if (option == "-d") {
depends_type = ARGV[ARGSTART + 1]
ARGSTART += 2
} else if (option == "-o") {
walk_order = ARGV[ARGSTART + 1]
ARGSTART += 2
} else if (option == "-r") {
do_root = 1
ARGSTART++
} else if (option == "-s") {
PKGSRCDIR = ARGV[ARGSTART + 1]
ARGSTART += 2
} else if (option == "--") {
ARGSTART++
break;
} else if (match(option, /^-.*/) != 0) {
option = substr(option, RSTART + 1, RLENGTH)
print self ": unknown option -- " option > "/dev/stderr"
usage()
exit 1
} else {
ARGSTART++
}
}
if (walk_order !~ /prefix|postfix/) {
print self ": unknown walk order -- " walk_order > "/dev/stderr"
usage()
exit 1
}
}
######################################################################
#
# main()
# This provides an implementation of the well-known non-recursive
# algorithm for depth-first-traversal of a graph, but with a
# small modification to allow visiting the nodes (package directories)
# in either "prefix" or "postfix" order. This more closely mimics
# a function stack than the usual non-recursive DFS algorithm.
#
######################################################################
function main( cmd, depends_pkgpath, dir, pkgpath) {
#
# Push the given package directories onto the stack.
while (ARGC >= ARGSTART) {
ARGC--;
cmd = TEST " -d " PKGSRCDIR "/" ARGV[ARGC]
if (system(cmd) == 0) {
if (do_root == 0) {
root[ARGV[ARGC]] = ARGV[ARGC]
}
if (status[ARGV[ARGC]] == "") {
push(dir_stack, ARGV[ARGC])
}
}
# Depth-first traversal of dependency graph.
while (!empty(dir_stack)) {
pkgpath = top(dir_stack)
if (status[pkgpath] != "") {
if (walk_order == "postfix" && status[pkgpath] != "visited") {
status[pkgpath] = "visited"
visit(pkgpath)
}
pop(dir_stack)
continue
}
status[pkgpath] = "walked"
if (walk_order == "prefix" && status[pkgpath] != "visited") {
status[pkgpath] = "visited"
visit(pkgpath)
}
# Grab the "depends_type" dependencies of the current
# package and push them onto the stack. We use the
# "show-depends-pkgpaths" target to fetch this information.
#
dir = PKGSRCDIR "/" pkgpath
cmd = "if " TEST " -d " dir "; then cd " dir " && " MAKE " show-depends-pkgpaths DEPENDS_TYPE=\"" depends_type "\"; fi"
while (cmd | getline depends_pkgpath) {
if (status[depends_pkgpath] == "") {
push(tmp_stack, depends_pkgpath)
}
}
close(cmd)
# This isn't really necessary, but does preserve child traversal
# order as presented by show-depends-pkgpaths
while (!empty(tmp_stack)) {
push(dir_stack, top(tmp_stack))
pop(tmp_stack)
}
}
}
exit 0
}
######################################################################
#
# visit(pkgpath)
# Visit the package directory by running the shell command
# specified on the command line and stored in "cmd_hook".
# If "cmd_hook" is empty, then just print the package directory
# name.
#
######################################################################
function visit(pkgpath, cmd, dir) {
if ((do_root == 0) && (root[pkgpath] != "")) {
return
}
if (cmd_hook == "") {
print pkgpath
} else {
dir = PKGSRCDIR "/" pkgpath
cmd = "cd " dir " && " cmd_hook
system(cmd)
}
}
######################################################################
#
# empty(stack)
# top(stack)
# push(stack, element)
# pop(stack)
# The well-known functions associated with a STACK.
#
######################################################################
function empty(stack) {
return (stack[0] <= 0)
}
function top(stack) {
return stack[stack[0]];
}
function push(stack, elt) {
stack[++stack[0]] = elt
}
function pop(stack) {
stack[0]--
}

5
mk/scripts/fail Normal file
View File

@@ -0,0 +1,5 @@
#! /bin/sh
# $NetBSD: fail,v 1.1 2007/01/06 19:53:01 rillig Exp $
"$@"
exit 1

390
mk/scripts/genindex.awk Executable file
View File

@@ -0,0 +1,390 @@
#!/usr/bin/awk -f
# $NetBSD: genindex.awk,v 1.8 2013/05/09 23:37:27 riastradh Exp $
#
# Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Dan McMahill.
#
# 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.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the NetBSD
# Foundation, Inc. and its contributors.
# 4. Neither the name of The NetBSD Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# 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.
#
# Global variables
#-----------------
# The following associative arrays are used for storing the dependency
# information and other information for the packages
#
# topdepends[] : index=pkgdir (math/scilab)
# List of explicitly listed depencencies by name.
# I.e. "xless-[0-9]* pvm-3.4.3"
#
# alldepends[] : index=pkgdir (math/scilab)
# Flattened dependency list by name.
#
#
BEGIN {
debug = 0;
printf("Reading database file\n");
}
#conflicts /usr/pkgsrc/math/scilab
#depends /usr/pkgsrc/math/scilab xless-[0-9]*:../../x11/xless pvm-3.4.3:../../parallel/pvm3
#
# XXX Need to handle BUILD_DEPENDS/TOOL_DEPENDS split.
/^(build_)?depends / {
#
# Read in the entire depends tree
# These lines look like:
#
#depends /usr/pkgsrc/math/scilab xless-[0-9]*:../../x11/xless pvm-3.4.3:../../parallel/pvm3
#build_depends /usr/pkgsrc/math/scilab libtool-base>=1.4.20010614nb9:../../devel/libtool-base
#
deptype=$1;
# pkg=fulldir2pkgdir($2);
pkg = $2;
if (pkg in topdepends) {}
else {topdepends[pkg] = "";}
if (pkg in topbuilddepends) {}
else {topbuilddepends[pkg] = "";}
for (i = 3; i <= NF; i++) {
split($i, a,":");
pkgpat = a[1];
pkgdir = a[2];
sub(/[\.\/]*/, "", pkgdir);
if (pkgdir !~ /\//) {
pkgcat = pkg;
gsub(/\/.*/, "", pkgcat);
pkgdir=pkgcat "/" pkgdir;
if (debug)
printf("Corrected missing category directory to get \"%s\"\n",
pkgdir);
}
if (debug){
printf("package in directory %s %s on:\n",
pkg, deptype);
printf("\tpkgpat = %s\n", pkgpat);
printf("\tpkgdir = %s\n", pkgdir);
}
#
# store the package directory in a associative array with the wildcard
# pattern as the index since we will need to be able to look this up later
#
pat2dir[pkgpat] = pkgdir;
if (deptype == "depends") {
topdepends[pkg] = topdepends[pkg] " " pkgpat " " ;
if (debug) {
printf("Appending %s to topdepends[%s] (%s)\n",
pkgpat, pkg, topdepends[pkg]);
}
}
else {
if (debug) {
printf("Appending %s to topbuilddepends[%s] (%s)\n",
pkgpat, pkg, topbuilddepends[pkg]);
}
topbuilddepends[pkg] = topbuilddepends[pkg] " " pkgpat " " ;
}
}
next;
}
/^categories /{
# note: we pick out the categories slightly differently than the comment
# and homepage because the category name will be included in the directory
# name and hence the index() call points to the wrong location
categories[$2] = $3;
for(i = 4; i <= NF; i = i + 1) {
categories[$2] = categories[$2] " " $i;
}
next;
}
/^comment /{
comment[$2] = substr($0, index($0, $3));
next;
}
/^descr /{
descr[$2] = substr($0, index($0, $3));
next;
}
/^homepage /{
if( NF>=3 ) {
homepage[$2] = substr($0, index($0, $3));
} else {
homepage[$2] = "";
}
next;
}
/^index / {
#
# read lines like:
#index /usr/pkgsrc/math/scilab scilab-2.6nb3
# and store the directory name in a associative array where the index
# is the package name and in a associative array that lets us lookup
# name from directory. We use fuldir2pkgdir to get "math/scilab"
# and drop the /usr/pkgsrc part.
#
# pkgname2dir[$3] = fulldir2pkgdir($2);
# pkgdir2name[fulldir2pkgdir($2)] = $3;
pkgname2dir[$3] = $2;
pkgdir2name[$2] = $3;
next;
}
/^license /{
license[$2] = substr($0, index($0, $3));
next;
}
/^maintainer /{
maintainer[$2] = substr($0, index($0, $3));
next;
}
/^notfor /{
notfor[$2] = substr($0, index($0, $3));
next;
}
/^onlyfor /{
onlyfor[$2] = substr($0, index($0, $3));
next;
}
/^prefix /{
prefix[$2] = substr($0, index($0, $3));
next;
}
/^wildcard /{
wildcard[$2] = substr($0, index($0, $3));
next;
}
#
# Now recurse the tree to give a flattened depends list for each pkg
#
END {
if( SORT == "" ) { SORT = "sort"; }
indexf = SORT " > INDEX";
if ( dependsfile == "" ) dependsfile = "/dev/null";
if ( builddependsfile == "" ) builddependsfile = "/dev/null";
printf("Flattening dependencies\n");
printf("") > dependsfile;
for (toppkg in topdepends){
if (debug) printf("calling find_all_depends(%s, run)\n", toppkg);
find_all_depends(toppkg, "run");
if (debug) printf("%s depends on: %s, topdepends on %s\n",
toppkg, alldepends[toppkg],
topdepends[toppkg]);
printf("%s depends on: %s\n",
toppkg, alldepends[toppkg]) >> dependsfile;
flatdepends[toppkg] = alldepends[toppkg];
}
close(dependsfile);
# clear out the flattened depends list and repeat for the build depends
for( pkg in alldepends) {
delete alldepends[pkg];
}
printf("Flattening build dependencies\n");
printf("") > builddependsfile;
for (toppkg in topbuilddepends){
find_all_depends(toppkg, "build");
printf("%s build_depends on: %s\n",
toppkg, alldepends[toppkg]) >> builddependsfile;
}
close(builddependsfile);
printf("Generating INDEX file\n");
# Output format:
# package-name|package-path|installation-prefix|comment| \
# description-file|maintainer|categories|build deps|run deps|for arch| \
# not for opsys|homepage
pkgcnt = 0;
for (toppkg in topdepends){
pkgcnt++;
printf("%s|", pkgdir2name[toppkg]) | indexf;
printf("%s|", toppkg) | indexf;
printf("%s|", prefix[toppkg]) | indexf;
printf("%s|", comment[toppkg]) | indexf;
printf("%s|", descr[toppkg]) | indexf;
printf("%s|", maintainer[toppkg]) | indexf;
printf("%s|", categories[toppkg]) | indexf;
gsub(/^ /, "", alldepends[toppkg]);
gsub(/ $/, "", alldepends[toppkg]);
printf("%s|", alldepends[toppkg]) | indexf;
gsub(/^ /, "", flatdepends[toppkg]);
gsub(/ $/, "", flatdepends[toppkg]);
printf("%s|", flatdepends[toppkg]) | indexf;
printf("%s|", onlyfor[toppkg]) | indexf;
printf("%s|", notfor[toppkg]) | indexf;
printf("%s", homepage[toppkg]) | indexf;
printf("\n") | indexf;
}
close(indexf);
printf("Indexed %d packages\n", pkgcnt);
exit 0;
}
function find_all_depends(pkg, type, pkgreg, i, deps, depdir, topdep){
# pkg is the package directory, like math/scilab
# printf("find_all_depends(%s, %s)\n", pkg, type);
# if we find the package already has been fully depended
# then return the depends list
if (pkg in alldepends){
if (debug) printf("\t%s is allready depended. Returning %s\n",
pkg, alldepends[pkg]);
return(alldepends[pkg]);
}
# if this package has no top dependencies, enter an empty flat dependency
# list for it.
if( type == "run" ) {
# we only want DEPENDS
topdep = topdepends[pkg];
} else {
# we want BUILD_DEPENDS and DEPENDS
topdep = topdepends[pkg] " " topbuilddepends[pkg];
}
if (topdep ~ "^[ \t]*$") {
alldepends[pkg] = " ";
if (debug) printf("\t%s has no depends(%s). Returning %s\n",
pkg, topdep, alldepends[pkg]);
return(alldepends[pkg]);
}
# recursively gather depends that each of the depends has
pkgreg = reg2str(pkg);
split(topdep, deps);
i = 1;
alldepends[pkg] = " ";
while ( i in deps ) {
# figure out the directory name associated with the package hame
# in (wild card/dewey) version form
depdir = pat2dir[deps[i]];
if (debug) printf("\tadding dependency #%d on \"%s\" (%s)\n",
i, deps[i], depdir);
# do not add ourselves to the list (should not happen, but
# we would like to not get stuck in a loop if one exists)
# if (" "deps[i]" " !~ pkgreg){
# if we do not already have this dependency (deps[i]) listed, then add
# it. However, we may have already added it because another package
# we depend on may also have depended on
# deps[i].
if (alldepends[pkg] !~ reg2str(deps[i])){
alldepends[pkg] = alldepends[pkg] " " deps[i] " " find_all_depends(depdir, type);
}
else {
if (debug) printf("\t%s is already listed in %s\n",
deps[i], alldepends[pkg]);
}
i = i + 1;
} # while i
if (debug) printf("\tcalling uniq() on alldepends[%s] = %s\n",
pkg, alldepends[pkg]);
alldepends[pkg] = uniq(alldepends[pkg]);
if (debug) printf("\tuniq() output alldepends[%s] = %s\n",
pkg, alldepends[pkg]);
return(alldepends[pkg]);
}
#
# take a string which has special characters like '+' in it and
# escape them. Also put a space before and after since that's how
# we'll distinguish things like gnome from gnome-libs
#
function reg2str(reg){
gsub(/\./, "\\.", reg);
gsub(/\+/, "\\+", reg);
gsub(/\*/, "\\*", reg);
gsub(/\?/, "\\?", reg);
gsub(/\[/, "\\[", reg);
gsub(/\]/, "\\]", reg);
reg = " "reg" ";
return(reg);
}
#
# accepts a full path to a package directory, like "/usr/pkgsrc/math/scilab"
# and returns just the last 2 directories, like "math/scilab"
#
function fulldir2pkgdir(d, i){
i = match(d, /\/[^\/]+\/[^\/]+$/);
return substr(d, i + 1);
}
#
# take the depends lists and uniq them.
#
function uniq(list, deps, i, ulist){
# split out the depends
split(list, deps);
i = 1;
ulist = " ";
while (i in deps){
# printf("uniq(): Checking \"%s\"\n", ulist);
# printf(" for \"%s\"\n", reg2str(deps[i]));
if (ulist !~reg2str(deps[i])){
ulist = ulist deps[i]" ";
}
i++;
}
return(ulist);
}

861
mk/scripts/genreadme.awk Executable file
View File

@@ -0,0 +1,861 @@
#!/usr/bin/awk -f
# $NetBSD: genreadme.awk,v 1.35 2013/05/09 23:37:27 riastradh Exp $
#
# Copyright (c) 2002, 2003, 2005, 2006 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Dan McMahill.
#
# 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.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the NetBSD
# Foundation, Inc. and its contributors.
# 4. Neither the name of The NetBSD Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# 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.
#
# Global variables
#-----------------
# The following associative arrays are used for storing the dependency
# information and other information for the packages
#
# topdepends[] : index=pkgdir (math/scilab)
# List of explicitly listed depencencies by name.
# I.e. "xless-[0-9]* pvm-3.4.3"
#
# alldepends[] : index=pkgdir (math/scilab)
# Flattened dependency list by name.
#
BEGIN {
do_pkg_readme=1;
# set to 1 to use "README-new.html" as the name
use_readme_new=0;
if (use_readme_new) {
readme_name = "README-new.html";
}
else {
readme_name = "README.html";
}
printf("Reading database file\n");
}
#conflicts /usr/pkgsrc/math/scilab
#depends /usr/pkgsrc/math/scilab xless-[0-9]*:../../x11/xless pvm-3.4.3:../../parallel/pvm3
#
/^(build_)?depends / {
#
# Read in the entire depends tree
# These lines look like:
#
#depends /usr/pkgsrc/math/scilab xless-[0-9]*:../../x11/xless pvm-3.4.3:../../parallel/pvm3
#build_depends /usr/pkgsrc/math/scilab libtool-base>=1.4.20010614nb9:../../devel/libtool-base
#
deptype=$1;
# pkg=fulldir2pkgdir($2);
pkg = $2;
if (pkg in topdepends) {}
else {topdepends[pkg] = "";}
if (pkg in topbuilddepends) {}
else {topbuilddepends[pkg] = "";}
for (i = 3; i <= NF; i++) {
split($i, a,":");
pkgpat = a[1];
pkgdir = a[2];
sub(/[\.\/]*/, "", pkgdir);
if (pkgdir !~ /\//) {
pkgcat = pkg;
gsub(/\/.*/, "", pkgcat);
pkgdir=pkgcat "/" pkgdir;
if (debug)
printf("Corrected missing category directory to get \"%s\"\n",
pkgdir);
}
if (debug){
printf("package in directory %s %s on:\n",
pkg, deptype);
printf("\tpkgpat = %s\n", pkgpat);
printf("\tpkgdir = %s\n", pkgdir);
}
#
# store the package directory in a associative array with the wildcard
# pattern as the index since we will need to be able to look this up later
#
pat2dir[pkgpat] = pkgdir;
if (deptype == "depends") {
topdepends[pkg] = topdepends[pkg] " " pkgpat " " ;
if (debug) {
printf("Appending %s to topdepends[%s] (%s)\n",
pkgpat, pkg, topdepends[pkg]);
}
}
else {
if (debug) {
printf("Appending %s to topbuilddepends[%s] (%s)\n",
pkgpat, pkg, topbuilddepends[pkg]);
}
topbuilddepends[pkg] = topbuilddepends[pkg] " " pkgpat " " ;
}
}
next;
}
/^comment /{
dir = $2;
gsub(/^comment[ \t]*/, "");
tmp = substr($0, length($1) + 1);
gsub(/^[ \t]*/, "", tmp);
gsub(/&/, "\\\\\\&amp;", tmp);
comment[dir] = tmp;
next;
}
/^homepage /{
homepage[$2] = $3;
gsub(/&/, "\\\\&", homepage[$2]);
next;
}
/^htmlname / {
#
# read lines like:
# htmlname /usr/pkgsrc/archivers/arc <a href=../../archivers/arc/README.html>arc-5.21e</A>
#
# dir=fulldir2pkgdir($2);
dir = $2;
htmlname = $3;
for (i = 4; i <= NF; i++){
htmlname = htmlname " " $i;
}
# If we are using a name other than README.html, change it
# here. This avoids having to process a huge line later which
# makes lesser awks puke.
gsub(/README.html/, readme_name, htmlname);
dir2htmlname[dir] = htmlname;
if (debug) printf("added dir2htmlname[%s]=%s\n", dir, htmlname);
next;
}
/^index / {
#
# read lines like:
#index /usr/pkgsrc/math/scilab scilab-2.6nb3
# and store the directory name in a associative array where the index
# is the package name and in a associative array that lets us lookup
# name from directory. We use fuldir2pkgdir to get "math/scilab"
# and drop the /usr/pkgsrc part.
#
# pkgname2dir[$3] = fulldir2pkgdir($2);
# pkgdir2name[fulldir2pkgdir($2)] = $3;
pkgname2dir[$3] = $2;
pkgdir2name[$2] = $3;
next;
}
/^license /{
license[$2] = $3;
next;
}
/^wildcard /{
wildcard[$2] = $3;
}
#
# Now recurse the tree to give a flattened depends list for each pkg
#
END {
readme = TMPDIR "/" readme_name;
if ( dependsfile == "" ) dependsfile = "/dev/stdout";
if ( builddependsfile == "" ) builddependsfile = "/dev/stdout";
printf("Making sure binary package cache file is up to date...\n");
if ( quiet == "yes" ){
cmd = sprintf("%s AWK=%s CMP=%s FIND=%s GREP=%s GZIP_CMD=\"%s\" PKG_INFO=\"%s\" PKG_SUFX=%s SED=%s SORT=%s %s/mk/scripts/binpkg-cache %s --packages %s",
SETENV, AWK, CMP, FIND, GREP, GZIP_CMD, PKG_INFO, PKG_SUFX, SED, SORT, PKGSRCDIR, summary, PACKAGES);
} else {
cmd = sprintf("%s AWK=%s CMP=%s FIND=%s GREP=%s GZIP_CMD=\"%s\" PKG_INFO=\"%s\" PKG_SUFX=%s SED=%s SORT=%s %s/mk/scripts/binpkg-cache %s --packages %s --verbose",
SETENV, AWK, CMP, FIND, GREP, GZIP_CMD, PKG_INFO, PKG_SUFX, SED, SORT, PKGSRCDIR, summary, PACKAGES);
}
if (debug) printf("\nExecute: %s\n",cmd);
rc = system(cmd);
if (rc != 0 && rc != 2) {
printf("\n**** WARNING ****\n") > "/dev/stderr";
printf("Command: %s\nfailed.", cmd) > "/dev/stderr";
printf("**** ------- ****\n") > "/dev/stderr";
exit(1);
}
if (rc == 2) {
printf("\n**** WARNING ****\n") > "/dev/stderr";
printf("* No binary packages directory found\n") > "/dev/stderr";
printf("* List of binary packages will not be generated\n") > "/dev/stderr";
printf("**** ------- ****\n") > "/dev/stderr";
} else {
printf("Loading binary package cache file...\n");
load_cache_file( PACKAGES "/.pkgcache" );
if(pkg_count["unknown"] > 0 ) {
printf(" Loaded %d binary packages with unknown PKGPATH\n", pkg_count["unknown"]);
}
}
printf("Flattening dependencies\n");
printf("") > dependsfile;
for (toppkg in topdepends){
if (debug) printf("calling find_all_depends(%s, run)\n", toppkg);
find_all_depends(toppkg, "run");
if (debug) printf("%s depends on: %s, topdepends on %s\n",
toppkg, alldepends[toppkg],
topdepends[toppkg]);
printf("%s depends on: %s\n",
toppkg, alldepends[toppkg]) >> dependsfile;
flatdepends[toppkg] = alldepends[toppkg];
}
close(dependsfile);
# clear out the flattened depends list and repeat for the build depends
for( key in alldepends ) {
delete alldepends[key];
}
printf("Flattening build dependencies\n");
printf("") > builddependsfile;
for (toppkg in topbuilddepends){
find_all_depends(toppkg, "build");
printf("%s build_depends on: %s\n",
toppkg, alldepends[toppkg]) >> builddependsfile;
}
close(builddependsfile);
# extract date for vulnerabilities file
if (SCAN_VULNERABILITIES == 0)
vuldate="<TR><TD><I>(no vulnerabilities list, update pkg_install)</I>";
else if (SCAN_VULNERABILITIES == 1)
vuldate="<TR><TD><I>(no vulnerabilities list available)</I>";
if (SINGLEPKG != "" ) {
printf("Only creating README for %s\n",SINGLEPKG);
for( key in topdepends ) {
delete topdepends[key];
}
topdepends[SINGLEPKG] = "yes";
}
printf("Generating README.html files\n");
pkgcnt = 0;
if (do_pkg_readme) {
templatefile = PKGSRCDIR "/templates/README.pkg";
fatal_check_file(templatefile);
for (toppkg in topdepends){
pkgcnt++;
pkgdir = PKGSRCDIR "/" toppkg;
readmenew=pkgdir "/" readme_name;
if (debug) printf("Creating %s for %s\n",
readme, readmenew);
if (quiet != "yes") {
printf(".");
if ((pkgcnt % 100) == 0) {
printf("\n%d\n", pkgcnt);
}
}
printf("") > readme;
htmldeps = "";
for( key in dpkgs ) {
delete dpkgs[key];
}
split(alldepends[toppkg], dpkgs);
i = 1;
htmldeps_file = TMPDIR "/htmldep";
printf("") > htmldeps_file;
while(i in dpkgs){
if (debug) {
printf("\tdpkg=%s, pat2dir[%s] = %s\n",
dpkgs[i],
dpkgs[i],
pat2dir[dpkgs[i]]);
}
nm=dpkgs[i];
gsub(/&/, "\\&amp;", nm);
gsub(/</, "\\&lt;", nm);
gsub(/>/, "\\&gt;", nm);
# htmldeps=sprintf("%s<a href=\"../../%s/%s\">%s</a>\n",
# htmldeps,
# pat2dir[dpkgs[i]],
# readme_name, nm);
# We use a temp file to hold the html dependencies because for
# packages like gnome, this list can get very very large and
# become larger than what some awk implementations can deal
# with. The nawk shipped with solaris 9 is an example of
# such a limited awk.
printf("%s<a href=\"../../%s/%s\">%s</a>\n",
htmldeps,
pat2dir[dpkgs[i]],
readme_name, nm) >> htmldeps_file;
i = i + 1;
}
if ( i == 1 ) {
printf("<EM>none</EM>") >> htmldeps_file;
}
close(htmldeps_file);
if (debug) printf("wrote = %d entries to \"%s\"\n",
i-1, htmldeps_file);
vul = "";
if (SCAN_VULNERABILITIES == 2) {
pkgbase = pkgdir2name[toppkg];
sub("-[^-]*$", "", pkgbase);
cmd = sprintf("%s audit-history %s", PKG_ADMIN, pkgbase);
while (cmd | getline vuln_entry) {
split(vuln_entry, entry, " ");
status_cmd = sprintf("if %s pmatch '%s' %s; then echo open; else echo fixed; fi",
PKG_ADMIN, entry[1], pkgdir2name[toppkg]);
status_cmd | getline status
close(status_cmd)
if (status == "open")
status = "an <STRONG>OPEN</STRONG>";
else
status = "a " status;
vul = sprintf("%s<LI>%s <a href=\"%s\">%s</a> vulnerability</LI>\n",
vul, status, entry[3], entry[2]);
}
close(cmd);
if ( vul == "" ) {
vul="<I>(no vulnerabilities known)</I>";
}
}
if (debug) {
printf("Checking for binary package with lookup_cache( %s)\n",
toppkg);
}
# lookup_cache( wildcard ) will produce HTML for the packages which are found
lookup_cache( toppkg );
if ( flatdepends[toppkg] ~ /^[ \t]*$/ ) {
rundeps = "<EM>none</EM>";
} else {
rundeps = flatdepends[toppkg];
}
while((getline < templatefile) > 0){
gsub(/%%PORT%%/, toppkg);
gsub(/%%PKG%%/, pkgdir2name[toppkg]);
gsub(/%%COMMENT%%/, comment[toppkg]);
if (homepage[toppkg] == "") {
gsub(/%%HOMEPAGE%%/, "");
} else {
gsub(/%%HOMEPAGE%%/,
"<p>This package has a home page at <a HREF=\"" homepage[toppkg] "\">" homepage[toppkg] "</a>.</p>");
}
if (license[toppkg] == "") {
gsub(/%%LICENSE%%/, "");
} else {
gsub(/%%LICENSE%%/,
"<p>Please note that this package has a " license[toppkg] " license.</p>");
}
gsub(/%%VULNERABILITIES%%/, ""vul"");
gsub(/%%VULDATE%%/, ""vuldate"");
gsub(/%%RUN_DEPENDS%%/, ""rundeps"");
line = $0;
if( line ~/%%BIN_PKGS%%/ ) {
gsub(/%%BIN_PKGS%%/, "", line);
while((getline < binpkgs_file) > 0) {
print >> readme;
}
close( binpkgs_file );
}
# XXX Need to handle BUILD_DEPENDS/TOOL_DEPENDS
# split.
if( line ~/%%BUILD_DEPENDS%%/ ) {
gsub(/%%BUILD_DEPENDS%%/, "", line);
while((getline < htmldeps_file) > 0) {
print >> readme;
}
close( htmldeps_file );
}
print line >> readme;
}
close(readme);
close(templatefile);
cmd = "if [ ! -d " pkgdir " ]; then exit 1 ; fi";
if (debug) printf("Execute: %s\n",cmd);
rc = system(cmd);
if (rc != 0) {
printf("\n**** WARNING ****\nPackage directory %s\n",
pkgdir) > "/dev/stderr";
printf("Does not exist. This is probably ") > "/dev/stderr";
printf("due to an incorrect DEPENDS line.\n") > "/dev/stderr";
printf("Try running: grep %s */*/Makefile\n", fulldir2pkgdir(pkgdir)) > "/dev/stderr";
printf("or: grep %s */*/buildlink3.mk\n", fulldir2pkgdir(pkgdir)) > "/dev/stderr";
printf("to find the problem\n", pkgdir) > "/dev/stderr";
printf("**** ------- ****\n") > "/dev/stderr";
} else {
copy_readme(readmenew, readme);
}
}
printf("\n");
} # if (do_pkg_readme)
printf("\n");
if (SINGLEPKG != "" ) {
close("/dev/stderr");
exit 0;
}
printf("Generating category readmes\n");
templatefile = PKGSRCDIR "/templates/README.category";
fatal_check_file(templatefile);
# string with URLs for all categories (used by the top README.html)
allcat = "";
# string with URLs for all pkgs (used by the top README-all.html)
tot_numpkg = 0;
top_make = PKGSRCDIR"/Makefile";
while((getline < top_make) > 0){
if ($0 ~ /^[ \t]*SUBDIR.*=[^\$]*$/) {
category = $0;
gsub(/^[ \t]*SUBDIR.*=[ \t]*/, "", category);
catdir = PKGSRCDIR"/"category;
readmenew = catdir"/"readme_name;
printf("Category = %s\n", category);
cat_make = catdir"/Makefile";
pkgs = "";
pkgs_file = TMPDIR "/pkgs_file";
printf("") > pkgs_file;
numpkg = 0;
print "" > readme;
while((getline < cat_make) > 0){
if ($0 ~ /^[ \t]*SUBDIR.*=[^\$]*$/) {
pkg = $0;
gsub(/^[ \t]*SUBDIR.*=[ \t]*/, "",
pkg);
dir = category"/"pkg;
numpkg++;
tot_numpkg++;
if (debug) {
printf("\tAdding %s (%s : %s)\n",
dir,
pkgdir2name[dir],
comment[dir]);
}
# pkgs = sprintf("%s<TR><TD VALIGN=TOP><a href=\"%s/%s\">%s</a>: %s<TD>\n",
# pkgs, pkg, readme_name,
# pkgdir2name[dir],
# comment[dir]);
# We use a temp file to hold the list of all packages because
# this list can get very very large and
# become larger than what some awk implementations can deal
# with. The nawk shipped with solaris 9 is an example of
# such a limited awk.
printf("<TR><TD VALIGN=TOP><a href=\"%s/%s\">%s</a>: %s<TD>\n",
pkg, readme_name,
pkgdir2name[dir],
comment[dir]) >> pkgs_file;
allpkg[tot_numpkg] = sprintf("<!-- %s (for sorting) --><TR VALIGN=TOP><TD><a href=\"%s/%s/%s\">%s</a>: <TD>(<a href=\"%s/%s\">%s</a>) <td>%s\n",
pkgdir2name[dir],
category, pkg,
readme_name,
pkgdir2name[dir],
category,
readme_name,
category,
comment[dir]);
# we need slightly fewer escapes here since we are not gsub()-ing
# allpkg[] into the output files but just printf()-ing it.
gsub(/\\&/, "\\&", allpkg[tot_numpkg]);
} else if ($0 ~ /^[ \t]*COMMENT/) {
descr = $0;
gsub(/^[ \t]*COMMENT.*=[ \t]*/, "",
descr);
}
}
while ((getline < templatefile) > 0){
gsub(/%%CATEGORY%%/, category);
gsub(/%%NUMITEMS%%/, numpkg);
gsub(/%%DESCR%%/, descr);
line = $0
if( $0 ~/%%SUBDIR%%/ ) {
gsub(/%%SUBDIR%%/, "", line);
while((getline < pkgs_file) > 0) {
gsub(/README.html/, readme_name);
print >> readme;
}
close( pkgs_file );
}
print line >> readme;
}
close(readme);
close(templatefile);
copy_readme(readmenew, readme);
gsub(/href=\"/, "href=\""category"/", pkgs);
allcat = sprintf("%s<TR><TD VALIGN=TOP><a href=\"%s/%s\">%s</a>: %s<TD>\n",
allcat, category, readme_name,
category, descr);
close(cat_make);
}
}
close(top_make);
printf("Generating toplevel readmes:\n");
templatefile = PKGSRCDIR "/templates/README.top";
fatal_check_file(templatefile);
readmenew = PKGSRCDIR "/"readme_name;
printf("\t%s\n", readmenew);
print "" > readme;
while((getline < templatefile) > 0){
gsub(/%%DESCR%%/, "");
gsub(/%%SUBDIR%%/, allcat);
gsub(/README.html/, readme_name);
print >> readme;
}
close(readme);
close(templatefile);
copy_readme(readmenew, readme);
templatefile = PKGSRCDIR "/templates/README.all";
fatal_check_file(templatefile);
readmenew = PKGSRCDIR "/README-all.html";
printf("\t%s\n", readmenew);
# sort the pkgs
sfile = TMPDIR"/unsorted";
spipe = "sort " sfile;
i = 1;
print "" >sfile;
while(i in allpkg) {
printf("%s",allpkg[i]) >> sfile;
i++;
}
close(sfile);
print "" > readme;
while((getline < templatefile) > 0){
line = $0;
if ($0 ~ /%%PKGS%%/) {
while((spipe | getline) > 0) {
print >> readme;
}
close(spipe);
} else {
gsub(/%%DESCR%%/, "", line);
gsub(/%%NPKGS%%/, tot_numpkg, line);
gsub(/README.html/, readme_name, line);
print line >> readme;
}
}
close(readme);
close(templatefile);
copy_readme(readmenew, readme);
close("/dev/stderr");
exit 0;
}
function find_all_depends(pkg, type, pkgreg, i, deps, depdir, topdep){
# pkg is the package directory, like math/scilab
# printf("find_all_depends(%s, %s)\n", pkg, type);
# if we find the package already has been fully depended
# then return the depends list
if (pkg in alldepends){
if (debug) printf("\t%s is allready depended. Returning %s\n",
pkg, alldepends[pkg]);
return(alldepends[pkg]);
}
# if this package has no top dependencies, enter an empty flat dependency
# list for it.
if( type == "run" ) {
# we only want DEPENDS
topdep = topdepends[pkg];
} else {
# we want BUILD_DEPENDS and DEPENDS
topdep = topdepends[pkg] " " topbuilddepends[pkg];
}
if (topdep ~ "^[ \t]*$") {
alldepends[pkg] = " ";
if (debug) printf("\t%s has no depends(%s). Returning %s\n",
pkg, topdep, alldepends[pkg]);
return(alldepends[pkg]);
}
# recursively gather depends that each of the depends has
pkgreg = reg2str(pkg);
split(topdep, deps);
i = 1;
alldepends[pkg] = " ";
while ( i in deps ) {
# figure out the directory name associated with the package hame
# in (wild card/dewey) version form
depdir = pat2dir[deps[i]];
if (debug) printf("\tadding dependency #%d on \"%s\" (%s)\n",
i, deps[i], depdir);
# do not add ourselves to the list (should not happen, but
# we would like to not get stuck in a loop if one exists)
# if (" "deps[i]" " !~ pkgreg){
# if we do not already have this dependency (deps[i]) listed, then add
# it. However, we may have already added it because another package
# we depend on may also have depended on
# deps[i].
if (alldepends[pkg] !~ reg2str(deps[i])){
alldepends[pkg] = alldepends[pkg] " " deps[i] " " find_all_depends(depdir, type);
}
else {
if (debug) printf("\t%s is already listed in %s\n",
deps[i], alldepends[pkg]);
}
i = i + 1;
} # while i
if (debug) printf("\tcalling uniq() on alldepends[%s] = %s\n",
pkg, alldepends[pkg]);
alldepends[pkg] = uniq(alldepends[pkg]);
if (debug) printf("\tuniq() output alldepends[%s] = %s\n",
pkg, alldepends[pkg]);
return(alldepends[pkg]);
}
#
# take a string which has special characters like '+' in it and
# escape them. Also put a space before and after since that's how
# we'll distinguish things like gnome from gnome-libs
#
function reg2str(reg){
gsub(/\./, "\\.", reg);
gsub(/\+/, "\\+", reg);
gsub(/\*/, "\\*", reg);
gsub(/\?/, "\\?", reg);
gsub(/\[/, "\\[", reg);
gsub(/\]/, "\\]", reg);
reg = " "reg" ";
return(reg);
}
#
# take a string which has a shell glob pattern and turn it into
# an awk regular expression.
#
function glob2reg(reg){
# escape some characters which are special in regular expressions
gsub(/\./, "\\.", reg);
gsub(/\+/, "\\+", reg);
# and reformat some others
gsub(/\*/, ".*", reg);
gsub(/\?/, ".?", reg);
# finally, expand {a,b,c} type patterns
return(reg);
}
#
# accepts a full path to a package directory, like "/usr/pkgsrc/math/scilab"
# and returns just the last 2 directories, like "math/scilab"
#
function fulldir2pkgdir(d, i){
i = match(d, /\/[^\/]+\/[^\/]+$/);
return substr(d, i + 1);
}
#
# take the depends lists and uniq them.
#
function uniq(list, deps, i, ulist){
# split out the depends
split(list, deps);
i = 1;
ulist = " ";
while (i in deps){
# printf("uniq(): Checking \"%s\"\n", ulist);
# printf(" for \"%s\"\n", reg2str(deps[i]));
if (ulist !~reg2str(deps[i])){
ulist = ulist deps[i]" ";
}
i++;
}
return(ulist);
}
function fatal_check_file(file, cmd){
cmd="test -f " file ;
if (debug) printf("Execute: %s\n",cmd);
if (system(cmd) != 0) {
printf("**** FATAL ****\nRequired file %s does not exist\n",
file) > "/dev/stderr";
printf("**** ------- ****\n") > "/dev/stderr";
close("/dev/stderr");
exit(1);
}
}
# 'new' is the newly created README.html file
# 'old' is the existing (possibly not present) README.html file
#
# This function copies over the 'new' file if the 'old' one does
# not exist or if they are different. In addition, the 'new' one
# which is a temporary file is removed at the end
function copy_readme(old, new, cmd, rc) {
# if the README.html file does not exist at all then copy over
# the one we created
cmd = "if [ ! -f "old" ]; then cp " new " " old " ; fi";
if (debug) printf("copy_readme() execute: %s\n",cmd);
rc = system(cmd);
if (rc != 0) {
printf("**** WARNING ****\nThe command\n %s\n", cmd) > "/dev/stderr";
printf("failed with result code %d\n", rc) > "/dev/stderr";
printf("**** ------- ****\n") > "/dev/stderr";
}
# Compare the existing README.html file to the one we created. If they are
# not the same, then copy over the one we created
cmd = sprintf("%s -s %s %s ; if test $? -ne 0 ; then mv -f %s %s ; fi",
CMP, new, old, new, old);
if (debug) printf("copy_readme() execute: %s\n",cmd);
rc = system(cmd);
if (rc != 0) {
printf("**** WARNING ****\nThe command\n %s\n", cmd) > "/dev/stderr";
printf("failed with result code %d\n", rc) > "/dev/stderr";
printf("**** ------- ****\n") > "/dev/stderr";
}
# If the temp file still exists, then delete it
cmd = " if [ -f "new" ]; then rm -f "new" ; fi";
if (debug) printf("copy_readme() execute: %s\n",cmd);
rc = system(cmd);
if (rc != 0) {
printf("**** WARNING ****\nThe command\n %s\n", cmd) > "/dev/stderr";
printf("failed with result code %d\n", rc) > "/dev/stderr";
printf("**** ------- ****\n") > "/dev/stderr";
}
}
function load_cache_file( file, pkgfile, opsys, osver, march, wk, rx ) {
if ( quiet != "yes" ) printf(" * %s\n", file);
fatal_check_file( file );
# read the cache file
while( getline < file ) {
# if this line points to another cache file, then recursively
# load it
if( $0 ~ /^pkgcache_cachefile/ ) {
if( debug ) printf("\tFound pkgcache_cachefile line.\n");
load_cache_file( $2 );
} else if( $0 ~/^pkgcache_begin /) {
pkgfile = $2;
if( debug ) printf("\tStarting %s\n", pkgfile);
opsys = "unknown";
osver = "unknown";
march = "unknown";
pkgpath = "unknown";
} else if( $0 ~/^PKGPATH=/ ) {
pkgpath = $0;
gsub(/PKGPATH=[ \t]*/, "", pkgpath);
} else if( $0 ~/^OPSYS=/ ) {
opsys = $0;
gsub(/OPSYS=[ \t]*/, "", opsys);
} else if( $0 ~/^OS_VERSION=/ ) {
osver = $0;
gsub(/OS_VERSION=[ \t]*/, "", osver);
} else if( $0 ~/^MACHINE_ARCH=/ ) {
march = $0;
gsub(/MACHINE_ARCH=[ \t]*/, "", march);
} else if( $0 ~/^pkgcache_end /) {
if( debug ) printf("\t%s, OPSYS=%s, OS_VERSION=%s, MACHINE_ARCH=%s, PKGPATH=%s\n",
pkgfile, opsys, osver, march, pkpath);
pkg_count[pkgpath] = pkg_count[pkgpath] + 1;
opsys_list[pkgpath, pkg_count[pkgpath]] = opsys;
osver_list[pkgpath, pkg_count[pkgpath]] = osver;
march_list[pkgpath, pkg_count[pkgpath]] = march;
pkgfile_list[pkgpath, pkg_count[pkgpath]] = pkgfile;
gsub(/.*\//, "", pkgfile);
pkgnm_list[pkgpath, pkg_count[pkgpath]] = pkgfile;
} else {
# skip this line
}
}
# close the cache file
close( file );
}
function lookup_cache( d, binpkgs) {
if( debug ) printf("lookup_cache( %s ): pkg_count = %d\n",
d, pkg_count[d]);
binpkgs_file = TMPDIR "/binpkgs";
spipe = SORT " > " binpkgs_file;
for(i=1 ; i<=pkg_count[d]; i=i+1) {
printf("<TR><TD>%s:<TD><a href=\"%s/%s\">%s</a><TD>(%s %s)\n",
march_list[d, i], PKG_URL, pkgfile_list[d, i], pkgnm_list[d, i],
opsys_list[d, i], osver_list[d, i]) | spipe;
}
if( pkg_count[d] == 0 ) {
printf("<TR><TD><EM>none</EM></TD></TR>\n") | spipe;
}
close( spipe );
}

211
mk/scripts/mkdatabase Executable file
View File

@@ -0,0 +1,211 @@
#!/bin/sh
# $NetBSD: mkdatabase,v 1.9 2005/11/18 11:07:27 rillig Exp $
#
# Script for generating a database with complete dependency information
# for a particular package
#
# Copyright (c) 2003 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Dan McMahill.
#
# 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.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the NetBSD
# Foundation, Inc. and its contributors.
# 4. Neither the name of The NetBSD Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# 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.
#
#
# Global variables, based on environment variables
#
TMPDIR=${TMPDIR:-/tmp}
BMAKE=${BMAKE:-make}
AWK=${AWK:-/usr/bin/awk}
DATABASE=${DATABASE:-${TMPDIR}/pkgdb.$$}
EXPR=${EXPR:-expr}
# as of 2003-01-04, metapkgs/gnome gets to pass #6 so
# it is very likely that if you reach 25, something is broken
MAX_PASS=${MAX_PASS:-25}
#
# Global variables
#
prog=$0
append_flag=no
debug_flag="" # meaning "no"
#
# Helper functions
#
usage() {
echo "$prog - Generates a complete dependency tree for a particular package"
echo "Usage: $prog [-a|--append] [-d|--debug] [-f|--database database]"
echo ""
echo " $prog -h|--help"
echo ""
echo " $prog -v|--version"
echo ""
echo "The options supported by $prog are: "
echo ""
echo " -a|--append Append to the database rather than overwriting it"
echo ""
echo " -d|--debug Enables debugging output"
echo ""
echo " -f|--database <file> Writes the database into file specified by <file>"
echo ""
echo " -h|--help Displays this help message"
echo ""
echo " -v|--version Displays the version of this script and exits."
echo ""
echo "Example: cd /usr/pkgsrc/graphics/gimp && $prog -d /tmp/gimp_database"
echo ""
}
######################################################################
#
# Handle command line options
#
######################################################################
while test $# -gt 0; do
case $1 in
# Append to the database
-a|--append)
append_flag=yes
shift
;;
# Turn on debugging
-d|--debug)
debug_flag=yes
shift
;;
# Use the specified database file
-f|--database)
DATABASE=$2
shift 2
;;
# Help
-h|--help)
usage
exit 0
;;
# Version
-v|--version)
${AWK} '/^#[ \t]*\$NetBSD/ {gsub(/,v/,"",$3);printf("%s: Version %s, %s\n",$3,$4,$5); exit 0;}' $prog
exit 0
;;
*) echo "$prog: ERROR: $1 is not a valid option"
usage
exit 1
;;
esac
done
case $debug_flag in
yes) set -v;;
esac
if [ ! -d "$TMPDIR" ]; then
# FIXME: wouldn't it be better to fail in this case?
mkdir -p "$TMPDIR"
fi
prompt="----> "
case ${DATABASE} in
/*)
# we already have the absolute path to the database file
# so do nothing
;;
*)
# FIXME: wouldn't it be better to fail in this case?
# make sure we have the full path to the database file
DATABASE=`pwd`/${DATABASE}
;;
esac
if [ $append_flag = yes ]; then
echo "$prompt Appending to database in ${DATABASE}"
if [ ! -f "${DATABASE}" ]; then
touch "${DATABASE}"
fi
# make sure we haven't already been listed before
# appending ourselves.
here=`pwd`
tmp1=`dirname "$here"`
pkgcat=`basename "$tmp1"`
pkg=`basename "$here"`
pkgpath=$pkgcat/$pkg
case $debug_flag in
yes) echo "Looking for $pkgpath before appending";;
esac
# FIXME: $pkgpath may contain special regex characters.
if grep "^index $pkgpath " "${DATABASE}" >/dev/null 2>&1 ; then
echo "$prompt $pkgpath has already been depended. Skipping..."
exit 0
else
${BMAKE} print-summary-data >> "${DATABASE}" || exit 1
fi
else
echo "$prompt Creating new database in ${DATABASE}"
${BMAKE} print-summary-data > "${DATABASE}" || exit 1
fi
here=`pwd`
echo "$prompt Depending in $here (pass #1)"
dirs=`${AWK} -f ../../mk/scripts/chkdatabase.awk debug=${debug_flag} "${DATABASE}"`
pass=2
while [ ! -z "$dirs" -a $pass -lt "${MAX_PASS}" ]; do
for d in $dirs ; do
echo "$prompt Depending in ../../$d (pass #$pass)" ;\
cd "../../$d" && ${BMAKE} print-summary-data >> "${DATABASE}" || exit 1
cd "$here"
done
dirs=`${AWK} -f ../../mk/scripts/chkdatabase.awk debug=${debug_flag} ${DATABASE}`
pass=`${EXPR} $pass + 1`
done
if [ $pass -eq ${MAX_PASS} ]; then
echo "ERROR: You have reached $pass times through the dependency tree"
echo " and _still_ not finished. This is probably due to a broken"
echo " set of dependencies. You may wish to examine the partial"
echo " database left in ${DATABASE}"
exit 1
else
echo "Complete dependency database left in ${DATABASE}"
fi

543
mk/scripts/mkreadme Executable file
View File

@@ -0,0 +1,543 @@
#!/bin/sh
# $NetBSD: mkreadme,v 1.26 2011/04/22 09:03:53 spz Exp $
#
# Script for README.html generation
#
# Copyright (c) 2002, 2005 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Dan McMahill.
#
# 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.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the NetBSD
# Foundation, Inc. and its contributors.
# 4. Neither the name of The NetBSD Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# 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.
#
TMPDIR=${TMPDIR:-/tmp/mkreadme}
PKGSRCDIR=${PKGSRCDIR:-/usr/pkgsrc}
AWK=${AWK:-/usr/bin/awk}
opsys=`uname -s`
case "$opsys" in
*BSD)
makeprog=make
;;
*)
makeprog=bmake
;;
esac
BMAKE=${BMAKE:-${makeprog}}
usage(){
echo "$prog - Generates README.html files for a pkgsrc tree"
echo "Usage: $prog [-c|--cdrom] [-C|--prune] [-d|--debug] [-f|--ftp] "
echo " [-q|--quiet] "
echo " [-p|--pkgsrc directory] "
echo " [-P|--packages directory] [-r|--restart] "
echo " [-s|--summary]"
echo " [-S|--save-database]"
echo " "
echo " $prog -h|--help"
echo " "
echo " $prog -v|--version"
echo " "
echo "The options supported by $prog are: "
echo " "
echo " -C|--prune Prune unused README.html files which may exist in"
echo " pkg directories which have been removed from CVS."
echo " "
echo " -c|--cdrom Generates CD-ROM README.html files"
echo " "
echo " -d|--debug Enables (extremely verbose) debug output"
echo " "
echo " -f|--ftp Generates FTP README.html files"
echo " "
echo " -h|--help Displays this help message"
echo " "
echo " -q|--quiet Does not give progress output"
echo " "
echo " -p|--pkgsrc dir Specifies the pkgsrc directory. Defaults to"
echo " the value of the PKGSRCDIR environment variable"
echo " if set or /usr/pkgsrc otherwise."
echo " "
echo " -P|--packages dir Specifies the packages directory."
echo " "
echo " -r|--restart Restart. This option assumes that the database file"
echo " from a previous run still exists and that the script"
echo " should use that instead of recreating the database."
echo " "
echo " -s|--summary Generate pkg_summary.gz files for the binary packages"
echo " directories while processing them."
echo " "
echo " -S|--save-database Does not delete the database file after the run."
echo " This is useful for debugging or re-running this script"
echo " with the -r option."
echo " "
echo " -v|--version Displays the version of this script and exits."
echo " "
echo "Example: $prog -p /pub/pkgsrc/current/pkgsrc -P /pub/pkgsrc -f"
echo " "
}
clean_and_exit(){
if [ "x$DEBUG" = "xno" -a "x$restart" = "xno" -a "x$save" = "xno" ]; then
rm -fr $TMPDIR
else
echo "Debugging output left in $TMP"
fi
exit 1
}
prog=$0
######################################################################
#
# Handle command line options
#
######################################################################
cmdline=$*
ftp_readme=no
restart=no
prune=no
DEBUG=no
save=no
pv=default
quiet=no
summary=""
while
test -n "$1"
do
case "$1"
in
# We're generating README.html's for a CD-ROM
-c|--cdrom)
ftp_readme=no
shift
;;
# Prune old README.html files from pkgs which no longer exist
-C|--prune)
prune=yes
shift
;;
# Turn on debugging
-d|--debug)
DEBUG=yes
shift
;;
# We're generating README.html's for a CD-ROM
-f|--ftp)
ftp_readme=yes
shift
;;
# Help
-h|--help)
usage
exit 0
;;
# be less talkative
-q|--quiet)
quiet=yes
shift
;;
# Specify pkgsrc directory
-p|--pkgsrc)
PKGSRCDIR=$2
shift 2
;;
# Specify PACKAGES directory
-P|--packages)
PKGDIR=$2
shift 2
;;
# Restart (ie, don't re-generate the database file)
-r|--restart)
restart=yes
shift
;;
# Generate the pkg_summary.gz files
-s|--summary)
summary="--summary"
shift
;;
# Save the database files
-S|--save-database)
save=yes
shift
;;
# Version
-v|--version)
${AWK} '/^#[ \t]*\$NetBSD/ {gsub(/,v/,"",$3);printf("%s: Version %s, %s\n",$3,$4,$5); exit 0;}' $prog
exit 0
;;
-*) echo "$prog: ERROR: $1 is not a valid option"
usage
clean_and_exit
;;
*)
break
;;
esac
done
if [ "x$DEBUG" = "xyes" ]; then
set -v
fi
if [ ! -d ${PKGSRCDIR} ]; then
echo "ERROR: package source directory ${PKGSRCDIR} does not exist"
echo ""
clean_and_exit
fi
if [ ! -d $TMPDIR ]; then
mkdir -p $TMPDIR
fi
DEPENDSTREEFILE=$TMPDIR/dependstree
export DEPENDSTREEFILE
DEPENDSFILE=$TMPDIR/depends
export DEPENDSFILE
SUPPORTSFILE=$TMPDIR/supports
export SUPPORTSFILE
INDEXFILE=$TMPDIR/index
export SUPPORTSFILE
ORDERFILE=$TMPDIR/order
export ORDERFILE
DATABASEFILE=$TMPDIR/database
export DATABASEFILE
BINPKGFILE=$TMPDIR/binpkglist
echo "Starting README.html generation: `date`"
######################################################################
#
# Extract key pkgsrc configuration variables
#
######################################################################
echo " "
echo "Extracting tool variables:"
echo " "
if [ -d ${PKGSRCDIR}/pkgtools/prereq-readme ]; then
cd ${PKGSRCDIR}/pkgtools/prereq-readme
eval "`${BMAKE} show-tools`"
for v in AWK CMP ECHO EXPR FGREP FIND GREP GZIP_CMD SED SETENV SORT
do
eval "echo '---->' ${v}=\"\${${v}}\""
done
else
echo "Error: ${PKGSRCDIR}/pkgtools/prereq-readme does not seem to exist"
exit 1
fi
echo " "
echo "Extracting configuration variables:"
echo " "
if [ -d ${PKGSRCDIR}/pkgtools/prereq-readme ]; then
cd ${PKGSRCDIR}/pkgtools/prereq-readme
for v in CDROM_PKG_URL_HOST CDROM_PKG_URL_DIR DISTDIR \
FTP_PKG_URL_HOST FTP_PKG_URL_DIR PACKAGES PKG_INFO PKG_SUFX PKG_ADMIN \
AUDIT_PACKAGES AUDIT_PACKAGES_FLAGS PKGTOOLS_VERSION
do
val=`${BMAKE} show-var VARNAME=${v}`
if [ $? != 0 ]; then
echo "Error: make show-var VARNAME=${v} in `pwd` "
echo "Failed. This is a fatal error"
clean_and_exit
fi
echo "----> ${v}=\"${val}\""
eval "${v}=\"${val}\""
done
else
echo "Error: ${PKGSRCDIR}/pkgtools/prereq-readme does not seem to exist"
exit 1
fi
if [ `${PKG_ADMIN} -V` -lt 20080415 ]; then
SCAN_VULNERABILITIES=0
echo "----> NOT checking for vulnerabilities, pkg_install too old"
else
_PVDIR=`${PKG_ADMIN} config-var PKGVULNDIR`;
if [ -e "${_PVDIR}"/pkg-vulnerabilities ]; then
SCAN_VULNERABILITIES=2
echo "----> Checking for vulnerabilities"
else
SCAN_VULNERABILITIES=1
echo "----> NOT checking for vulnerabilities"
fi
fi
######################################################################
#
# Decide on FTP vs CDROM README.html files
#
######################################################################
if [ "$ftp_readme" = "yes" ]; then
PKG_URL=${FTP_PKG_URL_HOST}${FTP_PKG_URL_DIR}
echo "Will generate FTP readme files with PKG_URL=$PKG_URL"
else
PKG_URL=${CDROM_PKG_URL_HOST}${CDROM_PKG_URL_DIR}
echo "Will generate CD-ROM readme files with PKG_URL=$PKG_URL"
fi
######################################################################
#
# Check for command line switch for packages directory
#
######################################################################
# we've been given the directory as a command line switch
if [ ! -z "$PKGDIR" ]; then
PACKAGES=$PKGDIR
echo "PACKAGES specified on command line to be $PKGDIR"
fi
######################################################################
#
# Extract Database for All Packages (longest step)
#
######################################################################
if [ "x$restart" = "xno" ] ; then
echo " "
echo "Extracting data. This could take a while"
echo "Started at: `date` "
echo " "
npkg=1
# make sure we don't have an old database lying around
rm -fr $DATABASEFILE
cd ${PKGSRCDIR}
cats=`${BMAKE} show-subdir-var VARNAME=SUBDIR`
for c in ${cats} ; do
if [ ! -d ${PKGSRCDIR}/${c} ]; then
echo "WARNING: The category directory ${c} does not seem to" > /dev/stderr
echo " exist under ${PKGSRCDIR}" > /dev/stderr
else
if [ "x$quiet" = "xno" ]; then
echo " "
echo "Extracting data for category ${c}"
fi
cd ${PKGSRCDIR}/${c}
list=`${BMAKE} show-subdir-var VARNAME=SUBDIR`
for pkgdir in $list ; do
cd ${PKGSRCDIR}/${c}
if [ ! -d $pkgdir ]; then
echo " "
echo "WARNING: the package directory $pkgdir is listed in" > /dev/stderr
echo " ${PKGSRCDIR}/${c}/Makefile" > /dev/stderr
echo " but the directory does not exist. Please fix this!" > /dev/stderr
else
cd ${PKGSRCDIR}/${c}/${pkgdir}
l=`${BMAKE} print-summary-data`
if [ $? != 0 ]; then
echo "WARNING (printdepends): the package in ${c}/${pkgdir} had problem with" \
> /dev/stderr
echo " ${BMAKE} print-summary-data" > /dev/stderr
echo " database information for this package" > /dev/stderr
echo " will be dropped." > /dev/stderr
${BMAKE} print-summary-data 2>&1 > /dev/stderr
else
echo "$l" >> $DATABASEFILE
fi
fi
if [ "x$quiet" = "xno" ]; then
${ECHO} -n "."
if [ `${EXPR} $npkg % 100 = 0` -eq 1 ]; then
echo " "
echo "$npkg"
fi
fi
npkg=`${EXPR} $npkg + 1`
cd ${PKGSRCDIR}
done
fi
done
echo " "
echo "Finished extracting data for ${npkg} packages at: `date` "
else
echo " "
echo "Using existing database (are you sure you wanted the -r/--restart flag?)"
echo " "
if [ ! -f $DATABASEFILE ]; then
echo " "
echo "ERROR: You have use the -r/--restart flag but the database "
echo " file $DATABASEFILE does not exist"
echo " "
exit 1
fi
fi
######################################################################
#
# Generate the package and category README.html files
#
######################################################################
echo " "
echo "Generating package README.html files"
echo " "
if [ "x$DEBUG" = "xyes" ]; then
debug=1;
else
debug=0;
fi
${AWK} -f ${PKGSRCDIR}/mk/scripts/genreadme.awk \
builddependsfile=${TMPDIR}/pkgsrc.builddepends.debug \
debug=$debug \
quiet=$quiet \
dependsfile=${TMPDIR}/pkgsrc.depends.debug \
summary=${summary} \
AWK=$AWK \
CMP=$CMP \
DISTDIR=$DISTDIR \
FIND=$FIND \
GREP=$GREP \
GZIP_CMD="$GZIP_CMD" \
PACKAGES=$PACKAGES \
PKG_ADMIN="$PKG_ADMIN" \
PKG_INFO="$PKG_INFO" \
PKG_SUFX=$PKG_SUFX \
PKG_URL=$PKG_URL \
PKGSRCDIR=$PKGSRCDIR \
PKGTOOLS_VERSION=$PKGTOOLS_VERSION \
SCAN_VULNERABILITIES=${SCAN_VULNERABILITIES} \
SED=$SED \
SETENV=$SETENV \
SORT=$SORT \
TMPDIR=$TMPDIR \
${DATABASEFILE}
if [ $? != 0 ]; then
echo "Error: genreadme.awk failed to create README.html files"
clean_and_exit
fi
######################################################################
#
# Generate the README-IPv6.html file
#
######################################################################
echo " "
echo "Generating the README-IPv6.html file"
echo " "
cd ${PKGSRCDIR}
ipv6=${TMPDIR}/ipv6pkgs
ipv6_entries=${TMPDIR}/ipv6_entries
echo -n "" > $ipv6
cats=`${BMAKE} show-subdir-var VARNAME=SUBDIR`
for c in ${cats} ; do
if [ -d ${c} ]; then
${GREP} -l -e '^BUILD_DEFS.*=.*IPV6_READY' -e '^PKG_SUPPORTED_OPTIONS.*=.*inet6' -e '^USE_FEATURES.*=.*inet6' ${c}/*/Makefile | ${SED} -e 's;Makefile;;g' >> $ipv6
arethereoptions=`ls ${c}/*/options.mk 2>/dev/null`
if [ ! -z "$arethereoptions" ]; then
${GREP} -l -e '^BUILD_DEFS.*=.*IPV6_READY' -e '^PKG_SUPPORTED_OPTIONS.*=.*inet6' -e '^USE_FEATURES.*=.*inet6' ${c}/*/options.mk | ${SED} -e 's;options.mk;;g' >> $ipv6
fi
fi
done
${FGREP} -f $ipv6 README-all.html | sort -t/ +1 > $ipv6_entries
${SED} \
-e "/%%TRS%%/r${ipv6_entries}" \
-e '/%%TRS%%/d' \
templates/README.ipv6 > ${TMPDIR}/README-IPv6.html
if [ $? != 0 ]; then
echo "Error: README-IPv6.html generation failed (on sed script)"
clean_and_exit
fi
if [ ! -f README-IPv6.html ]; then
mv -f ${TMPDIR}/README-IPv6.html README-IPv6.html
elif cmp -s ${TMPDIR}/README-IPv6.html README-IPv6.html ; then
echo "README-IPv6.html is unchanged (no changes were needed)"
else
mv -f ${TMPDIR}/README-IPv6.html README-IPv6.html
fi
######################################################################
#
# Prune README.html files which are no longer needed
#
######################################################################
if [ "x$prune" = "xyes" ]; then
echo " "
echo "Pruning unused README.html files"
echo " "
cd ${PKGSRCDIR}
for d in `ls -d */*` ; do
if [ -d $d -a ! -f ${d}/Makefile -a -f ${d}/README.html ]; then
echo "Pruning ${d}/README.html which is no longer used"
rm -f ${d}/README.html
fi
done
fi
######################################################################
#
# All done. Clean (if needed) and exit
#
######################################################################
echo " "
echo "README.html generation finished: `date`"
echo " "
if [ "x$DEBUG" = "xno" -a "x$restart" = "xno" -a "x$save" = "xno" ]; then
rm -fr $TMPDIR
else
echo "Debugging output left in $TMPDIR"
fi

115
mk/scripts/pkg_path Executable file
View File

@@ -0,0 +1,115 @@
#!/bin/sh
#
# $NetBSD: pkg_path,v 1.4 2007/10/31 19:20:08 rillig Exp $
#
# Copyright (c) 2006 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Johnny C. Lam.
#
# 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.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the NetBSD
# Foundation, Inc. and its contributors.
# 4. Neither the name of The NetBSD Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# 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.
#
######################################################################
#
# NAME
# pkg_path -- canonicalize directories into "package paths"
#
# SYNOPSIS
# pkg_path [-s pkgsrcdir] dir ...
#
# OPTIONS
# The following command line arguments are supported.
#
# -s pkgsrcdir Use the specified directory as the path to the
# pkgsrc directory tree. By default, this is the
# value stored in the PKGSRCDIR environment variable.
#
# DESCRIPTION
# pkg_path canonicalizes the specified directories into package
# paths that are relative to the pkgsrc directory tree, and prints
# each of them to standard output on a new line. The specified
# directories are taken to be relative to the current directory.
# Directories that are not valid package directories or are not
# found are skipped during processing.
#
# ENVIRONMENT
# PKGSRCDIR This is the location of the pkgsrc directory tree,
# which defaults to "/usr/pkgsrc".
#
######################################################################
: ${ECHO=echo}
: ${PKGSRCDIR="/usr/pkgsrc"}
: ${PWD_CMD="pwd -P"}
self="${0##*/}"
usage() {
${ECHO} 1>&2 "usage: $self [-s pkgsrcdir] dir ..."
}
exitcode=0
# Process optional arguments
while [ $# -gt 0 ]; do
case "$1" in
-s) PKGSRCDIR=$2; shift 2 ;;
--) shift; break ;;
-*) ${ECHO} 1>&2 "$self: unknown option -- ${1#-}"
usage
exit 1
;;
*) break ;;
esac
done
# Process required arguments
startdir=`${PWD_CMD}`
while [ $# -gt 0 ]; do
dir="$1"; shift
case "$dir" in
${PKGSRCDIR}/*) ;;
/*) ${ECHO} 1>&2 "$self: \`\`$dir'' not a valid package directory"
exitcode=1
continue
;;
esac
if [ ! -d "$startdir/$dir" ]; then
${ECHO} 1>&2 "$self: \`\`$dir'' not found"
exitcode=1
continue
fi
pkgpath=`cd $startdir/$dir && ${PWD_CMD}`
pkgpath="${pkgpath#${PKGSRCDIR}/}"
${ECHO} "$pkgpath"
done
exit $exitcode

43
mk/scripts/remove_todo Executable file
View File

@@ -0,0 +1,43 @@
#!/bin/sh
# usage:
# $0 TODO-FILE PKGBASE PKGVERSION
# for example
# $0 /usr/pkgsrc/doc/TODO opal 3.6.4
# removes an entry for opal 3.6.4 or an older version from /usr/pkgsrc/doc/TODO
#
# test cases:
# remove_todo foo-1.2 with no foo entry in TODO
# remove_todo foo-1.2 with "foo-1.1", "foo-1.2", or "foo-1.3" in TODO
# remove_todo foo-1.2 with "foo-bar-1.1" in TODO
# remove_todo foo-1.2 with "foo-1.1 [some comment]", "foo-1.2 [some comment]", "foo-1.3 [some comment] in TODO
set -e
if [ "$#" != 3 ]
then
echo incorrect number of arguments >&2
echo usage: $0 TODO-FILE PKGBASE PKGVERSION >&2
exit 1
fi
TODO=$1
PKGBASE=$(echo $2 | sed "s/^py[0-9][0-9]-/py-/")
PKGVERSION=$3
TMPFILE="$TODO.$$"
PKG_ADMIN="${PKG_ADMIN:-pkg_admin}"
MATCH=$(grep -n '^[ ]*o '"$PKGBASE"'-[0-9]' "$TODO" | sed 's/^\([^:]*:\)[ ]*o /\1/;s/ .*//')
if [ $(echo "$MATCH" | wc -l) != 1 ]; then
echo "$0: multiple matches" 1>&2
echo "$MATCH" 1>&2
exit 1
fi
LINE=$(echo "$MATCH" | sed 's/:.*//')
FOUNDPKG=$(echo "$MATCH" | sed -e "s/^[^:]*://")
if ${PKG_ADMIN} pmatch "$PKGBASE"\<="$PKGVERSION" "$FOUNDPKG"; then
echo Removing "$FOUNDPKG" from TODO
sed < "$TODO" "$LINE"d > "$TMPFILE"
mv "$TMPFILE" "$TODO"
fi

385
mk/scripts/shell-lib Normal file
View File

@@ -0,0 +1,385 @@
# $NetBSD: shell-lib,v 1.4 2006/10/22 00:35:26 rillig Exp $
#
# Copyright (c) 2004 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Johnny C. Lam.
#
# 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.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the NetBSD
# Foundation, Inc. and its contributors.
# 4. Neither the name of The NetBSD Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# 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.
#
######################################################################
# msg_log logfile msg
# Output msg to logfile. If logfile is "stdout" or "stderr"
# then output to there instead.
######################################################################
msg_log()
{
: ${echo=echo}
_msg_log="$1"; shift
case $_msg_log in
stdout) $echo "$@" ;;
stderr) $echo "$@" 1>&2 ;;
*) $echo "$@" >> $_msg_log ;;
esac
}
######################################################################
# die msg
# Output $msg to stderr, and exit with a positive error code.
######################################################################
die()
{
msg_log stderr "$@"
exit 1
}
######################################################################
# check_prog var prog ...
# If $var is empty or unset, then set it to the path of one of
# the program names in the list.
######################################################################
check_prog()
{
: ${test=test}
_ckp_var="$1"; shift
eval _ckp_tmp=\"\$$_ckp_var\"
if $test "x$_ckp_tmp" != "x"; then
return 0
fi
for _ckp_prog do
_ckp_IFS="${IFS}"; IFS=":"
for _ckp_dir in ${PATH}; do
if $test -x "$_ckp_dir/$_ckp_prog"; then
eval $_ckp_var=\""$_ckp_dir/$_ckp_prog"\"
return 1
fi
done
IFS="${_ckp_IFS}"
done
die "$_ckp_var could not be set."
}
######################################################################
# shquote arg
# Returns a backslashed and quoted version of arg in $shquoted.
######################################################################
shquote()
{
: ${echo=echo}
: ${sed=sed}
_shq_arg=$1
_shq_sed="$sed -e 1s/^X//"
_shq_sed_quote_subst='s/\([\`\"$\\]\)/\\\1/g'
case $_shq_arg in
*[\`\"\$\\]*)
shquoted=`$echo "X$_shq_arg" | $_shq_sed -e "$_shq_sed_quote_subst"`
;;
*)
shquoted="$_shq_arg"
;;
esac
case $shquoted in
*[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"")
shquoted="\"$shquoted\""
;;
esac
}
######################################################################
# lock_file -f path [-n token]
# Attempt to create a lockfile at $path. Any directories in the
# path should already exist. If $token is specified, then assume
# that it is unique between machines sharing an NFS mount.
#
# (1) Create globally-unique filename in the same filesystem as the
# lockfile.
# (2) Try to create a hard-link from this file to the lockfile, but
# ignoring any errors.
# (3) If the two files are the same file, then the lock was successfully
# obtained; otherwise, the lock attempt wasn't successful.
######################################################################
lock_file()
{
: ${dirname=dirname}
: ${echo=echo}
: ${link=link}
: ${mkdir=mkdir}
: ${mktemp=mktemp}
: ${rm=rm}
: ${test=test}
: ${touch=touch}
_lf_lockfile=
_lf_nfs=
while $test $# -gt 0; do
case $1 in
-f) _lf_lockfile="$2"; shift ;;
-n) _lf_nfs="$2"; shift ;;
esac
shift
done
if $test -z "$_lf_lockfile"; then
$echo 1>&2 "$0: no lock file specified."
exit
fi
_lf_pid=$$
_lf_lockdir=`$dirname $_lf_lockfile`
_lf_uniqfile=`$mktemp "$_lf_lockdir/.lock.$_lf_nfs.$_lf_pid.XXXXXX" 2>/dev/null` || return 1
if $test -n "$_lf_nfs"; then
{ $echo $_lf_pid; $echo $_lf_nfs; } > $_lf_uniqfile
else
$echo $_lf_pid > $_lf_uniqfile
fi
$link $_lf_uniqfile $_lf_lockfile 2>/dev/null
if $test $_lf_uniqfile -ef $_lf_lockfile; then
_lf_result=0
else
_lf_result=1
fi
$rm -f $_lf_uniqfile
return $_lf_result
}
######################################################################
######################################################################
###
### Queue routines. The queue is implemented as a set of variables
### that is unique to each queue name, thus the use of multiple queues
### is allowed.
###
######################################################################
######################################################################
######################################################################
# init_queue name
# Initialize the named queue.
######################################################################
init_queue()
{
_qname="$1"
eval "_q${_qname}head=1111111111"
eval "_q${_qname}tail=1111111111"
}
######################################################################
# append_queue name item ...
# Append items onto the end of the named queue in FIFO order.
######################################################################
append_queue()
{
: ${test=test}
_qname="$1"; shift
while $test $# -gt 0; do
eval "_qtail=\"\$_q${_qname}tail\""
eval "_q${_qname}${_qtail}=\"\${1}\""
case $_qtail in
*000000000) _qtail=${_qtail%000000000}1 ;;
*) _qtail=${_qtail}0 ;;
esac
eval "_q${_qname}tail=\"\${_qtail}\""
shift
done
}
######################################################################
# prepend_queue name item ...
# Prepend items to the head of the named queue in LIFO order.
######################################################################
prepend_queue()
{
: ${test=test}
_qname="$1"; shift
while $test $# -gt 0; do
eval "_qhead=\"\$_q${_qname}head\""
case $_qhead in
*1) _qhead=${_qhead%1}000000000 ;;
*) _qhead=${_qhead%0} ;;
esac
eval "_q${_qname}${_qhead}=\"\${1}\""
eval "_q${_qname}head=\"\${_qhead}\""
shift
done
}
######################################################################
# head_queue name var
# Return the head of the named queue in $var.
######################################################################
head_queue()
{
_qname="$1"; shift
eval "_qhead=\"\$_q${_qname}head\""
eval "${1}=\"\$_q${_qname}${_qhead}\""
}
######################################################################
# pop_queue name var
# Pop off the head of the named queue and return it in $var.
######################################################################
pop_queue()
{
_qname="$1"; shift
head_queue $_qname $1
case $_qhead in
*000000000) _qhead=${_qhead%000000000}1 ;;
*) _qhead=${_qhead}0 ;;
esac
eval "_q${_qname}head=\"\${_qhead}\""
}
######################################################################
# queue_is_empty name
# Return 0 if the named queue is empty and 1 otherwise.
######################################################################
queue_is_empty()
{
: ${test=test}
_qname="$1"
eval "_qhead=\"\$_q${_qname}head\""
eval "_qtail=\"\$_q${_qname}tail\""
$test "$_qhead" = "$_qtail"
return $?
}
######################################################################
######################################################################
###
### File queue routines. The file queue is implemented as a file
### whose lines represent the queue elements. The file queue name
### is simply the file used for the queue, thus the use of multiple
### queues is allowed.
###
######################################################################
######################################################################
######################################################################
# init_fqueue name
# Initialize the named file queue.
######################################################################
init_fqueue()
{
_fqname="$1"
: > "$_fqname"
}
######################################################################
# append_fqueue name item ...
# Append items onto the end of the named file queue in FIFO order.
######################################################################
append_fqueue()
{
: ${echo=echo}
: ${test=test}
_fqname="$1"; shift
while $test $# -gt 0; do
$echo "$1" >> "$_fqname"
shift
done
}
######################################################################
# prepend_fqueue name item ...
# Prepend items to the head of the named file queue in LIFO order.
######################################################################
prepend_fqueue()
{
: ${cat=cat}
: ${echo=echo}
: ${mv=mv}
_fqname="$1"; shift
_fqtmpfile="$_fqname.$$"
init_queue _fqtmpqueue
prepend_queue _fqtmpqueue "$@"
while ! queue_is_empty _fqtmpqueue; do
pop_queue _fqtmpqueue _fqelt
$echo "$_fqelt" >> "$_fqtmpfile"
done
$cat "$_fqname" >> "$_fqtmpfile"
$mv -f "$_fqtmpfile" "$_fqname"
}
######################################################################
# head_fqueue name var
# Return the head of the named file queue in $var.
######################################################################
head_fqueue()
{
: ${head=head}
_fqname="$1"; shift
_tmp=`$head -n 1 "$_fqname"`
eval "${1}=\"\$_tmp\""
}
######################################################################
# pop_fqueue name var
# Pop off the head of the named file queue and return it in $var.
######################################################################
pop_fqueue()
{
: ${mv=mv}
: ${sed=sed}
_fqname="$1"; shift
_fqtmpfile="$_fqname.$$"
head_fqueue "$_fqname" $1
$sed "1,1d" "$_fqname" >> "$_fqtmpfile"
$mv -f "$_fqtmpfile" "$_fqname"
}
######################################################################
# fqueue_is_empty name
# Return 0 if the named file queue is empty and >0 otherwise.
######################################################################
fqueue_is_empty()
{
: ${test=test}
: ${wc=wc}
_fqname="$1"
if $test -f "$_fqname"; then
_fqlines=`$wc -l < "$_fqname"`
return $_fqlines
else
return 1
fi
}

46
mk/scripts/shlib-type Executable file
View File

@@ -0,0 +1,46 @@
# /bin/sh
#
# $NetBSD: shlib-type,v 1.3 2007/08/02 16:00:33 jlam Exp $
#
# This code is derived from software contributed to The NetBSD Foundation
# by Alistair Crooks.
#
# This script returns the the library format for the platform. If
# the library format is "ELF/a.out", then we inspect the specified
# path to determine the correct object format (either ELF or a.out).
#
if [ -z "${FILE_CMD}" ]; then
FILE_CMD=file
fi
if [ $# -lt 2 ]; then
echo 1>&2 "usage: shlib-type libformat binpath"
exit 1
fi
libformat="$1"
binpath="$2"
sotype=none
case "$1" in
ELF/a.out)
if [ -f "$binpath" ]; then
output=`${FILE_CMD} $binpath 2>/dev/null`
else
output=
fi
case "$output" in
*ELF*dynamically*) sotype="ELF" ;;
*shared*library*) sotype="a.out" ;;
*dynamically*) sotype="a.out" ;;
*) sotype="ELF" ;; # guess "ELF"
esac
;;
*)
sotype="$1"
;;
esac
echo $sotype
exit 0