aboutsummaryrefslogtreecommitdiffstats
path: root/main/postgresql13/APKBUILD
blob: d9fb68081e430cae56e9e6d23a7212564e70c647 (plain)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
# Contributor: G.J.R. Timmer <gjr.timmer@gmail.com>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
_pkgname=postgresql
pkgver=13.8
pkgrel=0
_majorver=${pkgver%%.*}
# Should this aport provide libpq* and libecpg*? true/false
# Exactly one postgresql aport must be the default one!
_default_ver=false
pkgname=$_pkgname$_majorver
pkgdesc="A sophisticated object-relational DBMS, version $_majorver"
url="https://www.postgresql.org/"
arch="all"
license="PostgreSQL"
_llvmver=14
depends="$pkgname-client postgresql-common tzdata"
depends_dev="
	libpq-dev
	libecpg-dev
	clang
	icu-dev
	llvm$_llvmver
	openssl-dev>3
	"
checkdepends="diffutils"
makedepends="$depends_dev
	libxml2-dev
	linux-headers
	llvm$_llvmver-dev
	openldap-dev
	perl-dev
	python3-dev
	readline-dev
	tcl-dev
	util-linux-dev
	zlib-dev
	bison flex
	"
pkgusers="postgres"
pkggroups="postgres"
install="$pkgname.post-install $pkgname.pre-deinstall"
provider_priority=$_majorver
provides="postgresql"
replaces="postgresql"  # for backward compatibility
$_default_ver && subpackages="
	libpq
	libpq-dev:libpq_dev
	libecpg
	libecpg-dev:libecpg_dev
	"
subpackages="
	$subpackages
	$pkgname-client
	$pkgname-jit
	$pkgname-contrib
	$pkgname-plperl
	$pkgname-plperl-contrib:plperl_contrib
	$pkgname-plpython3
	$pkgname-plpython3-contrib:plpython3_contrib
	$pkgname-pltcl
	$pkgname-contrib-jit:contrib_jit
	$pkgname-dev
	$pkgname-doc
	$pkgname-openrc
	"
source="https://ftp.postgresql.org/pub/source/v$pkgver/postgresql-$pkgver.tar.bz2
	initdb.patch
	perl-rpath.patch
	per-version-dirs.patch
	unix_socket_directories.patch
	disable-broken-tests.patch
	disable-test-collate.icu.utf8.patch
	disable-html-docs.patch
	remove-libecpg_compat.patch
	czech-snowball-stemmer.patch
	make-split-headers.patch
	jit-datalayout-mismatch-on-s390x.patch
	pg_config-add-major-version.patch
	fix-test-temp-schema-cleanup.patch
	dont-use-locale-a-on-musl.patch
	icu-collations-hack.patch
	libpgport-pkglibdir.patch.txt
	external-libpq.patch.txt

	pltcl_create_tables.sql
	"
builddir="$srcdir/$_pkgname-$pkgver"

# secfixes:
#   13.8-r0:
#     - CVE-2022-2625
#   13.7-r0:
#     - CVE-2022-1552
#   13.5-r0:
#     - CVE-2021-23214
#     - CVE-2021-23222
#   13.4-r0:
#     - CVE-2021-3677
#   13.3-r0:
#     - CVE-2021-32027
#     - CVE-2021-32028
#     - CVE-2021-32029
#   13.2-r0:
#     - CVE-2021-3393
#     - CVE-2021-20229

_bindir=usr/libexec/$pkgname
_datadir=usr/share/$pkgname
_docdir=usr/share/doc/$pkgname
_mandir=$_datadir/man
_includedir=usr/include/postgresql
# Directory for server-related libraries. This is hard-coded in
# per-version-dirs.patch.
_srvlibdir=usr/lib/$pkgname

# Programs to be included in the -client subpackage.
# TODO: This was probably originally copied from Debian and I have no idea
#   why these are considered as front-end (client) programs and the rest of
#   the programs are not. So it should be reviewed.
_client_cmds="
	clusterdb
	createdb
	createuser
	dropdb
	dropuser
	pg_basebackup
	pg_dump
	pg_dumpall
	pg_isready
	pg_receivewal
	pg_recvlogical
	pg_restore
	pg_verifybackup
	pgbench
	psql
	reindexdb
	vacuumdb
	"

prepare() {
	default_prepare

	if $_default_ver; then
		cp -rl "$builddir" "$builddir-ifaces"
	else
		msg 'external-libpq.patch'
		patch -p1 < "$srcdir"/external-libpq.patch.txt
	fi
	# Note: This must be applied after clonning $builddir-ifaces.
	patch -p1 < "$srcdir"/libpgport-pkglibdir.patch.txt
}

