Fixup fromcvs/togit conversion
[minix-pkgsrc.git] / mk / bulk / printindex
blob332a199ad0c255bf89ec15b3122bad91d4fc27a1
1 #!/bin/sh
2 # $NetBSD: printindex,v 1.31 2008/01/04 15:49:08 rillig Exp $
5 # Copyright (c) 2001 The NetBSD Foundation, Inc.
6 # All rights reserved.
8 # This code is derived from software contributed to The NetBSD Foundation
9 # by
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
13 # are met:
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
20 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 # POSSIBILITY OF SUCH DAMAGE.
33 set -e
36 # Global variables
39 # The brokenfile_flag variable tells whether we want package-specific
40 # log files at all. If it is set to "yes", the mkdirs_flag
41 # variable tells whether the directories of the package-specific log
42 # files are created if necessary.
43 brokenfile_flag="yes"
44 mkdirs_flag="no"
45 pkgsrcdir="${PWD}"
46 bulkfilesdir="${pkgsrcdir}"
47 brokenfile=""
50 # Command line parsing
53 case $# in
54 0) brokenfile_flag="no"
56 1) brokenfile="$1"
58 2) brokenfile="$1"
59 bulkfilesdir="$2"
60 if [ "${bulkfilesdir}" != "${pkgsrcdir}" ]; then
61 mkdirs_flag="yes"
64 *) echo "usage: $0 [brokenfile [bulkfilesdir]]" 1>&2
65 exit 1
67 esac
70 # Sanity checks
73 case ${BMAKE-""} in
74 "") echo "$0: error: BMAKE must be set and non-empty." 1>&2
75 exit 1;;
76 esac
77 case ${bulkfilesdir} in
78 /*) ;;
79 *) echo "$0: error: The <bulkfilesdir> argument must be absolute." 1>&2
80 exit 1;;
81 esac
82 case ${brokenfile} in
83 */*) echo "$0: error: The <brokenfile> argument must not contain a slash." 1>&2
84 exit 1;;
85 esac
88 # Get additional system information
91 cd "${pkgsrcdir}/pkgtools/lintpkgsrc"
92 BULK_PREREQ=`${BMAKE} show-var VARNAME=BULK_PREREQ`
93 GREP=`${BMAKE} show-var VARNAME=GREP USE_TOOLS=grep`
94 MKDIR=`${BMAKE} show-var VARNAME=MKDIR USE_TOOLS=mkdir`
95 SED=`${BMAKE} show-var VARNAME=SED USE_TOOLS=sed`
96 cd "${pkgsrcdir}"
98 case $mkdirs_flag in
99 yes) mkbulkdir="${MKDIR}";;
100 *) mkbulkdir=":";;
101 esac
103 case ${PKGLIST-""} in
104 "") # List of all packages, from pkgsrc/*/Makefile
105 list=`${GREP} '^[[:space:]]*'SUBDIR */Makefile | ${GREP} -v regress/ | ${SED} 's,/Makefile.*=[[:space:]]*,/,'`
107 *) list="${PKGLIST}"
109 esac
112 # Sanity checks, part 2
115 allowed="
116 +./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_"
117 case $BULK_PREREQ in
118 *[!-"${allowed}"]*)
119 inval=`echo "${BULK_PREREQ}" | tr -d " +\\\\-${allowed}"`
120 echo "$0: error: BULK_PREREQ contains invalid characters (${inval})." 1>&2
121 exit 1
122 esac
123 case $list in
124 *[!-"${allowed}"]*)
125 inval=`echo "${list}" | tr -d " +\\\\-${allowed}"`
126 echo "$0: error: The package list contains invalid characters (${inval})." 1>&2
127 exit 1
128 esac
130 newline="
134 # Print the table of PKGPATH and PKGNAME.
136 # The check for duplicates is necessary to prevents double entries in
137 # the table. The use of the :detect_duplicates: delimiter prevents the
138 # inner "case" from occuring too often, as the $done_pkgs string grows
139 # to about 100k during one run of the program. This saves about
140 # 40 seconds on a 1 GHz Athlon.
142 done_pkgs=""
143 detect_duplicates=no
144 for pkgdir in $list :detect_duplicates: $BULK_PREREQ; do
146 case $pkgdir in :detect_duplicates:)
147 detect_duplicates=yes
148 continue;;
149 esac
150 case $detect_duplicates in yes)
151 case $done_pkgs in *="${pkgdir}"=*)
152 continue;;
153 esac;;
154 esac
156 if cd "${pkgsrcdir}/${pkgdir}"; then
158 # The NetBSD /bin/sh creates lots of zombies for the backticks
159 # line below, and it doesn't clean them up until a real
160 # command is executed. (See PR 35227)
162 cat </dev/null
164 if output=`${BMAKE} show-var VARNAME=PKGNAME can-be-built-here`; then
165 reasons=""
167 read pkgname
168 read can_be_built_here
169 while read reason; do
170 reasons="$reasons$reason$newline"
171 done
172 } <<EOF
173 $output
175 echo "${pkgdir} ${pkgname}"
176 done_pkgs="${done_pkgs} =${pkgdir}="
178 if [ "$can_be_built_here" != "yes" ]; then
179 ${mkbulkdir} "${bulkfilesdir}/${pkgdir}"
180 echo "$reasons" > "${bulkfilesdir}/${pkgdir}/${brokenfile}"
182 else
183 echo "$0: error: could not extract PKGNAME for ${pkgdir} -- skipping." 1>&2
185 case $brokenfile_flag in
186 no) continue;;
187 esac
189 ${mkbulkdir} "${bulkfilesdir}/${pkgdir}"
190 { echo "[printindex] command failed: ${BMAKE} show-var VARNAME=PKGNAME"
191 ( ${BMAKE} show-var VARNAME=PKGNAME
192 ) || true
193 } >> "${bulkfilesdir}/${pkgdir}/${brokenfile}" 2>&1
195 else
196 ${mkbulkdir} "${bulkfilesdir}"
197 { echo "[printindex] command failed: cd ${pkgsrcdir}/${pkgdir}"
198 ( cd "${pkgsrcdir}/${pkgdir}"
199 ) || true
200 } 1>&2
202 done