Annotation of pkgsrc/mk/scripts/mkdatabase, revision 1.10
1.1 dmcmahil 1: #!/bin/sh
1.10 ! bsiegert 2: # $NetBSD: mkdatabase,v 1.9 2005/11/18 11:07:27 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
1.9 rillig 142: # FIXME: wouldn't it be better to fail in this case?
1.5 rillig 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: *)
1.9 rillig 155: # FIXME: wouldn't it be better to fail in this case?
156:
1.1 dmcmahil 157: # make sure we have the full path to the database file
158: DATABASE=`pwd`/${DATABASE}
159: ;;
160: esac
161:
162:
1.10 ! bsiegert 163: here=`pwd`
! 164: tmp1=`dirname "$here"`
! 165: pkgcat=`basename "$tmp1"`
! 166: pkg=`basename "$here"`
! 167: pkgpath=$pkgcat/$pkg
1.8 rillig 168: if [ $append_flag = yes ]; then
1.3 dmcmahil 169: echo "$prompt Appending to database in ${DATABASE}"
1.5 rillig 170: if [ ! -f "${DATABASE}" ]; then
171: touch "${DATABASE}"
1.3 dmcmahil 172: fi
173: # make sure we haven't already been listed before
174: # appending ourselves.
1.6 rillig 175: case $debug_flag in
176: yes) echo "Looking for $pkgpath before appending";;
177: esac
1.9 rillig 178: # FIXME: $pkgpath may contain special regex characters.
1.5 rillig 179: if grep "^index $pkgpath " "${DATABASE}" >/dev/null 2>&1 ; then
1.3 dmcmahil 180: echo "$prompt $pkgpath has already been depended. Skipping..."
181: exit 0
182: else
1.5 rillig 183: ${BMAKE} print-summary-data >> "${DATABASE}" || exit 1
1.3 dmcmahil 184: fi
185: else
186: echo "$prompt Creating new database in ${DATABASE}"
1.10 ! bsiegert 187: o=`${BMAKE} show-options | ${AWK} -f ../../mk/scripts/htmloptions.awk`
! 188: echo "htmloptions ${pkgpath} $o" > ${DATABASE}
! 189: ${BMAKE} print-summary-data >> "${DATABASE}" || exit 1
1.3 dmcmahil 190: fi
1.1 dmcmahil 191: here=`pwd`
192: echo "$prompt Depending in $here (pass #1)"
1.6 rillig 193: dirs=`${AWK} -f ../../mk/scripts/chkdatabase.awk debug=${debug_flag} "${DATABASE}"`
1.1 dmcmahil 194: pass=2
1.5 rillig 195: while [ ! -z "$dirs" -a $pass -lt "${MAX_PASS}" ]; do
1.4 jmmv 196: for d in $dirs ; do
1.1 dmcmahil 197: echo "$prompt Depending in ../../$d (pass #$pass)" ;\
1.5 rillig 198: cd "../../$d" && ${BMAKE} print-summary-data >> "${DATABASE}" || exit 1
199: cd "$here"
1.1 dmcmahil 200: done
1.6 rillig 201: dirs=`${AWK} -f ../../mk/scripts/chkdatabase.awk debug=${debug_flag} ${DATABASE}`
1.2 dmcmahil 202: pass=`${EXPR} $pass + 1`
1.1 dmcmahil 203: done
204:
205: if [ $pass -eq ${MAX_PASS} ]; then
206: echo "ERROR: You have reached $pass times through the dependency tree"
207: echo " and _still_ not finished. This is probably due to a broken"
208: echo " set of dependencies. You may wish to examine the partial"
209: echo " database left in ${DATABASE}"
210: exit 1
211: else
212: echo "Complete dependency database left in ${DATABASE}"
213: fi
CVSweb <webmaster@jp.NetBSD.org>