-# Argument processing and global variable initialization is below.
-
-# Parse command line.
-set -- `getopt viap: $*`
-
-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
- ;;
- --)
- shift
- break
- ;;
- esac
-done
-
-# Get the package version from the changelog.
-LINE=`head -1 debian/changelog`
-VERSION=`expr "$LINE" : '.* (\(.*\))'`
+# 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
+ # 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 -l$isnative_changelog 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