# $Id: Makefile.am,v 1.123 2007/10/07 02:50:45 mrsam Exp $
#
# Copyright 1998 - 2007 Double Precision, Inc.  See COPYING for
# distribution information.

AUTOMAKE_OPTIONS=dist-bzip2

SUBDIRS=@LIBLTDL_SUBDIR@ @DBSUBDIR@ md5 sha1 libhmac numlib makedat userdb rfc822 random128 liblock liblog
DIST_SUBDIRS=libltdl gdbmobj bdbobj md5 sha1 libhmac numlib makedat userdb rfc822 random128 liblock liblog

INCLUDES = $(LTDLINCL)

modules=@LIBAUTHUSERDB@ \
	@LIBAUTHPAM@ @LIBAUTHPWD@ @LIBAUTHSHADOW@ \
	@LIBAUTHPGSQL@ @LIBAUTHLDAP@ @LIBAUTHMYSQL@ \
	@LIBAUTHCUSTOM@ @LIBAUTHVCHKPW@ @LIBAUTHPIPE@

pkglibexecdir=$(libexecdir)/courier-authlib
pkglibexec_SCRIPTS=authsystem.passwd

pkglib_LTLIBRARIES=libcourierauth.la \
	libcourierauthsasl.la libcourierauthsaslclient.la \
	libcourierauthcommon.la $(modules)
sbin_SCRIPTS=authdaemond
sbin_PROGRAMS=authtest authenumerate authpasswd
bin_PROGRAMS=courierauthconfig

EXTRA_LTLIBRARIES=libauthuserdb.la \
	libauthpam.la libauthpwd.la libauthshadow.la \
	libauthvchkpw.la \
	libauthpgsql.la \
	libauthldap.la \
	libauthmysql.la \
	libauthcustom.la \
	libauthpipe.la

CLEANFILES=authldaprc.h authmysqlrc.h authdaemonrc.h vpopmail_config.h \
	authpgsqlrc.h authpiperc.h authdaemon \
	authlib.3 authlib.html packageversion.h \
	authchangepwdir.h sbindir.h pkglibdir.h pkgincludedir.h \
	mailusergroup.h authinfodaemondlist.c permissions.dat \
	README.authdebug.html

DISTCLEANFILES=dbobj.config README_authlib.html

commonlibdep=libcourierauthcommon.la
commonldflags=-module -rpath $(pkglibdir) -export-symbols-regex 'courier_auth.*_init'
commonlibadd=libcourierauthcommon.la

libcourierauthcommon_t=@CRYPTLIBS@
libcourierauthcommon_la_SOURCES= \
	auth.h courierauth.h \
	authpwdenumerate.c \
	authsaslfrombase64.c authsasltobase64.c \
	authstaticlist.h \
	authsyschangepwd.c authsyscommon.c \
	cramlib.c cramlib.h \
	checkpassword.c cryptpassword.c \
	$(checkpasswordmd5c) $(checkpasswordsha1c)

libcourierauthcommon_la_DEPENDENCIES=libcourierauth.la
libcourierauthcommon_la_LIBADD=libcourierauth.la
libcourierauthcommon_la_LDFLAGS=$(libcourierauthcommon_t:%=-Wl,%)

libcourierauth_la_SOURCES=authdaemon.c authdaemonlib.c preauthdaemon.c \
	authmoduser2.c authmoduser3.c debug.c \
	courierauthdebug.h \
	authoption.c
libcourierauth_la_LIBADD=@HMACLIB@ @MD5LIB@ @SHA1LIB@ numlib/libnumlib.la \
	random128/librandom128.la rfc822/libencode.la
libcourierauth_la_LDFLAGS=@NETLIBS@

# The userdb module

libauthuserdb_t=userdb/libuserdb.la @dblibrary@ @LIBGDBM@ @LIBDB@
libauthuserdb_la_SOURCES=authuserdb.c preauthuserdb.c preauthuserdbcommon.c \
	 authuserdbpwd.c
libauthuserdb_la_DEPENDENCIES=libcourierauthcommon.la @dblibrary@
libauthuserdb_la_LIBADD=$(commonlibadd) $(libauthuserdb_t)
libauthuserdb_la_LDFLAGS=$(commonldflags)

