Jan Tattermusch | 81a14e8 | 2015-02-19 16:35:24 -0800 | [diff] [blame] | 1 | #!/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 Emiola | 1e3361c | 2015-04-07 20:22:25 -0700 | [diff] [blame] | 33 | set -x |
Tim Emiola | 2a113f6 | 2015-04-03 15:10:52 -0700 | [diff] [blame] | 34 | deb_dest="/tmp/deb_out" |
Jan Tattermusch | cf774b9 | 2015-02-19 18:38:12 -0800 | [diff] [blame] | 35 | mkdir -p $deb_dest |
Jan Tattermusch | 81a14e8 | 2015-02-19 16:35:24 -0800 | [diff] [blame] | 36 | |
Tim Emiola | 1e3361c | 2015-04-07 20:22:25 -0700 | [diff] [blame] | 37 | # Where the grpc disto is |
| 38 | grpc_root="/var/local/git/grpc" |
| 39 | |
Tim Emiola | 2a113f6 | 2015-04-03 15:10:52 -0700 | [diff] [blame] | 40 | # Update version from default values if the file /version.txt exists |
| 41 | # |
Tim Emiola | f82b378 | 2015-04-03 15:14:07 -0700 | [diff] [blame] | 42 | # - when present, /version.txt will added by the docker build. |
Jan Tattermusch | 28ab96c | 2015-02-26 10:38:06 -0800 | [diff] [blame] | 43 | pkg_version='0.5.0' |
Tim Emiola | 2a113f6 | 2015-04-03 15:10:52 -0700 | [diff] [blame] | 44 | if [ -f /version.txt ]; then |
| 45 | pkg_version=$(cat /version.txt) |
| 46 | fi |
| 47 | version="${pkg_version}.0" |
Tim Emiola | c76b565 | 2015-04-08 17:19:34 -0700 | [diff] [blame] | 48 | release_tag="release-${pkg_version//./_}" |
| 49 | echo "Target release => $pkg_version, will checkout tag $release_tag" |
| 50 | |
| 51 | # Switch grpc_root to the release tag |
| 52 | pushd $grpc_root |
| 53 | git checkout $release_tag || { echo "bad release tag ${release_tag}"; exit 1; } |
| 54 | popd |
Jan Tattermusch | 9dece9e | 2015-02-19 20:25:22 -0800 | [diff] [blame] | 55 | |
Jan Tattermusch | 6b2b05e | 2015-02-21 15:09:00 -0800 | [diff] [blame] | 56 | if [ -f /.dockerinit ]; then |
| 57 | # We're in Docker where uname -p returns "unknown". |
| 58 | arch=x86_64 |
| 59 | else |
| 60 | arch=`uname -p` |
| 61 | fi |
| 62 | |
Jan Tattermusch | 9dece9e | 2015-02-19 20:25:22 -0800 | [diff] [blame] | 63 | if [ $arch != "x86_64" ] |
| 64 | then |
| 65 | echo Unsupported architecture. |
| 66 | exit 1 |
| 67 | fi |
Jan Tattermusch | 81a14e8 | 2015-02-19 16:35:24 -0800 | [diff] [blame] | 68 | |
| 69 | # Build debian packages |
| 70 | for pkg_name in libgrpc libgrpc-dev |
| 71 | do |
| 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 Tattermusch | 9dece9e | 2015-02-19 20:25:22 -0800 | [diff] [blame] | 79 | arch_lib_dir=$tmp_dir/$pkg_name/usr/lib/$arch-linux-gnu |
| 80 | |
Jan Tattermusch | 81a14e8 | 2015-02-19 16:35:24 -0800 | [diff] [blame] | 81 | if [ $pkg_name == "libgrpc" ] |
| 82 | then |
Jan Tattermusch | 9dece9e | 2015-02-19 20:25:22 -0800 | [diff] [blame] | 83 | # Copy shared libraries |
Tim Emiola | 1e3361c | 2015-04-07 20:22:25 -0700 | [diff] [blame] | 84 | pushd $grpc_root |
| 85 | make install-shared_c prefix=$tmp_dir/$pkg_name/usr/lib |
| 86 | popd |
Jan Tattermusch | 9dece9e | 2015-02-19 20:25:22 -0800 | [diff] [blame] | 87 | 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 Tattermusch | 81a14e8 | 2015-02-19 16:35:24 -0800 | [diff] [blame] | 94 | fi |
| 95 | |
| 96 | if [ $pkg_name == "libgrpc-dev" ] |
| 97 | then |
Jan Tattermusch | 9dece9e | 2015-02-19 20:25:22 -0800 | [diff] [blame] | 98 | # Copy headers and static libraries |
Tim Emiola | 1e3361c | 2015-04-07 20:22:25 -0700 | [diff] [blame] | 99 | pushd $grpc_root |
| 100 | make install-headers_c install-static_c prefix=$tmp_dir/$pkg_name/usr/lib |
| 101 | popd |
| 102 | |
Jan Tattermusch | 9dece9e | 2015-02-19 20:25:22 -0800 | [diff] [blame] | 103 | 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 Tattermusch | 6b2b05e | 2015-02-21 15:09:00 -0800 | [diff] [blame] | 109 | base=`basename $libname .a` |
Jan Tattermusch | 9dece9e | 2015-02-19 20:25:22 -0800 | [diff] [blame] | 110 | ln -s $base.so.$version $arch_lib_dir/$base.so |
| 111 | done |
Jan Tattermusch | 81a14e8 | 2015-02-19 16:35:24 -0800 | [diff] [blame] | 112 | fi |
| 113 | |
| 114 | # Adjust mode for some files in the package |
| 115 | find $tmp_dir/$pkg_name -type d | xargs chmod 755 |
Jan Tattermusch | 6b2b05e | 2015-02-21 15:09:00 -0800 | [diff] [blame] | 116 | find $tmp_dir/$pkg_name -type d | xargs chmod a-s |
Jan Tattermusch | 4720bab | 2015-02-19 18:15:24 -0800 | [diff] [blame] | 117 | find $tmp_dir/$pkg_name -type f | xargs chmod 644 |
| 118 | chmod 755 $tmp_dir/$pkg_name/DEBIAN/{postinst,postrm} |
Jan Tattermusch | 81a14e8 | 2015-02-19 16:35:24 -0800 | [diff] [blame] | 119 | |
| 120 | # Build the debian package |
| 121 | fakeroot dpkg-deb --build $tmp_dir/$pkg_name || { echo "dpkg-deb failed"; exit 1; } |
| 122 | |
Jan Tattermusch | 28ab96c | 2015-02-26 10:38:06 -0800 | [diff] [blame] | 123 | deb_path=$deb_dest/${pkg_name}_${pkg_version}_amd64.deb |
Jan Tattermusch | 81a14e8 | 2015-02-19 16:35:24 -0800 | [diff] [blame] | 124 | |
Jan Tattermusch | 9dece9e | 2015-02-19 20:25:22 -0800 | [diff] [blame] | 125 | # Copy the .deb file to destination dir |
| 126 | cp $tmp_dir/$pkg_name.deb $deb_path |
| 127 | |
| 128 | echo "Resulting package: $deb_path" |
Jan Tattermusch | 81a14e8 | 2015-02-19 16:35:24 -0800 | [diff] [blame] | 129 | echo "Package info:" |
Jan Tattermusch | 9dece9e | 2015-02-19 20:25:22 -0800 | [diff] [blame] | 130 | dpkg-deb -I $deb_path |
Jan Tattermusch | 81a14e8 | 2015-02-19 16:35:24 -0800 | [diff] [blame] | 131 | echo "Package contents:" |
Jan Tattermusch | 9dece9e | 2015-02-19 20:25:22 -0800 | [diff] [blame] | 132 | dpkg-deb -c $deb_path |
Jan Tattermusch | ac5b5f2 | 2015-02-19 18:17:11 -0800 | [diff] [blame] | 133 | echo "Problems reported by lintian:" |
Jan Tattermusch | 9dece9e | 2015-02-19 20:25:22 -0800 | [diff] [blame] | 134 | lintian $deb_path |
Jan Tattermusch | 81a14e8 | 2015-02-19 16:35:24 -0800 | [diff] [blame] | 135 | echo |
| 136 | done |