##################### GENERAL ##################### 
GARNAME = iztaci-netqmail
GARVERSION = 2.1.0
GARELEASE = 2
HOME_URL = http://www.qmail.org/netqmail/
CATEGORIES = net/mail
MASTER_SITES += http://www.qmail.org/
DISTFILES = netqmail-1.06.tar.gz
PATCHFILES = iztaci-netqmail-2.0.0-combined.patch helohost_bindsenders_noany.patch bindsenders_man.patch
MAINTAINER = Felipe Sanchez <izto@asic-linux.com.mx>
LICENSE = Public Domain

DESCRIPTION = A secure and reliable MTA based on Dan Bernstein's qmail
define BLURB

qmail is a secure, reliable, efficient, simple message transfer agent.
It is meant as a replacement for the entire sendmail-binmail system on
typical Internet-connected UNIX hosts.

iztaci-netqmail is a modern fork of Dan Bernstein's original code for
qmail-1.03 + netqmail-1.06 + modern patches and functionality from various
sources.

Patches included:
SMTPAUTH+TLS, force-TLS, ext-todo, DNS-512+, queue-extra-log, validrcptto

endef

##################### PACKAGING #####################


#IZTACI_PACKAGE_PATH =

# Users and groups the binary package will create
# WHEN INSTALLED ON THE DESTINATION SYSTEM

CREATE_GROUPS = nofiles:70 qmail:71

CREATE_USERS  += alias:10:70:$(QMAIL_HOME)/alias:/bin/bash
CREATE_USERS  += qmaild:11:70:$(QMAIL_HOME)
CREATE_USERS  += qmaill:12:70:$(QMAIL_HOME)
CREATE_USERS  += qmailp:13:70:$(QMAIL_HOME)
CREATE_USERS  += qmailq:14:71:$(QMAIL_HOME)
CREATE_USERS  += qmailr:15:71:$(QMAIL_HOME)
CREATE_USERS  += qmails:16:71:$(QMAIL_HOME)
CREATE_USERS  += qmails:16:71:$(QMAIL_HOME)

# This is to be appended to the package's installation script
# Use it to set file owners, permissions, DB initialization, etc.
# Remember any shell variables (Such as $ROOT) have to be escaped
# like this: \$$ROOT

define DOINST_APPEND
# Some people substitute qmail-remote and/or qmail-local for a wrapper. We'll
# see if there is one present and create the appropriate symlinks otherwise.
for prog in qmail-remote qmail-local; do
   if ! test -e \$$ROOT/$(prefix)/bin/\$$prog; then
      ln -svf \$${prog}.bin \$$ROOT/$(prefix)/bin/\$$prog
   fi
done

QMAIL_HOME=$(QMAIL_HOME) QMAIL_BIN=$(prefix)/bin QMAIL_QUEUE=$(QMAIL_HOME)/queue qmail-set-perms

echo
echo ----------------------------------------------------------------------------
echo s6-rc services installed:
echo
echo \"    qmail-services\"
echo \"    qmail-smtpd\"
echo \"    qmail-log\"
echo \"    qmail\"
echo
echo Run \'rc update\' to add them to the live services database.
echo ----------------------------------------------------------------------------
echo
echo If this is a new installation you can initialize its configuration with:
echo
echo $(prefix)/bin/netqmail-config
echo
echo ----------------------------------------------------------------------------
echo
endef

# Required dependencies
define SLACK_REQUIRED
s6-networking
openssl
qmail-utils
qmqtool
endef

# Suggested dependencies
define SLACK_SUGGESTS
endef

# Package conflicts (lprng vs cups for example)
define SLACK_CONFLICTS
endef



##################### BUILDING #####################


CONFIGURE_SCRIPTS = 
BUILD_SCRIPTS = $(WORKSRC)/Makefile
INSTALL_SCRIPTS = custom

CONFIGURE_ARGS = $(DIRPATHS)
NODIRPATHS = 

