Annotation of pkgsrc/mk/scripts/mkdatabase, revision 1.2

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

CVSweb <webmaster@jp.NetBSD.org>