# the authpam module

libauthpam_t=-lpam @SHADOWLIBS@ @AUTHPAMCRYPT@ @LIBDL@

libauthpam_la_SOURCES=authpam.c preauthpam.c authwait.h
libauthpam_la_DEPENDENCIES=$(commonlibdep)
libauthpam_la_LIBADD=$(commonlibadd)
libauthpam_la_LDFLAGS=$(commonldflags) $(libauthpam_t)

# The authpwd module

libauthpwd_la_SOURCES=authpwd.c preauthpwd.c
libauthpwd_la_DEPENDENCIES=$(commonlibdep)
libauthpwd_la_LIBADD=$(commonlibadd)
libauthpwd_la_LDFLAGS=$(commonldflags)

# The authshadow module

libauthshadow_t=@SHADOWLIBS@

libauthshadow_la_SOURCES=authshadow.c preauthshadow.c
libauthshadow_la_DEPENDENCIES=$(commonlibdep)
libauthshadow_la_LIBADD=$(commonlibadd)
libauthshadow_la_LDFLAGS=$(commonldflags) $(libauthshadow_t)

# The authvchkpw module

libauthvchkpw_t=@VPOPMAILLIBS@ @LIBM@
libauthvchkpw_la_SOURCES=authvchkpw.c authvchkpwlib.c preauthvchkpw.c
libauthvchkpw_la_DEPENDENCIES=$(commonlibdep)
libauthvchkpw_la_LIBADD=$(commonlibadd)
libauthvchkpw_la_LDFLAGS=$(commonldflags) $(libauthvchkpw_t)

authvchkpw.lo: authvchkpw.c vpopmail_config.h
preauthvchkpw.lo: preauthvchkpw.c vpopmail_config.h

vpopmail_config.h:
	echo '#include "@vpopmail_home@/include/config.h"' >vpopmail_config.h

# The authpgsql module

libauthpgsql_t=@PGSQL_LIBS@ @LIBM@ @NETLIBS@

libauthpgsql_la_SOURCES=authpgsql.c preauthpgsql.c authpgsqllib.c authpgsql.h
libauthpgsql_la_DEPENDENCIES=$(commonlibdep)
libauthpgsql_la_LIBADD=$(commonlibadd)
libauthpgsql_la_LDFLAGS=$(commonldflags) $(libauthpgsql_t)

authpgsqllib.lo: authpgsqllib.c authpgsqlrc.h


if HAVE_AUTHPGSQL

install-authpgsqlrc:
	$(mkinstalldirs) $(DESTDIR)`dirname @authpgsqlrc@` || :
	$(INSTALL_DATA) -m 660 $(srcdir)/authpgsqlrc \
		$(DESTDIR)@authpgsqlrc@.dist
	-chown @mailuser@ $(DESTDIR)@authpgsqlrc@.dist
	-chgrp @mailgroup@ $(DESTDIR)@authpgsqlrc@.dist

uninstall-authpgsqlrc:
	rm -f $(DESTDIR)@authpgsqlrc@.dist

else

install-authpgsqlrc:
	@:

uninstall-authpgsqlrc:
	@:
endif

authpgsqlrc.h:
	echo "#define AUTHPGSQLRC \"@authpgsqlrc@\"" >authpgsqlrc.h


# The authldap module

libauthldap_t=@LDAPLIBS@ @NETLIBS@
libauthldap_la_SOURCES=authldap.c preauthldap.c authldaplib.c authldap.h
libauthldap_la_DEPENDENCIES=$(commonlibdep)
libauthldap_la_LIBADD=$(commonlibadd)
libauthldap_la_LDFLAGS=$(commonldflags) $(libauthldap_t)

authldaplib.lo: authldaplib.c authldaprc.h

if HAVE_LDAP

install-authldaprc:
	$(mkinstalldirs) $(DESTDIR)`dirname @authldaprc@` || :
	$(INSTALL_DATA) -m 660 $(srcdir)/authldaprc \
		$(DESTDIR)@authldaprc@.dist
	-chown @mailuser@ $(DESTDIR)@authldaprc@.dist
	-chgrp @mailgroup@ $(DESTDIR)@authldaprc@.dist