# Directories to be created as part of the install process.
# Can be inside the final package or just transient dirs we need
# while building it.
INSTALL_DIRS += $(DESTDIR)/etc/skel
INSTALL_DIRS += $(DESTDIR)/etc/s6-rc/source
INSTALL_DIRS += $(DESTDIR)/etc/sysconfig
INSTALL_DIRS += $(DESTDIR)/$(QMAIL_HOME)
INSTALL_DIRS += $(DESTDIR)/$(prefix)/share/doc
INSTALL_DIRS += $(DESTDIR)/$(prefix)/sbin
INSTALL_DIRS += $(DESTDIR)/var/log

# If some dirs are trying to install into /, list their names
# here, such as: prefix bindir mandir
INSTALL_OVERRIDE_DIRS = 


# Dependencies are of the form categorydir/packagedir
# LIBDEPS are for libraries, and DEPENDS are for everything else
DEPENDS =
LIBDEPS =
DEPENDS =
# Builddeps are installed in the build DESTIMG
BUILDDEPS =

##################### GAR #####################

# This should go before any hand-made rules.
include config.mk
include ../level.mk

##################### CUSTOMIZING #####################

pre-build:
	echo $(DESTDIR)/$(QMAIL_HOME) > $(WORKSRC)/conf-destdir
	echo $(QMAIL_HOME) > $(WORKSRC)/conf-qmail
	$(MAKECOOKIE)

install-custom:
	cd $(WORKSRC); make setup check
	$(MAKECOOKIE)

post-install:
	cp -av files/service   $(DESTDIR)/$(QMAIL_HOME)/control
	mv -v  $(DESTDIR)/$(QMAIL_HOME)/man $(DESTDIR)/$(mandir)
	ln -sv $(mandir) $(DESTDIR)/$(QMAIL_HOME)/man

	mv -v  $(DESTDIR)/$(QMAIL_HOME)/doc $(DESTDIR)/$(docdir)
	ln -sv $(docdir) $(DESTDIR)/$(QMAIL_HOME)/doc

	mv -v $(DESTDIR)/$(QMAIL_HOME)/bin $(DESTDIR)/$(bindir)
	ln -sv $(bindir) $(DESTDIR)/$(QMAIL_HOME)/bin

	mv -v $(DESTDIR)/$(QMAIL_HOME)/control $(DESTDIR)/etc/qmail
	ln -sv /etc/qmail $(DESTDIR)/$(QMAIL_HOME)/control

	# For legacy reasons
	if [ "$(QMAIL_HOME)" != "/var/qmail" ]; then \
	   ln -s $(QMAIL_HOME) $(DESTDIR)/var/qmail; \
	fi

	ln -sv $(QMAIL_HOME)/bin/sendmail $(DESTDIR)$(prefix)/sbin/sendmail

	# Some people substitute qmail-remote and/or qmail-local for a wrapper
	# so we move these to another stable name. The doinst.sh script will
	# create the appropriate symlinks if needed.
	mv $(DESTDIR)/$(bindir)/qmail-remote $(DESTDIR)/$(bindir)/qmail-remote.bin
	mv $(DESTDIR)/$(bindir)/qmail-local  $(DESTDIR)/$(bindir)/qmail-local.bin

	$(MAKE) docupatches
	cp -av files/all-patches $(DESTDIR)/$(docdir)

	install -v -m 0644 files/dotqmail-log $(DESTDIR)/var/log/.qmail.new
	install -v -m 0600 files/dotqmail-skel $(DESTDIR)/etc/skel/.qmail.new

	cp -av files/tcpserver $(DESTDIR)/etc

	$(MAKE) s6rc
	$(MAKE) sysconfig

	cp -av files/alias/Maildir $(DESTDIR)/$(QMAIL_HOME)/alias/
	cp -av files/cron.daily $(DESTDIR)/etc

	$(MAKE) gzip-man
	$(MAKE) strip
	$(MAKECOOKIE)
