Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 1 | #!/bin/bash -e |
| 2 | |
| 3 | # This takes one commandline argument, the name of the package. If no |
| 4 | # name is given, then we'll end up just using the name associated with |
| 5 | # an arbitrary .tar.gz file in the rootdir. That's fine: there's probably |
| 6 | # only one. |
| 7 | # |
| 8 | # Run this from the 'packages' directory, just under rootdir |
| 9 | |
| 10 | ## Set LIB to lib if exporting a library, empty-string else |
| 11 | LIB= |
| 12 | #LIB=lib |
| 13 | |
| 14 | PACKAGE="$1" |
| 15 | VERSION="$2" |
| 16 | |
| 17 | # We can only build Debian packages, if the Debian build tools are installed |
| 18 | if [ \! -x /usr/bin/debuild ]; then |
| 19 | echo "Cannot find /usr/bin/debuild. Not building Debian packages." 1>&2 |
| 20 | exit 0 |
| 21 | fi |
| 22 | |
| 23 | # Double-check we're in the packages directory, just under rootdir |
| 24 | if [ \! -r ../Makefile -a \! -r ../INSTALL ]; then |
| 25 | echo "Must run $0 in the 'packages' directory, under the root directory." 1>&2 |
| 26 | echo "Also, you must run \"make dist\" before running this script." 1>&2 |
| 27 | exit 0 |
| 28 | fi |
| 29 | |
| 30 | # Find the top directory for this package |
| 31 | topdir="${PWD%/*}" |
| 32 | |
| 33 | # Find the tar archive built by "make dist" |
| 34 | archive="${PACKAGE}-${VERSION}" |
| 35 | archive_with_underscore="${PACKAGE}_${VERSION}" |
| 36 | if [ -z "${archive}" ]; then |
| 37 | echo "Cannot find ../$PACKAGE*.tar.gz. Run \"make dist\" first." 1>&2 |
| 38 | exit 0 |
| 39 | fi |
| 40 | |
| 41 | # Create a pristine directory for building the Debian package files |
| 42 | trap 'rm -rf '`pwd`/tmp'; exit $?' EXIT SIGHUP SIGINT SIGTERM |
| 43 | |
| 44 | rm -rf tmp |
| 45 | mkdir -p tmp |
| 46 | cd tmp |
| 47 | |
| 48 | # Debian has very specific requirements about the naming of build |
| 49 | # directories, and tar archives. It also wants to write all generated |
| 50 | # packages to the parent of the source directory. We accommodate these |
| 51 | # requirements by building directly from the tar file. |
| 52 | ln -s "${topdir}/${archive}.tar.gz" "${LIB}${archive}.orig.tar.gz" |
| 53 | # Some version of debuilder want foo.orig.tar.gz with _ between versions. |
| 54 | ln -s "${topdir}/${archive}.tar.gz" "${LIB}${archive_with_underscore}.orig.tar.gz" |
| 55 | tar zfx "${LIB}${archive}.orig.tar.gz" |
| 56 | [ -n "${LIB}" ] && mv "${archive}" "${LIB}${archive}" |
| 57 | cd "${LIB}${archive}" |
| 58 | # This is one of those 'specific requirements': where the deb control files live |
| 59 | cp -a "packages/deb" "debian" |
| 60 | |
| 61 | # Now, we can call Debian's standard build tool |
| 62 | debuild -uc -us |
| 63 | cd ../.. # get back to the original top-level dir |
| 64 | |
| 65 | # We'll put the result in a subdirectory that's named after the OS version |
| 66 | # we've made this .deb file for. |
| 67 | destdir="debian-$(cat /etc/debian_version 2>/dev/null || echo UNKNOWN)" |
| 68 | |
| 69 | rm -rf "$destdir" |
| 70 | mkdir -p "$destdir" |
| 71 | mv $(find tmp -mindepth 1 -maxdepth 1 -type f) "$destdir" |
| 72 | |
| 73 | echo |
| 74 | echo "The Debian package files are located in $PWD/$destdir" |