uninstall-authldaprc:
	rm -f $(DESTDIR)@authldaprc@.dist

else
install-authldaprc:
	@:

uninstall-authldaprc:
	@:
endif

authldaprc.h:
	echo "#define AUTHLDAPRC \"@authldaprc@\"" >authldaprc.h

# The authmysql module

libauthmysql_t=@MYSQL_LIBS@ @LIBM@ @NETLIBS@

libauthmysql_la_SOURCES=authmysql.c preauthmysql.c authmysqllib.c authmysql.h
libauthmysql_la_DEPENDENCIES=$(commonlibdep)
libauthmysql_la_LIBADD=$(commonlibadd)
libauthmysql_la_LDFLAGS=$(commonldflags) $(libauthmysql_t)

authmysqllib.lo: authmysqllib.c authmysqlrc.h

if HAVE_AUTHMYSQL
install-authmysqlrc:
	$(mkinstalldirs) $(DESTDIR)`dirname @authmysqlrc@` || :
	$(INSTALL_DATA) -m 660 $(srcdir)/authmysqlrc \
		$(DESTDIR)@authmysqlrc@.dist
	-chown @mailuser@ $(DESTDIR)@authmysqlrc@.dist
	-chgrp @mailgroup@ $(DESTDIR)@authmysqlrc@.dist

uninstall-authmysqlrc:
	rm -f $(DESTDIR)@authmysqlrc@.dist

else
install-authmysqlrc:
	@:

uninstall-authmysqlrc:
	@:
endif

authmysqlrc.h:
	echo "#define AUTHMYSQLRC \"@authmysqlrc@\"" >authmysqlrc.h

# The authcustom module

libauthcustom_la_SOURCES=authcustom.c preauthcustom.c authcustom.h
libauthcustom_la_DEPENDENCIES=$(commonlibdep)
libauthcustom_la_LIBADD=$(commonlibadd)
libauthcustom_la_LDFLAGS=$(commonldflags)

# The authpipe module
libauthpipe_la_SOURCES=authpipe.c authpipelib.h authpipelib.c
libauthpipe_la_DEPENDENCIES=$(commonlibdep)
libauthpipe_la_LIBADD=$(commonlibadd)
libauthpipe_la_LDFLAGS=$(commonldflags)

authpipelib.lo: authpipelib.c authpipelib.h authpiperc.h

authpiperc.h:
	echo "#define PIPE_PROGRAM \"@authProg@\"" >authpiperc.h


#
# AUTHMODULES should be listed in the best authentication order
#

noinst_PROGRAMS= \
	authdaemontest authmksock \
	authdaemondprog


if HAVE_MD5
checkpasswordmd5c=checkpasswordmd5.c
else
checkpasswordmd5c=
endif

if HAVE_SHA1
checkpasswordsha1c=checkpasswordsha1.c
else
checkpasswordsha1c=
endif

install-authdaemonrc:
	$(mkinstalldirs) $(DESTDIR)`dirname @authdaemonrc@` || :
	sed 's/@ALLMODULES@/$(modules:lib%.la=%)/' <authdaemonrc >authdaemonrc.tmp
	$(INSTALL_DATA) -m 660 authdaemonrc.tmp $(DESTDIR)@authdaemonrc@.dist
	rm -f authdaemonrc.tmp
	-chown @mailuser@ $(DESTDIR)@authdaemonrc@.dist
	-chgrp @mailgroup@ $(DESTDIR)@authdaemonrc@.dist

uninstall-authdaemonrc:
	rm -f $(DESTDIR)@authdaemonrc@.dist

authdaemonrc.h:
	echo "#define AUTHDAEMONRC \"@authdaemonrc@\"" >authdaemonrc.h
	echo "#define AUTHDAEMONVAR \"@authdaemonvar@\"" >>authdaemonrc.h
	echo "#define AUTHDAEMONPID AUTHDAEMONVAR \"/pid\"" >>authdaemonrc.h
	echo "#define AUTHDAEMONSOCK AUTHDAEMONVAR \"/socket\"" >>authdaemonrc.h
	echo "#define AUTHDAEMONLOCK AUTHDAEMONVAR \"/lock\"" >>authdaemonrc.h

