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,21 +12,39 @@ 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
+
15
18
# last release: https://openldap.org/software/download/
16
- ldap_version=" 2.6.3 "
19
+ ldap_version=" 2.6.8 "
17
20
18
21
# last release: https://github.com/cyrusimap/cyrus-sasl/releases
19
22
sasl_version=" 2.1.28"
20
23
21
24
export LIBPQ_BUILD_PREFIX=${LIBPQ_BUILD_PREFIX:-/ tmp/ libpq.build}
22
25
23
- if [[ -f " ${LIBPQ_BUILD_PREFIX} /lib/libpq.so" ]]; then
26
+ case " $( uname) " in
27
+ Darwin)
28
+ ID=macos
29
+ library_suffix=dylib
30
+ ;;
31
+
32
+ Linux)
33
+ source /etc/os-release
34
+ library_suffix=so
35
+ ;;
36
+
37
+ * )
38
+ echo " $0 : unexpected Operating system: '$( uname) '" >&2
39
+ exit 1
40
+ ;;
41
+ esac
42
+
43
+ if [[ -f " ${LIBPQ_BUILD_PREFIX} /lib/libpq.${library_suffix} " ]]; then
24
44
echo " libpq already available: build skipped" >&2
25
45
exit 0
26
46
fi
27
47
28
- source /etc/os-release
29
-
30
48
case " $ID " in
31
49
centos)
32
50
yum update -y
@@ -38,39 +56,101 @@ case "$ID" in
38
56
apk add --no-cache zlib-dev krb5-dev linux-pam-dev openldap-dev openssl-dev
39
57
;;
40
58
59
+ macos)
60
+ brew install automake m4 libtool
61
+ # If available, libpq seemingly insists on linking against homebrew's
62
+ # openssl no matter what so remove it. Since homebrew's curl depends on
63
+ # it, force use of system curl.
64
+ brew uninstall --force --ignore-dependencies openssl gettext curl
65
+ if [ -z " ${MACOSX_ARCHITECTURE:- } " ]; then
66
+ MACOSX_ARCHITECTURE=" $( uname -m) "
67
+ fi
68
+ # Set the deployment target to be <= to that of the oldest supported Python version.
69
+ # e.g. https://www.python.org/downloads/release/python-380/
70
+ if [ " $MACOSX_ARCHITECTURE " == " x86_64" ]; then
71
+ export MACOSX_DEPLOYMENT_TARGET=10.9
72
+ else
73
+ export MACOSX_DEPLOYMENT_TARGET=11.0
74
+ fi
75
+ ;;
76
+
41
77
* )
42
78
echo " $0 : unexpected Linux distribution: '$ID '" >&2
43
79
exit 1
44
80
;;
45
81
esac
46
82
47
- if [ " $ID " == " centos" ]; then
83
+
84
+ if [ " $ID " == " macos" ]; then
85
+ make_configure_standard_flags=( \
86
+ --prefix=${LIBPQ_BUILD_PREFIX} \
87
+ " CPPFLAGS=-I${LIBPQ_BUILD_PREFIX} /include/ -arch $MACOSX_ARCHITECTURE " \
88
+ " LDFLAGS=-L${LIBPQ_BUILD_PREFIX} /lib -arch $MACOSX_ARCHITECTURE " \
89
+ )
90
+ else
91
+ make_configure_standard_flags=( \
92
+ --prefix=${LIBPQ_BUILD_PREFIX} \
93
+ CPPFLAGS=-I${LIBPQ_BUILD_PREFIX} /include/ \
94
+ LDFLAGS=-L${LIBPQ_BUILD_PREFIX} /lib \
95
+ )
96
+ fi
97
+
98
+
99
+ if [ " $ID " == " centos" ] || [ " $ID " == " macos" ]; then
48
100
49
101
# Build openssl if needed
50
102
openssl_tag=" OpenSSL_${openssl_version// ./ _} "
51
103
openssl_dir=" openssl-${openssl_tag} "
52
- if [ ! -d " ${openssl_dir} " ]; then curl -sL \
104
+ if [ ! -d " ${openssl_dir} " ]; then
105
+ curl -sL \
53
106
https://github.com/openssl/openssl/archive/${openssl_tag} .tar.gz \
54
107
| tar xzf -
55
108
56
- cd " ${openssl_dir} "
109
+ pushd " ${openssl_dir} "
110
+
111
+ options=(--prefix=${LIBPQ_BUILD_PREFIX} --openssldir=${LIBPQ_BUILD_PREFIX} \
112
+ zlib -fPIC shared)
113
+ if [ -z " ${MACOSX_ARCHITECTURE:- } " ]; then
114
+ ./config $options
115
+ else
116
+ ./configure " darwin64-$MACOSX_ARCHITECTURE -cc" $options
117
+ fi
57
118
58
- ./config --prefix=${LIBPQ_BUILD_PREFIX} --openssldir=${LIBPQ_BUILD_PREFIX} \
59
- zlib -fPIC shared
60
119
make depend
61
120
make
62
121
else
63
- cd " ${openssl_dir} "
122
+ pushd " ${openssl_dir} "
64
123
fi
65
124
66
125
# Install openssl
67
126
make install_sw
68
- cd ..
127
+ popd
128
+
129
+ fi
130
+
131
+
132
+ if [ " $ID " == " macos" ]; then
133
+
134
+ # Build kerberos if needed
135
+ krb5_dir=" krb5-${krb5_version} /src"
136
+ if [ ! -d " ${krb5_dir} " ]; then
137
+ curl -sL " https://kerberos.org/dist/krb5/${krb5_version% .* } /krb5-${krb5_version} .tar.gz" \
138
+ | tar xzf -
139
+
140
+ pushd " ${krb5_dir} "
141
+ ./configure " ${make_configure_standard_flags[@]} "
142
+ make
143
+ else
144
+ pushd " ${krb5_dir} "
145
+ fi
146
+
147
+ make install
148
+ popd
69
149
70
150
fi
71
151
72
152
73
- if [ " $ID " == " centos" ]; then
153
+ if [ " $ID " == " centos" ] || [ " $ID " == " macos " ] ; then
74
154
75
155
# Build libsasl2 if needed
76
156
# The system package (cyrus-sasl-devel) causes an amazing error on i686:
@@ -83,26 +163,25 @@ if [ "$ID" == "centos" ]; then
83
163
https://github.com/cyrusimap/cyrus-sasl/archive/${sasl_tag} .tar.gz \
84
164
| tar xzf -
85
165
86
- cd " ${sasl_dir} "
166
+ pushd " ${sasl_dir} "
87
167
88
168
autoreconf -i
89
- ./configure --prefix=${LIBPQ_BUILD_PREFIX} \
90
- CPPFLAGS=-I${LIBPQ_BUILD_PREFIX} /include/ LDFLAGS=-L${LIBPQ_BUILD_PREFIX} /lib
169
+ ./configure " ${make_configure_standard_flags[@]} " --disable-macos-framework
91
170
make
92
171
else
93
- cd " ${sasl_dir} "
172
+ pushd " ${sasl_dir} "
94
173
fi
95
174
96
175
# Install libsasl2
97
176
# requires missing nroff to build
98
177
touch saslauthd/saslauthd.8
99
178
make install
100
- cd ..
179
+ popd
101
180
102
181
fi
103
182
104
183
105
- if [ " $ID " == " centos" ]; then
184
+ if [ " $ID " == " centos" ] || [ " $ID " == " macos " ] ; then
106
185
107
186
# Build openldap if needed
108
187
ldap_tag=" ${ldap_version} "
@@ -112,25 +191,24 @@ if [ "$ID" == "centos" ]; then
112
191
https://www.openldap.org/software/download/OpenLDAP/openldap-release/openldap-${ldap_tag} .tgz \
113
192
| tar xzf -
114
193
115
- cd " ${ldap_dir} "
194
+ pushd " ${ldap_dir} "
116
195
117
- ./configure --prefix=${LIBPQ_BUILD_PREFIX} --enable-backends=no --enable-null \
118
- CPPFLAGS=-I${LIBPQ_BUILD_PREFIX} /include/ LDFLAGS=-L${LIBPQ_BUILD_PREFIX} /lib
196
+ ./configure " ${make_configure_standard_flags[@]} " --enable-backends=no --enable-null
119
197
120
198
make depend
121
199
make -C libraries/liblutil/
122
200
make -C libraries/liblber/
123
201
make -C libraries/libldap/
124
202
else
125
- cd " ${ldap_dir} "
203
+ pushd " ${ldap_dir} "
126
204
fi
127
205
128
206
# Install openldap
129
207
make -C libraries/liblber/ install
130
208
make -C libraries/libldap/ install
131
209
make -C include/ install
132
- chmod +x ${LIBPQ_BUILD_PREFIX} /lib/{libldap,liblber}* .so *
133
- cd ..
210
+ chmod +x ${LIBPQ_BUILD_PREFIX} /lib/{libldap,liblber}* .${library_suffix} *
211
+ popd
134
212
135
213
fi
136
214
@@ -143,32 +221,33 @@ if [ ! -d "${postgres_dir}" ]; then
143
221
https://github.com/postgres/postgres/archive/${postgres_tag} .tar.gz \
144
222
| tar xzf -
145
223
146
- cd " ${postgres_dir} "
224
+ pushd " ${postgres_dir} "
147
225
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 .*' \
226
+ if [ " $ID " != " macos" ]; then
227
+ # Match the default unix socket dir default with what defined on Ubuntu and
228
+ # Red Hat, which seems the most common location
229
+ sed -i ' s|#define DEFAULT_PGSOCKET_DIR .*' \
151
230
' |#define DEFAULT_PGSOCKET_DIR "/var/run/postgresql"|' \
152
- src/include/pg_config_manual.h
231
+ src/include/pg_config_manual.h
232
+ fi
153
233
154
234
# Often needed, but currently set by the workflow
155
235
# export LD_LIBRARY_PATH="${LIBPQ_BUILD_PREFIX}/lib"
156
236
157
- ./configure --prefix= ${LIBPQ_BUILD_PREFIX} --sysconfdir=/etc/postgresql-common \
237
+ ./configure " ${make_configure_standard_flags[@]} " --sysconfdir=/etc/postgresql-common \
158
238
--with-gssapi --with-openssl --with-pam --with-ldap \
159
- --without-readline --without-icu \
160
- CPPFLAGS=-I${LIBPQ_BUILD_PREFIX} /include/ LDFLAGS=-L${LIBPQ_BUILD_PREFIX} /lib
239
+ --without-readline --without-icu
161
240
make -C src/interfaces/libpq
162
241
make -C src/bin/pg_config
163
242
make -C src/include
164
243
else
165
- cd " ${postgres_dir} "
244
+ pushd " ${postgres_dir} "
166
245
fi
167
246
168
247
# Install libpq
169
248
make -C src/interfaces/libpq install
170
249
make -C src/bin/pg_config install
171
250
make -C src/include install
172
- cd ..
251
+ popd
173
252
174
- find ${LIBPQ_BUILD_PREFIX} -name \* .so .\* -type f -exec strip --strip-unneeded {} \;
253
+ find ${LIBPQ_BUILD_PREFIX} -name \* .${library_suffix} .\* -type f -exec strip --strip-unneeded {} \;
0 commit comments