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