HTMLFILES=README.html NEWS.html INSTALL.html \
		README.authmysql.html README.authpostgres.html

EXTRA_DIST=$(HTMLFILES) sysconftool COPYING COPYING.GPL\
	authldap.schema \
	checkpasswordmd5.c checkpasswordsha1.c \
	authldaprc authmysqlrc authpgsqlrc README.ldap \
	README.authmysql.myownquery \
	README.authdebug.html.in \
	courier-authlib.spec \
	courier-authlib.lpspec pgpkeys.txt \
	README_authlib.html.in \
	authlib.html.in authlib.3.in \
	authpasswd.html authpasswd.1 \
	authtest.html authtest.1 \
	auth_sasl.html auth_sasl.3 \
	auth_generic.html auth_generic.3 \
	auth_login.html auth_login.3 \
	auth_passwd.html auth_passwd.3 \
	auth_getuserinfo.html auth_getuserinfo.3 \
	auth_enumerate.html auth_enumerate.3 \
	auth_getoption.html auth_getoption.3 \
	samplepipe.pl

README: README.html
	links -dump -no-references README.html >README

NEWS: NEWS.html
	links -dump -no-references NEWS.html >NEWS

INSTALL: INSTALL.html
	rm -f INSTALL; links -dump -no-references INSTALL.html >INSTALL

libcourierauthsasl_la_SOURCES=\
	authsasl.c courierauthsasl.h \
	authsaslcram.c authsasllogin.c authsaslplain.c \
	authsaslfrombase64.c authsasltobase64.c
libcourierauthsasl_la_LIBADD=libcourierauth.la
libcourierauthsasl_la_LDFLAGS=-export-symbols-regex '^auth_sasl$$'

libcourierauthsaslclient_la_SOURCES=courierauthsaslclient.h \
	authsaslclient.c authsaslclient.h authsaslclientcram.c \
	authsaslclientcrammd5.c authsaslclientcramsha1.c \
	authsaslclientlogin.c authsaslclientplain.c \
	authsaslfrombase64.c authsasltobase64.c
libcourierauthsaslclient_la_LIBADD=libcourierauth.la
libcourierauthsaslclient_la_LDFLAGS=-export-symbols-regex '^auth_sasl_client$$'

include_HEADERS=courier_auth_config.h courierauth.h courierauthsasl.h \
	courierauthsaslclient.h courierauthdebug.h

courierauthconfig_SOURCES=authinfo.c

authpasswd_SOURCES=authpasswd.c
authpasswd_LDADD=libcourierauthcommon.la \
        libhmac/libhmac.la md5/libmd5.la sha1/libsha1.la rfc822/libencode.la

authtest_SOURCES=authtest.c
authtest_DEPENDENCIES=libcourierauth.la
authtest_LDADD=libcourierauth.la

authenumerate_SOURCES=authenumerate.c
authenumerate_DEPENDENCIES = libcourierauth.la \
	numlib/libnumlib.la
authenumerate_LDADD = libcourierauth.la \
	numlib/libnumlib.la
authenumerate_LDFLAGS=

#
# The main daemon.

authdaemondprog_SOURCES=authdaemond.c
authdaemondprog_DEPENDENCIES=libcourierauthcommon.la \
	liblock/liblock.la $(modules) \
	libhmac/libhmac.la md5/libmd5.la sha1/libsha1.la \
	rfc822/libencode.la numlib/libnumlib.la
authdaemondprog_LDADD=$(LIBLTDL) libcourierauthcommon.la liblock/liblock.la \
	libhmac/libhmac.la md5/libmd5.la sha1/libsha1.la \
	rfc822/libencode.la numlib/libnumlib.la
authdaemondprog_LDFLAGS=-export-dynamic $(modules:%=-dlopen %) @NETLIBS@

authdaemontest_SOURCES=authdaemontest.c
authdaemontest_DEPENDENCIES=libcourierauthcommon.la
authdaemontest_LDADD=libcourierauthcommon.la @NETLIBS@
authdaemontest_LDFLAGS=-static

authmksock_SOURCES=authmksock.c
authmksock_LDADD=@NETLIBS@