build() {
	export PYTHON=/usr/bin/python3
	export CFLAGS="${CFLAGS/-Os/-O2}"
	export CPPFLAGS="${CPPFLAGS/-Os/-O2}"

	_configure --with-ldap
	make world

	if $_default_ver; then
		cd "$builddir-ifaces"

		_configure --without-ldap
		local dir; for dir in include common port interfaces bin/pg_config; do
			make -C src/$dir
		done
	fi
}

_configure() {
	local _extra_opts
	# When disable-spinlocks is no longer required - check postgresql-bdr package.
	case "$CARCH" in
		riscv64) _extra_opts='--disable-spinlocks';;
	esac

	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--bindir=/$_bindir \
		--datarootdir=/usr/share \
		--datadir=/$_datadir \
		--docdir=/$_docdir \
		--includedir=/$_includedir \
		--libdir=/usr/lib \
		--mandir=/$_mandir \
		--sysconfdir=/etc/postgresql \
		--disable-rpath \
		--with-system-tzdata=/usr/share/zoneinfo \
		--with-libxml \
		--with-openssl \
		--with-uuid=e2fs \
		--with-llvm \
		--with-icu \
		--with-perl \
		--with-python \
		--with-tcl \
		$_extra_opts \
		"$@"
}

check() {
	_run_tests src/test
	_run_tests src/pl
	_run_tests contrib
}

package() {
	make DESTDIR="$pkgdir" install install-docs

	if $_default_ver; then
		cd "$builddir-ifaces"

		# Override libpq and libecpg files with the build without LDAP support.
		local dir; for dir in common port interfaces bin/pg_config; do
			make -C src/$dir DESTDIR="$pkgdir" bindir=/usr/bin install
		done
		make -C src/include DESTDIR="$pkgdir" install-interfaces
	fi

	cd "$pkgdir"

	# Duplicate of usr/bin/ecpg.
	rm -f ./$_bindir/ecpg

	mkdir -p ./usr/bin
	ln -s /$_bindir/postgres ./usr/bin/postgres$_majorver

	# This file is used by pg_versions and init script.
	echo "$_majorver" > ./$_bindir/PG_VERSION

	install -d -m750 -o postgres -g postgres \
		./etc/postgresql$_majorver \
		./var/lib/postgresql \
		./var/log/postgresql

	local server_cmds=$(_setdiff "$(ls -1 $_bindir)" "$_client_cmds pg_config ecpg PG_VERSION")
	[ "$server_cmds" ] || die 'package: variable server_cmds is empty'

	# These commands are symlinked to /usr/bin by pg_versions script after
	# installation.
	provides="$provides $(echo "$server_cmds" | sed 's/^/cmd:&/')"
}

libpq() {
	pkgdesc="PostgreSQL client library"
	depends=""
	replaces=""

	amove usr/lib/libpq.so.*
}

