blob: a1cdf321ef58d760437be580839ae4234dc3e8e8 [file] [log] [blame]
Austin Schuh906616c2019-01-21 20:25:11 -08001#!/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
11LIB=
12#LIB=lib
13
14PACKAGE="$1"
15VERSION="$2"
16
17# We can only build Debian packages, if the Debian build tools are installed
18if [ \! -x /usr/bin/debuild ]; then
19 echo "Cannot find /usr/bin/debuild. Not building Debian packages." 1>&2
20 exit 0
21fi
22
23# Double-check we're in the packages directory, just under rootdir
24if [ \! -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
28fi
29
30# Find the top directory for this package
31topdir="${PWD%/*}"
32
33# Find the tar archive built by "make dist"
34archive="$PACKAGE-$VERSION"
35if [ -z "${archive}" ]; then
36 echo "Cannot find ../$PACKAGE*.tar.gz. Run \"make dist\" first." 1>&2
37 exit 0
38fi
39
40# Create a pristine directory for building the Debian package files
41trap 'rm -rf '`pwd`/tmp'; exit $?' EXIT SIGHUP SIGINT SIGTERM
42
43rm -rf tmp
44mkdir -p tmp
45cd tmp
46
47package="google-glog_$VERSION"
48
49# Debian has very specific requirements about the naming of build
50# directories, and tar archives. It also wants to write all generated
51# packages to the parent of the source directory. We accommodate these
52# requirements by building directly from the tar file.
53ln -s "${topdir}/${archive}.tar.gz" "${LIB}${package}.orig.tar.gz"
54tar zfx "${LIB}${package}.orig.tar.gz"
55mv "${archive}" "${LIB}${package}"
56cd "${LIB}${package}"
57# This is one of those 'specific requirements': where the deb control files live
58cp -a "packages/deb" "debian"
59
60# Now, we can call Debian's standard build tool
61debuild -uc -us
62cd ../.. # get back to the original top-level dir
63
64# We'll put the result in a subdirectory that's named after the OS version
65# we've made this .deb file for.
66destdir="debian-$(cat /etc/debian_version 2>/dev/null || echo UNKNOWN)"
67
68rm -rf "$destdir"
69mkdir -p "$destdir"
70mv $(find tmp -mindepth 1 -maxdepth 1 -type f) "$destdir"
71
72echo
73echo "The Debian package files are located in $PWD/$destdir"