| 1 | #!/bin/bash -exu |
| 2 | # |
| 3 | # Copyright (C) 2015 - Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com> |
| 4 | # |
| 5 | # This program is free software: you can redistribute it and/or modify |
| 6 | # it under the terms of the GNU General Public License as published by |
| 7 | # the Free Software Foundation, either version 3 of the License, or |
| 8 | # (at your option) any later version. |
| 9 | # |
| 10 | # This program is distributed in the hope that it will be useful, |
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | # GNU General Public License for more details. |
| 14 | # |
| 15 | # You should have received a copy of the GNU General Public License |
| 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | # Version compare functions |
| 19 | verlte() { |
| 20 | [ "$1" = "`printf '%s\n%s' $1 $2 | sort -V | head -n1`" ] |
| 21 | } |
| 22 | |
| 23 | verlt() { |
| 24 | [ "$1" = "$2" ] && return 1 || verlte $1 $2 |
| 25 | } |
| 26 | |
| 27 | vergte() { |
| 28 | [ "$1" = "`printf '%s\n%s' $1 $2 | sort -V | tail -n1`" ] |
| 29 | } |
| 30 | |
| 31 | vergt() { |
| 32 | [ "$1" = "$2" ] && return 1 || vergte $1 $2 |
| 33 | } |
| 34 | |
| 35 | |
| 36 | # Create build directory |
| 37 | rm -rf $WORKSPACE/build |
| 38 | mkdir -p $WORKSPACE/build |
| 39 | |
| 40 | PREFIX="$WORKSPACE/build" |
| 41 | |
| 42 | # Set platform variables |
| 43 | case "$arch" in |
| 44 | solaris10) |
| 45 | MAKE=gmake |
| 46 | TAR=gtar |
| 47 | NPROC=gnproc |
| 48 | CFLAGS="-D_XOPEN_SOURCE=1 -D_XOPEN_SOURCE_EXTENDED=1 -D__EXTENSIONS__=1" |
| 49 | ;; |
| 50 | |
| 51 | solaris11) |
| 52 | MAKE=gmake |
| 53 | TAR=gtar |
| 54 | NPROC=nproc |
| 55 | CFLAGS="-D_XOPEN_SOURCE=1 -D_XOPEN_SOURCE_EXTENDED=1 -D__EXTENSIONS__=1" |
| 56 | export PATH="$PATH:/usr/perl5/bin" |
| 57 | ;; |
| 58 | |
| 59 | *) |
| 60 | MAKE=make |
| 61 | TAR=tar |
| 62 | NPROC=nproc |
| 63 | CFLAGS="" |
| 64 | ;; |
| 65 | esac |
| 66 | |
| 67 | # Set configure options for each build configuration |
| 68 | CONF_OPTS="" |
| 69 | case "$conf" in |
| 70 | static) |
| 71 | echo "Static build" |
| 72 | CONF_OPTS="--enable-static --disable-shared" |
| 73 | ;; |
| 74 | |
| 75 | tls_fallback) |
| 76 | echo "Using pthread_getspecific() to emulate TLS" |
| 77 | CONF_OPTS="--disable-compiler-tls" |
| 78 | ;; |
| 79 | |
| 80 | *) |
| 81 | echo "Standard build" |
| 82 | CONF_OPTS="" |
| 83 | ;; |
| 84 | esac |
| 85 | |
| 86 | |
| 87 | # Run bootstrap prior to configure |
| 88 | ./bootstrap |
| 89 | |
| 90 | # Get source version from configure script |
| 91 | eval `grep '^PACKAGE_VERSION=' ./configure` |
| 92 | |
| 93 | |
| 94 | # Build type |
| 95 | # oot : out-of-tree build |
| 96 | # dist: build via make dist |
| 97 | # * : normal tree build |
| 98 | # |
| 99 | # Make sure to move to the build_path and configure |
| 100 | # before continuing |
| 101 | BUILD_PATH=$WORKSPACE |
| 102 | case "$build" in |
| 103 | oot) |
| 104 | echo "Out of tree build" |
| 105 | BUILD_PATH=$WORKSPACE/oot |
| 106 | mkdir -p $BUILD_PATH |
| 107 | cd $BUILD_PATH |
| 108 | MAKE=$MAKE CFLAGS="$CFLAGS" $WORKSPACE/configure --prefix=$PREFIX $CONF_OPTS |
| 109 | ;; |
| 110 | |
| 111 | dist) |
| 112 | echo "Distribution out of tree build" |
| 113 | BUILD_PATH=`mktemp -d` |
| 114 | |
| 115 | # Initial configure and generate tarball |
| 116 | MAKE=$MAKE ./configure |
| 117 | $MAKE dist |
| 118 | |
| 119 | mkdir -p $BUILD_PATH |
| 120 | cp *.tar.* $BUILD_PATH/ |
| 121 | cd $BUILD_PATH |
| 122 | |
| 123 | # Ignore level 1 of tar |
| 124 | $TAR xvf *.tar.* --strip 1 |
| 125 | |
| 126 | MAKE=$MAKE CFLAGS="$CFLAGS" $BUILD_PATH/configure --prefix=$PREFIX $CONF_OPTS |
| 127 | ;; |
| 128 | *) |
| 129 | BUILD_PATH=$WORKSPACE |
| 130 | echo "Standard tree build" |
| 131 | MAKE=$MAKE CFLAGS="$CFLAGS" $WORKSPACE/configure --prefix=$PREFIX $CONF_OPTS |
| 132 | ;; |
| 133 | esac |
| 134 | |
| 135 | # BUILD! |
| 136 | $MAKE -j `$NPROC` V=1 |
| 137 | $MAKE install |
| 138 | |
| 139 | # Run tests |
| 140 | $MAKE check |
| 141 | # Only run regtest for 0.9 and up |
| 142 | if vergte "$PACKAGE_VERSION" "0.9"; then |
| 143 | $MAKE regtest |
| 144 | fi |
| 145 | |
| 146 | # Cleanup |
| 147 | $MAKE clean |
| 148 | |
| 149 | # Cleanup rpath in executables and shared libraries |
| 150 | #find $WORKSPACE/build/bin -type f -perm -0500 -exec chrpath --delete {} \; |
| 151 | find $WORKSPACE/build/lib -name "*.so" -exec chrpath --delete {} \; |
| 152 | |
| 153 | # Remove libtool .la files |
| 154 | find $WORKSPACE/build/lib -name "*.la" -exec rm -f {} \; |
| 155 | |
| 156 | # Cleanup temp directory of dist build |
| 157 | if [ "$build" = "dist" ]; then |
| 158 | cd $WORKSPACE |
| 159 | rm -rf $BUILD_PATH |
| 160 | fi |
| 161 | |
| 162 | # EOF |