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

1.1       dmcmahil    1: #!/bin/sh
1.6     ! rillig      2: # $NetBSD: mkdatabase,v 1.5 2005/11/17 21:46:42 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.6     ! rillig     60: debug_flag=""          # meaning "no"
        !            61: 
        !            62: #
        !            63: # Helper functions
        !            64: #
1.1       dmcmahil   65: 
1.6     ! rillig     66: usage() {
1.1       dmcmahil   67:     echo "$prog - Generates a complete dependency tree for a particular package"
1.3       dmcmahil   68:     echo "Usage:      $prog [-a|--append] [-d|--debug] [-f|--database database]"
1.6     ! rillig     69:     echo ""
1.1       dmcmahil   70:     echo "            $prog -h|--help"
1.6     ! rillig     71:     echo ""
1.1       dmcmahil   72:     echo "            $prog -v|--version"
1.6     ! rillig     73:     echo ""
1.1       dmcmahil   74:     echo "The options supported by $prog are: "
1.6     ! rillig     75:     echo ""
1.3       dmcmahil   76:     echo "  -a|--append           Append to the database rather than overwriting it"
1.6     ! rillig     77:     echo ""
1.1       dmcmahil   78:     echo "  -d|--debug            Enables debugging output"
1.6     ! rillig     79:     echo ""
1.1       dmcmahil   80:     echo "  -f|--database <file>  Writes the database into file specified by <file>"
1.6     ! rillig     81:     echo ""
1.1       dmcmahil   82:     echo "  -h|--help             Displays this help message"
1.6     ! rillig     83:     echo ""
1.1       dmcmahil   84:     echo "  -v|--version          Displays the version of this script and exits."
1.6     ! rillig     85:     echo ""
1.1       dmcmahil   86:     echo "Example:    cd /usr/pkgsrc/graphics/gimp && $prog -d /tmp/gimp_database"
1.6     ! rillig     87:     echo ""
1.1       dmcmahil   88: }
                     89: 
                     90: ######################################################################
                     91: #
                     92: #  Handle command line options
                     93: #
                     94: ######################################################################
                     95: 
1.3       dmcmahil   96: append=no
1.1       dmcmahil   97: 
1.5       rillig     98: while test $# -gt 0; do
                     99:     case $1 in
1.1       dmcmahil  100: 
1.3       dmcmahil  101:     # Append to the database
                    102:     -a|--append)
                    103:        append=yes
                    104:        shift
                    105:        ;;
                    106: 
1.1       dmcmahil  107:     # Turn on debugging
                    108:     -d|--debug)
1.6     ! rillig    109:        debug_flag=yes
1.1       dmcmahil  110:        shift
                    111:        ;;
                    112: 
                    113:     # Use the specified database file
                    114:     -f|--database)
                    115:        DATABASE=$2
                    116:        shift 2
                    117:        ;;
                    118: 
                    119:     # Help
                    120:     -h|--help)
                    121:        usage
                    122:        exit 0
                    123:        ;;
                    124: 
                    125:     # Version
1.4       jmmv      126:     -v|--version)
1.1       dmcmahil  127:        ${AWK} '/^#[ \t]*\$NetBSD/ {gsub(/,v/,"",$3);printf("%s:  Version %s, %s\n",$3,$4,$5); exit 0;}' $prog
                    128:        exit 0
                    129:         ;;
                    130: 
                    131:     -*) echo "$prog:  ERROR:  $1 is not a valid option"
                    132:        usage
1.6     ! rillig    133:        exit 1
1.1       dmcmahil  134:        ;;
                    135: 
1.4       jmmv      136:     *) 
1.1       dmcmahil  137:        break
                    138:        ;;
                    139: 
                    140:     esac
                    141: done
                    142: 
1.6     ! rillig    143: case $debug_flag in
        !           144: yes)   set -v;;
        !           145: esac
1.1       dmcmahil  146: 
1.5       rillig    147: if [ ! -d "$TMPDIR" ]; then
                    148:        mkdir -p "$TMPDIR"
1.1       dmcmahil  149: fi
                    150: 
                    151: prompt="----> "
                    152: 
1.4       jmmv      153: case ${DATABASE} in
1.1       dmcmahil  154:     /*)
                    155:        # we already have the absolute path to the database file
                    156:        # so do nothing
                    157:        ;;
                    158: 
                    159:     *)
                    160:        # make sure we have the full path to the database file
                    161:        DATABASE=`pwd`/${DATABASE}
                    162:        ;;
                    163: esac
                    164: 
                    165: 
1.3       dmcmahil  166: if [ "X$append" = "Xyes" ]; then
                    167:     echo "$prompt Appending to database in ${DATABASE}"
1.5       rillig    168:     if [ ! -f "${DATABASE}" ]; then
                    169:        touch "${DATABASE}"
1.3       dmcmahil  170:     fi
                    171:     # make sure we haven't already been listed before
                    172:     # appending ourselves.
                    173:     here=`pwd`
1.5       rillig    174:     tmp1=`dirname "$here"`
                    175:     pkgcat=`basename "$tmp1"`
                    176:     pkg=`basename "$here"`
1.3       dmcmahil  177:     pkgpath=$pkgcat/$pkg
1.6     ! rillig    178:     case $debug_flag in
        !           179:     yes)       echo "Looking for $pkgpath before appending";;
        !           180:     esac
1.5       rillig    181:     if grep "^index $pkgpath " "${DATABASE}" >/dev/null 2>&1 ; then
1.3       dmcmahil  182:        echo "$prompt $pkgpath has already been depended.  Skipping..."
                    183:        exit 0
                    184:     else
1.5       rillig    185:        ${BMAKE} print-summary-data >> "${DATABASE}" || exit 1
1.3       dmcmahil  186:     fi
                    187: else
                    188:     echo "$prompt Creating new database in ${DATABASE}"
1.5       rillig    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>