# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../postfix/postfix.conf
# Copyright (C) 2008 - 2010 The OpenSDE Project
# Copyright (C) 2004 - 2006 The T2 SDE Project
# Copyright (C) 1998 - 2003 Clifford Wolf
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---

pkg_postfix_premake() {
	pkginstalled cyrus-sasl2 && {
		var_append CCARGS  ' ' "-DUSE_SASL_AUTH -I$( pkgprefix includedir cyrus-sasl2 )"
		var_append AUXLIBS ' ' "-L$( pkgprefix libdir cyrus-sasl2 ) -lsasl2"
	}
	pkginstalled openldap && {
		var_append CCARGS  ' ' "-DHAS_LDAP -I$( pkgprefix includedir openldap )"
		var_append AUXLIBS ' ' "-L$( pkgprefix libdir openldap ) -lldap -llber"
	}
	pkginstalled mysql && {
		var_append CCARGS  ' ' "-DHAS_MYSQL -I$( pkgprefix includedir mysql ) -R$( pkgprefix libdir mysql )"
		var_append AUXLIBS ' ' "-L$( pkgprefix libdir mysql ) -lmysqlclient -lz -lm"
		var_append LD_RUN_PATH ':' "$( pkgprefix libdir mysql )"
		export LD_RUN_PATH
	}
	pkginstalled openssl && {
		var_append CCARGS  ' ' "-DHAS_SSL -I$( pkgprefix includedir openssl )"
		var_append AUXLIBS ' ' "-L$( pkgprefix libdir openssl ) -lssl -lcrypto"
	}
	export CCARGS
	export AUXLIBS
	$MAKE -f Makefile.init makefiles
}

pkg_postfix_inmake() {
        chmod +x postfix-install

	# Due to the compare and remove operation in the install file we really
	# need to really modify the config and the filenames - the
	# INSTALL_WRAPPER can not be used.

        sed -i -e "s,man1/mailq.1,man1/mailq_postfix.1," \
	      -e "s,man1/newaliases.1,man1/newaliases_postfix.1," \
	      -e "s,man5/aliases.5,man5/aliases_postfix.5," \
	      conf/postfix-files
	mv man/man5/aliases{,_postfix}.5
	mv man/man1/newaliases{,_postfix}.1
	mv man/man1/mailq{,_postfix}.1
}

pkg_postfix_postmake() {
	./postfix-install -non-interactive \
		sendmail_path=$sbindir/sendmail_postfix \
		newaliases_path=$bindir/newaliases_postfix \
		mailq_path=$bindir/mailq_postfix \
		install_root=$root \
		manpage_directory=$mandir \
		sample_directory=$docdir \
		readme_directory=$docdir
	install_setmailer postfix
}

runconf=0
hook_add premake 5 pkg_postfix_premake
hook_add inmake 5 pkg_postfix_inmake
makeinstopt=
hook_add postmake 5 "pkg_postfix_postmake"