man3=authlib.3 auth_generic.3 auth_login.3 auth_getuserinfo.3 \
	auth_enumerate.3 auth_passwd.3 auth_getoption.3 auth_sasl.3
man1=authpasswd.1 authtest.1

man_MANS=$(man1) $(man3)

BUILT1=authlib.html authldaprc.h authmysqlrc.h authpgsqlrc.h authpiperc.h \
	authdaemonrc.h vpopmail_config.h packageversion.h \
	authchangepwdir.h sbindir.h \
	pkglibdir.h pkgincludedir.h mailusergroup.h \
	README_authlib.html
BUILT_SOURCES=$(BUILT1) $(man3:%.3=%.html) $(man1:%.1=%.html)

authchangepwdir.h: config.status
	echo '#define AUTHCHANGEPWDIR "$(pkglibexecdir)"' >authchangepwdir.h

sbindir.h: config.status
	echo '#define SBINDIR "@sbindir@"' >sbindir.h

pkglibdir.h: config.status
	echo '#define PKGLIBDIR "$(pkglibdir)"' >pkglibdir.h

packageversion.h: config.status
	echo '#define PKGVERSION "@PACKAGE_VERSION@"' >packageversion.h

pkgincludedir.h: config.status
	echo '#define PKGINCLUDEDIR "$(includedir)"' >pkgincludedir.h

mailusergroup.h: config.status
	echo '#define MAILUSER "@mailuser@"' >mailusergroup.h
	echo '#define MAILGROUP "@mailgroup@"' >>mailusergroup.h

noinst_DATA=$(BUILT_SOURCES)

dist-hook:
	for f in $(BUILT1) ; do rm -f $(distdir)/$$f; done

# automake still a bit stupid...

install-data-hook: install-authdaemonrc install-authpgsqlrc \
	install-authldaprc install-authmysqlrc
	:

install-exec-hook:
	$(mkinstalldirs) $(DESTDIR)$(bindir) || :
	$(mkinstalldirs) $(DESTDIR)$(sbindir) || :
	$(mkinstalldirs) $(DESTDIR)$(pkglibexecdir) || :
	$(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) authdaemondprog $(DESTDIR)$(pkglibexecdir)/authdaemond
	$(mkinstalldirs) $(DESTDIR)@authdaemonvar@ || :
	chmod 750 $(DESTDIR)@authdaemonvar@
	-chown @mailuser@ $(DESTDIR)@authdaemonvar@
	-chgrp @mailgroup@ $(DESTDIR)@authdaemonvar@
	test "@LIBAUTHUSERDB@" = "" && exit 0 ;\
		$(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) makedat/makedatprog \
				$(DESTDIR)$(pkglibexecdir)/makedatprog ; \
		$(INSTALL_SCRIPT) userdb/vchkpw2userdb \
				$(DESTDIR)$(sbindir)/vchkpw2userdb ; \
		$(INSTALL_SCRIPT) userdb/pw2userdb \
				$(DESTDIR)$(sbindir)/pw2userdb ; \
		$(INSTALL_SCRIPT) userdb/makeuserdb \
				$(DESTDIR)$(sbindir)/makeuserdb ; \
		$(INSTALL_SCRIPT) userdb/userdb.pl \
				$(DESTDIR)$(sbindir)/userdb ; \
		$(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) userdb/userdbpw \
				$(DESTDIR)$(sbindir)/userdbpw ; \
		$(INSTALL_SCRIPT) userdb-test-cram-md5.pl \
				$(DESTDIR)$(sbindir)/userdb-test-cram-md5

uninstall-hook: uninstall-authldaprc uninstall-authdaemonrc uninstall-authmysqlrc uninstall-authpgsqlrc
	rm -f $(DESTDIR)$(pkglibexecdir)/authdaemond
	test "@AUTHUSERDB@" = "" && exit 0 ;\
		rm -f $(DESTDIR)$(pkglibexecdir)/makedatprog \
				$(DESTDIR)$(sbindir)/vchkpw2userdb \
				$(DESTDIR)$(sbindir)/pw2userdb \
				$(DESTDIR)$(sbindir)/makeuserdb \
				$(DESTDIR)$(sbindir)/userdb \
				$(DESTDIR)$(sbindir)/userdbpw \
				$(DESTDIR)$(sbindir)/userdb-test-cram-md5

