##################### GENERAL ##################### 
GARNAME = dovecot
GARVERSION = 2.3.6
GARELEASE = 3
HOME_URL = https://www.dovecot.org
CATEGORIES = net/mail
MASTER_SITES += https://dovecot.org/releases/2.3/
DISTFILES = dovecot-$(GARVERSION).tar.gz 
PATCHFILES = 
MAINTAINER = Felipe Sanchez <izto@asic-linux.com.mx>
LICENSE = GPL

DESCRIPTION = IMAP and POP3 server 
define BLURB
endef

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


#IZTACI_PACKAGE_PATH =

# Users and groups the binary package will create
# WHEN INSTALLED ON THE DESTINATION SYSTEM
CREATE_GROUPS = dovenull:64 dovecot:65
CREATE_USERS  = dovenull:64:64 dovecot:65:65

# 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
echo
echo ------------------------------------------------------------------
echo s6-rc services installed:
echo
echo \"    dovecot-server\"
echo \"    dovecot-log\"
echo \"    dovecot\"
echo
echo Run \'rc update\' to add them to the live services database.
echo ------------------------------------------------------------------
echo
endef

# Required dependencies
define SLACK_REQUIRED
bzip2
libcap
libtirpc
linux-pam
openssl
xz
zlib
endef

# Suggested dependencies
define SLACK_SUGGESTS
iztaci-netqmail
endef

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



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


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

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/s6-rc/source
INSTALL_DIRS += $(DESTDIR)/etc/sysconfig
INSTALL_DIRS += $(DESTDIR)/etc/dovecot

# 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:
	cd $(WORKSRC); sed -e "s;#include <unistd.h>;&\n#include <crypt.h>;" -i src/auth/mycrypt.c
	cp -v files/checkvpw-dovecot-wrapper.c $(WORKSRC)
	$(MAKECOOKIE)

post-build:
	cd $(WORKSRC); cc checkvpw-dovecot-wrapper.c -o checkvpw-dovecot-wrapper
	$(MAKECOOKIE)

test:
	chown -Rv $(TESTUSER) $(WORKSRC)
	cd $(WORKSRC); su $(TESTUSER) -s /bin/bash -c "PATH=$$PATH make -k check"
	$(MAKECOOKIE)

post-install:
	$(MAKE) test
	echo '#!include auth-checkvpw.conf.ext' >> $(DESTDIR)$(docdir)/example-config/conf.d/10-auth.conf
	cp -v files/auth-checkvpw.conf.ext $(DESTDIR)$(docdir)/example-config/conf.d
	cp -av $(DESTDIR)/usr/share/doc/$(DISTNAME)/example-config/. $(DESTDIR)/etc/dovecot
	$(MAKE) etc-new
	$(MAKE) s6rc
	$(MAKE) sysconfig
	$(MAKE) strip
	$(MAKE) gzip-man
	$(MAKECOOKIE)
