diff --git a/ax_init_standard_project.m4 b/ax_init_standard_project.m4 index b49e82e..6dec56e 100644 --- a/ax_init_standard_project.m4 +++ b/ax_init_standard_project.m4 @@ -696,3 +696,15 @@ AC_DEFUN([AX_CHECK_VALID_LD_FLAG], [ AC_SUBST(LDFLAGS) AC_MSG_RESULT([$newflag in $LDFLAGS]) ]) + +# Check if a package exists in the current distribution, if yes, require it +# in debian/control.in append @DEB_DEPEND_IFEXISTS@ to Build-Depends +# - parameter: +# $1 = package name +AC_DEFUN([AX_DEB_DEPEND_IFEXISTS], [ + pkg=$1 + if test -n "$(apt-cache policy -q ${pkg} 2> /dev/null)"; then + DEB_DEPEND_IFEXISTS+=", ${pkg}" + fi + AC_SUBST(DEB_DEPEND_IFEXISTS) +]) diff --git a/resolve-debbuilddeps.sh b/resolve-debbuilddeps.sh index 92a1b67..fe44d0d 100755 --- a/resolve-debbuilddeps.sh +++ b/resolve-debbuilddeps.sh @@ -12,22 +12,40 @@ SCHROOTNAME="$1" +function install() { + if test -n "${SCHROOTNAME}"; then + if schroot -c "${SCHROOTNAME}" -u root -d / -- apt-get -y install $*; then + return 0 + fi + else + if apt-get -y install $*; then + return 0 + fi + fi +} + +TO_INSTALL= + if test -e debian/control.in -a ! -e debian/control; then - sed 's,@[^@]*@, dummytext,g' debian/control.in > debian/control + for f in $(sed -n 's, *AX_DEB_DEPEND_IFEXISTS(\([^)]*\)).*,\1,p' configure.ac); do + if test -n "$(apt-cache policy -q ${f})" && ! dpkg -l "${f}"; then + TO_INSTALL+=" ${f}" + fi + done trap "rm debian/control" INT TERM EXIT + sed 's,@DEB_DEPEND_IFEXISTS@,,g' debian/control.in | \ + sed 's,@[^@]*@, dummytext,g' > debian/control fi if test -n "${SCHROOTNAME}"; then - schroot -c "${SCHROOTNAME}" -u root -d / -- apt-get install -y dpkg-dev + schroot -c "${SCHROOTNAME}" -u root -d / -- apt-get -y install dpkg-dev DEPS=$(schroot -c "${SCHROOTNAME}" -- dpkg-checkbuilddeps 2>&1 || true) else - apt-get install -y dpkg-dev - apt-get update + apt-get -y install dpkg-dev DEPS=$(dpkg-checkbuilddeps 2>&1 || true) fi DEPS=$(echo "$DEPS" | sed -n '/Unmet build dependencies/ { s,.*Unmet build dependencies: ,,g; s, ([^)]*),,g; s, *| *,|,g; p}') -TO_INSTALL= for pa in ${DEPS}; do if test ${pa//|/} = ${pa}; then TO_INSTALL+=" ${pa}" @@ -35,16 +53,10 @@ for pa in ${DEPS}; do fi success=0 for p in ${pa//|/ }; do - if test -n "${SCHROOTNAME}"; then - if schroot -c "${SCHROOTNAME}" -u root -d / -- apt-get -y install ${p}; then - success=1 - break; - fi - else - if apt-get -y install ${p}; then - success=1 - break; - fi + if install ${TO_INSTALL} ${p}; then + TO_INSTALL+=" ${p}" + success=1 + break fi done if test ${success} -eq 0; then @@ -53,18 +65,8 @@ for pa in ${DEPS}; do fi done -success=0 -if test -n "${SCHROOTNAME}"; then - if schroot -c "${SCHROOTNAME}" -u root -d / -- apt-get -y install ${TO_INSTALL}; then - success=1 - fi -else - if apt-get -y install ${TO_INSTALL}; then - success=1 - fi -fi -if test ${success} -eq 0; then - echo "**** Error: Installation Failed: ${pa}" +if test -n "${TO_INSTALL}" && ! install ${TO_INSTALL}; then + echo "**** Error: Installation Failed: ${TO_INSTALL}" exit 1 fi