authlib.html: authlib.html.in
	CONFIG_FILES=authlib.html CONFIG_HEADERS= $(SHELL) ./config.status

authlib.3: authlib.3.in
	CONFIG_FILES=authlib.3 CONFIG_HEADERS= $(SHELL) ./config.status

if HAVE_SGML
authpasswd.html: authpasswd.sgml docbook/sgml2html
	docbook/sgml2html authpasswd.sgml authpasswd.html

authpasswd.1: authpasswd.sgml docbook/sgml2man
	docbook/sgml2man authpasswd.sgml authpasswd.1

authtest.html: authtest.sgml docbook/sgml2html
	docbook/sgml2html authtest.sgml authtest.html

authtest.1: authtest.sgml docbook/sgml2man
	docbook/sgml2man authtest.sgml authtest.1

authlib.html.in: authlib.sgml docbook/sgml2html
	docbook/sgml2html authlib.sgml authlib.html.in

authlib.3.in: authlib.sgml docbook/sgml2man
	docbook/sgml2man authlib.sgml authlib.3.in

README_authlib.html.in: README_authlib.sgml docbook/sgml2html
	docbook/sgml2html README_authlib.sgml README_authlib.html.in

auth_generic.html: auth_generic.sgml authcallback.sgml docbook/sgml2html
	docbook/sgml2html auth_generic.sgml auth_generic.html

auth_generic.3: auth_generic.sgml authcallback.sgml docbook/sgml2man
	docbook/sgml2man auth_generic.sgml auth_generic.3

auth_login.html: auth_login.sgml authcallback.sgml docbook/sgml2html
	docbook/sgml2html auth_login.sgml auth_login.html

auth_login.3: auth_login.sgml authcallback.sgml docbook/sgml2man
	docbook/sgml2man auth_login.sgml auth_login.3

auth_getuserinfo.html: auth_getuserinfo.sgml authcallback.sgml docbook/sgml2html
	docbook/sgml2html auth_getuserinfo.sgml auth_getuserinfo.html

auth_getuserinfo.3: auth_getuserinfo.sgml authcallback.sgml docbook/sgml2man
	docbook/sgml2man auth_getuserinfo.sgml auth_getuserinfo.3

auth_enumerate.html: auth_enumerate.sgml docbook/sgml2html
	docbook/sgml2html auth_enumerate.sgml auth_enumerate.html

auth_enumerate.3: auth_enumerate.sgml docbook/sgml2man
	docbook/sgml2man auth_enumerate.sgml auth_enumerate.3

auth_passwd.html: auth_passwd.sgml docbook/sgml2html
	docbook/sgml2html auth_passwd.sgml auth_passwd.html

auth_passwd.3: auth_passwd.sgml docbook/sgml2man
	docbook/sgml2man auth_passwd.sgml auth_passwd.3

auth_getoption.html: auth_getoption.sgml docbook/sgml2html
	docbook/sgml2html auth_getoption.sgml auth_getoption.html

auth_getoption.3: auth_getoption.sgml docbook/sgml2man
	docbook/sgml2man auth_getoption.sgml auth_getoption.3

auth_sasl.html: auth_sasl.sgml docbook/sgml2html
	docbook/sgml2html auth_sasl.sgml auth_sasl.html

auth_sasl.3: auth_sasl.sgml docbook/sgml2man
	docbook/sgml2man auth_sasl.sgml auth_sasl.3


endif

README_authlib.html: README_authlib.html.in config.status
	CONFIG_FILES=README_authlib.html CONFIG_HEADERS= $(SHELL) ./config.status

authdaemond.o: authdaemonrc.h authdaemond.c


install-migrate: authmigrate
	@SHELL@ authmigrate

