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