Home | History | Annotate | Download | only in packages
      1 #!/bin/bash -e
      2 # Copyright 2005 Google Inc.
      3 # Author: Craig Silverstein
      4 #
      5 # Licensed under the Apache License, Version 2.0 (the "License");
      6 # you may not use this file except in compliance with the License.
      7 # You may obtain a copy of the License at
      8 #
      9 #      http://www.apache.org/licenses/LICENSE-2.0
     10 #
     11 # Unless required by applicable law or agreed to in writing, software
     12 # distributed under the License is distributed on an "AS IS" BASIS,
     13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 # See the License for the specific language governing permissions and
     15 # limitations under the License.
     16 #
     17 # This takes one commandline argument, the name of the package.  If no
     18 # name is given, then we'll end up just using the name associated with
     19 # an arbitrary .tar.gz file in the rootdir.  That's fine: there's probably
     20 # only one.
     21 #
     22 # Run this from the 'packages' directory, just under rootdir
     23 
     24 ## Set LIB to lib if exporting a library, empty-string else
     25 LIB=
     26 #LIB=lib
     27 
     28 PACKAGE="$1"
     29 VERSION="$2"
     30 
     31 # We can only build Debian packages, if the Debian build tools are installed
     32 if [ \! -x /usr/bin/debuild ]; then
     33   echo "Cannot find /usr/bin/debuild. Not building Debian packages." 1>&2
     34   exit 0
     35 fi
     36 
     37 # Double-check we're in the packages directory, just under rootdir
     38 if [ \! -r ../Makefile -a \! -r ../INSTALL ]; then
     39   echo "Must run $0 in the 'packages' directory, under the root directory." 1>&2
     40   echo "Also, you must run \"make dist\" before running this script." 1>&2
     41   exit 0
     42 fi
     43 
     44 # Find the top directory for this package
     45 topdir="${PWD%/*}"
     46 
     47 # Find the tar archive built by "make dist"
     48 archive="${PACKAGE}-${VERSION}"
     49 archive_with_underscore="${PACKAGE}_${VERSION}"
     50 if [ -z "${archive}" ]; then
     51   echo "Cannot find ../$PACKAGE*.tar.gz. Run \"make dist\" first." 1>&2
     52   exit 0
     53 fi
     54 
     55 # Create a pristine directory for building the Debian package files
     56 trap 'rm -rf '`pwd`/tmp'; exit $?' EXIT SIGHUP SIGINT SIGTERM
     57 
     58 rm -rf tmp
     59 mkdir -p tmp
     60 cd tmp
     61 
     62 # Debian has very specific requirements about the naming of build
     63 # directories, and tar archives. It also wants to write all generated
     64 # packages to the parent of the source directory. We accommodate these
     65 # requirements by building directly from the tar file.
     66 ln -s "${topdir}/${archive}.tar.gz" "${LIB}${archive}.orig.tar.gz"
     67 # Some version of debuilder want foo.orig.tar.gz with _ between versions.
     68 ln -s "${topdir}/${archive}.tar.gz" "${LIB}${archive_with_underscore}.orig.tar.gz"
     69 tar zfx "${LIB}${archive}.orig.tar.gz"
     70 [ -n "${LIB}" ] && mv "${archive}" "${LIB}${archive}"
     71 cd "${LIB}${archive}"
     72 # This is one of those 'specific requirements': where the deb control files live
     73 cp -a "packages/deb" "debian"
     74 
     75 # Now, we can call Debian's standard build tool
     76 debuild -uc -us
     77 cd ../..                            # get back to the original top-level dir
     78 
     79 # We'll put the result in a subdirectory that's named after the OS version
     80 # we've made this .deb file for.
     81 destdir="debian-$(cat /etc/debian_version 2>/dev/null || echo UNKNOWN)"
     82 
     83 rm -rf "$destdir"
     84 mkdir -p "$destdir"
     85 mv $(find tmp -mindepth 1 -maxdepth 1 -type f) "$destdir"
     86 
     87 echo
     88 echo "The Debian package files are located in $PWD/$destdir"
     89