PortSystem 1.0

name			postgresql7
version			7.4.24
revision        3
categories		databases
platforms		darwin
maintainers		nomaintainer
license			Permissive
description		The most advanced open-source database available anywhere
long_description PostgreSQL is Object-Relational Database Management System. \
			It supports almost all SQL constructs, including transactions, \
			subselects, and user-defined types and functions. Write-ahead \
			logging means increased performance while retaining data \
			integrity. \
			This version does not work on Mac OS X Intel!

homepage		https://www.postgresql.org/
master_sites		http://ftp.de.postgresql.org/mirror/postgresql//source/v${version} \
			postgresql:source/v${version}

checksums           md5     8287efcb6d4d0f2a631fd35149e8b8d2 \
                    sha1    a38d8045d2d01f501671e1a4b72473d7f8739107 \
                    rmd160  63a7908aef92ddc591d58332ff4bd0bdaa6b0fcf
use_bzip2		yes

depends_lib		port:readline \
				path:lib/libssl.dylib:openssl \
				port:zlib \
				port:bison

distname		postgresql-${version}

set libdir		${prefix}/lib/pgsql7
configure.args	--sysconfdir=${prefix}/etc/pgsql7 \
				--bindir=${libdir}/bin \
				--libdir=${libdir} \
				--includedir=${prefix}/include/pgsql7 \
				--datadir=${prefix}/share/${name} \
				--mandir=${prefix}/share/man \
				--docdir=${prefix}/share/doc/${name} \
				--with-docdir=${prefix}/share/doc/${name} \
				--with-includes=${prefix}/include \
				--with-libraries=${prefix}/lib \
				--with-openssl=${prefix} \
				--with-rendezvous \
				--with-readline \
				--with-zlib \
				--enable-thread-safety \
				--enable-integer-datetimes \
				--enable-multibyte \
				--enable-unicode

build.type		gnu

post-build	{
	# build autovacuum
	system "cd ${worksrcpath}/contrib/pg_autovacuum && ${build.cmd}"
	# build tsearch2
	system "cd ${worksrcpath}/contrib/tsearch2 && ${build.cmd}"
}

test.run		yes
test.target		check

# install headers too
destroot.target-append  install-all-headers
post-destroot	{
	# install autovacuum
	xinstall -m 755 -s ${worksrcpath}/contrib/pg_autovacuum/pg_autovacuum \
		${destroot}${libdir}/bin
	# install tsearch2
	system "cd ${worksrcpath}/contrib/tsearch2 && ${build.cmd} install ${destroot.destdir}"
	# symlinks
	system "cd ${destroot}${prefix}/bin && ln -sf ${libdir}/bin/psql psql7"
	# nuke nonsense
	system "cd ${destroot}${prefix}/share && rm -rf doc"
}

# Defaults for database
set dbdir	${prefix}/var/db/pgsql7/defaultdb
set logdir	${prefix}/var/log/pgsql7
set dbuser	postgres7
set dbgrp	postgres

variant perl description {add Perl support} {
	configure.args-append	--with-perl
	depends_lib-append	bin:perl:perl5
}

variant java  description {add Java support} {
	configure.args-append	--with-java
	depends_build		port:apache-ant
	depends_lib-append	bin:java:kaffe
	configure.env-append	ANT=${prefix}/share/java/apache-ant/bin/ant
}

variant tcltk description {add tcl, tk support} {
	configure.args-append	--with-tcl \
				--with-tclconfig=${prefix}/lib \
				--with-tkconfig=${prefix}/lib
	configure.env-append	TCLSH=${prefix}/bin/tclsh
	depends_lib-append	port:tcl port:tk
}

variant server description {add startup item for server} {
	startupitem.create	yes
	startupitem.init	\
"PGCTL=${libdir}/bin/pg_ctl"
	startupitem.start	\
"su ${dbuser} -c \"\${PGCTL} -D \${POSTGRESQL7DATA:=${dbdir}} start -l ${logdir}/postgres.log\""
	startupitem.stop	\
"su ${dbuser} -c \"\${PGCTL} -D \${POSTGRESQL8DATA:=${dbdir}} stop -s -m fast\""

	pre-destroot {
		xinstall -m 755 -d ${destroot}${dbdir} \
			${destroot}${prefix}/var/log/pgsql \
			${destroot}${prefix}/var/db/pgsql
		# Add User postgres:postgres
		addgroup ${dbuser}
		set gid [existsgroup ${dbgrp}]
		adduser ${dbuser} shell=/bin/sh gid=${gid} \
			home=${prefix}/var/db/pgsql7 \
			realname=PostgreSQL-7\ Server
	}

	post-destroot {
		destroot.keepdirs ${destroot}${prefix}/var/db/pgsql
		system "cd ${destroot}${prefix}/var/log/pgsql && \
			touch pgsql.log pg_autovacuum.log"

		foreach d { db/pgsql log/pgsql log/pgsql/pgsql.log log/pgsql/pg_autovacuum.log } {
			file attributes ${destroot}${prefix}/var/${d} \
				-group ${dbgr} -owner ${dbuser}
		}
	}

	post-install {
		ui_msg "\nTo create a database instance, after install do\n\
			sudo su ${dbuser} -c \'${libdir}/bin/initdb -D ${dbdir}\'"
	}
}

platform darwin i386 {
	extract { return -code error "\n\nThis platform is not supported by PostgreSQL 7. Please migrate to the PostgreSQL 8 series!\n" }
}

livecheck.type	none
livecheck.url	${homepage}
livecheck.regex	(7.4.\[0-9\]+)