install-configure:
	test -f $(DESTDIR)@authdaemonrc@.dist && @SYSCONFTOOL@ $(DESTDIR)@authdaemonrc@.dist || true
	test -f $(DESTDIR)@authmysqlrc@.dist && @SYSCONFTOOL@ $(DESTDIR)@authmysqlrc@.dist || true
	test -f $(DESTDIR)@authpgsqlrc@.dist && @SYSCONFTOOL@ $(DESTDIR)@authpgsqlrc@.dist || true
	test -f $(DESTDIR)@authldaprc@.dist && @SYSCONFTOOL@ $(DESTDIR)@authldaprc@.dist || true

# For maintainer's use only

distrelease:
	umask 022; $(MAKE) -$(MAKEFLAGS) distcheck
	$(MAKE) -$(MAKEFLAGS) rpm
	socksify cvs commit
	socksify cvs tag -F @PACKAGE@-latest
	$(MAKE) -$(MAKEFLAGS)
	$(MAKE) -$(MAKEFLAGS)
	rm -f @PACKAGE@.spec @PACKAGE@.lpspec
	$(MAKE) -$(MAKEFLAGS) @PACKAGE@.spec @PACKAGE@.lpspec
	$(MAKE) -$(MAKEFLAGS) dist

tagrelease:
	socksify cvs tag -F -r @PACKAGE@-latest \
               `echo @PACKAGE@-@VERSION@ | tr '.' '-'`

rpm: rpm-build

rpm-build:
	$(MAKE) -$(MAKEFLAGS) bump.rpm.release
	$(MAKE) -$(MAKEFLAGS) dist
	$(MAKE) -$(MAKEFLAGS) dorpm

lpm: lpm-build

lpm-build:
	$(MAKE) -$(MAKEFLAGS) bump.rpm.release
	$(MAKE) -$(MAKEFLAGS) dist
	$(MAKE) -$(MAKEFLAGS) dolpm

dolpm:
	rm -rf lpm
	mkdir lpm
	lpbuild `test "@REPOSITORY@" == "" || echo --define "repository=1"` --srcbuild -o lpm @PACKAGE@-@VERSION@.tar.bz2

publish: publish-@REPOSITORY@

publish-dev:
	$(MAKE) -$(MAKEFLAGS) dopublish SUBDIR=dev

publish-prod:
	$(MAKE) -$(MAKEFLAGS) dopublish SUBDIR=prod

dopublish:
	lpbuild --resign lpm/*
	rm -rf lpmtmp
	mkdir lpmtmp
	ln lpm/* lpmtmp
	rm -f lpmtmp/*debuginfo*
	mv lpmtmp/*.src.lp repository-$(SUBDIR)/`lpm -q --distribution`/sources
	mv lpmtmp/*.lp repository-$(SUBDIR)/`lpm -q --distribution`/packages
	rm -rf lpmtmp
	ls -t repository-$(SUBDIR)/`lpm -q --distribution`/sources | tail -n +6 | xargs -r -n 1 lpm --erase repository-$(SUBDIR)
	lpm --sync repository-$(SUBDIR)
	rsync -a -v --delete-after repository-$(SUBDIR)/`lpm -q --distribution`/. headache:lpmtool.com/www/repositories/$(SUBDIR)/courier-authlib/`lpm -q --distribution`

dorpm:
	rm -rf rpm/BUILD/*
	rm -f rpm/RPMS/*/*
	rm -f rpm/SOURCES/*
	rm -f rpm/SPECS/*
	rm -f rpm/SRPMS/*
	unset MAKEFLAGS ; test ! -f $$HOME/.bashrc || . $$HOME/.bashrc; rpmbuild -ta --clean @PACKAGE@-@VERSION@.tar.bz2

bump.rpm.release: @PACKAGE@.spec @PACKAGE@.lpspec
	test -f $(srcdir)/rpm.release && . $(srcdir)/rpm.release; \
	NEXT_RELEASE=0; \
	test "$$VERSION" = "@VERSION@" && NEXT_RELEASE="$$RELEASE"; \
	RELEASE=`expr $$NEXT_RELEASE + 1`; \
	echo "VERSION=@VERSION@" >$(srcdir)/rpm.release; \
	echo "RELEASE=$$RELEASE" >>$(srcdir)/rpm.release; \
	sed 's/^Release: .*/Release: '$$RELEASE'%{?dist}%{?courier_release}/' \
		<@PACKAGE@.spec >@PACKAGE@.spec.new; \
	mv @PACKAGE@.spec.new @PACKAGE@.spec; \
	sed 's/^Release: .*/Release: '$$RELEASE'/' \
		<@PACKAGE@.lpspec >@PACKAGE@.lpspec.new; \
	mv @PACKAGE@.lpspec.new @PACKAGE@.lpspec

