deb.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. if [ -z "${archive}" ]; then
  29. echo "Cannot find ../$PACKAGE*.tar.gz. Run \"make dist\" first." 1>&2
  30. exit 0
  31. fi
  32. # Create a pristine directory for building the Debian package files
  33. trap 'rm -rf '`pwd`/tmp'; exit $?' EXIT SIGHUP SIGINT SIGTERM
  34. rm -rf tmp
  35. mkdir -p tmp
  36. cd tmp
  37. package="google-glog_$VERSION"
  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}${package}.orig.tar.gz"
  43. tar zfx "${LIB}${package}.orig.tar.gz"
  44. mv "${archive}" "${LIB}${package}"
  45. cd "${LIB}${package}"
  46. # This is one of those 'specific requirements': where the deb control files live
  47. cp -a "packages/deb" "debian"
  48. # Now, we can call Debian's standard build tool
  49. debuild -uc -us
  50. cd ../.. # get back to the original top-level dir
  51. # We'll put the result in a subdirectory that's named after the OS version
  52. # we've made this .deb file for.
  53. destdir="debian-$(cat /etc/debian_version 2>/dev/null || echo UNKNOWN)"
  54. rm -rf "$destdir"
  55. mkdir -p "$destdir"
  56. mv $(find tmp -mindepth 1 -maxdepth 1 -type f) "$destdir"
  57. echo
  58. echo "The Debian package files are located in $PWD/$destdir"