2
# Usage: build-dpkg.sh [target dir]
3
# The default target directory is the current directory. If it is not
4
# supplied and the current directory is not empty, it will issue an error in
5
# order to avoid polluting the current directory after a test run.
7
# The program will setup the dpkg building environment and ultimately call
8
# dpkg-buildpackage with the appropiate parameters.
11
# Bail out on errors, be strict
15
go_out="$(getopt --options "k:Ke:bBDS" \
16
--longoptions key:,nosign,epoch:,binary,binarydep,nodebug,source \
17
--name "$(basename "$0")" -- "$@")"
18
test $? -eq 0 || exit 1
30
-k | --key ) shift; BUILDPKG_KEY="-pgpg -k$1"; shift;;
31
-K | --nosign ) shift; BUILDPKG_KEY="-uc -us";;
32
-e | --epoch ) shift; EPOCH="$1:"; shift;;
33
-b | --binary ) shift; DPKG_BINSRC='-b';;
34
-B | --binarydep ) shift; DPKG_BINSRC='-B';;
35
-D | --nodebug ) shift; SKIPDEBUG='yes';;
36
-S | --source ) shift; DPKG_BINSRC='-S';;
45
# Check that the current directory is not empty
46
if test "x$(echo *)" != "x*"
49
"Current directory is not empty. Use $0 . to force build in ."
57
# Check that the provided directory exists and is a directory
58
if ! test -d "$WORKDIR"
60
echo >&2 "$WORKDIR is not a directory"
65
echo >&2 "Usage: $0 [target dir]"
70
SOURCEDIR="$(cd $(dirname "$0"); cd ..; pwd)"
71
test -e "$SOURCEDIR/Makefile" || exit 2
73
# The number of processors is a good default for -j
74
if test -e "/proc/cpuinfo"
76
PROCESSORS="$(grep -c ^processor /proc/cpuinfo)"
81
# Extract version from the Makefile
82
MYSQL_VERSION="$(grep ^MYSQL_VERSION= "$SOURCEDIR/Makefile" \
84
WSREP_VERSION="$(grep WSREP_INTERFACE_VERSION "$SOURCEDIR/wsrep/wsrep_api.h" |
85
cut -d '"' -f2).$(grep 'SET(WSREP_PATCH_VERSION' \
86
"$SOURCEDIR/cmake/wsrep.cmake" | cut -d '"' -f2)"
87
PERCONA_SERVER_VERSION="$(grep ^PERCONA_SERVER_VERSION= "$SOURCEDIR/Makefile" | cut -d = -f 2)"
88
PRODUCT="Percona-XtraDB-Cluster-$MYSQL_VERSION"
89
DEBIAN_VERSION="$(lsb_release -sc)"
92
export REVISION="$(cd "$SOURCEDIR"; bzr revno)"
93
export WSREP_REV="$(cd "$SOURCEDIR";test -r WSREP-REVISION && cat WSREP-REVISION || echo "$REVISION")"
94
export DEB_BUILD_OPTIONS='debug nocheck'
95
export BB_PERCONA_REVISION="$(cd "$SOURCEDIR"; bzr revno)"
98
export CC="${CC:-gcc}"
99
export CXX="${CXX:-gcc}"
100
export HS_CXX=${HS_CXX:-g++}
101
export UDF_CXX=${UDF_CXX:-g++}
102
export CFLAGS="-fPIC -Wall -O3 -g -static-libgcc -fno-omit-frame-pointer -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION ${CFLAGS:-}"
103
export CXXFLAGS="-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fno-exceptions -DPERCONA_INNODB_VERSION=$PERCONA_SERVER_VERSION ${CXXFLAGS:-}"
104
export MAKE_JFLAG="${MAKE_JFLAG:--j$PROCESSORS}"
114
# Make a copy in workdir and copy debian files
118
cp -a "$SOURCEDIR/$PRODUCT/" .
122
# Copy debian files from source
123
cp -R "$SOURCEDIR/build/debian" .
124
chmod +x debian/rules
126
# If nodebug is set, do not ship mysql-debug
127
if test "x$SKIPDEBUG" = "xyes"
129
sed -i '/mysqld-debug/d' debian/percona-server-server-5.5.install
132
# Update distribution name
133
dch -m -D "$DEBIAN_VERSION" --force-distribution -v "$EPOCH$MYSQL_VERSION-$WSREP_VERSION-$BB_PERCONA_REVISION.$DEBIAN_VERSION" 'Update distribution'
135
DEB_CFLAGS_APPEND="$CFLAGS" DEB_CXXFLAGS_APPEND="$CXXFLAGS" \
136
SKIP_DEBUG_BINARY="$SKIPDEBUG" \
137
dpkg-buildpackage $DPKG_BINSRC -rfakeroot $BUILDPKG_KEY