# Tanım: Gelişmiş nesne-ilişkisel veritabanı yönetim sistemi (ORDBMS). 
# URL: http://www.postgresql.org/docs
# Paketçi: milisarge
# Gerekler: python3 
# Grup: sistem

isim=postgresql
surum=10.5
devir=1
kaynak=(https://ftp.postgresql.org/pub/source/v$surum/postgresql-$surum.tar.bz2
		postgresql.logrotate
		postgresql.pam
		postgresql-check-db-dir
		postgresql_db_yukselt)

derle() {
	cd $isim-$surum
	sed -i '/DEFAULT_PGSOCKET_DIR/s@/tmp@/run/postgresql@' src/include/pg_config_manual.h &&
	./configure \
	--prefix=/usr \
	--sysconfdir=/etc \
	--includedir=/usr/include \
	--datarootdir=/usr/share \
	--datadir=/usr/share/postgresql \
	--with-openssl \
	--with-tcl \
	--with-perl \
	--with-pam \
	--with-python \
	--with-libxml \
	--with-libxslt \
	--enable-thread-safety \
	--with-system-tzdata=/usr/share/zoneinfo \
	--enable-nls \
	--disable-rpath

	make
	make DESTDIR=$PKG install
	
	PG_EXTENSIONS=${PG_EXTENSIONS:-"adminpack pgcrypto ltree xml2 postgres_fdw file_fdw hstore citext"}

	if [ "x$PG_EXTENSIONS" = "xALL" ];then
		cd $SRC/$isim-$surum/contrib
		make all
		make install-strip DESTDIR=$PKG
	else
		for ext in $PG_EXTENSIONS; do
			cd $SRC/$isim-$surum/contrib/$ext
			make
			make install-strip DESTDIR=$PKG
		done
	fi
	
	# logrotate betiği
	mkdir -p $PKG/etc/logrotate.d
    cat $SRC/$isim.logrotate > $PKG/etc/logrotate.d/$isim
    
    mkdir -p "${PKG}/etc/pam.d"
	install -Dm 755 "${SRC}/postgresql-check-db-dir" -t "${PKG}/usr/bin"
	install -Dm 755 "${SRC}/postgresql_db_yukselt" -t "${PKG}/usr/bin"
	install -Dm 644 "${SRC}/postgresql.pam" "${PKG}/etc/pam.d/postgresql"
	
	cd /sources/milis.git/ayarlar/servisler
	make DESTDIR=$PKG kur-$isim   
	
	rm -rf $PKG/usr/share/doc
	rm -rf $PKG/etc/sysconfig
}
