As we discussed a day or two ago, here is a patch that cleans up the following aspects of the generic build script (today's CVS version):
- Invokes the shell by /bin/sh -e. - Removes the many superfluous &&'s, ;'s, and \'s between commands and at end of lines. - Removes all of the $STATUS junk at the end. There's no more need for this, since with -e the script will fail when any subcommand fails. - Replaces all instances of 'if [ ! -d xxx ] ; then mkdir -p xxx ; fi' with just 'mkdir -p xxx'. The second form is equivalent but simpler. - Adds -r to every invocation of xargs. In every case this is desirable and will prevent errors in null cases. With /bin/sh -e, one has to be careful about trapping unwanted non-zero exit statuses. The only place I found where this was an issue was in mkpatch(), because diff has an exit status of 1 if it finds differences. Because of this I added '|| true' after the diff command. One could be fussier here and check for an exit status of 1 (which is okay) or 2 (which is an error), but I didn't bother. I removed all other instances of trailing 'true's from the script. I've tested the revised gbs by building three different packages, and tested each operation at least once. I had no problems. Andrew. --- generic-build-script.orig 2004-10-15 13:48:32.000000000 -0400 +++ generic-build-script 2004-10-15 16:54:26.000000000 -0400 @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/sh -e # # Generic package build script # @@ -123,25 +123,23 @@ unpack() { tar xv${opt_decomp}f "$1" } - mkdirs() { - (cd ${topdir} && \ - rm -fr ${objdir} ${instdir} ${srcinstdir} && \ - mkdir -p ${objdir} && \ - mkdir -p ${instdir} && \ + (cd ${topdir} + rm -fr ${objdir} ${instdir} ${srcinstdir} + mkdir -p ${objdir} + mkdir -p ${instdir} mkdir -p ${srcinstdir} ) } prep() { - (cd ${topdir} && \ - unpack ${src_orig_pkg} && \ - cd ${topdir} && \ - if [ -f ${src_patch} ] ; then \ - patch -Z -p0 < ${src_patch} ;\ - fi && \ + (cd ${topdir} + unpack ${src_orig_pkg} + if [ -f ${src_patch} ] ; then + patch -Z -p0 < ${src_patch} + fi mkdirs ) } conf() { - (cd ${objdir} && \ + (cd ${objdir} CFLAGS="${MY_CFLAGS}" LDFLAGS="${MY_LDFLAGS}" \ ${srcdir}/configure \ --srcdir=${srcdir} --prefix="${prefix}" \ @@ -152,115 +150,100 @@ --datadir='${prefix}/share' ) } reconf() { - (cd ${topdir} && \ - rm -fr ${objdir} && \ - mkdir -p ${objdir} && \ + (cd ${topdir} + rm -fr ${objdir} + mkdir -p ${objdir} conf ) } build() { - (cd ${objdir} && \ + (cd ${objdir} CFLAGS="${MY_CFLAGS}" make ) } check() { - (cd ${objdir} && \ + (cd ${objdir} make ${test_rule} | tee ${checkfile} 2>&1 ) } clean() { - (cd ${objdir} && \ + (cd ${objdir} make clean ) } install() { - (cd ${objdir} && \ - rm -fr ${instdir}/* && \ - make install DESTDIR=${instdir} && \ - for f in ${prefix}/share/info/dir ${prefix}/info/dir ; do \ - if [ -f ${instdir}${f} ] ; then \ - rm -f ${instdir}${f} ; \ - fi ;\ - done &&\ - for d in ${prefix}/share/doc/${BASEPKG} ${prefix}/share/doc/Cygwin ; do \ - if [ ! -d ${instdir}${d} ] ; then \ - mkdir -p ${instdir}${d} ;\ - fi ;\ - done &&\ - if [ -d ${instdir}${prefix}/share/info ] ; then \ - find ${instdir}${prefix}/share/info -name "*.info" | xargs -r gzip -q ; \ - fi && \ - if [ -d ${instdir}${prefix}/share/man ] ; then \ + (cd ${objdir} + rm -fr ${instdir}/* + make install DESTDIR=${instdir} + for f in ${prefix}/share/info/dir ${prefix}/info/dir ; do + if [ -f ${instdir}${f} ] ; then + rm -f ${instdir}${f} + fi + done + mkdir -p ${instdir}${prefix}/share/doc/${BASEPKG} ${instdir}${prefix}/share/doc/Cygwin + if [ -d ${instdir}${prefix}/share/info ] ; then + find ${instdir}${prefix}/share/info -name "*.info" | xargs -r gzip -q + fi + if [ -d ${instdir}${prefix}/share/man ] ; then find ${instdir}${prefix}/share/man -name "*.1" -o -name "*.3" -o \ -name "*.3x" -o -name "*.3pm" -o -name "*.5" -o -name "*.6" -o \ - -name "*.7" -o -name "*.8" | xargs gzip -q ; \ - fi && \ - templist="" && \ - for fp in ${install_docs} ; do \ - for f in ${srcdir}/$fp ; do \ - if [ -f $f ] ; then \ - templist="$templist $f"; \ - fi ; \ - done ; \ - done && \ - if [ ! "x$templist" = "x" ]; then \ + -name "*.7" -o -name "*.8" | xargs -r gzip -q + fi + templist="" + for fp in ${install_docs} ; do + for f in ${srcdir}/$fp ; do + if [ -f $f ] ; then + templist="$templist $f" + fi + done + done + if [ ! "x$templist" = "x" ]; then /usr/bin/install -m 644 $templist \ - ${instdir}${prefix}/share/doc/${BASEPKG} ; \ - fi && \ - if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}.README ]; then \ + ${instdir}${prefix}/share/doc/${BASEPKG} + fi + if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}.README ]; then /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/${PKG}.README \ - ${instdir}${prefix}/share/doc/Cygwin/${BASEPKG}.README ; \ - elif [ -f ${srcdir}/CYGWIN-PATCHES/README ] ; then \ + ${instdir}${prefix}/share/doc/Cygwin/${BASEPKG}.README + elif [ -f ${srcdir}/CYGWIN-PATCHES/README ] ; then /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/README \ - ${instdir}${prefix}/share/doc/Cygwin/${BASEPKG}.README ; \ - fi && \ - if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}.sh ] ; then \ - if [ ! -d ${instdir}${sysconfdir}/postinstall ]; then \ - mkdir -p ${instdir}${sysconfdir}/postinstall ; \ - fi && \ + ${instdir}${prefix}/share/doc/Cygwin/${BASEPKG}.README + fi + if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}.sh ] ; then + mkdir -p ${instdir}${sysconfdir}/postinstall /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/${PKG}.sh \ - ${instdir}${sysconfdir}/postinstall/${PKG}.sh ; \ - elif [ -f ${srcdir}/CYGWIN-PATCHES/postinstall.sh ] ; then \ - if [ ! -d ${instdir}${sysconfdir}/postinstall ]; then \ - mkdir -p ${instdir}${sysconfdir}/postinstall ; \ - fi && \ + ${instdir}${sysconfdir}/postinstall/${PKG}.sh + elif [ -f ${srcdir}/CYGWIN-PATCHES/postinstall.sh ] ; then + mkdir -p ${instdir}${sysconfdir}/postinstall /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/postinstall.sh \ - ${instdir}${sysconfdir}/postinstall/${PKG}.sh ; \ - fi && \ - if [ -f ${srcdir}/CYGWIN-PATCHES/preremove.sh ] ; then \ - if [ ! -d ${instdir}${sysconfdir}/preremove ]; then \ - mkdir -p ${instdir}${sysconfdir}/preremove ; \ - fi && \ + ${instdir}${sysconfdir}/postinstall/${PKG}.sh + fi + if [ -f ${srcdir}/CYGWIN-PATCHES/preremove.sh ] ; then + mkdir -p ${instdir}${sysconfdir}/preremove /usr/bin/install -m 755 ${srcdir}/CYGWIN-PATCHES/preremove.sh \ - ${instdir}${sysconfdir}/preremove/${PKG}.sh ; \ + ${instdir}${sysconfdir}/preremove/${PKG}.sh fi ) } strip() { - (cd ${instdir} && \ - find . -name "*.dll" -or -name "*.exe" | xargs strip 2>&1 ; \ - true ) + find ${instdir} -name "*.dll" -or -name "*.exe" | xargs -r strip } list() { - (cd ${instdir} && \ - find . -name "*" ! -type d | sed 's%^\.% %' ; \ - true ) + (cd ${instdir} + find . ! -type d | sed 's%^\.% %' | sort ) } depend() { - (cd ${instdir} && \ - find ${instdir} -name "*.exe" -o -name "*.dll" | xargs cygcheck | \ - sed -e '/\.exe/d' -e 's,\\,/,g' | sort -bu | xargs -n1 cygpath -u \ - | xargs cygcheck -f | sed 's%^% %' | sort -u ; \ - true ) + (cd ${instdir} + find . -name "*.exe" -o -name "*.dll" | xargs -r cygcheck \ + | sed -e '/\.exe/d' -e 's,\\,/,g' | sort -bu | xargs -r -n1 cygpath -u \ + | xargs -r cygcheck -f | sed 's%^% %' | sort -u ) } pkg() { - (cd ${instdir} && \ + (cd ${instdir} tar cvjf ${bin_pkg} * ) } mkpatch() { - (cd ${srcdir} && \ - find . -name "autom4te.cache" | xargs rm -rf ; \ - unpack ${src_orig_pkg} && \ - mv ${BASEPKG} ../${BASEPKG}-orig && \ - cd ${topdir} && \ + (cd ${srcdir} + find . -name "autom4te.cache" | xargs -r rm -rf + unpack ${src_orig_pkg} + mv ${BASEPKG} ../${BASEPKG}-orig + cd ${topdir} diff -urN -x '.build' -x '.inst' -x '.sinst' \ - ${BASEPKG}-orig ${BASEPKG} > \ - ${srcinstdir}/${src_patch_name} ; \ + ${BASEPKG}-orig ${BASEPKG} > ${srcinstdir}/${src_patch_name} || true rm -rf ${BASEPKG}-orig ) } # Note: maintainer-only functionality @@ -268,91 +251,84 @@ cp --backup=numbered ${srcinstdir}/${src_patch_name} ${topdir} } spkg() { - (mkpatch && \ - if [ "${SIG}" -eq 1 ] ; then \ - name=${srcinstdir}/${src_patch_name} text="PATCH" sigfile ; \ - fi && \ - cp ${src_orig_pkg} ${srcinstdir}/${src_orig_pkg_name} && \ - if [ -e ${src_orig_pkg}.sig ] ; then \ - cp ${src_orig_pkg}.sig ${srcinstdir}/ ; \ - fi && \ - cp $0 ${srcinstdir}/`basename $0` && \ - name=$0 text="SCRIPT" sigfile && \ - if [ "${SIG}" -eq 1 ] ; then \ - cp $0.sig ${srcinstdir}/ ; \ - fi && \ - cd ${srcinstdir} && \ + (mkpatch + if [ "${SIG}" -eq 1 ] ; then + name=${srcinstdir}/${src_patch_name} text="PATCH" sigfile + fi + cp ${src_orig_pkg} ${srcinstdir}/${src_orig_pkg_name} + if [ -e ${src_orig_pkg}.sig ] ; then + cp ${src_orig_pkg}.sig ${srcinstdir} + fi + cp $0 ${srcinstdir}/`basename $0` + name=$0 text="SCRIPT" sigfile + if [ "${SIG}" -eq 1 ] ; then + cp $0.sig ${srcinstdir} + fi + cd ${srcinstdir} tar cvjf ${src_pkg} * ) } finish() { rm -rf ${srcdir} } sigfile() { - if [ \( "${SIG}" -eq 1 \) -a \( -e $name \) -a \( \( ! -e $name.sig \) -o \( $name -nt $name.sig \) \) ]; then \ - if [ -x /usr/bin/gpg ]; then \ - echo "$text signature need to be updated"; \ - rm -f $name.sig; \ - /usr/bin/gpg --detach-sign $name; \ - else \ - echo "You need the gnupg package installed in order to make signatures."; \ - fi; \ + if [ \( "${SIG}" -eq 1 \) -a \( -e $name \) -a \( \( ! -e $name.sig \) -o \( $name -nt $name.sig \) \) ]; then + if [ -x /usr/bin/gpg ]; then + echo "$text signature need to be updated" + rm -f $name.sig + /usr/bin/gpg --detach-sign $name + else + echo "You need the gnupg package installed in order to make signatures." + fi fi } checksig() { - if [ -x /usr/bin/gpg ]; then \ - if [ -e ${src_orig_pkg}.sig ]; then \ - echo "ORIGINAL PACKAGE signature follows:"; \ - /usr/bin/gpg --verify ${src_orig_pkg}.sig ${src_orig_pkg}; \ - else \ - echo "ORIGINAL PACKAGE signature missing."; \ - fi; \ - if [ -e $0.sig ]; then \ - echo "SCRIPT signature follows:"; \ - /usr/bin/gpg --verify $0.sig $0; \ - else \ - echo "SCRIPT signature missing."; \ - fi; \ - if [ -e ${src_patch}.sig ]; then \ - echo "PATCH signature follows:"; \ - /usr/bin/gpg --verify ${src_patch}.sig ${src_patch}; \ - else \ - echo "PATCH signature missing."; \ - fi; \ + if [ -x /usr/bin/gpg ]; then + if [ -e ${src_orig_pkg}.sig ]; then + echo "ORIGINAL PACKAGE signature follows:" + /usr/bin/gpg --verify ${src_orig_pkg}.sig ${src_orig_pkg} else - echo "You need the gnupg package installed in order to check signatures." ; \ + echo "ORIGINAL PACKAGE signature missing." + fi + if [ -e $0.sig ]; then + echo "SCRIPT signature follows:" + /usr/bin/gpg --verify $0.sig $0 + else + echo "SCRIPT signature missing." + fi + if [ -e ${src_patch}.sig ]; then + echo "PATCH signature follows:" + /usr/bin/gpg --verify ${src_patch}.sig ${src_patch} + else + echo "PATCH signature missing." + fi + else + echo "You need the gnupg package installed in order to check signatures." fi } + while test -n "$1" ; do case $1 in - prep) prep ; STATUS=$? ;; - mkdirs) mkdirs ; STATUS=$? ;; - conf) conf ; STATUS=$? ;; - configure) conf ; STATUS=$? ;; - reconf) reconf ; STATUS=$? ;; - build) build ; STATUS=$? ;; - make) build ; STATUS=$? ;; - check) check ; STATUS=$? ;; - test) check ; STATUS=$? ;; - clean) clean ; STATUS=$? ;; - install) install ; STATUS=$? ;; - list) list ; STATUS=$? ;; - depend) depend ; STATUS=$? ;; - strip) strip ; STATUS=$? ;; - package) pkg ; STATUS=$? ;; - pkg) pkg ; STATUS=$? ;; - mkpatch) mkpatch ; STATUS=$? ;; - acceptpatch) acceptpatch ; STATUS=$? ;; - src-package) spkg ; STATUS=$? ;; - spkg) spkg ; STATUS=$? ;; - finish) finish ; STATUS=$? ;; - checksig) checksig ; STATUS=$? ;; - first) mkdirs && spkg && finish ; STATUS=$? ;; - all) checksig && prep && conf && build && install && \ - strip && pkg && spkg && finish ; \ - STATUS=$? ;; + prep) prep ;; + mkdirs) mkdirs ;; + conf|configure) conf ;; + reconf) reconf ;; + build|make) build ;; + check|test) check ;; + clean) clean ;; + install) install ;; + list) list ;; + depend) depend ;; + strip) strip ;; + package|pkg) pkg ;; + mkpatch) mkpatch ;; + acceptpatch) acceptpatch ;; + src-package|spkg) spkg ;; + finish) finish ;; + checksig) checksig ;; + first) mkdirs ; spkg ; finish ;; + all) checksig ; prep ; conf ; build ; install ; + strip ; pkg ; spkg ; finish ;; *) echo "Error: bad arguments" ; exit 1 ;; esac - ( exit ${STATUS} ) || exit ${STATUS} shift done -