Annotation of pkgsrc/mk/scripts/mkdatabase, revision 1.7
1.1 dmcmahil 1: #!/bin/sh
1.7 ! rillig 2: # $NetBSD: mkdatabase,v 1.6 2005/11/18 10:51:53 rillig Exp $
1.1 dmcmahil 3: #
4: # Script for generating a database with complete dependency information
5: # for a particular package
6: #
7: # Copyright (c) 2003 The NetBSD Foundation, Inc.
8: # All rights reserved.
9: #
10: # This code is derived from software contributed to The NetBSD Foundation
11: # by Dan McMahill.
12: #
13: # Redistribution and use in source and binary forms, with or without
14: # modification, are permitted provided that the following conditions
15: # are met:
16: # 1. Redistributions of source code must retain the above copyright
17: # notice, this list of conditions and the following disclaimer.
18: # 2. Redistributions in binary form must reproduce the above copyright
19: # notice, this list of conditions and the following disclaimer in the
20: # documentation and/or other materials provided with the distribution.
21: # 3. All advertising materials mentioning features or use of this software
22: # must display the following acknowledgement:
23: # This product includes software developed by the NetBSD
24: # Foundation, Inc. and its contributors.
25: # 4. Neither the name of The NetBSD Foundation nor the names of its
26: # contributors may be used to endorse or promote products derived
27: # from this software without specific prior written permission.
28: #
29: # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
30: # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
31: # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32: # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
33: # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34: # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35: # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36: # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37: # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38: # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39: # POSSIBILITY OF SUCH DAMAGE.
40: #
41:
1.6 rillig 42: #
43: # Global variables, based on environment variables
44: #
1.1 dmcmahil 45:
46: TMPDIR=${TMPDIR:-/tmp}
47: BMAKE=${BMAKE:-make}
48: AWK=${AWK:-/usr/bin/awk}
49: DATABASE=${DATABASE:-${TMPDIR}/pkgdb.$$}
1.2 dmcmahil 50: EXPR=${EXPR:-expr}
1.1 dmcmahil 51: # as of 2003-01-04, metapkgs/gnome gets to pass #6 so
52: # it is very likely that if you reach 25, something is broken
53: MAX_PASS=${MAX_PASS:-25}
54:
1.6 rillig 55: #
56: # Global variables
57: #
58:
1.1 dmcmahil 59: prog=$0
1.6 rillig 60: debug_flag="" # meaning "no"
61:
62: #
63: # Helper functions
64: #
1.1 dmcmahil 65:
1.6 rillig 66: usage() {
1.1 dmcmahil 67: echo "$prog - Generates a complete dependency tree for a particular package"
1.3 dmcmahil 68: echo "Usage: $prog [-a|--append] [-d|--debug] [-f|--database database]"
1.6 rillig 69: echo ""
1.1 dmcmahil 70: echo " $prog -h|--help"
1.6 rillig 71: echo ""
1.1 dmcmahil 72: echo " $prog -v|--version"
1.6 rillig 73: echo ""
1.1 dmcmahil 74: echo "The options supported by $prog are: "
1.6 rillig 75: echo ""
1.3 dmcmahil 76: echo " -a|--append Append to the database rather than overwriting it"
1.6 rillig 77: echo ""
1.1 dmcmahil 78: echo " -d|--debug Enables debugging output"
1.6 rillig 79: echo ""
1.1 dmcmahil 80: echo " -f|--database <file> Writes the database into file specified by <file>"
1.6 rillig 81: echo ""
1.1 dmcmahil 82: echo " -h|--help Displays this help message"
1.6 rillig 83: echo ""
1.1 dmcmahil 84: echo " -v|--version Displays the version of this script and exits."
1.6 rillig 85: echo ""
1.1 dmcmahil 86: echo "Example: cd /usr/pkgsrc/graphics/gimp && $prog -d /tmp/gimp_database"
1.6 rillig 87: echo ""
1.1 dmcmahil 88: }
89:
90: ######################################################################
91: #
92: # Handle command line options
93: #
94: ######################################################################
95:
1.3 dmcmahil 96: append=no
1.1 dmcmahil 97:
1.5 rillig 98: while test $# -gt 0; do
99: case $1 in
1.1 dmcmahil 100:
1.3 dmcmahil 101: # Append to the database
102: -a|--append)
103: append=yes
104: shift
105: ;;
106:
1.1 dmcmahil 107: # Turn on debugging
108: -d|--debug)
1.6 rillig 109: debug_flag=yes
1.1 dmcmahil 110: shift
111: ;;
112:
113: # Use the specified database file
114: -f|--database)
115: DATABASE=$2
116: shift 2
117: ;;
118:
119: # Help
120: -h|--help)
121: usage
122: exit 0
123: ;;
124:
125: # Version
1.4 jmmv 126: -v|--version)
1.1 dmcmahil 127: ${AWK} '/^#[ \t]*\$NetBSD/ {gsub(/,v/,"",$3);printf("%s: Version %s, %s\n",$3,$4,$5); exit 0;}' $prog
128: exit 0
129: ;;
130:
1.7 ! rillig 131: *) echo "$prog: ERROR: $1 is not a valid option"
1.1 dmcmahil 132: usage
1.6 rillig 133: exit 1
1.1 dmcmahil 134: ;;
135: esac
136: done
137:
1.6 rillig 138: case $debug_flag in
139: yes) set -v;;
140: esac
1.1 dmcmahil 141:
1.5 rillig 142: if [ ! -d "$TMPDIR" ]; then
143: mkdir -p "$TMPDIR"
1.1 dmcmahil 144: fi
145:
146: prompt="----> "
147:
1.4 jmmv 148: case ${DATABASE} in
1.1 dmcmahil 149: /*)
150: # we already have the absolute path to the database file
151: # so do nothing
152: ;;
153:
154: *)
155: # make sure we have the full path to the database file
156: DATABASE=`pwd`/${DATABASE}
157: ;;
158: esac
159:
160:
1.3 dmcmahil 161: if [ "X$append" = "Xyes" ]; then
162: echo "$prompt Appending to database in ${DATABASE}"
1.5 rillig 163: if [ ! -f "${DATABASE}" ]; then
164: touch "${DATABASE}"
1.3 dmcmahil 165: fi
166: # make sure we haven't already been listed before
167: # appending ourselves.
168: here=`pwd`
1.5 rillig 169: tmp1=`dirname "$here"`
170: pkgcat=`basename "$tmp1"`
171: pkg=`basename "$here"`
1.3 dmcmahil 172: pkgpath=$pkgcat/$pkg
1.6 rillig 173: case $debug_flag in
174: yes) echo "Looking for $pkgpath before appending";;
175: esac
1.5 rillig 176: if grep "^index $pkgpath " "${DATABASE}" >/dev/null 2>&1 ; then
1.3 dmcmahil 177: echo "$prompt $pkgpath has already been depended. Skipping..."
178: exit 0
179: else
1.5 rillig 180: ${BMAKE} print-summary-data >> "${DATABASE}" || exit 1
1.3 dmcmahil 181: fi
182: else
183: echo "$prompt Creating new database in ${DATABASE}"
1.5 rillig 184: ${BMAKE} print-summary-data > "${DATABASE}" || exit 1
1.3 dmcmahil 185: fi
1.1 dmcmahil 186: here=`pwd`
187: echo "$prompt Depending in $here (pass #1)"
1.6 rillig 188: dirs=`${AWK} -f ../../mk/scripts/chkdatabase.awk debug=${debug_flag} "${DATABASE}"`
1.1 dmcmahil 189: pass=2
1.5 rillig 190: while [ ! -z "$dirs" -a $pass -lt "${MAX_PASS}" ]; do
1.4 jmmv 191: for d in $dirs ; do
1.1 dmcmahil 192: echo "$prompt Depending in ../../$d (pass #$pass)" ;\
1.5 rillig 193: cd "../../$d" && ${BMAKE} print-summary-data >> "${DATABASE}" || exit 1
194: cd "$here"
1.1 dmcmahil 195: done
1.6 rillig 196: dirs=`${AWK} -f ../../mk/scripts/chkdatabase.awk debug=${debug_flag} ${DATABASE}`
1.2 dmcmahil 197: pass=`${EXPR} $pass + 1`
1.1 dmcmahil 198: done
199:
200: if [ $pass -eq ${MAX_PASS} ]; then
201: echo "ERROR: You have reached $pass times through the dependency tree"
202: echo " and _still_ not finished. This is probably due to a broken"
203: echo " set of dependencies. You may wish to examine the partial"
204: echo " database left in ${DATABASE}"
205: exit 1
206: else
207: echo "Complete dependency database left in ${DATABASE}"
208: fi
CVSweb <webmaster@jp.NetBSD.org>