blob: 0beb41ed0a5ae036302856f84f54d1d8516279fd [file] [log] [blame]
Jan Tattermusch81a14e82015-02-19 16:35:24 -08001#!/bin/bash
2
3# Copyright 2015, Google Inc.
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met:
9#
10# * Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# * Redistributions in binary form must reproduce the above
13# copyright notice, this list of conditions and the following disclaimer
14# in the documentation and/or other materials provided with the
15# distribution.
16# * Neither the name of Google Inc. nor the names of its
17# contributors may be used to endorse or promote products derived from
18# this software without specific prior written permission.
19#
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32# Where to put resulting .deb packages.
Tim Emiola1e3361c2015-04-07 20:22:25 -070033set -x
Tim Emiola2a113f62015-04-03 15:10:52 -070034deb_dest="/tmp/deb_out"
Jan Tattermuschcf774b92015-02-19 18:38:12 -080035mkdir -p $deb_dest
Jan Tattermusch81a14e82015-02-19 16:35:24 -080036
Tim Emiola1e3361c2015-04-07 20:22:25 -070037# Where the grpc disto is
38grpc_root="/var/local/git/grpc"
39
Tim Emiola2a113f62015-04-03 15:10:52 -070040# Update version from default values if the file /version.txt exists
41#
Tim Emiolaf82b3782015-04-03 15:14:07 -070042# - when present, /version.txt will added by the docker build.
Jan Tattermusch28ab96c2015-02-26 10:38:06 -080043pkg_version='0.5.0'
Tim Emiola2a113f62015-04-03 15:10:52 -070044if [ -f /version.txt ]; then
45 pkg_version=$(cat /version.txt)
46fi
47version="${pkg_version}.0"
Tim Emiolac76b5652015-04-08 17:19:34 -070048release_tag="release-${pkg_version//./_}"
49echo "Target release => $pkg_version, will checkout tag $release_tag"
50
51# Switch grpc_root to the release tag
52pushd $grpc_root
53git checkout $release_tag || { echo "bad release tag ${release_tag}"; exit 1; }
54popd
Jan Tattermusch9dece9e2015-02-19 20:25:22 -080055
Jan Tattermusch6b2b05e2015-02-21 15:09:00 -080056if [ -f /.dockerinit ]; then
57 # We're in Docker where uname -p returns "unknown".
58 arch=x86_64
59else
60 arch=`uname -p`
61fi
62
Jan Tattermusch9dece9e2015-02-19 20:25:22 -080063if [ $arch != "x86_64" ]
64then
65 echo Unsupported architecture.
66 exit 1
67fi
Jan Tattermusch81a14e82015-02-19 16:35:24 -080068
69# Build debian packages
70for pkg_name in libgrpc libgrpc-dev
71do
72 echo
73 echo "Building package $pkg_name"
74 tmp_dir=`mktemp -d`
75 echo "Using tmp dir $tmp_dir to build the package"
76
77 cp -a templates/$pkg_name $tmp_dir
78
Jan Tattermusch9dece9e2015-02-19 20:25:22 -080079 arch_lib_dir=$tmp_dir/$pkg_name/usr/lib/$arch-linux-gnu
80
Jan Tattermusch81a14e82015-02-19 16:35:24 -080081 if [ $pkg_name == "libgrpc" ]
82 then
Jan Tattermusch9dece9e2015-02-19 20:25:22 -080083 # Copy shared libraries
Tim Emiola1e3361c2015-04-07 20:22:25 -070084 pushd $grpc_root
85 make install-shared_c prefix=$tmp_dir/$pkg_name/usr/lib
86 popd
Jan Tattermusch9dece9e2015-02-19 20:25:22 -080087 mv $tmp_dir/$pkg_name/usr/lib/lib $arch_lib_dir
88
89 # non-dev package should contain so.0 symlinks
90 for symlink in $arch_lib_dir/*.so
91 do
92 mv $symlink $symlink.0
93 done
Jan Tattermusch81a14e82015-02-19 16:35:24 -080094 fi
95
96 if [ $pkg_name == "libgrpc-dev" ]
97 then
Jan Tattermusch9dece9e2015-02-19 20:25:22 -080098 # Copy headers and static libraries
Tim Emiola1e3361c2015-04-07 20:22:25 -070099 pushd $grpc_root
100 make install-headers_c install-static_c prefix=$tmp_dir/$pkg_name/usr/lib
101 popd
102
Jan Tattermusch9dece9e2015-02-19 20:25:22 -0800103 mv $tmp_dir/$pkg_name/usr/lib/include $tmp_dir/$pkg_name/usr/include
104 mv $tmp_dir/$pkg_name/usr/lib/lib $arch_lib_dir
105
106 # create symlinks to shared libraries
107 for libname in $arch_lib_dir/*.a
108 do
Jan Tattermusch6b2b05e2015-02-21 15:09:00 -0800109 base=`basename $libname .a`
Jan Tattermusch9dece9e2015-02-19 20:25:22 -0800110 ln -s $base.so.$version $arch_lib_dir/$base.so
111 done
Jan Tattermusch81a14e82015-02-19 16:35:24 -0800112 fi
113
114 # Adjust mode for some files in the package
115 find $tmp_dir/$pkg_name -type d | xargs chmod 755
Jan Tattermusch6b2b05e2015-02-21 15:09:00 -0800116 find $tmp_dir/$pkg_name -type d | xargs chmod a-s
Jan Tattermusch4720bab2015-02-19 18:15:24 -0800117 find $tmp_dir/$pkg_name -type f | xargs chmod 644
118 chmod 755 $tmp_dir/$pkg_name/DEBIAN/{postinst,postrm}
Jan Tattermusch81a14e82015-02-19 16:35:24 -0800119
120 # Build the debian package
121 fakeroot dpkg-deb --build $tmp_dir/$pkg_name || { echo "dpkg-deb failed"; exit 1; }
122
Jan Tattermusch28ab96c2015-02-26 10:38:06 -0800123 deb_path=$deb_dest/${pkg_name}_${pkg_version}_amd64.deb
Jan Tattermusch81a14e82015-02-19 16:35:24 -0800124
Jan Tattermusch9dece9e2015-02-19 20:25:22 -0800125 # Copy the .deb file to destination dir
126 cp $tmp_dir/$pkg_name.deb $deb_path
127
128 echo "Resulting package: $deb_path"
Jan Tattermusch81a14e82015-02-19 16:35:24 -0800129 echo "Package info:"
Jan Tattermusch9dece9e2015-02-19 20:25:22 -0800130 dpkg-deb -I $deb_path
Jan Tattermusch81a14e82015-02-19 16:35:24 -0800131 echo "Package contents:"
Jan Tattermusch9dece9e2015-02-19 20:25:22 -0800132 dpkg-deb -c $deb_path
Jan Tattermuschac5b5f22015-02-19 18:17:11 -0800133 echo "Problems reported by lintian:"
Jan Tattermusch9dece9e2015-02-19 20:25:22 -0800134 lintian $deb_path
Jan Tattermusch81a14e82015-02-19 16:35:24 -0800135 echo
136done