~akopytov/percona-xtrabackup/bug1166888-2.0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/sh
#
# Execute this tool to setup the environment and build binary releases
# for xtrabackup starting from a fresh tree.
#
# Usage: build-binary.sh [target dir]
# The default target directory is the current directory. If it is not
# supplied and the current directory is not empty, it will issue an error in
# order to avoid polluting the current directory after a test run.
#

# Bail out on errors, be strict
set -ue

# Examine parameters
TARGET="$(uname -m)"
TARGET_CFLAGS=''

# Some programs that may be overriden
TAR=${TAR:-tar}

# Check if we have a functional getopt(1)
if ! getopt --test
then
    go_out="$(getopt --options="i" --longoptions=i686 \
        --name="$(basename "$0")" -- "$@")"
    test $? -eq 0 || exit 1
    eval set -- $go_out
fi

for arg
do
    case "$arg" in
    -- ) shift; break;;
    -i | --i686 )
        shift
        TARGET="i686"
        TARGET_CFLAGS="-m32 -march=i686"
        ;;
    esac
done

# Working directory
if test "$#" -eq 0
then
    WORKDIR="$(pwd)"
    
    # Check that the current directory is not empty
    if test "x$(echo *)" != "x*"
    then
        echo >&2 \
            "Current directory is not empty. Use $0 . to force build in ."
        exit 1
    fi

    WORKDIR_ABS="$(cd "$WORKDIR"; pwd)"

elif test "$#" -eq 1
then
    WORKDIR="$1"

    # Check that the provided directory exists and is a directory
    if ! test -d "$WORKDIR"
    then
        echo >&2 "$WORKDIR is not a directory"
        exit 1
    fi

    WORKDIR_ABS="$(cd "$WORKDIR"; pwd)"

else
    echo >&2 "Usage: $0 [target dir]"
    exit 1

fi

SOURCEDIR="$(cd $(dirname "$0"); cd ..; pwd)"
test -e "$SOURCEDIR/VERSION" || exit 2

# Read XTRABACKUP_VERSION from the VERSION file
. $SOURCEDIR/VERSION

# Build information
REVISION="$(cd "$SOURCEDIR"; bzr revno)"

# Compilation flags
export CC=${CC:-gcc}
export CXX=${CXX:-g++}
export CFLAGS="-fPIC -Wall -O3 -g -static-libgcc -fno-omit-frame-pointer ${CFLAGS:-}"
export CXXFLAGS="-O2 -fno-omit-frame-pointer -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fno-exceptions ${CXXFLAGS:-}"
export MAKE_JFLAG=-j4

# Create a temporary working directory
BASEINSTALLDIR="$(cd "$WORKDIR" && TMPDIR="$WORKDIR_ABS" mktemp -d xtrabackup-build.XXXXXX)"
INSTALLDIR="$WORKDIR_ABS/$BASEINSTALLDIR/percona-xtrabackup-$XTRABACKUP_VERSION"   # Make it absolute

mkdir "$INSTALLDIR"

export AUTO_DOWNLOAD=yes

# Build
(
    cd "$WORKDIR"

    # Make a copy of the source
    rm -f "percona-xtrabackup-$XTRABACKUP_VERSION"

    bzr export "percona-xtrabackup-$XTRABACKUP_VERSION" "$SOURCEDIR"

    # Build proper
    (
        cd "percona-xtrabackup-$XTRABACKUP_VERSION"

        # Install the files
        mkdir "$INSTALLDIR/bin" "$INSTALLDIR/share"
        mkdir -p "$INSTALLDIR/share/doc/percona-xtrabackup"

        bash utils/build.sh xtradb55
        install -m 755 src/xtrabackup_55 "$INSTALLDIR/bin"

        bash utils/build.sh innodb56
        install -m 755 src/xtrabackup_56 "$INSTALLDIR/bin"

        bash utils/build.sh xtradb
        install -m 755 src/xtrabackup "$INSTALLDIR/bin"

        bash utils/build.sh 5.1
        install -m 755 src/xtrabackup_51 "$INSTALLDIR/bin"

        install -m 755 src/xbstream "$INSTALLDIR/bin"

        install -m 755 innobackupex "$INSTALLDIR/bin"
        ln -s innobackupex "$INSTALLDIR/bin/innobackupex-1.5.1"

        install -m 644 COPYING "$INSTALLDIR/share/doc/percona-xtrabackup"

        cp -R test "$INSTALLDIR/share/percona-xtrabackup-test"

    )
    exit_value=$?

    if test "x$exit_value" = "x0"
    then
        $TAR czf "percona-xtrabackup-$XTRABACKUP_VERSION-$REVISION.tar.gz" \
            --owner=0 --group=0 -C "$INSTALLDIR/../" \
            "percona-xtrabackup-$XTRABACKUP_VERSION"
    fi

    # Clean up build dir
    rm -rf "percona-xtrabackup-$XTRABACKUP_VERSION"
    
    exit $exit_value
    
)
exit_value=$?

# Clean up
rm -rf "$WORKDIR_ABS/$BASEINSTALLDIR"

exit $exit_value