description="Advanced object-relational database management system (ORDBMS)."
url="http://www.postgresql.org/docs"

packager="spiky <spiky@nutyx.org>"
contributors="Pierre,Tnut"

makedepends=(readline flex bison perl python libxml2 libxslt openldap pam kerberos)
run=(shadow)

PKGMK_GROUPS=(lib doc man devel service)

name=postgresql
version=14.6
runyx_version=20201011

source=(https://downloads.tuxfamily.org/nutyx/files/runyx-${runyx_version}.tar.xz
	https://ftp.postgresql.org/pub/source/v$version/$name-$version.tar.bz2)

prepare() {
groupadd -g 41 postgres
useradd -c "PostgreSQL Server" -g postgres -d /srv/pgsql/data \
 -u 41 postgres
}

build() {
cd $name-$version
# prepare
sed -i '/DEFAULT_PGSOCKET_DIR/s@/tmp@/run/postgresql@' \
src/include/pg_config_manual.h

# configure
./configure --prefix=/usr \
--docdir=/usr/share/doc/$name-$version \
--enable-thread-safety \
--with-system-tzdata=/usr/share/zoneinfo \
--with-pam

# build
make

# install
make DESTDIR=$PKG install
make DESTDIR=$PKG install-docs

# service
cd $SRC/runyx-${runyx_version}
make DESTDIR=$PKG install-sysv-postgresql
make DESTDIR=$PKG install-runyx-postgresql
make DESTDIR=$PKG install-sysd-postgresql

}
service() {
cd $PKG
bsdtar -r -f \
$PKGMK_PACKAGE_DIR/${name}.${group}${PKGMK_BUILDVER}any.${PKGMK_PACKAGE_EXT} \
etc/rc.d usr/bin/initdb etc/init lib/init lib/systemd
rm -r etc/rc.d usr/bin/initdb etc/init lib/init lib/systemd
}
