2021-05-30 00:16:28 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-11-22 22:53:41 +03:00
|
|
|
# Build a modern version of libpq and depending libs from source on Centos 5, Alpine or macOS
|
2021-05-30 00:16:28 +03:00
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
set -x
|
|
|
|
|
2022-10-06 05:14:06 +03:00
|
|
|
# Last release: https://www.postgresql.org/ftp/source/
|
2023-02-08 17:55:01 +03:00
|
|
|
# IMPORTANT! Change the cache key in packages.yml when upgrading libraries
|
2023-04-03 06:07:01 +03:00
|
|
|
postgres_version="${LIBPQ_VERSION}"
|
2023-02-08 17:55:01 +03:00
|
|
|
|
2022-10-06 05:14:06 +03:00
|
|
|
# last release: https://www.openssl.org/source/
|
2023-04-03 06:07:01 +03:00
|
|
|
openssl_version="${OPENSSL_VERSION}"
|
2023-02-08 17:55:01 +03:00
|
|
|
|
2024-11-22 22:53:41 +03:00
|
|
|
# last release: https://kerberos.org/dist/
|
|
|
|
krb5_version="1.21.3"
|
|
|
|
|
|
|
|
# last release: https://www.gnu.org/software/gettext/
|
|
|
|
gettext_version="0.22.5"
|
|
|
|
|
2022-10-06 05:14:06 +03:00
|
|
|
# last release: https://openldap.org/software/download/
|
2024-11-22 22:53:41 +03:00
|
|
|
ldap_version="2.6.8"
|
2023-02-08 17:55:01 +03:00
|
|
|
|
2022-10-06 05:14:06 +03:00
|
|
|
# last release: https://github.com/cyrusimap/cyrus-sasl/releases
|
|
|
|
sasl_version="2.1.28"
|
2021-05-30 00:16:28 +03:00
|
|
|
|
2023-04-02 18:33:56 +03:00
|
|
|
export LIBPQ_BUILD_PREFIX=${LIBPQ_BUILD_PREFIX:-/tmp/libpq.build}
|
2021-05-30 00:16:28 +03:00
|
|
|
|
2024-11-22 22:53:41 +03:00
|
|
|
case "$(uname)" in
|
|
|
|
Darwin)
|
|
|
|
ID=macos
|
|
|
|
library_suffix=dylib
|
|
|
|
;;
|
|
|
|
|
|
|
|
Linux)
|
|
|
|
source /etc/os-release
|
|
|
|
library_suffix=so
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
echo "$0: unexpected Operating system: '$(uname)'" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [[ -f "${LIBPQ_BUILD_PREFIX}/lib/libpq.${library_suffix}" ]]; then
|
2023-02-08 17:55:01 +03:00
|
|
|
echo "libpq already available: build skipped" >&2
|
|
|
|
exit 0
|
|
|
|
fi
|
2021-05-30 00:16:28 +03:00
|
|
|
|
2023-02-08 17:55:01 +03:00
|
|
|
case "$ID" in
|
|
|
|
centos)
|
|
|
|
yum update -y
|
|
|
|
yum install -y zlib-devel krb5-devel pam-devel
|
|
|
|
;;
|
|
|
|
|
|
|
|
alpine)
|
|
|
|
apk upgrade
|
2024-09-16 22:23:46 +03:00
|
|
|
apk add --no-cache zlib-dev krb5-dev linux-pam-dev openldap-dev openssl-dev
|
2024-11-22 22:53:41 +03:00
|
|
|
;;
|
|
|
|
|
|
|
|
macos)
|
|
|
|
brew install automake m4 libtool
|
|
|
|
# If available, libpq seemingly insists on linking against homebrew's
|
|
|
|
# openssl no matter what so remove it. Since homebrew's curl depends on
|
|
|
|
# it, force use of system curl.
|
2025-01-05 22:20:06 +03:00
|
|
|
brew uninstall --force --ignore-dependencies openssl gettext curl
|
2025-01-05 17:51:07 +03:00
|
|
|
if [ -z "$MACOSX_ARCHITECTURE" ]; then
|
|
|
|
MACOSX_ARCHITECTURE="$(uname -m)"
|
|
|
|
fi
|
|
|
|
# Set the deployment target to be <= to that of the oldest supported Python version.
|
2024-11-22 22:53:41 +03:00
|
|
|
# e.g. https://www.python.org/downloads/release/python-380/
|
2025-01-05 17:51:07 +03:00
|
|
|
if [ "$MACOSX_ARCHITECTURE" == "x86_64" ]; then
|
2024-11-22 22:53:41 +03:00
|
|
|
export MACOSX_DEPLOYMENT_TARGET=10.9
|
|
|
|
else
|
|
|
|
export MACOSX_DEPLOYMENT_TARGET=11.0
|
|
|
|
fi
|
2023-02-08 17:55:01 +03:00
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
echo "$0: unexpected Linux distribution: '$ID'" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2025-01-05 17:51:07 +03:00
|
|
|
|
|
|
|
if [ "$ID" == "macos" ]; then
|
|
|
|
make_configure_standard_flags=( \
|
|
|
|
--prefix=${LIBPQ_BUILD_PREFIX} \
|
|
|
|
"CPPFLAGS=-I${LIBPQ_BUILD_PREFIX}/include/ -arch $MACOSX_ARCHITECTURE" \
|
|
|
|
"LDFLAGS=-L${LIBPQ_BUILD_PREFIX}/lib -arch $MACOSX_ARCHITECTURE" \
|
|
|
|
)
|
|
|
|
else
|
|
|
|
make_configure_standard_flags=( \
|
|
|
|
--prefix=${LIBPQ_BUILD_PREFIX} \
|
|
|
|
CPPFLAGS=-I${LIBPQ_BUILD_PREFIX}/include/ \
|
|
|
|
LDFLAGS=-L${LIBPQ_BUILD_PREFIX}/lib \
|
|
|
|
)
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2024-11-22 22:53:41 +03:00
|
|
|
if [ "$ID" == "centos" ] || [ "$ID" == "macos" ]; then
|
2023-02-08 17:55:01 +03:00
|
|
|
|
|
|
|
# Build openssl if needed
|
|
|
|
openssl_tag="OpenSSL_${openssl_version//./_}"
|
|
|
|
openssl_dir="openssl-${openssl_tag}"
|
2025-01-05 22:20:06 +03:00
|
|
|
if [ ! -d "${openssl_dir}" ]; then
|
|
|
|
curl -sL \
|
2023-02-08 17:55:01 +03:00
|
|
|
https://github.com/openssl/openssl/archive/${openssl_tag}.tar.gz \
|
|
|
|
| tar xzf -
|
|
|
|
|
|
|
|
cd "${openssl_dir}"
|
|
|
|
|
2025-01-05 17:51:07 +03:00
|
|
|
options=(--prefix=${LIBPQ_BUILD_PREFIX} --openssldir=${LIBPQ_BUILD_PREFIX} \
|
|
|
|
zlib -fPIC shared)
|
|
|
|
if [ -z "$MACOSX_ARCHITECTURE" ]; then
|
|
|
|
./config $options
|
|
|
|
else
|
|
|
|
./configure "darwin64-$MACOSX_ARCHITECTURE-cc" $options
|
|
|
|
fi
|
|
|
|
|
2023-02-08 17:55:01 +03:00
|
|
|
make depend
|
|
|
|
make
|
|
|
|
else
|
|
|
|
cd "${openssl_dir}"
|
|
|
|
fi
|
2021-05-30 00:16:28 +03:00
|
|
|
|
2023-02-08 17:55:01 +03:00
|
|
|
# Install openssl
|
|
|
|
make install_sw
|
|
|
|
cd ..
|
2021-05-30 00:16:28 +03:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2024-11-22 22:53:41 +03:00
|
|
|
if [ "$ID" == "macos" ]; then
|
|
|
|
|
|
|
|
# Build kerberos if needed
|
|
|
|
krb5_dir="krb5-${krb5_version}/src"
|
|
|
|
if [ ! -d "${krb5_dir}" ]; then
|
2025-01-05 22:20:06 +03:00
|
|
|
curl -sL "https://kerberos.org/dist/krb5/${krb5_version%.*}/krb5-${krb5_version}.tar.gz" \
|
2024-11-22 22:53:41 +03:00
|
|
|
| tar xzf -
|
|
|
|
|
|
|
|
cd "${krb5_dir}"
|
2025-01-05 17:51:07 +03:00
|
|
|
./configure "${make_configure_standard_flags[@]}"
|
2024-11-22 22:53:41 +03:00
|
|
|
make
|
|
|
|
else
|
|
|
|
cd "${krb5_dir}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
make install
|
|
|
|
cd ../..
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$ID" == "macos" ]; then
|
|
|
|
|
|
|
|
# Build gettext if needed
|
|
|
|
gettext_dir="gettext-${gettext_version}"
|
|
|
|
if [ ! -d "${gettext_dir}" ]; then
|
2025-01-05 22:20:06 +03:00
|
|
|
curl -sL "https://ftp.gnu.org/pub/gnu/gettext/gettext-${gettext_version}.tar.gz" \
|
2024-11-22 22:53:41 +03:00
|
|
|
| tar xzf -
|
|
|
|
|
|
|
|
cd "${gettext_dir}"
|
2025-01-05 17:51:07 +03:00
|
|
|
./configure --disable-java "${make_configure_standard_flags[@]}"
|
2024-11-22 22:53:41 +03:00
|
|
|
make -C gettext-runtime all
|
|
|
|
else
|
|
|
|
cd "${gettext_dir}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
make -C gettext-runtime install
|
|
|
|
cd ..
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$ID" == "centos" ] || [ "$ID" == "macos" ]; then
|
2021-05-30 00:16:28 +03:00
|
|
|
|
2023-02-08 17:55:01 +03:00
|
|
|
# Build libsasl2 if needed
|
|
|
|
# The system package (cyrus-sasl-devel) causes an amazing error on i686:
|
|
|
|
# "unsupported version 0 of Verneed record"
|
|
|
|
# https://github.com/pypa/manylinux/issues/376
|
|
|
|
sasl_tag="cyrus-sasl-${sasl_version}"
|
|
|
|
sasl_dir="cyrus-sasl-${sasl_tag}"
|
|
|
|
if [ ! -d "${sasl_dir}" ]; then
|
2025-01-05 22:20:06 +03:00
|
|
|
curl -sL \
|
2023-02-08 17:55:01 +03:00
|
|
|
https://github.com/cyrusimap/cyrus-sasl/archive/${sasl_tag}.tar.gz \
|
|
|
|
| tar xzf -
|
2021-05-30 00:16:28 +03:00
|
|
|
|
2023-02-08 17:55:01 +03:00
|
|
|
cd "${sasl_dir}"
|
|
|
|
|
|
|
|
autoreconf -i
|
2025-01-05 17:51:07 +03:00
|
|
|
./configure "${make_configure_standard_flags[@]}" --disable-macos-framework
|
2023-02-08 17:55:01 +03:00
|
|
|
make
|
|
|
|
else
|
|
|
|
cd "${sasl_dir}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Install libsasl2
|
|
|
|
# requires missing nroff to build
|
|
|
|
touch saslauthd/saslauthd.8
|
|
|
|
make install
|
|
|
|
cd ..
|
2021-05-30 00:16:28 +03:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2024-11-22 22:53:41 +03:00
|
|
|
if [ "$ID" == "centos" ] || [ "$ID" == "macos" ]; then
|
2021-05-30 00:16:28 +03:00
|
|
|
|
2023-02-08 17:55:01 +03:00
|
|
|
# Build openldap if needed
|
|
|
|
ldap_tag="${ldap_version}"
|
|
|
|
ldap_dir="openldap-${ldap_tag}"
|
|
|
|
if [ ! -d "${ldap_dir}" ]; then
|
2025-01-05 22:20:06 +03:00
|
|
|
curl -sL \
|
2023-02-08 17:55:01 +03:00
|
|
|
https://www.openldap.org/software/download/OpenLDAP/openldap-release/openldap-${ldap_tag}.tgz \
|
|
|
|
| tar xzf -
|
2021-05-30 00:16:28 +03:00
|
|
|
|
2023-02-08 17:55:01 +03:00
|
|
|
cd "${ldap_dir}"
|
2021-05-30 00:16:28 +03:00
|
|
|
|
2025-01-05 17:51:07 +03:00
|
|
|
./configure "${make_configure_standard_flags[@]}" --enable-backends=no --enable-null
|
2021-05-30 00:16:28 +03:00
|
|
|
|
2023-02-08 17:55:01 +03:00
|
|
|
make depend
|
|
|
|
make -C libraries/liblutil/
|
|
|
|
make -C libraries/liblber/
|
|
|
|
make -C libraries/libldap/
|
|
|
|
else
|
|
|
|
cd "${ldap_dir}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Install openldap
|
|
|
|
make -C libraries/liblber/ install
|
|
|
|
make -C libraries/libldap/ install
|
|
|
|
make -C include/ install
|
2024-11-22 22:53:41 +03:00
|
|
|
chmod +x ${LIBPQ_BUILD_PREFIX}/lib/{libldap,liblber}*.${library_suffix}*
|
2023-02-08 17:55:01 +03:00
|
|
|
cd ..
|
|
|
|
|
|
|
|
fi
|
2021-05-30 00:16:28 +03:00
|
|
|
|
|
|
|
|
|
|
|
# Build libpq if needed
|
|
|
|
postgres_tag="REL_${postgres_version//./_}"
|
|
|
|
postgres_dir="postgres-${postgres_tag}"
|
|
|
|
if [ ! -d "${postgres_dir}" ]; then
|
2025-01-05 22:20:06 +03:00
|
|
|
curl -sL \
|
2021-05-30 00:16:28 +03:00
|
|
|
https://github.com/postgres/postgres/archive/${postgres_tag}.tar.gz \
|
|
|
|
| tar xzf -
|
|
|
|
|
|
|
|
cd "${postgres_dir}"
|
|
|
|
|
2024-11-22 22:53:41 +03:00
|
|
|
if [ "$ID" != "macos" ]; then
|
|
|
|
# Match the default unix socket dir default with what defined on Ubuntu and
|
|
|
|
# Red Hat, which seems the most common location
|
|
|
|
sed -i 's|#define DEFAULT_PGSOCKET_DIR .*'\
|
2021-05-30 00:16:28 +03:00
|
|
|
'|#define DEFAULT_PGSOCKET_DIR "/var/run/postgresql"|' \
|
2024-11-22 22:53:41 +03:00
|
|
|
src/include/pg_config_manual.h
|
|
|
|
fi
|
2021-05-30 00:16:28 +03:00
|
|
|
|
2023-02-08 17:55:01 +03:00
|
|
|
# Often needed, but currently set by the workflow
|
2023-04-02 18:33:56 +03:00
|
|
|
# export LD_LIBRARY_PATH="${LIBPQ_BUILD_PREFIX}/lib"
|
2021-05-30 00:16:28 +03:00
|
|
|
|
2025-01-05 17:51:07 +03:00
|
|
|
./configure "${make_configure_standard_flags[@]}" --sysconfdir=/etc/postgresql-common \
|
2023-09-28 10:16:38 +03:00
|
|
|
--with-gssapi --with-openssl --with-pam --with-ldap \
|
2025-01-05 17:51:07 +03:00
|
|
|
--without-readline --without-icu
|
2021-05-30 00:16:28 +03:00
|
|
|
make -C src/interfaces/libpq
|
|
|
|
make -C src/bin/pg_config
|
|
|
|
make -C src/include
|
|
|
|
else
|
|
|
|
cd "${postgres_dir}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Install libpq
|
|
|
|
make -C src/interfaces/libpq install
|
|
|
|
make -C src/bin/pg_config install
|
|
|
|
make -C src/include install
|
|
|
|
cd ..
|
|
|
|
|
2024-11-22 22:53:41 +03:00
|
|
|
find ${LIBPQ_BUILD_PREFIX} -name \*.${library_suffix}.\* -type f -exec strip --strip-unneeded {} \;
|