1
1
#! /bin/bash
2
2
3
- # Build a modern version of libpq and depending libs from source on Centos 5
3
+ # Build a modern version of libpq and depending libs from source on Centos 5, Alpine or macOS
4
4
5
5
set -euo pipefail
6
6
set -x
@@ -12,30 +12,69 @@ postgres_version="${LIBPQ_VERSION}"
12
12
# last release: https://www.openssl.org/source/
13
13
openssl_version=" ${OPENSSL_VERSION} "
14
14
15
+ # last release: https://kerberos.org/dist/
16
+ krb5_version=" 1.21.3"
17
+
18
+ # last release: https://www.gnu.org/software/gettext/
19
+ gettext_version=" 0.22.5"
20
+
15
21
# last release: https://openldap.org/software/download/
16
- ldap_version=" 2.6.3 "
22
+ ldap_version=" 2.6.8 "
17
23
18
24
# last release: https://github.com/cyrusimap/cyrus-sasl/releases
19
25
sasl_version=" 2.1.28"
20
26
21
27
export LIBPQ_BUILD_PREFIX=${LIBPQ_BUILD_PREFIX:-/ tmp/ libpq.build}
22
28
23
- if [[ -f " ${LIBPQ_BUILD_PREFIX} /lib/libpq.so" ]]; then
29
+ case " $( uname) " in
30
+ Darwin)
31
+ ID=macos
32
+ library_suffix=dylib
33
+ ;;
34
+
35
+ Linux)
36
+ source /etc/os-release
37
+ library_suffix=so
38
+ ;;
39
+
40
+ * )
41
+ echo " $0 : unexpected Operating system: '$( uname) '" >&2
42
+ exit 1
43
+ ;;
44
+ esac
45
+
46
+ if [[ -f " ${LIBPQ_BUILD_PREFIX} /lib/libpq.${library_suffix} " ]]; then
24
47
echo " libpq already available: build skipped" >&2
25
48
exit 0
26
49
fi
27
50
28
- source /etc/os-release
29
-
30
51
case " $ID " in
31
52
centos)
32
53
yum update -y
33
54
yum install -y zlib-devel krb5-devel pam-devel
55
+ curl=" $( which curl) "
34
56
;;
35
57
36
58
alpine)
37
59
apk upgrade
38
60
apk add --no-cache zlib-dev krb5-dev linux-pam-dev openldap-dev openssl-dev
61
+ curl=" $( which curl) "
62
+ ;;
63
+
64
+ macos)
65
+ brew install automake m4 libtool
66
+ # If available, libpq seemingly insists on linking against homebrew's
67
+ # openssl no matter what so remove it. Since homebrew's curl depends on
68
+ # it, force use of system curl.
69
+ brew uninstall --force --ignore-dependencies openssl gettext
70
+ curl=" /usr/bin/curl"
71
+ # The deployment target should be <= to that of the oldest supported Python version.
72
+ # e.g. https://www.python.org/downloads/release/python-380/
73
+ if [ " $( uname -m) " == " x86_64" ]; then
74
+ export MACOSX_DEPLOYMENT_TARGET=10.9
75
+ else
76
+ export MACOSX_DEPLOYMENT_TARGET=11.0
77
+ fi
39
78
;;
40
79
41
80
* )
@@ -44,12 +83,12 @@ case "$ID" in
44
83
;;
45
84
esac
46
85
47
- if [ " $ID " == " centos" ]; then
86
+ if [ " $ID " == " centos" ] || [ " $ID " == " macos " ] ; then
48
87
49
88
# Build openssl if needed
50
89
openssl_tag=" OpenSSL_${openssl_version// ./ _} "
51
90
openssl_dir=" openssl-${openssl_tag} "
52
- if [ ! -d " ${openssl_dir} " ]; then curl -sL \
91
+ if [ ! -d " ${openssl_dir} " ]; then " $ curl" -sL \
53
92
https://github.com/openssl/openssl/archive/${openssl_tag} .tar.gz \
54
93
| tar xzf -
55
94
@@ -70,7 +109,55 @@ if [ "$ID" == "centos" ]; then
70
109
fi
71
110
72
111
73
- if [ " $ID " == " centos" ]; then
112
+ if [ " $ID " == " macos" ]; then
113
+
114
+ # Build kerberos if needed
115
+ krb5_dir=" krb5-${krb5_version} /src"
116
+ if [ ! -d " ${krb5_dir} " ]; then
117
+ " $curl " -sL \
118
+ curl -sL " https://kerberos.org/dist/krb5/$( echo 1.21.3 | grep -oE ' \d+\.\d+' ) /krb5-${krb5_version} .tar.gz" \
119
+ | tar xzf -
120
+
121
+ cd " ${krb5_dir} "
122
+
123
+ ./configure --prefix=${LIBPQ_BUILD_PREFIX} \
124
+ CPPFLAGS=-I${LIBPQ_BUILD_PREFIX} /include/ LDFLAGS=-L${LIBPQ_BUILD_PREFIX} /lib
125
+ make
126
+ else
127
+ cd " ${krb5_dir} "
128
+ fi
129
+
130
+ make install
131
+ cd ../..
132
+
133
+ fi
134
+
135
+
136
+ if [ " $ID " == " macos" ]; then
137
+
138
+ # Build gettext if needed
139
+ gettext_dir=" gettext-${gettext_version} "
140
+ if [ ! -d " ${gettext_dir} " ]; then
141
+ " $curl " -sL \
142
+ curl -sL " https://ftp.gnu.org/pub/gnu/gettext/gettext-${gettext_version} .tar.gz" \
143
+ | tar xzf -
144
+
145
+ cd " ${gettext_dir} "
146
+
147
+ ./configure --prefix=${LIBPQ_BUILD_PREFIX} --disable-java \
148
+ CPPFLAGS=-I${LIBPQ_BUILD_PREFIX} /include/ LDFLAGS=-L${LIBPQ_BUILD_PREFIX} /lib
149
+ make -C gettext-runtime all
150
+ else
151
+ cd " ${gettext_dir} "
152
+ fi
153
+
154
+ make -C gettext-runtime install
155
+ cd ..
156
+
157
+ fi
158
+
159
+
160
+ if [ " $ID " == " centos" ] || [ " $ID " == " macos" ]; then
74
161
75
162
# Build libsasl2 if needed
76
163
# The system package (cyrus-sasl-devel) causes an amazing error on i686:
@@ -79,14 +166,14 @@ if [ "$ID" == "centos" ]; then
79
166
sasl_tag=" cyrus-sasl-${sasl_version} "
80
167
sasl_dir=" cyrus-sasl-${sasl_tag} "
81
168
if [ ! -d " ${sasl_dir} " ]; then
82
- curl -sL \
169
+ " $ curl" -sL \
83
170
https://github.com/cyrusimap/cyrus-sasl/archive/${sasl_tag} .tar.gz \
84
171
| tar xzf -
85
172
86
173
cd " ${sasl_dir} "
87
174
88
175
autoreconf -i
89
- ./configure --prefix=${LIBPQ_BUILD_PREFIX} \
176
+ ./configure --prefix=${LIBPQ_BUILD_PREFIX} --disable-macos-framework \
90
177
CPPFLAGS=-I${LIBPQ_BUILD_PREFIX} /include/ LDFLAGS=-L${LIBPQ_BUILD_PREFIX} /lib
91
178
make
92
179
else
@@ -102,13 +189,13 @@ if [ "$ID" == "centos" ]; then
102
189
fi
103
190
104
191
105
- if [ " $ID " == " centos" ]; then
192
+ if [ " $ID " == " centos" ] || [ " $ID " == " macos " ] ; then
106
193
107
194
# Build openldap if needed
108
195
ldap_tag=" ${ldap_version} "
109
196
ldap_dir=" openldap-${ldap_tag} "
110
197
if [ ! -d " ${ldap_dir} " ]; then
111
- curl -sL \
198
+ " $ curl" -sL \
112
199
https://www.openldap.org/software/download/OpenLDAP/openldap-release/openldap-${ldap_tag} .tgz \
113
200
| tar xzf -
114
201
@@ -129,7 +216,7 @@ if [ "$ID" == "centos" ]; then
129
216
make -C libraries/liblber/ install
130
217
make -C libraries/libldap/ install
131
218
make -C include/ install
132
- chmod +x ${LIBPQ_BUILD_PREFIX} /lib/{libldap,liblber}* .so *
219
+ chmod +x ${LIBPQ_BUILD_PREFIX} /lib/{libldap,liblber}* .${library_suffix} *
133
220
cd ..
134
221
135
222
fi
139
226
postgres_tag=" REL_${postgres_version// ./ _} "
140
227
postgres_dir=" postgres-${postgres_tag} "
141
228
if [ ! -d " ${postgres_dir} " ]; then
142
- curl -sL \
229
+ " $ curl" -sL \
143
230
https://github.com/postgres/postgres/archive/${postgres_tag} .tar.gz \
144
231
| tar xzf -
145
232
146
233
cd " ${postgres_dir} "
147
234
148
- # Match the default unix socket dir default with what defined on Ubuntu and
149
- # Red Hat, which seems the most common location
150
- sed -i ' s|#define DEFAULT_PGSOCKET_DIR .*' \
235
+ if [ " $ID " != " macos" ]; then
236
+ # Match the default unix socket dir default with what defined on Ubuntu and
237
+ # Red Hat, which seems the most common location
238
+ sed -i ' s|#define DEFAULT_PGSOCKET_DIR .*' \
151
239
' |#define DEFAULT_PGSOCKET_DIR "/var/run/postgresql"|' \
152
- src/include/pg_config_manual.h
240
+ src/include/pg_config_manual.h
241
+ fi
153
242
154
243
# Often needed, but currently set by the workflow
155
244
# export LD_LIBRARY_PATH="${LIBPQ_BUILD_PREFIX}/lib"
@@ -171,4 +260,4 @@ make -C src/bin/pg_config install
171
260
make -C src/include install
172
261
cd ..
173
262
174
- find ${LIBPQ_BUILD_PREFIX} -name \* .so .\* -type f -exec strip --strip-unneeded {} \;
263
+ find ${LIBPQ_BUILD_PREFIX} -name \* .${library_suffix} .\* -type f -exec strip --strip-unneeded {} \;
0 commit comments