# $Id: Portfile,v 1.29 2003/08/05 09:28:59 jkh Exp $

PortSystem 1.0
name			mysql
version			3.23.52
categories		databases
maintainers		eric@opendarwin.org
description		Multithreaded SQL database server
long_description	MySQL is an open-source, multi-threaded SQL database \
			with a command syntax very similar to mSQL.
homepage		http://www.mysql.com/
platforms		darwin
master_sites		ftp://ftp.sunet.se/pub/unix/databases/relational/mysql/Downloads/MySQL-3.23/ \
			ftp://ftp.FreeBSD.org/pub/FreeBSD/distfiles/ \
			http://distfiles.opendarwin.org/:lt

set filename		${portname}-${portversion}${extract.sufx}
distfiles		${filename} ltconfig13:lt ltmain13:lt
extract.only		${filename}
depends_lib		lib:libdl.1:dlcompat

checksums		mysql-3.23.52.tar.gz md5 \
			88705b7f38e64b5c21ebb68c77b75e5a \
			ltconfig13 md5 ea53f42a550c9f9e653758a8ed91574e \
			ltmain13 md5 e094ae92724c4015dbab97de151c2525

post-patch {		system "cp ${distpath}/ltconfig13 ${worksrcpath}/ltconfig"
			system "cp ${distpath}/ltmain13 ${worksrcpath}/ltmain.sh"
}

set dbdir		${prefix}/var/db/mysql

configure.env		LDFLAGS=-L${prefix}/lib\\ -lncurses \
			CPPFLAGS=-I${prefix}/include

configure.args		--localstatedir=${dbdir} \
			--without-bench

pre-destroot		{ system "install -o root -m 755 -d ${dbdir}" }

variant server	{
	depends_run path:/Library/StartupItems/DarwinPortsStartup:DarwinPortsStartup

	post-destroot {
		addgroup mysql
		set gid [existsgroup mysql]
		adduser mysql gid=${gid} realname=MySQL\ Server

		#system "${destroot}${prefix}/bin/mysql_install_db"
		#system "chown -R mysql:mysql ${dbdir}"
		
		system "install -o root -m 755 -d ${destroot}${prefix}/etc/rc.d"
		set script [open ${destroot}${prefix}/etc/rc.d/mysql.sh w 0755]
		puts $script "#!/bin/sh"
		puts $script "${prefix}/bin/safe_mysqld --user=mysql &"
		close $script
	}
}
