Annotation of pkgsrc/mk/scripts/mkdatabase, revision 1.8
1.1 dmcmahil 1: #!/bin/sh
1.8 ! rillig 2: # $NetBSD: mkdatabase,v 1.7 2005/11/18 10:55:30 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.8 ! rillig 60: append_flag=no
1.6 rillig 61: debug_flag="" # meaning "no"
62:
63: #
64: # Helper functions
65: #
1.1 dmcmahil 66:
1.6 rillig 67: usage() {
1.1 dmcmahil 68: echo "$prog - Generates a complete dependency tree for a particular package"
1.3 dmcmahil 69: echo "Usage: $prog [-a|--append] [-d|--debug] [-f|--database database]"
1.6 rillig 70: echo ""
1.1 dmcmahil 71: echo " $prog -h|--help"
1.6 rillig 72: echo ""
1.1 dmcmahil 73: echo " $prog -v|--version"
1.6 rillig 74: echo ""
1.1 dmcmahil 75: echo "The options supported by $prog are: "
1.6 rillig 76: echo ""
1.3 dmcmahil 77: echo " -a|--append Append to the database rather than overwriting it"
1.6 rillig 78: echo ""
1.1 dmcmahil 79: echo " -d|--debug Enables debugging output"
1.6 rillig 80: echo ""
1.1 dmcmahil 81: echo " -f|--database <file> Writes the database into file specified by <file>"
1.6 rillig 82: echo ""
1.1 dmcmahil 83: echo " -h|--help Displays this help message"
1.6 rillig 84: echo ""
1.1 dmcmahil 85: echo " -v|--version Displays the version of this script and exits."
1.6 rillig 86: echo ""
1.1 dmcmahil 87: echo "Example: cd /usr/pkgsrc/graphics/gimp && $prog -d /tmp/gimp_database"
1.6 rillig 88: echo ""
1.1 dmcmahil 89: }
90:
91: ######################################################################
92: #
93: # Handle command line options
94: #
95: ######################################################################
96:
1.5 rillig 97: while test $# -gt 0; do
98: case $1 in
1.1 dmcmahil 99:
1.3 dmcmahil 100: # Append to the database
101: -a|--append)
1.8 ! rillig 102: append_flag=yes
1.3 dmcmahil 103: shift
104: ;;
105:
1.1 dmcmahil 106: # Turn on debugging
107: -d|--debug)
1.6 rillig 108: debug_flag=yes
1.1 dmcmahil 109: shift
110: ;;
111:
112: # Use the specified database file
113: -f|--database)
114: DATABASE=$2
115: shift 2
116: ;;
117:
118: # Help
119: -h|--help)
120: usage
121: exit 0
122: ;;
123:
124: # Version
1.4 jmmv 125: -v|--version)
1.1 dmcmahil 126: ${AWK} '/^#[ \t]*\$NetBSD/ {gsub(/,v/,"",$3);printf("%s: Version %s, %s\n",$3,$4,$5); exit 0;}' $prog
127: exit 0
128: ;;
129:
1.7 rillig 130: *) echo "$prog: ERROR: $1 is not a valid option"
1.1 dmcmahil 131: usage
1.6 rillig 132: exit 1
1.1 dmcmahil 133: ;;
134: esac
135: done
136:
1.6 rillig 137: case $debug_flag in
138: yes) set -v;;
139: esac
1.1 dmcmahil 140:
1.5 rillig 141: if [ ! -d "$TMPDIR" ]; then
142: mkdir -p "$TMPDIR"
1.1 dmcmahil 143: fi
144:
145: prompt="----> "
146:
1.4 jmmv 147: case ${DATABASE} in
1.1 dmcmahil 148: /*)
149: # we already have the absolute path to the database file
150: # so do nothing
151: ;;
152:
153: *)
154: # make sure we have the full path to the database file
155: DATABASE=`pwd`/${DATABASE}
156: ;;
157: esac
158:
159:
1.8 ! rillig 160: if [ $append_flag = yes ]; then
1.3 dmcmahil 161: echo "$prompt Appending to database in ${DATABASE}"
1.5 rillig 162: if [ ! -f "${DATABASE}" ]; then
163: touch "${DATABASE}"
1.3 dmcmahil 164: fi
165: # make sure we haven't already been listed before
166: # appending ourselves.
167: here=`pwd`
1.5 rillig 168: tmp1=`dirname "$here"`
169: pkgcat=`basename "$tmp1"`
170: pkg=`basename "$here"`
1.3 dmcmahil 171: pkgpath=$pkgcat/$pkg
1.6 rillig 172: case $debug_flag in
173: yes) echo "Looking for $pkgpath before appending";;
174: esac
1.5 rillig 175: if grep "^index $pkgpath " "${DATABASE}" >/dev/null 2>&1 ; then
1.3 dmcmahil 176: echo "$prompt $pkgpath has already been depended. Skipping..."
177: exit 0
178: else
1.5 rillig 179: ${BMAKE} print-summary-data >> "${DATABASE}" || exit 1
1.3 dmcmahil 180: fi
181: else
182: echo "$prompt Creating new database in ${DATABASE}"
1.5 rillig 183: ${BMAKE} print-summary-data > "${DATABASE}" || exit 1
1.3 dmcmahil 184: fi
1.1 dmcmahil 185: here=`pwd`
186: echo "$prompt Depending in $here (pass #1)"
1.6 rillig 187: dirs=`${AWK} -f ../../mk/scripts/chkdatabase.awk debug=${debug_flag} "${DATABASE}"`
1.1 dmcmahil 188: pass=2
1.5 rillig 189: while [ ! -z "$dirs" -a $pass -lt "${MAX_PASS}" ]; do
1.4 jmmv 190: for d in $dirs ; do
1.1 dmcmahil 191: echo "$prompt Depending in ../../$d (pass #$pass)" ;\
1.5 rillig 192: cd "../../$d" && ${BMAKE} print-summary-data >> "${DATABASE}" || exit 1
193: cd "$here"
1.1 dmcmahil 194: done
1.6 rillig 195: dirs=`${AWK} -f ../../mk/scripts/chkdatabase.awk debug=${debug_flag} ${DATABASE}`
1.2 dmcmahil 196: pass=`${EXPR} $pass + 1`
1.1 dmcmahil 197: done
198:
199: if [ $pass -eq ${MAX_PASS} ]; then
200: echo "ERROR: You have reached $pass times through the dependency tree"
201: echo " and _still_ not finished. This is probably due to a broken"
202: echo " set of dependencies. You may wish to examine the partial"
203: echo " database left in ${DATABASE}"
204: exit 1
205: else
206: echo "Complete dependency database left in ${DATABASE}"
207: fi
CVSweb <webmaster@jp.NetBSD.org>