X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=dh_lib;h=020f9e6d79675973058b5b014d7578a9dde01f55;hb=050d55509586c51def636f895075c62877c9fae7;hp=c2dd9777b8ee76d0ce53931429378bdf448e76c0;hpb=0c4875b3fecb5b376257e248b129537dd148e0c4;p=debhelper.git diff --git a/dh_lib b/dh_lib index c2dd977..020f9e6 100644 --- a/dh_lib +++ b/dh_lib @@ -1,19 +1,29 @@ # 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 # function. -# Unfortunatly, this function doesn't work if your command uses redirection, -# you will have to call verbose_echo by hand then. +# Note that this cannot handle complex commands, especially anything +# involving redirection. Use complex_doit instead. doit() { - verbose_echo "$*" - $* + verbose_echo "$@" + eval '$@' +} + + +# This is an identical command to doit, except the parameter passed to it +# are evaled with double quotes. This version can handle compound commands. +complex_doit() { + verbose_echo "$@" + eval "$@" } # Echo something if the verbose flag is on. verbose_echo() { if [ "$DH_VERBOSE" ]; then - echo " $*" + echo " $@" fi } @@ -36,14 +46,52 @@ 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, 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 } +# Returns 1 if the package is a native debian package, null otherwise. +# As a side effect, sets $VERSION to the version of this package. +# Caches return code so it only needs to run dpkg-parsechangelog once. +isnative() { + if [ -z "$DH_ISNATIVE" ]; then + # 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: \(.*\).*Distribution:'` + # Is this a native Debian package? + if expr "$VERSION" : '.*-' >/dev/null; then + DH_ISNATIVE=1 + else + DH_ISNATIVE=0 + fi + fi + + return "$DH_ISNATIVE" +} + # Automatically add a shell script snippet to a debian script. # Only works if the script has #DEBHELPER# in it. # @@ -67,91 +115,35 @@ autoscript() { fi fi - # Running doit doesn't cut it here. - verbose_echo echo "# Automatically added by `basename $0` on `822-date`" ">>" $autoscript_debscript - echo "# Automatically added by `basename $0` on `822-date`" >> $autoscript_debscript - verbose_echo sed "$autoscript_sed" $autoscript_filename ">>" $autoscript_debscript - sed "$autoscript_sed" $autoscript_filename >> $autoscript_debscript - verbose_echo echo "# End automatically added section" ">>" $autoscript_debscript - echo "# End automatically added section" >> $autoscript_debscript + complex_doit "echo \"# Automatically added by `basename $0` on `822-date`\" >> $autoscript_debscript" + complex_doit "sed \"$autoscript_sed\" $autoscript_filename >> $autoscript_debscript" + complex_doit "echo '# End automatically added section' >> $autoscript_debscript" } -# Argument processing and global variable initialization is below. - -# Parse command line. -set -- `getopt xvianp:P: $*` - -for i; do - case "$i" - in - -v) - DH_VERBOSE=1 - shift - ;; - -i) - DH_DOINDEP=1 - shift - ;; - -a) - DH_DOARCH=1 - shift - ;; - -p) - DH_DOPACKAGES="$DH_DOPACKAGES $2" - shift - shift - ;; - -n) - DH_NOSCRIPTS=1 - shift - ;; - -x) - DH_EXCLUDE=1 - shift - ;; - -P) - DH_TMPDIR="$2" - shift - shift - ;; - --) - shift - break - ;; - esac -done - -# Get the package version from the changelog. -LINE=`head -1 debian/changelog` -VERSION=`expr "$LINE" : '.* (\(.*\))'` - -# Get the name of the main binary package. -MAINPACKAGE=`grep ^Package: debian/control | cut -d " " -f 2 | head -1` - -# Is this a native Debian package? -if ! expr "$VERSION" : '.*-' >/dev/null; then - NATIVE=1 -fi - -if [ "$DH_DOINDEP" -o "$DH_DOARCH" ]; then - # Figure out all the binary packages to be produced, by looking at the - # control file. Break it into 2 lists, INDEP_PACKAGES and ARCH_PACKAGES. - # +# 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. - PACKAGES=`grep ^Package: debian/control | cut -d " " -f 2 | tr "\n" " "` + # 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. Note that we tac the result to reverse - # it, becuase we are going through the list of packages in reverse. - for ARCH in `grep ^Architecture: debian/control | tac | cut -d " " -f 2` ; do + # 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 + 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 @@ -162,26 +154,60 @@ if [ "$DH_DOINDEP" -o "$DH_DOARCH" ]; then if [ "$PACKAGES" ]; then error "debian/control invalid - too many Architecure lines or too few Package lines" fi - if [ "$DH_DOINDEP" ]; then - DH_DOPACKAGES="$DH_DOPACKAGES $INDEP_PACKAGES" +} + +# Argument processing and global variable initialization is below. + +# 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 - if [ "$DH_DOARCH" ]; then - DH_DOPACKAGES="$DH_DOPACKAGES $ARCH_PACKAGES" +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` + # Check if packages to build have been specified, if not, fall back to -# the default, doing them all. Note that DH_DOPACKAGES may have a leading -# space and be empty otherwise. -if [ ! "$DH_DOPACKAGES" -o "$DH_DOPACKAGES" = " " ]; then +# the default, doing them all. +if [ ! "$DH_DOPACKAGES" ]; then if [ "$DH_DOINDEP" -o "$DH_DOARCH" ]; then error "I have no package to build." fi - DH_DOPACKAGES=`grep ^Package: debian/control | cut -d " " -f 2` + DH_DOPACKAGES=`grep ^Package: debian/control | cut -d " " -f 2 | tr "\n" " "` fi # Check to see if -P was specified. If so, we can only act on a single # package. -if [ "$DH_TMPDIR" ] && echo "$DH_DOPACKAGES" | grep -q " "; then +if [ "$DH_TMPDIR" ] && echo "$DH_DOPACKAGES" | egrep -q '.+ .+' ; then error "-P was specified, but multiple packages would be acted on." fi + +# Figure out which package is the first one we were instructed to build. +# This package gets special treatement, files and directories specified on +# the command line may effect it. +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 arguements 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