libpq_dev() {
	pkgdesc="PostgreSQL client library (development files)"
	depends=""
	replaces=""

	amove usr/bin/pg_config

	amove $_includedir/internal/*
	amove $_includedir/libpq-*.h
	amove $_includedir/libpq/*
	amove $_includedir/pg_config*.h
	amove $_includedir/postgres_ext.h

	amove usr/lib/libpq.*
	amove usr/lib/libpgcommon*.a
	amove usr/lib/libpgport*.a
	amove usr/lib/pkgconfig/libpq.pc
}

libecpg() {
	pkgdesc="ECPG - Embedded SQL in C"
	depends=""
	provides="postgresql-libs"  # for backward compatibility (Alpine <3.15)
	replaces="$provides"  # for backward compatibility (Alpine <3.15)

	amove usr/lib/libecpg.so.*
	amove usr/lib/libpgtypes.so.*
}

libecpg_dev() {
	pkgdesc="ECPG - Embedded SQL in C (development files)"
	depends="libpq-dev=$pkgver-r$pkgrel"
	replaces=""

	amove usr/bin/ecpg

	amove $_includedir/ecpg*.h
	amove $_includedir/informix/*
	amove $_includedir/pgtypes*.h
	amove $_includedir/sql3types.h
	amove $_includedir/sqlca.h
	amove $_includedir/sqlda*.h

	amove usr/lib/libecpg.*
	amove usr/lib/libpgtypes.*
	amove usr/lib/pkgconfig/libecpg.pc
	amove usr/lib/pkgconfig/libpgtypes.pc
}

client() {
	pkgdesc="PostgreSQL client"
	depends="postgresql-common"
	_subpkg_common

	local cmd; for cmd in $_client_cmds; do
		amove $_bindir/$cmd
		# These commands are symlinked to /usr/bin by pg_versions script after
		# installation.
		provides="$provides cmd:$cmd"
	done
	amove $_bindir/PG_VERSION
}

jit() {
	pkgdesc="Just-in-time compilation support for PostgreSQL"
	depends="$pkgname=$pkgver-r$pkgrel"
	_subpkg_common

	amove $_srvlibdir/bitcode/*
	amove $_srvlibdir/llvmjit.so
	amove $_srvlibdir/llvmjit_types.bc
}

contrib() {
	pkgdesc="Extension modules distributed with PostgreSQL"
	depends="$pkgname=$pkgver-r$pkgrel"
	_subpkg_common

	cd "$builddir"

	# Avoid installing plperl and plpython extensions, these will be
	# installed into separate subpackages.
	sed -Ei -e 's/(.*_plperl)/#\1/' \
		-e 's/(.*_plpython)/#\1/' \
		contrib/Makefile

	make -C contrib DESTDIR="$subpkgdir" install

	_contrib_common

	provides="$provides $(ls -1 "$subpkgdir"/$_bindir | sed 's/^/cmd:&/')"
}

pltcl() {
	pkgdesc="PL/Tcl procedural language for PostgreSQL"
	depends="$pkgname=$pkgver-r$pkgrel pgtcl"
	_subpkg_common

	amove $_srvlibdir/pltcl.so
	amove $_datadir/extension/pltcl*

	install -m 644 "$srcdir"/pltcl_create_tables.sql -t "$subpkgdir"/$_datadir/
}

plperl() {
	pkgdesc="PL/Perl procedural language for PostgreSQL"
	depends="$pkgname=$pkgver-r$pkgrel"
	_subpkg_common

	amove $_srvlibdir/plperl.so
	amove $_datadir/extension/plperl*
}

plperl_contrib() {
	_plcontrib plperl "PL/Perl"

	cd "$builddir"
	make -C contrib/hstore_plperl DESTDIR="$subpkgdir" install

	_contrib_common
}

plpython3() {
	pkgdesc="PL/Python3 procedural language for PostgreSQL"
	depends="$pkgname=$pkgver-r$pkgrel python3"
	_subpkg_common

	amove $_srvlibdir/plpython3.so
	amove $_datadir/extension/plpython*
}

plpython3_contrib() {
	_plcontrib plpython3 "PL/Python 3"

	cd "$builddir"
	make -C contrib/hstore_plpython DESTDIR="$subpkgdir" install
	make -C contrib/ltree_plpython DESTDIR="$subpkgdir" install

	cd "$subpkgdir"/$_datadir/extension/
	rm ./*plpython2* ./*plpythonu*

	_contrib_common
}

contrib_jit() {
	pkgdesc="Extension modules distributed with PostgreSQL (JIT support)"
	depends="$pkgname-contrib=$pkgver-r$pkgrel"
	install_if="$pkgname-jit $pkgname-contrib=$pkgver-r$pkgrel"
	_subpkg_common

	amove $_srvlibdir/bitcode/*
}

dev() {
	default_dev
	_subpkg_common
	replaces=""

	amove $_srvlibdir/pgxs/*
}

doc() {
	default_doc
	_subpkg_common

	amove $_mandir
}

openrc() {
	default_openrc
	depends="postgresql-common-openrc"

	mkdir -p "$subpkgdir"
}

_plcontrib() {
	local subname="$1"
	pkgdesc="$2 extension modules distributed with PostgreSQL"
	depends="$pkgname-$subname=$pkgver-r$pkgrel"
	install_if="$pkgname-$subname=$pkgver-r$pkgrel $pkgname-contrib=$pkgver-r$pkgrel"
	_subpkg_common
}

_subpkg_common() {
	provides="postgresql${subpkgname#$pkgname}"
	replaces="$provides"  # for backward compatibility
}

_contrib_common() {
	# Move headers, bitcode and docs from subpackage back to pkgdir, so it
	# can be catched by subsequent split functions.
	local dir; for dir in $_includedir $_srvlibdir/bitcode $_docdir; do
		[ -d "$subpkgdir"/$dir ] || continue

		mkdir -p "$pkgdir"/$dir
		cp -rf "$subpkgdir"/$dir/* "$pkgdir"/$dir/
		rm -rf "$subpkgdir"/$dir/*
		rmdir -p "$subpkgdir"/$dir || true
	done
}

_run_tests() {
	local path="$1"; shift

	msg "Running test suite at $path..."
	# Note: some tests fail when running in parallel.
	make -k -j 1 -C "$path" "$@" check MAX_CONNECTIONS=5 || {
		printf "\n%s\n\n" "Trying to find all regression.diffs files in build directory..." >&2
		find "$path" -name regression.diffs | while read -r file; do
			echo "=== test failure: $file ===" >&2
			cat "$file" >&2
		done
		return 1
	}
}

# $1: whitespace-separated items of set A
# $2: whitespace-separated items of set B
# stdout: newline-separated items of A - B
_setdiff() {
	python3 -c 'import sys;print("\n".join(set(sys.argv[1].split()).difference(set(sys.argv[2].split()))))' "$@"
}

sha512sums="
3b39448b291342a5e9b610d410c222aeb85f8acf95632e73e138ae316133af3dadc795a6e706f6447f543cf10df3c786da4f1afa1d91489b50eb77e2d9ed5d84  postgresql-13.8.tar.bz2
1f8e7dc58f5b0a12427cf2fd904ffa898a34f23f3332c8382b94e0d991c007289e7913a69e04498f3d93fc5701855796c207b4b1cc4a0b366f586050124d7fcc  initdb.patch
27e00b58fe5c3899c66fc0dde51846c14701bcfedd132b106d676783ba603e8cbdc6e620f29b52dc892bdaa9302052788cf5e575a1659f61c017a12e0d2ee4d0  perl-rpath.patch
92d28f91b57a01afc81a00d386e87b9e2aa812f341a1578f262af372ee905530205592eda595111827582acceacd1bf244d1df130330003f05e74e4ddb5a7c4f  per-version-dirs.patch
d0040599d7646b709af4e3413bf0c228090f256395e806f3fee230ccc6037ed9c0df1cd160d01b6a73b25a742fdd3fb070733a14a78f53d297fbdbbb44f6f878  unix_socket_directories.patch
c4179fcd8b71791cdc41ea7b622cf82e9bd42ac1de66999234b98a83c0c508c79c492a9301274fe859c06a3f1a8b17b53ab97541ab76801a985f8f0b9b8716e7  disable-broken-tests.patch
14703da0a9441ae1bbad9fe124c4c267526975a22080c5f3e8c3a323164b743158ee10fcff31f18131a64e765c89125410652b317da46e92e962f251079f5a9a  disable-test-collate.icu.utf8.patch
2e33e1ae38d60e0daf3ed18e6eaa9ddf6762b4b1bb7e51f1d2690e3df9d602aa1a700e603ba3ee69314a75a963131c7dc67c1b1f8b7eb5564e9c4253e81a4db4  disable-html-docs.patch
d8eb4274a54b94bed4a2ded7ae775c5a95ca0f051b831b859ccf78bf6d2ea6fe89a9a0611771f6ad85573995a7e3af1fdf5859e20cae3267a52239f12e1b61c3  remove-libecpg_compat.patch
2bd10c4911a50432a00d47bf423c2bb120bacd01a04b41430aa427ae15eafeb3f61e386893211fd147bc7972e4e7f9075ec9e0cd18d50caac14ab0eddb707ef7  czech-snowball-stemmer.patch
5262f4944844bccc839c4441570b9eb2e0792390234ebfdb8ebb7b83380ce5f5de84b038cb03045526da202a185af9c3972c2ae1b9e0e743a95c6e84f4621cf9  make-split-headers.patch
87f470bb8d08050dd955bd6f1da291891970027e6cd001452efc0bd6a57ac46187082393cd5910c289fc6e1daaf0967415393629379c07aed4e78b8e87e5fff7  jit-datalayout-mismatch-on-s390x.patch
7790e4e4374f7bdc6b4484ba87a5fa709d30d3cbdce61ee7bf9c5dfce40cb51c7bd54ab42f4050fb48eede08ef573624d819128e57cc8c976e01202854740308  pg_config-add-major-version.patch
1826ad7dfea705b9f62bb913e45865b9d9aefec9b6115aa9f4a648caa8ce85767ebf342ca1acbc49ca645599360d6218a2b6cd022930d240f2c5702b9e87281b  fix-test-temp-schema-cleanup.patch
b0688d66fdd7d612c24d9aa69bdd80d30787d2d6409b4524c79b41797144fc743213460e6de9c536bfb72da089f92cf89731f15137b1407fd04ca97fd393bfd2  dont-use-locale-a-on-musl.patch
0ebee9cf40a7e84e8eda3998c0dd0f7601d9288233411f45f9710fcafc5f4ca3e4a91e8e1b552cc4f4d2c0e8fa6512703b1094e501f132ea2842db0398e62934  icu-collations-hack.patch
f8ed2b7b96fd22cd87c982151e659d82bcae10033a97f403f7847fce6daa8fc580e998cfb3813af9cb59a12f0c6bcc276397c28b1fc48321eed8c7ba5f3f92ed  libpgport-pkglibdir.patch.txt
6078defb3da67e7df96665cc130d32b69eebfcaf49d92eef368ea8eea8bb311fab56064c104bc97f53da9cd925301bef696b506af33e0b66d65bc6cd41ec7499  external-libpq.patch.txt
5c9bfd9e295dcf678298bf0aa974347a7c311d6e7c2aa76a6920fcb751d01fd1ab77abbec11f3c672f927ad9deaa88e04e370c0b5cd1b60087554c474b748731  pltcl_create_tables.sql
"