openpkg/rpmtool

changeset 13
cb59d6afeb61
child 346
c403d9dd5e0e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/openpkg/rpmtool	Tue Jan 06 23:40:39 2009 +0100
     1.3 @@ -0,0 +1,1155 @@
     1.4 +#!@l_prefix@/lib/openpkg/bash
     1.5 +##
     1.6 +##  rpmtool -- OpenPKG RPM Auxiliary Tool
     1.7 +##  Copyright (c) 2000-2007 OpenPKG Foundation e.V. <http://openpkg.net/>
     1.8 +##  Copyright (c) 2000-2007 Ralf S. Engelschall <http://engelschall.com/>
     1.9 +##
    1.10 +##  Permission to use, copy, modify, and distribute this software for
    1.11 +##  any purpose with or without fee is hereby granted, provided that
    1.12 +##  the above copyright notice and this permission notice appear in all
    1.13 +##  copies.
    1.14 +##
    1.15 +##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
    1.16 +##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    1.17 +##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    1.18 +##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
    1.19 +##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.20 +##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.21 +##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
    1.22 +##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    1.23 +##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    1.24 +##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    1.25 +##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    1.26 +##  SUCH DAMAGE.
    1.27 +##
    1.28 +
    1.29 +prog_path="$0"
    1.30 +prog_name="rpmtool"
    1.31 +prog_vers="1.1.0"
    1.32 +prog_date="05-Mar-2007"
    1.33 +
    1.34 +if [ $# -eq 0 ]; then
    1.35 +    echo "$0:Error: invalid command line" 1>&2
    1.36 +    echo "$0:Hint:  run \`$0 -h' for usage" 1>&2
    1.37 +    exit 1
    1.38 +fi
    1.39 +if [ ".$1" = ".-h" -o ".$1" = ".--help" ]; then
    1.40 +    echo "This is $prog_name, version $prog_vers ($prog_date)"
    1.41 +    echo "Copyright (c) 2000-2004 Ralf S. Engelschall <rse@engelschall.com>"
    1.42 +    echo ''
    1.43 +    echo "Usage: $prog_name [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]"
    1.44 +    echo ''
    1.45 +    echo 'Available global <options>:'
    1.46 +    echo '  -d, --debug     enable internal debugging'
    1.47 +    echo '  -v, --version   display version information'
    1.48 +    echo '  -h, --help      display usage help page (this one)'
    1.49 +    echo ''
    1.50 +    echo 'Available <cmd-name> [<cmd-options>] [<cmd-args>]:'
    1.51 +    echo '  platform'
    1.52 +    echo '  mflags [-O] <tool>'
    1.53 +    echo '  cflags [-O] <tool>'
    1.54 +    echo '  cppflags [-p <prefix>] [<subdir> ...]'
    1.55 +    echo '  ldflags  [-p <prefix>] [<subdir> ...]'
    1.56 +    echo '  files  [-v] [-o <outfile>] [-r <buildroot>] [<filelist>]'
    1.57 +    echo '  signal [-v] [-t] [-n] [-c] [-d <delay>] [-p <pid>] [-m <pattern>] <sig> [<sig> ...]'
    1.58 +    echo '  config [-v] [-s] [-a] [-r] [-b <ext>] [-p <tagprefix>] [-t <tagname>] [-i <tagid>] <file>'
    1.59 +    echo '  msg    [-b] [-r] [-t <type>]'
    1.60 +    echo ''
    1.61 +    exit 0
    1.62 +fi
    1.63 +if [ ".$1" = ".-v" -o ".$1" = ."--version" ]; then
    1.64 +    echo "$prog_name $prog_vers ($prog_date)"
    1.65 +    exit 0
    1.66 +fi
    1.67 +if [ ".$1" = ".-d" -o ".$1" = ."--debug" ]; then
    1.68 +    shift
    1.69 +    set -x
    1.70 +fi
    1.71 +
    1.72 +tool="$1"
    1.73 +shift
    1.74 +arg_spec=""
    1.75 +opt_spec=""
    1.76 +gen_tmpfile=no
    1.77 +
    1.78 +#   configure tool specific option parsing
    1.79 +case $tool in
    1.80 +    platform )
    1.81 +        str_usage=""
    1.82 +        arg_spec="0="
    1.83 +        opt_spec=""
    1.84 +        ;;
    1.85 +    mflags )
    1.86 +        str_usage="[-O] <tool>"
    1.87 +        arg_spec="1="
    1.88 +        opt_spec="O."
    1.89 +        opt_O=no
    1.90 +        ;;
    1.91 +    cflags )
    1.92 +        str_usage="[-O] <tool>"
    1.93 +        arg_spec="1="
    1.94 +        opt_spec="O."
    1.95 +        opt_O=no
    1.96 +        ;;
    1.97 +    cppflags )
    1.98 +        str_usage="[-p <prefix>] [-i] [<subdir> ...]"
    1.99 +        arg_spec="0+"
   1.100 +        opt_spec="p:i."
   1.101 +        opt_p="/"
   1.102 +        ;;
   1.103 +    ldflags )
   1.104 +        str_usage="[-p <prefix>] [<subdir> ...]"
   1.105 +        arg_spec="0+"
   1.106 +        opt_spec="p:"
   1.107 +        opt_p="/"
   1.108 +        ;;
   1.109 +    files )
   1.110 +        gen_tmpfile=yes
   1.111 +        str_usage="[-v] [-o <outfile>] [-r <buildroot>] [<filelist>]"
   1.112 +        arg_spec="0+"
   1.113 +        opt_spec="v.o:r:"
   1.114 +        opt_v=no
   1.115 +        opt_o=''
   1.116 +        opt_r=''
   1.117 +        ;;
   1.118 +    signal )
   1.119 +        str_usage="[-v] [-t] [-n] [-c] [-d <delay>] [-p <pid>] [-m <pattern>] <sig> [<sig> ...]"
   1.120 +        arg_spec="1+"
   1.121 +        opt_spec="v.t.n.c.d:p:m:"
   1.122 +        opt_v=no
   1.123 +        opt_t=no
   1.124 +        opt_n=no
   1.125 +        opt_c=no
   1.126 +        opt_d=1
   1.127 +        opt_p=""
   1.128 +        opt_m=""
   1.129 +        ;;
   1.130 +    config )
   1.131 +        str_usage="[-v] [-s] [-a] [-r] [-b <ext>] [-p <tagprefix>] [-t <tagname>] [-i <tagid>] <file>"
   1.132 +        arg_spec="1="
   1.133 +        opt_spec="v.s.a.r.b:p:t:i:c:"
   1.134 +        opt_v=no
   1.135 +        opt_s=no
   1.136 +        opt_a=no
   1.137 +        opt_r=no
   1.138 +        opt_b=""
   1.139 +        opt_p="#"
   1.140 +        opt_t="OpenPKG"
   1.141 +        opt_i=""
   1.142 +        gen_tmpfile=yes
   1.143 +        ;;
   1.144 +    msg )
   1.145 +        str_usage="[-b] [-r] [-t <type>]"
   1.146 +        arg_spec="0="
   1.147 +        opt_spec="b.r.t:"
   1.148 +        opt_b=no
   1.149 +        opt_r=no
   1.150 +        opt_t=info
   1.151 +        ;;
   1.152 +    check-class )
   1.153 +        str_usage=""
   1.154 +        arg_spec="1="
   1.155 +        opt_spec=""
   1.156 +        ;;
   1.157 +    -* )
   1.158 +        echo "$prog_name:Error: unknown option \`$tool'" 2>&1
   1.159 +        echo "$prog_name:Hint:  run \`$0 -h' for usage" 2>&1
   1.160 +        exit 1
   1.161 +        ;;
   1.162 +    * )
   1.163 +        echo "$prog_name:Error: unknown command \`$tool'" 2>&1
   1.164 +        echo "$prog_name:Hint:  run \`$0 -h' for usage" 2>&1
   1.165 +        exit 1
   1.166 +        ;;
   1.167 +esac
   1.168 +
   1.169 +#   tool information
   1.170 +toolcmd="$0 $tool"
   1.171 +toolcmdhelp="$prog_name $tool"
   1.172 +msgprefix="$prog_name:$tool"
   1.173 +
   1.174 +#   parse argument specification string
   1.175 +eval `echo $arg_spec |\
   1.176 +      sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'`
   1.177 +
   1.178 +#   parse option specification string
   1.179 +eval `echo h.$opt_spec |\
   1.180 +      sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'`
   1.181 +
   1.182 +#   iterate over argument line
   1.183 +opt_PREV=''
   1.184 +while [ $# -gt 0 ]; do
   1.185 +    #   special option stops processing
   1.186 +    if [ ".$1" = ".--" ]; then
   1.187 +        shift
   1.188 +        break
   1.189 +    fi
   1.190 +
   1.191 +    #   determine option and argument
   1.192 +    opt_ARG_OK=no
   1.193 +    if [ ".$opt_PREV" != . ]; then
   1.194 +        #   merge previous seen option with argument
   1.195 +        opt_OPT="$opt_PREV"
   1.196 +        opt_ARG="$1"
   1.197 +        opt_ARG_OK=yes
   1.198 +        opt_PREV=''
   1.199 +    else
   1.200 +        #   split argument into option and argument
   1.201 +        case "$1" in
   1.202 +            -[a-zA-Z0-9]*)
   1.203 +                eval `echo "x$1" |\
   1.204 +                      sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \
   1.205 +                          -e 's/";\(.*\)$/"; opt_ARG="\1"/'`
   1.206 +                ;;
   1.207 +            -[a-zA-Z0-9])
   1.208 +                opt_OPT=`echo "x$1" | cut -c3-`
   1.209 +                opt_ARG=''
   1.210 +                ;;
   1.211 +            *)
   1.212 +                break
   1.213 +                ;;
   1.214 +        esac
   1.215 +    fi
   1.216 +
   1.217 +    #   eat up option
   1.218 +    shift
   1.219 +
   1.220 +    #   determine whether option needs an argument
   1.221 +    eval "opt_MODE=\$opt_MODE_${opt_OPT}"
   1.222 +    if [ ".$opt_ARG" = . -a ".$opt_ARG_OK" != .yes ]; then
   1.223 +        if [ ".$opt_MODE" = ".:" -o ".$opt_MODE" = ".+" ]; then
   1.224 +            opt_PREV="$opt_OPT"
   1.225 +            continue
   1.226 +        fi
   1.227 +    fi
   1.228 +
   1.229 +    #   process option
   1.230 +    case $opt_MODE in
   1.231 +        '.' )
   1.232 +            #   boolean option
   1.233 +            eval "opt_${opt_OPT}=yes"
   1.234 +            ;;
   1.235 +        ':' )
   1.236 +            #   option with argument (multiple occurances override)
   1.237 +            eval "opt_${opt_OPT}=\"\$opt_ARG\""
   1.238 +            ;;
   1.239 +        '+' )
   1.240 +            #   option with argument (multiple occurances append)
   1.241 +            eval "opt_${opt_OPT}=\"\$opt_${opt_OPT} \$opt_ARG\""
   1.242 +            ;;
   1.243 +        * )
   1.244 +            echo "$msgprefix:Error: unknown option: \`-$opt_OPT'" 1>&2
   1.245 +            echo "$msgprefix:Hint:  run \`$toolcmdhelp -h' or \`man $prog_name' for details" 1>&2
   1.246 +            exit 1
   1.247 +            ;;
   1.248 +    esac
   1.249 +done
   1.250 +if [ ".$opt_PREV" != . ]; then
   1.251 +    echo "$msgprefix:Error: missing argument to option \`-$opt_PREV'" 1>&2
   1.252 +    echo "$msgprefix:Hint:  run \`$toolcmdhelp -h' or \`man $prog_name' for details" 1>&2
   1.253 +    exit 1
   1.254 +fi
   1.255 +
   1.256 +#   process help option
   1.257 +if [ ".$opt_h" = .yes ]; then
   1.258 +    echo "Usage: $toolcmdhelp $str_usage"
   1.259 +    exit 0
   1.260 +fi
   1.261 +
   1.262 +#   complain about incorrect number of arguments
   1.263 +case $arg_MODE in
   1.264 +    '=' )
   1.265 +        if [ $# -ne $arg_NUMS ]; then
   1.266 +            echo "$msgprefix:Error: invalid number of arguments (exactly $arg_NUMS expected)" 1>&2
   1.267 +            echo "$msgprefix:Hint:  run \`$toolcmd -h' or \`man $prog_name' for details" 1>&2
   1.268 +            exit 1
   1.269 +        fi
   1.270 +        ;;
   1.271 +    '+' )
   1.272 +        if [ $# -lt $arg_NUMS ]; then
   1.273 +            echo "$msgprefix:Error: invalid number of arguments (at least $arg_NUMS expected)" 1>&2
   1.274 +            echo "$msgprefix:Hint:  run \`$toolcmd -h' or \`man $prog_name' for details" 1>&2
   1.275 +            exit 1
   1.276 +        fi
   1.277 +        ;;
   1.278 +esac
   1.279 +
   1.280 +#   establish a temporary file on request
   1.281 +if [ ".$gen_tmpfile" = .yes ]; then
   1.282 +    if [ ".$TMPDIR" != . ]; then
   1.283 +        tmpdir="$TMPDIR"
   1.284 +    else
   1.285 +        tmpdir="/tmp"
   1.286 +    fi
   1.287 +    tmpfile="$tmpdir/.$prog_name.$$"
   1.288 +    rm -f $tmpfile >/dev/null 2>&1
   1.289 +    touch $tmpfile
   1.290 +fi
   1.291 +
   1.292 +#   provide a few useful variables
   1.293 +NL="
   1.294 +"
   1.295 +TAB="	"
   1.296 +DIFS=" ${TAB}${NL}"
   1.297 +
   1.298 +#   determine platform information
   1.299 +platform_machine=`(uname -m) 2>/dev/null` ||\
   1.300 +platform_machine=`(uname -p) 2>/dev/null` ||\
   1.301 +platform_machine='unknown'
   1.302 +if [ ".$platform_machine" = ".Power Macintosh" ]; then
   1.303 +    platform_machine=`(uname -p) 2>/dev/null`
   1.304 +fi
   1.305 +platform_release=`(uname -r) 2>/dev/null` ||\
   1.306 +platform_release='unknown'
   1.307 +platform_system=`(uname -s) 2>/dev/null` ||\
   1.308 +platform_system='unknown'
   1.309 +platform_version=`(uname -v) 2>/dev/null` ||\
   1.310 +platform_version='unknown'
   1.311 +platform="${platform_machine}:${platform_system}:${platform_release}:${platform_version}"
   1.312 +
   1.313 +#   dispatch into tools
   1.314 +case $tool in
   1.315 +    platform )
   1.316 +        #    provide unique platform id
   1.317 +        m=`echo "$platform_machine" | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
   1.318 +        s=`echo "$platform_system"  | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
   1.319 +        r=`echo "$platform_release" | sed -e 's;-.*$;;'`
   1.320 +        echo "${m}-${s}${r}"
   1.321 +        ;;
   1.322 +
   1.323 +    mflags )
   1.324 +        tool="$1"
   1.325 +        isgmake=no
   1.326 +        if [ ".`$tool -v -f /dev/null 2>/dev/null | grep 'GNU Make'`" != . ]; then
   1.327 +            isgmake=yes
   1.328 +        fi
   1.329 +        mflags=''
   1.330 +        if [ ".$isgmake" = .yes ]; then
   1.331 +            mflags="--no-print-directory"
   1.332 +        fi
   1.333 +        if [ ".$opt_O" = .yes ]; then
   1.334 +            case $platform in
   1.335 +                *:SunOS:5.*:* | *:OSF1:*:* )
   1.336 +                    if [ ".$isgmake" = .yes ]; then
   1.337 +                        n=`(/bin/uname -X) 2>/dev/null | grep -i NumCPU | awk '{ print $3; }'`
   1.338 +                        if [ ".$n" != . ]; then
   1.339 +                            if [ $n -gt 1 ]; then
   1.340 +                                n=`expr $n \* 2`
   1.341 +                                mflags="$mflags -j$n"
   1.342 +                            fi
   1.343 +                        fi
   1.344 +                    fi
   1.345 +                    ;;
   1.346 +                *:FreeBSD:[4-8].*:* )
   1.347 +                    n=`/sbin/sysctl -n hw.ncpu`
   1.348 +                    if [ ".$n" != . ]; then
   1.349 +                        if [ $n -gt 1 ]; then
   1.350 +                            n=`expr $n \* 2`
   1.351 +                            mflags="$mflags -j$n"
   1.352 +                            if [ ".$isgmake" = .no ]; then
   1.353 +                                mflags="$mflags -B"
   1.354 +                            fi
   1.355 +                        fi
   1.356 +                    fi
   1.357 +                    ;;
   1.358 +                *:NetBSD:1.[56]*:* | *:NetBSD:[2345].*:* )
   1.359 +                    n=`/sbin/sysctl -n hw.ncpu`
   1.360 +                    if [ ".$n" != . ]; then
   1.361 +                        if [ $n -gt 1 ]; then
   1.362 +                            n=`expr $n \* 2`
   1.363 +                            mflags="$mflags -j$n"
   1.364 +                            if [ ".$isgmake" = .no ]; then
   1.365 +                                mflags="$mflags -B"
   1.366 +                            fi
   1.367 +                        fi
   1.368 +                    fi
   1.369 +                    ;;
   1.370 +                *:Linux:*:* )
   1.371 +                    n=`grep ^processor /proc/cpuinfo | wc -l | awk '{ print $1; }'`
   1.372 +                    if [ ".$n" != . ]; then
   1.373 +                        if [ $n -gt 1 ]; then
   1.374 +                            n=`expr $n \* 2`
   1.375 +                            mflags="$mflags -j$n"
   1.376 +                        fi
   1.377 +                    fi
   1.378 +                    ;;
   1.379 +                *:HP-UX:*:* )
   1.380 +                    if [ ".$isgmake" = .yes ]; then
   1.381 +                        n=`ioscan -d processor -k -F | wc -l`
   1.382 +                        if [ ".$n" != . ]; then
   1.383 +                            if [ $n -gt 1 ]; then
   1.384 +                                n=`expr $n \* 2`
   1.385 +                                mflags="$mflags -j$n"
   1.386 +                            fi
   1.387 +                        fi
   1.388 +                    fi
   1.389 +                    ;;
   1.390 +                *:IRIX64:6.*:* )
   1.391 +                    if [ ".$isgmake" = .yes ]; then
   1.392 +                        n=`/usr/sbin/sysconf | awk '/NUM_PROCESSORS/ { print $2; }'`
   1.393 +                        if [ ".$n" != . ]; then
   1.394 +                            if [ $n -gt 1 ]; then
   1.395 +                                n=`expr $n \* 2`
   1.396 +                                mflags="$mflags -j$n"
   1.397 +                            fi
   1.398 +                        fi
   1.399 +                    fi
   1.400 +                    ;;
   1.401 +                *:Darwin:*:* )
   1.402 +                    n=`/usr/sbin/sysctl hw.ncpu | awk '{ print $3; }'`
   1.403 +                    if [ ".$n" != . ]; then
   1.404 +                        if [ $n -gt 1 ]; then
   1.405 +                            n=`expr $n \* 2`
   1.406 +                            mflags="$mflags -j$n"
   1.407 +                            if [ ".$isgmake" = .no ]; then
   1.408 +                                mflags="$mflags -B"
   1.409 +                            fi
   1.410 +                        fi
   1.411 +                    fi
   1.412 +                    ;;
   1.413 +                *:AIX:*:* )
   1.414 +                    if [ ".$isgmake" = .yes ]; then
   1.415 +                        if [ -x /usr/sbin/lsdev ]; then
   1.416 +                            n=`/usr/sbin/lsdev -C -c processor -S available | wc -l | awk '{ print $1; }'`
   1.417 +                            if [ ".$n" != . ]; then
   1.418 +                                if [ $n -gt 1 ]; then
   1.419 +                                    n=`expr $n \* 2`
   1.420 +                                    mflags="$mflags -j$n"
   1.421 +                                fi
   1.422 +                            fi
   1.423 +                        fi
   1.424 +                    fi
   1.425 +                    ;;
   1.426 +            esac
   1.427 +        fi
   1.428 +        echo "x$mflags" | sed -e 's;^x;;'
   1.429 +        ;;
   1.430 +
   1.431 +    cflags )
   1.432 +        tool="$1"
   1.433 +        echo $tool | grep ^/ >/dev/null
   1.434 +        if [ $? -eq 0 ]; then
   1.435 +            if [ ! -x "$tool" -o -d "$tool" ]; then
   1.436 +                echo "$msgprefix:Error: specified tool \`$tool' not found or not executable" 1>&2
   1.437 +                exit 1
   1.438 +            fi
   1.439 +        else
   1.440 +            shtool=`echo $prog_path | sed -e 's;/[^/]*$;/shtool;'`
   1.441 +            sh $shtool path --suppress $tool
   1.442 +            if [ $? -ne 0 ]; then
   1.443 +                echo "$msgprefix:Error: specified tool \`$tool' not found in PATH" 1>&2
   1.444 +                exit 1
   1.445 +            fi
   1.446 +        fi
   1.447 +        isgcc=no
   1.448 +        if [ ".`($tool -v; $tool --version) </dev/null 2>&1 | grep -i 'gcc'`" != . ]; then
   1.449 +            isgcc=yes
   1.450 +        fi
   1.451 +        cflags=''
   1.452 +        if [ ".$opt_O" = .yes ]; then
   1.453 +            if [ ".$isgcc" = .yes ]; then
   1.454 +                case "$platform:`$tool -dumpversion 2>/dev/null`" in
   1.455 +                    *:NetBSD:1.6*:*:2.* )
   1.456 +                        #   NetBSD 1.6.x with GCC 2.95.x suffers from memory
   1.457 +                        #   exhaustion problems under GCC optimizations.
   1.458 +                        ;;
   1.459 +                    * )
   1.460 +                        cflags="-O2"
   1.461 +                        ;;
   1.462 +                esac
   1.463 +                if [ ".`$tool -v 2>/dev/null | grep 'with-gnu-as'`" != . ] || \
   1.464 +                   [ ".`(as --version </dev/null) 2>/dev/null | grep 'GNU'`" != . ]; then
   1.465 +                    cflags="$cflags -pipe"
   1.466 +                fi
   1.467 +            else
   1.468 +                cflags="-O"
   1.469 +            fi
   1.470 +        fi
   1.471 +        case "$platform" in
   1.472 +            amd64:FreeBSD:*:* | ia64:FreeBSD:*:* | sparc64:FreeBSD:*:* | x86_64:Linux:*:* )
   1.473 +                #   at least under FreeBSD on amd64, ia64 and sparc64
   1.474 +                #   the GNU binutils strictly require Position In-
   1.475 +                #   dependent Code (PIC) when Dynamic Shared Objects
   1.476 +                #   (DSO) are involved. As an ugly workaround we
   1.477 +                #   build everything with PIC there, although this is
   1.478 +                #   more than required. We also can assume that the C
   1.479 +                #   compiler is always GCC, either the OpenPKG one or
   1.480 +                #   the FreeBSD one.
   1.481 +                cflags="-fPIC"
   1.482 +                ;;
   1.483 +        esac
   1.484 +        echo "x$cflags" | sed -e 's;^x;;'
   1.485 +        ;;
   1.486 +
   1.487 +     cppflags )
   1.488 +        std=0
   1.489 +        cppflags=""
   1.490 +        for pkg in .. $*; do
   1.491 +            [ ".$pkg" = ... ] && continue
   1.492 +            if [ ".$pkg" = .. ]; then
   1.493 +                cppflags="$cppflags -I${opt_p}/include"
   1.494 +                std=1
   1.495 +            else
   1.496 +                cppflags="$cppflags -I${opt_p}/include/$pkg"
   1.497 +            fi
   1.498 +        done
   1.499 +        if [ $std -eq 0 ]; then
   1.500 +            cppflags="-I${opt_p}/include$cppflags"
   1.501 +        fi
   1.502 +        if [ ".$opt_i" = .yes ]; then
   1.503 +            arch="unknown"; os_name="unknown"; os_vers="0"
   1.504 +            shtool=`echo $prog_path | sed -e 's;/[^/]*$;/shtool;'`
   1.505 +            eval `sh $shtool platform -U -S ":" -C "" -F "%<ac>:%<st>" |\
   1.506 +                  sed -e 's/^\(.*\):\(.*\):\(.*\)$/arch="\1"; os_name="\2"; os_vers="\3";/'`
   1.507 +            V=0; R=0; L=0
   1.508 +            eval `echo "$os_vers" |\
   1.509 +                  sed -e 's/^/X/' \
   1.510 +                      -e 's/^X[^0-9]*\([0-9][0-9]*\)[^0-9][^0-9]*\([0-9][0-9]*\)[^0-9][^0-9]*\([0-9][0-9]*\).*$/V="\1"; R="\2"; L="\3";/' \
   1.511 +                      -e 's/^X[^0-9]*\([0-9][0-9]*\)[^0-9][^0-9]*\([0-9][0-9]*\).*$/V="\1"; R="\2";/' \
   1.512 +                      -e 's/^X[^0-9]*\([0-9][0-9]*\).*$/V="\1";/' \
   1.513 +                      -e 's/^X.*$/:/'`
   1.514 +            os_vers=`echo . | awk '{ printf("%02d%02d%02d", V, R, L); }' V="$V" R="$R" L="$L"`
   1.515 +            cppflags="$cppflags -D__OPENPKG_${arch} -D__OPENPKG_${os_name}=${os_vers}"
   1.516 +        fi
   1.517 +        echo "x$cppflags" | sed -e 's;^x;;' -e 's;^ *;;'
   1.518 +        ;;
   1.519 +
   1.520 +     ldflags )
   1.521 +        std=0
   1.522 +        ldflags=""
   1.523 +        for pkg in .. $*; do
   1.524 +            [ ".$pkg" = ... ] && continue
   1.525 +            if [ ".$pkg" = .. ]; then
   1.526 +                ldflags="$ldflags -L${opt_p}/lib"
   1.527 +                std=1
   1.528 +            else
   1.529 +                ldflags="$ldflags -L${opt_p}/lib/$pkg"
   1.530 +            fi
   1.531 +        done
   1.532 +        if [ $std -eq 0 ]; then
   1.533 +            ldflags="-L${opt_p}/lib$ldflags"
   1.534 +        fi
   1.535 +        echo "x$ldflags" | sed -e 's;^x;;' -e 's;^ *;;'
   1.536 +        ;;
   1.537 +
   1.538 +     files )
   1.539 +        #   if a Perl interpreter is available, we perform the operation
   1.540 +        #   with it because Perl is a magnitude (factor 10!) faster than
   1.541 +        #   what we can do here in Bourne-Shell.
   1.542 +        perl=''
   1.543 +        for dir in `echo "$PATH:@l_prefix@/lib/openpkg" | sed -e 's/:/ /g'` .; do
   1.544 +            [ ".$dir" = .. -o ".$dir" = . ] && continue
   1.545 +            for tool in perl5 perl miniperl; do
   1.546 +                if [ -f "$dir/$tool" ]; then
   1.547 +                    perl="$dir/$tool"
   1.548 +                    break
   1.549 +                fi
   1.550 +            done
   1.551 +            if [ ".$perl" != . ]; then
   1.552 +                break
   1.553 +            fi
   1.554 +        done
   1.555 +        if [ ".$perl" != . ]; then
   1.556 +            cat >$tmpfile <<'EOT'
   1.557 +            ##
   1.558 +            ##  PERL IMPLEMENTATION (FAST)
   1.559 +            ##
   1.560 +
   1.561 +            my $opt_v = 0;
   1.562 +            my $opt_o = '';
   1.563 +            my $opt_r = '';
   1.564 +            while ($ARGV[0] =~ m|^-(.)(.*)$|) {
   1.565 +                my ($opt, $arg) = ($1, $2);
   1.566 +                shift(@ARGV);
   1.567 +                unshift(@ARGV, $arg)  if ($arg ne '');
   1.568 +                $opt_v = 1            if ($opt eq 'v');
   1.569 +                $opt_o = shift(@ARGV) if ($opt eq 'o');
   1.570 +                $opt_r = shift(@ARGV) if ($opt eq 'r');
   1.571 +            }
   1.572 +
   1.573 +            #   remember the build root in a reasonable short variable ;)
   1.574 +            my $br = "$opt_r";
   1.575 +
   1.576 +            #   read input file list
   1.577 +            my @L = ();
   1.578 +            if ($#ARGV == -1 or ($#ARGV == 0 and $ARGV[0] eq "-")) {
   1.579 +                #    read file list from stdin
   1.580 +                while (<STDIN>) {
   1.581 +                    s/\n$//s;
   1.582 +                    push(@L, $_);
   1.583 +                }
   1.584 +            }
   1.585 +            else {
   1.586 +                #    read file list from argument line
   1.587 +                @L = @ARGV;
   1.588 +            }
   1.589 +
   1.590 +            #   PASS 1: PREPARATION AND SYNTACTICAL EXPANSION
   1.591 +            if ($opt_v == 1) {
   1.592 +                print STDERR "rpmtool:files: pass 1 (preparation and syntactical expansions)\n";
   1.593 +            }
   1.594 +            my @T = ();
   1.595 +            my $l;
   1.596 +            foreach $l (@L) {
   1.597 +                #   replace tabs with spaces, reduce multiple spaces to single
   1.598 +                #   spaces, and remove leading and trailing spaces
   1.599 +                $l =~ s|[ \t\n]+| |sg;
   1.600 +                $l =~ s|^[ \t]+||sg;
   1.601 +                $l =~ s|[ \t]+$||sg;
   1.602 +
   1.603 +                #   move tags to end of entry for easier parsing
   1.604 +                1 while ($l =~ s|^(%\S+) (.+)|$2 $1|);
   1.605 +
   1.606 +                #   use `:' as a dummy path for tag-only entries (like `%defattr')
   1.607 +                #   to avoid special cases in the later processing
   1.608 +                if ($l =~ m|^%.+|) {
   1.609 +                    $l = ": $l";
   1.610 +                }
   1.611 +
   1.612 +                #   split entry into path and optional tags
   1.613 +                my ($p, $t) = ($l =~ m|^(\S+)(.*)$|);
   1.614 +
   1.615 +                #   expand `{foo,bar,quux}' constructs in path (silent
   1.616 +                #   assumtion to make life easier is that the constructs
   1.617 +                #   occurs only once in a path!)
   1.618 +                if ($p =~ m|^(.*)\{([^\}]+)\}(.*)$|) {
   1.619 +                    #   split path into prolog, the set construct, and the epilog
   1.620 +                    my ($pro, $set, $epi) = ($1, $2, $3);
   1.621 +
   1.622 +                    #   repeat prolog and epilog for all elements in set
   1.623 +                    my $x;
   1.624 +                    foreach $x (split(/,/, $set)) {
   1.625 +                        push(@T, "${pro}${x}${epi}${t}");
   1.626 +                    }
   1.627 +                }
   1.628 +                else {
   1.629 +                    #   else just take over the entry as is
   1.630 +                    push(@T, $l);
   1.631 +                }
   1.632 +            }
   1.633 +            @L = @T;
   1.634 +
   1.635 +            #   PASS 2: FILESYSTEM-BASED EXPANSIONS
   1.636 +            if ($opt_v == 1) {
   1.637 +                print STDERR "rpmtool:files: pass 2 (filesystem-based expansions)\n";
   1.638 +            }
   1.639 +            @T = ();
   1.640 +            foreach $l (@L) {
   1.641 +                #   split entry into path and optional tags
   1.642 +                my ($p, $t) = ($l =~ m|^(\S*)(.*)$|);
   1.643 +
   1.644 +                #   expand...
   1.645 +                if (-d "$br$p" and $t !~ m|.*%dir.*|) {
   1.646 +                    #   expand path because it is not tagged with %dir
   1.647 +                    my @X = `cd "$br$p" && find . -print`;
   1.648 +                    my $x;
   1.649 +                    foreach $x (@X) {
   1.650 +                        $x =~ s|\n$||s;
   1.651 +                        $x =~ s|^\.|$p|s;
   1.652 +                        push(@T, "${x}${t}");
   1.653 +                    }
   1.654 +                }
   1.655 +                else {
   1.656 +                    #   expand path wildcards (`*' and `[..]')
   1.657 +                    #   (if not wildcards are present, this doesn't harm)
   1.658 +                    my @X = glob("$br$p");
   1.659 +                    my $x;
   1.660 +                    foreach $x (@X) {
   1.661 +                        my $brqm = quotemeta($br);
   1.662 +                        $x =~ s|^$brqm||s;
   1.663 +                        push(@T, "${x}${t}");
   1.664 +                    }
   1.665 +                }
   1.666 +            }
   1.667 +            @L = @T;
   1.668 +
   1.669 +            #   PASS 3: DUPLICATION REMOVAL AND CLEANUP
   1.670 +            if ($opt_v == 1) {
   1.671 +                print STDERR "rpmtool:files: pass 3 (duplication removal and cleanup)\n";
   1.672 +            }
   1.673 +            @T = ();
   1.674 +            foreach $l (@L) {
   1.675 +                #   split entry into path and optional tags
   1.676 +                my ($p, $t) = ($l =~ m|^(\S*)(.*)$|);
   1.677 +
   1.678 +                #   add %dir tag if entry is a directory, but still not
   1.679 +                #   tagged as such (else RPM would again expand it recursively)
   1.680 +                if (-d "$br$p") {
   1.681 +                    if ($t !~ m|%dir|) {
   1.682 +                        $t .= " %dir";
   1.683 +                    }
   1.684 +                }
   1.685 +
   1.686 +                #   remove duplicate entries in already processed part
   1.687 +                #   (but make sure we keep the entries with the dummy tags)
   1.688 +                if ($p ne ":") {
   1.689 +                    my @T2 = ();
   1.690 +                    foreach $t (@T) {
   1.691 +                        my $pqm = quotemeta($p);
   1.692 +                        next if ($t =~ m|^$pqm | or $t eq $p);
   1.693 +                        push(@T2, $t);
   1.694 +                    }
   1.695 +                    @T = @T2;
   1.696 +                }
   1.697 +
   1.698 +                #   keep entry only if no %not tag is present
   1.699 +                #   (else all entries are removed)
   1.700 +                if ($t !~ m|.*%not.*|) {
   1.701 +                    push(@T, "${p}${t}");
   1.702 +                }
   1.703 +            }
   1.704 +            @L = @T;
   1.705 +
   1.706 +            #   write out new file list
   1.707 +            @T = ();
   1.708 +            foreach $l (@L) {
   1.709 +                $l =~ s|^(\S+) (.*)$|$2 $1|sg;
   1.710 +                $l =~ s|^\s+||s;
   1.711 +                $l =~ s|\s+$||s;
   1.712 +                $l =~ s|\s+:$||s;
   1.713 +                push(@T, $l);
   1.714 +            }
   1.715 +            @L = @T;
   1.716 +            if ($opt_o eq '' or $opt_o eq '-') {
   1.717 +                print STDOUT join("\n", @L)."\n";
   1.718 +            }
   1.719 +            else {
   1.720 +                open(FP, ">$opt_o");
   1.721 +                print FP join("\n", @L)."\n";
   1.722 +                close(FP);
   1.723 +            }
   1.724 +EOT
   1.725 +            cmd="$perl $tmpfile";
   1.726 +            if [ ".$opt_v" = .yes ]; then
   1.727 +                cmd="$cmd -v"
   1.728 +            fi
   1.729 +            if [ ".$opt_o" != . ]; then
   1.730 +                cmd="$cmd -o \"$opt_o\""
   1.731 +            fi
   1.732 +            if [ ".$opt_r" != . ]; then
   1.733 +                cmd="$cmd -r \"$opt_r\""
   1.734 +            fi
   1.735 +            for arg
   1.736 +            do
   1.737 +                cmd="$cmd \"$arg\""
   1.738 +            done
   1.739 +            eval "$cmd"
   1.740 +        else
   1.741 +            ##
   1.742 +            ##  BOURNE-SHELL IMPLEMENTATION (PORTABLE)
   1.743 +            ##
   1.744 +
   1.745 +            #   remember the build root in a reasonable short variable ;)
   1.746 +            br="$opt_r"
   1.747 +
   1.748 +            #   make sure filename expansion is disabled per default
   1.749 +            set -f
   1.750 +
   1.751 +            #    read input file list
   1.752 +            L=''
   1.753 +            if [ $# -eq 0 ] || [ $# -eq 1 -a ".$1" = ".-" ]; then
   1.754 +                #    read file list from stdin
   1.755 +                L=`cat`
   1.756 +            else
   1.757 +                #    read file list from argument line
   1.758 +                for arg
   1.759 +                do
   1.760 +                    L="$L$NL$arg"
   1.761 +                done
   1.762 +            fi
   1.763 +
   1.764 +            #   PASS 1: PREPARATION AND SYNTACTICAL EXPANSION
   1.765 +            if [ ".$opt_v" = .yes ]; then
   1.766 +                echo "rpmtool:files: pass 1 (preparation and syntactical expansions)" 1>&2
   1.767 +            fi
   1.768 +            T=''
   1.769 +            OIFS="$IFS"; IFS="$NL"
   1.770 +            for l in $L; do
   1.771 +                [ ".$l" = . ] && continue
   1.772 +
   1.773 +                #   replace tabs with spaces, reduce multiple spaces to single
   1.774 +                #   spaces, and remove leading and trailing spaces
   1.775 +                l=`echo "$l" | sed -e "s;${TAB}; ;g" -e 's;  *; ;g' -e 's;^ *;;' -e 's; *$;;'`
   1.776 +
   1.777 +                #   move tags to end of entry for easier parsing
   1.778 +                while [ ".`echo \"$l\" | grep '^%[^ ]* .*'`" != . ]; do
   1.779 +                    l=`echo "$l" | sed -e 's;^\(%[^ ]*\) \(.*\);\2 \1;'`
   1.780 +                done
   1.781 +
   1.782 +                #   use `:' as a dummy path for tag-only entries (like `%defattr')
   1.783 +                #   to avoid special cases in the later processing
   1.784 +                if [ ".`echo \"$l\" | grep '^%.*'`" != . ]; then
   1.785 +                    l=": $l"
   1.786 +                fi
   1.787 +
   1.788 +                #   split entry into path and optional tags
   1.789 +                eval `echo ".$l" | sed -e 's;^\.\([^ ]*\)\(.*\)$;p="\1" t="\2";'`
   1.790 +
   1.791 +                #   expand `{foo,bar,quux}' constructs in path (silent
   1.792 +                #   assumtion to make life easier is that the constructs
   1.793 +                #   occurs only once in a path!)
   1.794 +                if [ ".`echo \".$p\" | grep '^\..*{[^}]*}.*$'`" != . ]; then
   1.795 +
   1.796 +                    #   split path into prolog, the set construct, and the epilog
   1.797 +                    eval `echo ".$p" | sed -e 's;^\.\(.*\){\([^}]*\)}\(.*\)$;pro="\1" set="\2" epi="\3";'`
   1.798 +
   1.799 +                    #   repeat prolog and epilog for all elements in set
   1.800 +                    OIFS2="$IFS"; IFS=","
   1.801 +                    for x in $set; do
   1.802 +                        T="$T$NL${pro}${x}${epi}${t}"
   1.803 +                    done
   1.804 +                    IFS="$OIFS2"
   1.805 +                else
   1.806 +                    #   else just take over the entry as is
   1.807 +                    T="$T$NL$l"
   1.808 +                fi
   1.809 +            done
   1.810 +            L="$T"
   1.811 +            IFS="$OIFS"
   1.812 +
   1.813 +            #   PASS 2: FILESYSTEM-BASED EXPANSIONS
   1.814 +            if [ ".$opt_v" = .yes ]; then
   1.815 +                echo "rpmtool:files: pass 2 (filesystem-based expansions)" 1>&2
   1.816 +            fi
   1.817 +            T=''
   1.818 +            OIFS="$IFS"; IFS="$NL"
   1.819 +            for l in $L; do
   1.820 +                [ ".$l" = . ] && continue
   1.821 +
   1.822 +                #   split entry into path and optional tags
   1.823 +                eval `echo ".$l" | sed -e 's;^\.\([^ ]*\)\(.*\)$;p="\1" t="\2";'`
   1.824 +
   1.825 +                #   expand...
   1.826 +                if [ -d "$br$p" -a ".`expr \".$t\" : '\..*%dir.*'`" = .0 ]; then
   1.827 +                    #   expand path because it is not tagged with %dir
   1.828 +                    OIFS2="$IFS"; IFS="$DIFS"
   1.829 +                    for x in `cd "$br$p" && find . -print | sed -e "s;^\\.;$p;"`; do
   1.830 +                        T="$T$NL${x}${t}"
   1.831 +                    done
   1.832 +                    IFS="$OIFS2"
   1.833 +                else
   1.834 +                    #   expand path wildcards (`*' and `[..]')
   1.835 +                    #   (if not wildcards are present, this doesn't harm)
   1.836 +                    OIFS2="$IFS"; IFS="$DIFS"
   1.837 +                    for x in `(set +f; echo $br$p) | sed -e "s;^$br;;" -e "s; $br; ;g"`; do
   1.838 +                        T="$T$NL${x}${t}"
   1.839 +                    done
   1.840 +                    IFS="$OIFS2"
   1.841 +                fi
   1.842 +            done
   1.843 +            IFS="$OIFS"
   1.844 +            L="$T"
   1.845 +
   1.846 +            #   PASS 3: DUPLICATION REMOVAL AND CLEANUP
   1.847 +            if [ ".$opt_v" = .yes ]; then
   1.848 +                echo "rpmtool:files: pass 3 (duplication removal and cleanup)" 1>&2
   1.849 +            fi
   1.850 +            T=''
   1.851 +            OIFS="$IFS"; IFS="$NL"
   1.852 +            for l in $L; do
   1.853 +                [ ".$l" = . ] && continue
   1.854 +
   1.855 +                #   split entry into path and optional tags
   1.856 +                eval `echo ".$l" | sed -e 's;^\.\([^ ]*\)\(.*\)$;p="\1" t="\2";'`
   1.857 +
   1.858 +                #   add %dir tag if entry is a directory, but still not
   1.859 +                #   tagged as such (else RPM would again expand it recursively)
   1.860 +                if [ -d "$br$p" ]; then
   1.861 +                    if [ ".`expr \".$t\" : '\..*%dir.*'`" = .0 ]; then
   1.862 +                        t="$t %dir"
   1.863 +                    fi
   1.864 +                fi
   1.865 +
   1.866 +                #   remove duplicate entries in already processed part
   1.867 +                #   (but make sure we keep the entries with the dummy tags)
   1.868 +                if [ ".$p" != ".:" ]; then
   1.869 +                    T=`echo "$T" | grep -v "^$p " | grep -v "^$p\$"`
   1.870 +                fi
   1.871 +
   1.872 +                #   keep entry only if no %not tag is present
   1.873 +                #   (else all entries are removed)
   1.874 +                if [ ".`expr \".$t\" : '\..*%not.*'`" = .0 ]; then
   1.875 +                    T="$T$NL${p}${t}"
   1.876 +                fi
   1.877 +            done
   1.878 +            IFS="$OIFS"
   1.879 +            L="$T"
   1.880 +
   1.881 +            #   write out new file list
   1.882 +            if [ ".$opt_o" = . -o ".$opt_o" = ".-" ]; then
   1.883 +                outcmd="cat"
   1.884 +            else
   1.885 +                outcmd="cat > $opt_o"
   1.886 +            fi
   1.887 +            echo "$L" |\
   1.888 +            sed -e '/^$/d' \
   1.889 +                -e 's;^\([^ ]*\) *\(.*\)$;\2 \1;g' \
   1.890 +                -e 's;^ *;;' \
   1.891 +                -e 's; *$;;' \
   1.892 +                -e 's; *:$;;' | eval $outcmd
   1.893 +        fi
   1.894 +        ;;
   1.895 +
   1.896 +    signal )
   1.897 +        if [ ".$opt_p" = . -a ".$opt_m" = . ]; then
   1.898 +            echo "$msgprefix:Error: either option -p or -m has to be specified" 1>&2
   1.899 +            exit 1
   1.900 +        fi
   1.901 +        case "$platform" in
   1.902 +            *:FreeBSD:*:* | *:NetBSD:*:* )
   1.903 +                cmd0="ps -ax -o pid"
   1.904 +                cmd1="ps -ax -o command"
   1.905 +                cmd2="ps -ax -o pid,command"
   1.906 +                cmd3="ps -ax -o pid,ppid"
   1.907 +                ;;
   1.908 +            *:Linux:*:* | *:OSF1:5.*:* )
   1.909 +                cmd0="ps axo pid"
   1.910 +                cmd1="ps axo cmd"
   1.911 +                cmd2="ps axo pid,cmd"
   1.912 +                cmd3="ps axo pid,ppid"
   1.913 +                ;;
   1.914 +            *:SunOS:5.*:* )
   1.915 +                cmd0="ps -ef -o pid"
   1.916 +                cmd1="ps -ef -o args"
   1.917 +                cmd2="ps -ef -o pid,args"
   1.918 +                cmd3="ps -ef -o pid,ppid"
   1.919 +                ;;
   1.920 +            *:HP-UX:*:* )
   1.921 +                cmd0="ps -ef" # FIXME
   1.922 +                cmd1="ps -ef" # FIXME
   1.923 +                cmd2="ps -ef" # FIXME
   1.924 +                cmd3="ps -ef" # FIXME
   1.925 +                ;;
   1.926 +            *:IRIX64:6.*:* )
   1.927 +                cmd0="ps -ef -o pid"
   1.928 +                cmd1="ps -ef -o args"
   1.929 +                cmd2="ps -ef -o pid,args"
   1.930 +                cmd3="ps -ef -o pid,ppid"
   1.931 +                ;;
   1.932 +            *:Darwin:*:* )
   1.933 +                cmd0="ps -ax -opid"
   1.934 +                cmd1="ps -ax -ocommand"
   1.935 +                cmd2="ps -ax -opid,command"
   1.936 +                cmd3="ps -ax -opid,ppid"
   1.937 +        esac
   1.938 +        #   try all signals in order
   1.939 +        i=$#
   1.940 +        for sig in "$@"; do
   1.941 +            #   check whether program is still running/active
   1.942 +            active=""
   1.943 +            if [ ".$opt_p" != . ]; then
   1.944 +                active=`$cmd0 | grep "$opt_p" | grep -v grep | grep -v rpmtool`
   1.945 +            elif [ ".$opt_m" != . ]; then
   1.946 +                active=`$cmd1 | grep "$opt_m" | grep -v grep | grep -v rpmtool`
   1.947 +            fi
   1.948 +            if [ ".$active" = . ]; then
   1.949 +                break
   1.950 +            fi
   1.951 +
   1.952 +            #   send signal to program
   1.953 +            if [ ".$opt_p" != . ]; then
   1.954 +                pids="$opt_p"
   1.955 +            elif [ ".$opt_m" != . ]; then
   1.956 +                pids=`$cmd2 | sed -e "s;^[ ${TAB}]*;;" | egrep "[0-9]* .*$opt_m" |\
   1.957 +                      grep -v grep | grep -v rpmtool |\
   1.958 +                      awk '{ printf("%s\n", $1); }'`
   1.959 +            fi
   1.960 +            for pid in $pids; do
   1.961 +                if [ ".$opt_v" = .yes ]; then
   1.962 +                    echo "sending $sig signal to process $pid"
   1.963 +                fi
   1.964 +                if [ ".$opt_t" = .yes ]; then
   1.965 +                    echo "kill -$sig $pid"
   1.966 +                fi
   1.967 +                if [ ".$opt_n" = .no ]; then
   1.968 +                    eval "kill -$sig $pid"
   1.969 +                fi
   1.970 +            done
   1.971 +
   1.972 +            #   optionally send signal to childs of program
   1.973 +            if [ ".$opt_c" = .yes ]; then
   1.974 +                for pid in $pids; do
   1.975 +                    cpids=`$cmd3 | sed -e "s;^[ ${TAB}]*;;" | egrep "[0-9]* $pid" |\
   1.976 +                           grep -v grep | grep -v rpmtool |\
   1.977 +                           awk '{ printf("%s\n", $1); }'`
   1.978 +                    for cpid in $cpids; do
   1.979 +                        if [ ".$opt_v" = .yes ]; then
   1.980 +                            echo "sending $sig signal to child process $cpid"
   1.981 +                        fi
   1.982 +                        if [ ".$opt_t" = .yes ]; then
   1.983 +                            echo "kill -$sig $cpid"
   1.984 +                        fi
   1.985 +                        if [ ".$opt_n" = .no ]; then
   1.986 +                            eval "kill -$sig $cpid >/dev/null 2>&1"
   1.987 +                        fi
   1.988 +                    done
   1.989 +                done
   1.990 +            fi
   1.991 +
   1.992 +            #   perform optional delay
   1.993 +            i=`expr $i - 1`
   1.994 +            if [ $i -gt 0 ]; then
   1.995 +                if [ ".$opt_d" != . -a ".$opt_d" != . ]; then
   1.996 +                    sleep $opt_d
   1.997 +                fi
   1.998 +            fi
   1.999 +        done
  1.1000 +        ;;
  1.1001 +
  1.1002 +    config )
  1.1003 +        #   usage consistency
  1.1004 +        if [ ".$opt_a" = .no -a ".$opt_r" = .no ]; then
  1.1005 +            echo "$msgprefix:Error: either option -a or -r has to be specified" 1>&2
  1.1006 +            exit 1
  1.1007 +        fi
  1.1008 +        configfile="$1"
  1.1009 +
  1.1010 +        #   determine block markers
  1.1011 +        block_start="${opt_p}<${opt_t}"
  1.1012 +        if [ ".$opt_i" != . ]; then
  1.1013 +            block_start="${block_start} id=\"${opt_i}\""
  1.1014 +        fi
  1.1015 +        block_start="${block_start}>"
  1.1016 +        block_end="${opt_p}</${opt_t}>"
  1.1017 +
  1.1018 +        #   slash-escaped versions of block markers (for sed(3) call)
  1.1019 +        block_start_esc=`echo "$block_start" | sed -e 's;/;\\\\/;g'`
  1.1020 +        block_end_esc=`echo "$block_end" | sed -e 's;/;\\\\/;g'`
  1.1021 +
  1.1022 +        #   determine backup extension
  1.1023 +        case "X$opt_b" in
  1.1024 +            X   ) ext=".bak"    ;;
  1.1025 +            X.* ) ext="$opt_b"  ;;
  1.1026 +            X*  ) ext=".$opt_b" ;;
  1.1027 +        esac
  1.1028 +
  1.1029 +        #   check for block in config file
  1.1030 +        if [ -f $configfile ]; then
  1.1031 +            check=`grep "^${block_start}" $configfile`
  1.1032 +        else
  1.1033 +            touch $configfile
  1.1034 +            check=""
  1.1035 +        fi
  1.1036 +
  1.1037 +        #   add entry
  1.1038 +        if [ ".$opt_a" = .yes ]; then
  1.1039 +            if [ ".$check" != . ]; then
  1.1040 +                if [ ".$opt_s" = .yes ]; then
  1.1041 +                    exit 0
  1.1042 +                else
  1.1043 +                    echo "$msgprefix:Error: config entry already exists" 1>&2
  1.1044 +                    exit 1
  1.1045 +                fi
  1.1046 +            fi
  1.1047 +            cp $configfile $configfile$ext
  1.1048 +            echo "${block_start}" >$tmpfile
  1.1049 +            cat >>$tmpfile
  1.1050 +            echo "${block_end}" >>$tmpfile
  1.1051 +            cat $tmpfile >>$configfile
  1.1052 +
  1.1053 +        #   remove entry
  1.1054 +        elif [ ".$opt_r" = .yes ]; then
  1.1055 +            if [ ".$check" = . ]; then
  1.1056 +                if [ ".$opt_s" = .yes ]; then
  1.1057 +                    exit 0
  1.1058 +                else
  1.1059 +                    echo "$msgprefix:Error: config entry does not exist" 1>&2
  1.1060 +                    exit 1
  1.1061 +                fi
  1.1062 +            fi
  1.1063 +            cp $configfile $configfile$ext
  1.1064 +            sed -e "/^${block_start_esc}/,/^${block_end_esc}/d" \
  1.1065 +                <$configfile$ext >$configfile
  1.1066 +        fi
  1.1067 +
  1.1068 +        #   verbosity
  1.1069 +        if [ ".$opt_v" = .yes ]; then
  1.1070 +            (diff -u1 $configfile$ext $configfile >$tmpfile) 2>/dev/null
  1.1071 +            if [ ".`cat $tmpfile`" = . ]; then
  1.1072 +                (diff -C1 $configfile$ext $configfile >$tmpfile) 2>/dev/null
  1.1073 +                if [ ".`cat $tmpfile`" = . ]; then
  1.1074 +                    if [ ".$opt_s" = .no ]; then
  1.1075 +                        echo "$msgprefix:Warning: unable to show difference for config file \`$configfile'" 1>&2
  1.1076 +                    fi
  1.1077 +                fi
  1.1078 +            fi
  1.1079 +            echo "editing $configfile:"
  1.1080 +            cat $tmpfile
  1.1081 +        fi
  1.1082 +
  1.1083 +        #   optionally remove backup file
  1.1084 +        if [ ".$opt_b" = . ]; then
  1.1085 +            rm -f $configfile$ext
  1.1086 +        fi
  1.1087 +        ;;
  1.1088 +
  1.1089 +    msg )
  1.1090 +        #   optionally beep before message
  1.1091 +        if [ ".$opt_b" = .yes ]; then
  1.1092 +            echo . | awk '{ printf("%c", 7); }'
  1.1093 +        fi
  1.1094 +        title=""
  1.1095 +        case $opt_t in
  1.1096 +            info   ) title="-------" ;;
  1.1097 +            notice ) title="Notice-" ;;
  1.1098 +            warn   ) title="Warning" ;;
  1.1099 +            error  ) title="Error--" ;;
  1.1100 +            *      ) echo "$msgprefix:Error: invalid message type \`$opt_t'" 1>&2; exit 1 ;;
  1.1101 +        esac
  1.1102 +
  1.1103 +        #   display message
  1.1104 +        if [ ".$opt_r" != .yes ]; then
  1.1105 +            echo . | awk '{ printf("\r"); }'
  1.1106 +        fi
  1.1107 +        echo "+----------------------------------${title}------------------------------------+"
  1.1108 +        expand -t 8 | sed -e 's; *$;;' | awk '{ printf("| %-75s |\n", substr($0, 0, 75)); }'
  1.1109 +        echo "+-----------------------------------------------------------------------------+"
  1.1110 +        ;;
  1.1111 +    check-class )
  1.1112 +        #   check package class from within .spec file macro expansion for %prep section
  1.1113 +        class="$1"; shift
  1.1114 +        case "$class" in
  1.1115 +            CORE|BASE )
  1.1116 +                ;;
  1.1117 +            PLUS )
  1.1118 +                echo "set +x"
  1.1119 +                ( echo "This OpenPKG package is of class PLUS."
  1.1120 +                  echo "This means it is still in extended QUALITY ASSURANCE state."
  1.1121 +                  echo "Hence it is still NOT ready for careless use."
  1.1122 +                  echo "Do not use it in critical production environments."
  1.1123 +                  echo "It might be still potentially unstable under run-time."
  1.1124 +                ) | sh $prog_path msg -r -t notice | sed -e 's;^;echo ";' -e 's;$;";'
  1.1125 +                echo "set -x"
  1.1126 +                ;;
  1.1127 +            EVAL )
  1.1128 +                echo "set +x"
  1.1129 +                ( echo "This OpenPKG package is of class EVAL."
  1.1130 +                  echo "This means it is still in EVALUATION and QUALITY ASSURANCE state."
  1.1131 +                  echo "Hence it is still NOT ready for general use."
  1.1132 +                  echo "Do not use it in production environments."
  1.1133 +                  echo "It might be unstable under run-time or still incompletely packaged."
  1.1134 +                ) | sh $prog_path msg -r -t warn | sed -e 's;^;echo ";' -e 's;$;";'
  1.1135 +                echo "set -x"
  1.1136 +                ;;
  1.1137 +            JUNK )
  1.1138 +                echo "set +x"
  1.1139 +                ( echo "This OpenPKG package is of class JUNK."
  1.1140 +                  echo "This means it is still in DEVELOPMENT state."
  1.1141 +                  echo "Hence it is still NOT ready even for general evaluation."
  1.1142 +                  echo "Do not use it at all, except in development environments!"
  1.1143 +                  echo "It is definitely unstable and incompletely packaged."
  1.1144 +                ) | sh $prog_path msg -r -t warn | sed -e 's;^;echo ";' -e 's;$;";'
  1.1145 +                echo "set -x"
  1.1146 +                ;;
  1.1147 +        esac
  1.1148 +        ;;
  1.1149 +esac
  1.1150 +
  1.1151 +#   cleanup
  1.1152 +if [ ".$gen_tmpfile" = .yes ]; then
  1.1153 +    rm -f $tmpfile >/dev/null 2>&1
  1.1154 +fi
  1.1155 +
  1.1156 +#   die gracefully ;)
  1.1157 +exit 0
  1.1158 +

mercurial