-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_pgzint.sh
executable file
·86 lines (74 loc) · 2.68 KB
/
build_pgzint.sh
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
#!/bin/bash
PROG=$(basename $0)
UTILDIR=$(dirname $0)
PGVERSIONS="9.4.22 9.5.17 9.6.13 10.8 11.3"
PGCONFIG="--with-readline --with-openssl --with-pam --with-krb5"
PGZINTVER=0.1.4
PGZINTURL="https://github.com/davidbeauchamp/pgzint.git"
INITIALPATH="$PATH"
STARTDIR=$(pwd)
BUILDDIR=$(pwd)/pgzint_builds
OS=$(uname -s)
function die() {
echo "$*"
exit 2
}
case $OS in
Darwin) ARCHES="x86_64"
PGCONFIG="$PG_CONFIG --with-bonjour"
;;
Linux) ARCHES=$(uname -i)
;;
esac
if [ "$UTILDIR" = "." -o "$UTILDIR" = "./" ] ; then
UTILDIR="$(pwd)"
elif ! [[ $UTILDIR =~ ^/ ]] ; then
UTILDIR="$(pwd)/$UTILDIR"
fi
[ -d "$BUILDDIR" ] || mkdir -p "$BUILDDIR" || die
cd "$BUILDDIR" || die
rm -rf "${BUILDDIR}/pgzint"
mkdir -p "${BUILDDIR}/pgzint" || die
for PGVER in $PGVERSIONS ; do
if [ ! -f postgresql-${PGVER}.tar.bz2 ] ; then
curl https://ftp.postgresql.org/pub/source/v${PGVER}/postgresql-${PGVER}.tar.bz2 \
-o postgresql-${PGVER}.tar.bz2 || die
fi
done
for PGVER in $PGVERSIONS ; do
LIPOARGS=""
for ARCH in $ARCHES ; do
cd "${BUILDDIR}"
PATH="$INITIALPATH"
if [ ! -d postgresql-${PGVER}-${ARCH} ] ; then
tar xf postgresql-${PGVER}.tar.bz2 || die
mv postgresql-${PGVER} postgresql-${PGVER}-${ARCH} || die
fi
cd postgresql-${PGVER}-${ARCH} || die
if [ "$OS" = Darwin ] ; then
./configure --prefix="${BUILDDIR}/pg-${PGVER}-${ARCH}" $PGCONFIG CFLAGS="-arch $ARCH" || die
else
./configure --prefix="${BUILDDIR}/pg-${PGVER}-${ARCH}" $PGCONFIG || die
fi
make -j$(nproc) install || die
cd ${BUILDDIR} || die
[ -d pgzint_${ARCH} ] || git clone $PGZINTURL pgzint_${ARCH} || die
cd ${BUILDDIR}/pgzint_${ARCH} || die
make clean
git checkout ${PGZINTVER} || die
PATH="${BUILDDIR}/pg-${PGVER}-${ARCH}/bin:${INITIALPATH}"
make -j$(nproc) || die
LIPOARGS="${LIPOARGS} -arch ${ARCH} $(pwd)/pgzint.so"
done
case ${OS} in
Darwin)
lipo -create -output "${BUILDDIR}/pgzint/pgzint_${PGVER}.so" $LIPOARGS || die
;;
*)
cp pgzint.so "${BUILDDIR}/pgzint/pgzint_${PGVER}.so" || die
;;
esac
done
cd "${BUILDDIR}" || die
cp "${BUILDDIR}"/pgzint_${ARCH}/*.{sql,control} pgzint || die
tar czf pgzint.tgz pgzint || die