2
0

deb.sh 2.5 KB

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