upload-beta:
	rm -f @PACKAGE@-@VERSION@.tar.bz2.sig; gpg --detach-sign --default-key mrsam@courier-mta.com @PACKAGE@-@VERSION@.tar.bz2; test -f @PACKAGE@-@VERSION@.tar.bz2.sig || exit 1
	socksify ssh grace.speakeasy.net echo @PACKAGE@-@VERSION@.tar.bz2 `ls -l @PACKAGE@-@VERSION@.tar.bz2 | awk ' { print $$5 } '` \>courier-mta.org/@PACKAGE@.beta
	ssh headache 'cd torrents.courier-mta.org/pub/@PACKAGE@-dev && rm -rf @PACKAGE@-@VERSION@ && mkdir @PACKAGE@-@VERSION@ && echo seeder_args=--max_upload_rate 50 >@PACKAGE@-@VERSION@.info && ls -t | sed 1,6d | xargs rm -rf '
	scp @PACKAGE@-@VERSION@.tar.bz2 @PACKAGE@-@VERSION@.tar.bz2.sig headache:torrents.courier-mta.org/pub/@PACKAGE@-dev/@PACKAGE@-@VERSION@

upload-dist:
	rm -f @PACKAGE@-@VERSION@.tar.bz2.sig; gpg --detach-sign --default-key mrsam@courier-mta.com @PACKAGE@-@VERSION@.tar.bz2; test -f @PACKAGE@-@VERSION@.tar.bz2.sig || exit 1
	socksify cvs tag -F -r @PACKAGE@-latest \
               `echo @PACKAGE@-@VERSION@ | tr '.' '-'`
	socksify perl -e 'use Net::FTP; $$ftp=Net::FTP->new("upload.sourceforge.net.", Debug => 1, Passive => 1 ) || die; $$ftp->login("anonymous", "anonymous") || die; $$ftp->cwd("/incoming") && $$ftp->binary() && $$ftp->hash(1) && $$ftp->put("@PACKAGE@-@VERSION@.tar.bz2") && $$ftp->put("@PACKAGE@-@VERSION@.tar.bz2.sig") && exit 0; die;'
	ssh headache 'cd torrents.courier-mta.org/pub/@PACKAGE@ && rm -rf @PACKAGE@-@VERSION@ && mkdir @PACKAGE@-@VERSION@ && echo seeder_args=--max_upload_rate 50 >@PACKAGE@-@VERSION@.info && ls -t | sed 1,6d | xargs rm -rf '
	scp @PACKAGE@-@VERSION@.tar.bz2 @PACKAGE@-@VERSION@.tar.bz2.sig headache:torrents.courier-mta.org/pub/@PACKAGE@/@PACKAGE@-@VERSION@


release-dist:
	test -z "$(SFPASSWD)" && exit 1; exit 0
	./changelog.pl >changelog.txt
	emacs releasenotes.txt
	test -f releasenotes.txt || exit 1
	socksify ../sftools/release.pl mrsam $(SFPASSWD) courier authlib @VERSION@ releasenotes.txt changelog.txt @PACKAGE@-@VERSION@.tar.bz2 @PACKAGE@-@VERSION@.tar.bz2.sig
	socksify ssh grace.speakeasy.net rm -f courier-mta.org/@PACKAGE@.beta

HTMLDOCFILES=$(HTMLFILES) README.authdebug.html README_authlib.html \
	$(man3:%.3=%.html) $(man1:%.1=%.html)

htmldoc: $(HTMLDOCFILES)
	for f in $^; do d=`basename $$f`; test "$$d" = "README.html" && d="index2.html"; xsltproc --nonet $$HOME/www/www.courier-mta.org/xsl/authlib.xsl $$f | perl -ne 's~\$(id):.*\$$~\$(id):'"$$h"'\$$~; print' >html/$$d; done


syntax highlighted by Code2HTML, v. 0.9.1