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

1.1       dmcmahil    1: #!/bin/sh
1.5     ! rillig      2: # $NetBSD: mkdatabase,v 1.4 2003/05/06 17:42:05 jmmv 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"
1.3       dmcmahil   57:     echo "Usage:      $prog [-a|--append] [-d|--debug] [-f|--database database]"
1.1       dmcmahil   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 " "
1.3       dmcmahil   65:     echo "  -a|--append           Append to the database rather than overwriting it"
                     66:     echo " "
1.1       dmcmahil   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=
1.3       dmcmahil   91: append=no
1.1       dmcmahil   92: 
1.5     ! rillig     93: while test $# -gt 0; do
        !            94:     case $1 in
1.1       dmcmahil   95: 
1.3       dmcmahil   96:     # Append to the database
                     97:     -a|--append)
                     98:        append=yes
                     99:        shift
                    100:        ;;
                    101: 
1.1       dmcmahil  102:     # Turn on debugging
                    103:     -d|--debug)
                    104:        DEBUG=yes
                    105:        shift
                    106:        ;;
                    107: 
                    108:     # Use the specified database file
                    109:     -f|--database)
                    110:        DATABASE=$2
                    111:        shift 2
                    112:        ;;
                    113: 
                    114:     # Help
                    115:     -h|--help)
                    116:        usage
                    117:        exit 0
                    118:        ;;
                    119: 
                    120:     # Version
1.4       jmmv      121:     -v|--version)
1.1       dmcmahil  122:        ${AWK} '/^#[ \t]*\$NetBSD/ {gsub(/,v/,"",$3);printf("%s:  Version %s, %s\n",$3,$4,$5); exit 0;}' $prog
                    123:        exit 0
                    124:         ;;
                    125: 
                    126:     -*) echo "$prog:  ERROR:  $1 is not a valid option"
                    127:        usage
                    128:        clean_and_exit
                    129:        ;;
                    130: 
1.4       jmmv      131:     *) 
1.1       dmcmahil  132:        break
                    133:        ;;
                    134: 
                    135:     esac
                    136: done
                    137: 
                    138: if [ "x$DEBUG" = "xyes" ]; then
                    139:     set -v
                    140: fi
                    141: 
1.5     ! rillig    142: if [ ! -d "$TMPDIR" ]; then
        !           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:     *)
                    155:        # make sure we have the full path to the database file
                    156:        DATABASE=`pwd`/${DATABASE}
                    157:        ;;
                    158: esac
                    159: 
                    160: 
1.3       dmcmahil  161: if [ "X$append" = "Xyes" ]; then
                    162:     echo "$prompt Appending to database in ${DATABASE}"
1.5     ! rillig    163:     if [ ! -f "${DATABASE}" ]; then
        !           164:        touch "${DATABASE}"
1.3       dmcmahil  165:     fi
                    166:     # make sure we haven't already been listed before
                    167:     # appending ourselves.
                    168:     here=`pwd`
1.5     ! rillig    169:     tmp1=`dirname "$here"`
        !           170:     pkgcat=`basename "$tmp1"`
        !           171:     pkg=`basename "$here"`
1.3       dmcmahil  172:     pkgpath=$pkgcat/$pkg
                    173:     if [ "x$DEBUG" = "xyes" ]; then
                    174:        echo "Looking for $pkgpath before appending"
                    175:     fi
1.5     ! rillig    176:     if grep "^index $pkgpath " "${DATABASE}" >/dev/null 2>&1 ; then
1.3       dmcmahil  177:        echo "$prompt $pkgpath has already been depended.  Skipping..."
                    178:        exit 0
                    179:     else
1.5     ! rillig    180:        ${BMAKE} print-summary-data >> "${DATABASE}" || exit 1
1.3       dmcmahil  181:     fi
                    182: else
                    183:     echo "$prompt Creating new database in ${DATABASE}"
1.5     ! rillig    184:     ${BMAKE} print-summary-data > "${DATABASE}" || exit 1
1.3       dmcmahil  185: fi
1.1       dmcmahil  186: here=`pwd`
                    187: echo "$prompt Depending in $here (pass #1)"
1.5     ! rillig    188: dirs=`${AWK} -f ../../mk/scripts/chkdatabase.awk debug=${DEBUG} "${DATABASE}"`
1.1       dmcmahil  189: pass=2
1.5     ! rillig    190: while [ ! -z "$dirs" -a $pass -lt "${MAX_PASS}" ]; do
1.4       jmmv      191:        for d in $dirs ; do
1.1       dmcmahil  192:                echo "$prompt Depending in ../../$d (pass #$pass)" ;\
1.5     ! rillig    193:                cd "../../$d" && ${BMAKE} print-summary-data >> "${DATABASE}" || exit 1
        !           194:                cd "$here"
1.1       dmcmahil  195:        done
                    196:        dirs=`${AWK} -f ../../mk/scripts/chkdatabase.awk debug=${DEBUG} ${DATABASE}`
1.2       dmcmahil  197:        pass=`${EXPR} $pass + 1`
1.1       dmcmahil  198: done
                    199: 
                    200: if [ $pass -eq ${MAX_PASS} ]; then
                    201:        echo "ERROR:  You have reached $pass times through the dependency tree"
                    202:        echo "        and _still_ not finished.  This is probably due to a broken"
                    203:        echo "        set of dependencies.  You may wish to examine the partial"
                    204:        echo "        database left in ${DATABASE}"
                    205:        exit 1
                    206: else
                    207:        echo "Complete dependency database left in ${DATABASE}"
                    208: fi

CVSweb <webmaster@jp.NetBSD.org>