X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=dh_lib;h=a0f8bb91e453249e2b88c002c8f3f8c5c34b278b;hb=5386c00b1883bef4ba45179d75d4ba8064c3e147;hp=39dae2a5d6ecb4eccf553cd2bc693957b581efc1;hpb=94f1df06050aa3c512fd8af6e67690f482fbcd5a;p=debhelper.git diff --git a/dh_lib b/dh_lib index 39dae2a..a0f8bb9 100644 --- a/dh_lib +++ b/dh_lib @@ -1,4 +1,6 @@ # Library functions for debhelper programs. +# +# Joey Hess, GPL copyright 1997, 1998. # Run a command, and display the command to stdout if verbose mode is on. # All commands that modifiy files in $TMP should be ran via this @@ -7,7 +9,9 @@ # involving redirection. Use complex_doit instead. doit() { verbose_echo "$@" - eval '$@' + if [ ! "$DH_NO_ACT" ]; then + eval '$@' + fi } @@ -15,7 +19,9 @@ doit() { # are evaled with double quotes. This version can handle compound commands. complex_doit() { verbose_echo "$@" - eval "$@" + if [ ! "$DH_NO_ACT" ]; then + eval "$@" + fi } # Echo something if the verbose flag is on. @@ -31,6 +37,11 @@ error() { exit 1 } +# Output a warning. +warning() { + echo `basename $0`": $1" >&2 +} + # Pass it a name of a binary package, it returns the name of the tmp dir to # use, for that package. # This is for back-compatability with the debian/tmp tradition. @@ -44,11 +55,25 @@ tmpdir() { fi } +# Pass this the name of a binary package, and the name of the file wanted +# for the package, and it will return the actual filename to use. For +# example if the package is foo, and the file is somefile, it will look for +# debian/somefile, and if found return that, otherwise, if the package is +# the main package, it will look for debian/foo, and if found, return that. +# Failing that, it will return nothing. +pkgfile() { + if [ -e "debian/$1.$2" ]; then + echo "debian/$1.$2" + elif [ "$1" = "$MAINPACKAGE" -a -e "debian/$2" ]; then + echo "debian/$2" + fi +} + # Pass it a name of a binary package, it returns the name to prefix to files # in debian for this package. pkgext() { if [ "$1" != "$MAINPACKAGE" ]; then - echo "$PACKAGE." + echo "$PACKAGE." fi } @@ -57,13 +82,18 @@ pkgext() { # Caches return code so it only needs to run dpkg-parsechangelog once. isnative() { if [ -z "$DH_ISNATIVE" ]; then + # Make sure we look at the correct changelog. + isnative_changelog=`pkgfile $PACKAGE changelog` + if [ ! "$isnative_changelog" ]; then + isnative_changelog=debian/changelog + fi # Get the package version. # Note that the 2>/dev/null is because a bug in dpkg-parsechangelog makes it # output a bogus error message to stderr. # If it actually has a real error, then the expr will fail, and this whole # script will come crashing to a halt, which is good enough to inform # the user something's wrong. :-) - VERSION=`expr "\`dpkg-parsechangelog 2>/dev/null\`" : \ + VERSION=`expr "\`dpkg-parsechangelog -l$isnative_changelog 2>/dev/null\`" : \ '.*Version: \(.*\).*Distribution:'` # Is this a native Debian package? if expr "$VERSION" : '.*-' >/dev/null; then @@ -99,139 +129,45 @@ autoscript() { fi fi - complex_doit "echo \"# Automatically added by `basename $0` on `822-date`\" >> $autoscript_debscript" + complex_doit "echo \"# Automatically added by `basename $0`\" >> $autoscript_debscript" complex_doit "sed \"$autoscript_sed\" $autoscript_filename >> $autoscript_debscript" complex_doit "echo '# End automatically added section' >> $autoscript_debscript" } -# Sets 2 global variables, INDEP_PACKAGES is all the arch-independant -# packages, ARCH_PACKAGES is the arch-dependant packages. -get_arch_indep_packages() { - INDEP_PACKAGES="" - ARCH_PACKAGES="" - - # First, get the list of all binary packages. - # Notice we want the list in reverse order, thus the tac. - PACKAGES=`grep ^Package: debian/control | cut -d " " -f 2 | tac | tr "\n" " "` - # Remove trailing space. - PACKAGES=`expr "$PACKAGES" : '\(.*\) '` - # Loop on the list of architectures. - for ARCH in `grep ^Architecture: debian/control | cut -d " " -f 2` ; do - # Pull the last package off the list. - THISPKG=`expr "$PACKAGES" : '.* \(.*\)'` || true - if [ ! "$THISPKG" ]; then - THISPKG=$PACKAGES - fi - PACKAGES=`expr "$PACKAGES" : '\(.*\) .*'` || true - - if [ ! "$THISPKG" ]; then - error "debian/control invalid - too many Architecture lines or too few Package lines" - fi - - if [ "$ARCH" = "all" ]; then - INDEP_PACKAGES="$INDEP_PACKAGES $THISPKG" - else - ARCH_PACKAGES="$ARCH_PACKAGES $THISPKG" - fi - done - - if [ "$PACKAGES" ]; then - error "debian/control invalid - too many Architecure lines or too few Package lines" - fi -} - # Argument processing and global variable initialization is below. -# Parse command line. -set -- `getopt xvidrnakVAp:P:u:m: $*` +# If DH_OPTIONS is set, prepend it to the command line. +if [ "$DH_OPTIONS" ]; then + set -- $DH_OPTIONS $@ +fi -for i; do - case "$i" - in - -v) - DH_VERBOSE=1 - shift - ;; - -i) - get_arch_indep_packages - DH_DOPACKAGES="$DH_DOPACKAGES $INDEP_PACKAGES" - DH_DOINDEP=1 - shift - ;; - -a) - get_arch_indep_packages - DH_DOPACKAGES="$DH_DOPACKAGES $ARCH_PACKAGES" - DH_DOARCH=1 - shift - ;; - -p) - DH_DOPACKAGES="$DH_DOPACKAGES $2" - shift - shift - ;; - -n) - DH_NOSCRIPTS=1 - shift - ;; - -x) - DH_EXCLUDE=1 - shift - ;; - -d) - DH_D_FLAG=1 - shift - ;; - -r) - DH_R_FLAG=1 - shift - ;; - -k) - DH_K_FLAG=1 - shift - ;; - -P) - DH_TMPDIR="$2" - shift - shift - ;; - -u) - DH_U_PARAMS="$2" - shift - shift - ;; - -m) - DH_M_PARAMS="$2" - shift - shift - ;; - -V) - DH_V_FLAG=1 - shift - ;; - -A) - DH_PARAMS_ALL=1 - shift - ;; - --) - shift - break - ;; - esac +# Check to see if an argument on the command line starts with a dash. +# if so, we need to pass this off to the resource intensive perl. +for arg; do + if expr "$arg" : '-' >/dev/null ; then + parseopt=1 + break + fi done +if [ "$parseopt" ]; then + parseopt="" + # Parse command line. I wrote a perl program to do this becuase + # getopt(1) is so broken. Note: the quotes around $@ are very + # important! + eval `dh_getopt.pl "$@"` + if [ "$DH_PARSE_ERROR" ]; then + error "$DH_PARSE_ERROR" + fi +fi # Get the name of the main binary package (first one listed in # debian/control). MAINPACKAGE=`grep ^Package: debian/control | cut -d " " -f 2 | head -1` -# Remove leading spaces from DH_DOPACKAGES. -if expr "$DH_DOPACKAGES" : ' *.*' >/dev/null ; then - DH_DOPACKAGES_NEW=`expr "$DH_DOPACKAGES" : ' *\(.*\)'` -fi - # Check if packages to build have been specified, if not, fall back to # the default, doing them all. if [ ! "$DH_DOPACKAGES" ]; then - if [ "$DH_DOINDEP" -o "$DH_DOARCH" ]; then + if [ "$DH_DOINDEP" -o "$DH_DOARCH" -o "$DH_DOSAME" ]; then error "I have no package to build." fi DH_DOPACKAGES=`grep ^Package: debian/control | cut -d " " -f 2 | tr "\n" " "` @@ -250,11 +186,3 @@ for PACKAGE in $DH_DOPACKAGES ; do DH_FIRSTPACKAGE="$PACKAGE" break done - -# Check to see if: DH_FIRSTPACKAGE is not the MAINPACKAGE, and -# some command line arguemnts are passed. Display a warning, becuase -# debhelper's behaviour has changed in this case. -if [ "$DH_FIRSTPACKAGE" != "$MAINPACKAGE" -a "$*" ]; then - echo `basename $0`": Warning: my behavior has changed, and command line" >&2 - echo `basename $0`": arguments \"$*\" will apply to package \"$DH_FIRSTPACKAGE\"" >&2 -fi