# Don't edit Makefile!  Use conf-* for configuration.
#
# Generated by spac see http://untroubled.org/spac/

SHELL=/bin/sh

DEFAULT: all

all: libraries programs docs

backend-echo.so: makeso backend-echo.c mailfront.h responses.h constants.h
	./makeso backend-echo.c  -lbg -lbg-sysdeps 

backend-qmail.so: makeso backend-qmail.c mailfront.h responses.h constants.h conf_qmail.c
	./makeso backend-qmail.c  -lbg -lbg-sysdeps 

builtins.o: compile builtins.c mailfront-internal.h mailfront.h responses.h constants.h
	./compile builtins.c

clean: TARGETS
	rm -f `cat TARGETS`

clean-spac: clean AUTOFILES
	rm -f `cat AUTOFILES`

compile: conf-cc conf-bgincs
	( bgincs=`head -n 1 conf-bgincs`; \
	  echo '#!/bin/sh'; \
	  echo 'source=$$1; shift'; \
	  echo 'base=`echo "$$source" | sed -e s:\\\\.c$$::`'; \
	  echo exec `head -n 1 conf-cc` -I. "-I'$${bgincs}'" '-o $${base}.o -c $$source $${1+"$$@"}'; \
	) >compile
	chmod 755 compile

conf_modules.c: conf-modules
	head -n 1 conf-modules | \
	  sed -e 's/"/\\"/g' \
	      -e 's/^/const char conf_modules[] = "/' \
	      -e 's/$$/";/' >conf_modules.c

conf_qmail.c: conf-qmail
	head -n 1 conf-qmail | \
	  sed -e 's/"/\\"/g' \
	      -e 's/^/const char conf_qmail[] = "/' \
	      -e 's/$$/";/' >conf_qmail.c

dl.lib: compile load
	@echo -n 'Checking for -ldl: '
	@echo 'main() { ; }' >trylib-ldl.c
	@{ ./compile trylib-ldl.c && ./load trylib-ldl -ldl; } >/dev/null 2>&1 \
	  && { echo -ldl >dl.lib; echo yes; } \
	  || { echo -n >dl.lib; echo no; }
	@rm -f trylib-ldl.c trylib-ldl.o trylib-ldl

docs: 

getprotoenv.o: compile getprotoenv.c mailfront.h responses.h constants.h
	./compile getprotoenv.c

imapfront-auth: imapfront-auth.o load timeout.o socket.lib
	./load imapfront-auth timeout.o -lcvm-sasl -lcvm-v2client -lbg `cat socket.lib`

imapfront-auth.o: compile imapfront-auth.c
	./compile imapfront-auth.c

install: INSTHIER conf-bin conf-modules conf-include
	bg-installer -v <INSTHIER
	bg-installer -c <INSTHIER

iobytes.o: compile iobytes.c
	./compile iobytes.c

libraries: pop3.a plugin-add-received.so plugin-check-fqdn.so plugin-relayclient.so plugin-require-auth.so plugin-counters.so plugin-qmail-validate.so plugin-clamav.so plugin-mailrules.so backend-echo.so plugin-reject.so protocol-qmtp.so plugin-force-file.so protocol-qmqp.so backend-qmail.so plugin-patterns.so plugin-cvm-validate.so protocol-smtp.so plugin-spamassassin.so

load: conf-ld conf-bglibs
	( bglibs=`head -n 1 conf-bglibs`; \
	  echo '#!/bin/sh';\
	  echo 'main="$$1"; shift';\
	  echo exec `head -n 1 conf-ld` -L. "-L'$${bglibs}'" "-Wl,-R'$${bglibs}'" '-o "$$main" "$$main.o" $${1+"$$@"}' -lbg-sysdeps; \
	) >load
	chmod 755 load

mailfront: mailfront.o load builtins.o getprotoenv.o iobytes.o modules.o responses.o session.o timeout.o socket.lib dl.lib
	./load mailfront builtins.o getprotoenv.o iobytes.o modules.o responses.o session.o timeout.o -lbg -rdynamic `cat socket.lib` `cat dl.lib`

mailfront.o: compile mailfront.c mailfront-internal.h mailfront.h responses.h constants.h
	./compile mailfront.c

makelib: 
	( echo '#!/bin/sh'; \
	  echo 'lib="$$1"; shift';\
	  echo 'rm -f "$$lib"';\
	  echo 'ar cr "$$lib" $${1+"$$@"}';\
	  echo 'ranlib "$$lib"';\
	) >makelib
	chmod 755 makelib

makeso: conf-ccso conf-ld conf-bgincs conf-bglibs
	( bgincs=`head -n 1 conf-bgincs`; \
	  bglibs=`head -n 1 conf-bglibs`; \
	  echo '#!/bin/sh'; \
	  echo 'source=$$1; shift'; \
	  echo 'base=`echo "$$source" | sed -e s:\\\\.c$$::`'; \
	  echo exec `head -n 1 conf-ccso` -DSHARED -I. "-I'$${bgincs}'" -L. "-L'$${bglibs}'" '-o $${base}.so $$source $${1+"$$@"}'; \
	) >makeso
	chmod 755 makeso

modules.o: compile modules.c mailfront-internal.h mailfront.h responses.h constants.h conf_modules.c
	./compile modules.c

plugin-add-received.so: makeso plugin-add-received.c mailfront.h responses.h constants.h
	./makeso plugin-add-received.c  -lbg -lbg-sysdeps 

plugin-check-fqdn.so: makeso plugin-check-fqdn.c mailfront.h responses.h constants.h
	./makeso plugin-check-fqdn.c  -lbg -lbg-sysdeps 

plugin-clamav.so: makeso plugin-clamav.c mailfront.h responses.h constants.h
	./makeso plugin-clamav.c  -lbg -lbg-sysdeps 

plugin-counters.so: makeso plugin-counters.c mailfront.h responses.h constants.h
	./makeso plugin-counters.c  -lbg -lbg-sysdeps 

plugin-cvm-validate.so: makeso plugin-cvm-validate.c mailfront.h responses.h constants.h
	./makeso plugin-cvm-validate.c  -lcvm-v2client -lbg -lbg-sysdeps 

plugin-force-file.so: makeso plugin-force-file.c mailfront.h responses.h constants.h
	./makeso plugin-force-file.c   

plugin-mailrules.so: makeso plugin-mailrules.c mailfront.h responses.h constants.h
	./makeso plugin-mailrules.c  -lbg -lbg-sysdeps 

plugin-patterns.so: makeso plugin-patterns.c mailfront.h responses.h constants.h
	./makeso plugin-patterns.c  -lbg -lbg-sysdeps 

plugin-qmail-validate.so: makeso plugin-qmail-validate.c mailfront.h responses.h constants.h conf_qmail.c
	./makeso plugin-qmail-validate.c  -lbg -lbg-sysdeps 

plugin-reject.so: makeso plugin-reject.c mailfront.h responses.h constants.h
	./makeso plugin-reject.c   

plugin-relayclient.so: makeso plugin-relayclient.c mailfront.h responses.h constants.h
	./makeso plugin-relayclient.c  -lbg -lbg-sysdeps 

plugin-require-auth.so: makeso plugin-require-auth.c mailfront.h responses.h constants.h
	./makeso plugin-require-auth.c   

plugin-spamassassin.so: makeso plugin-spamassassin.c mailfront.h responses.h constants.h
	./makeso plugin-spamassassin.c  -lbg -lbg-sysdeps 

pop3-capa.o: compile pop3-capa.c pop3.h constants.h
	./compile pop3-capa.c

pop3-mainloop.o: compile pop3-mainloop.c pop3.h constants.h
	./compile pop3-mainloop.c

pop3-response.o: compile pop3-response.c pop3.h constants.h
	./compile pop3-response.c

pop3.a: makelib iobytes.o timeout.o pop3-capa.o pop3-mainloop.o pop3-response.o
	./makelib pop3.a iobytes.o timeout.o pop3-capa.o pop3-mainloop.o pop3-response.o

pop3front-auth: pop3front-auth.o load pop3.a socket.lib
	./load pop3front-auth pop3.a -lcvm-sasl -lcvm-v2client -lbg `cat socket.lib`

pop3front-auth.o: compile pop3front-auth.c pop3.h constants.h
	./compile pop3front-auth.c

pop3front-maildir: pop3front-maildir.o load pop3.a
	./load pop3front-maildir pop3.a -lbg -lcvm-sasl -lcvm-v2client 

pop3front-maildir.o: compile pop3front-maildir.c pop3.h constants.h
	./compile pop3front-maildir.c

programs: mailfront pop3front-auth imapfront-auth pop3front-maildir qmtpfront-echo qmtpfront-qmail smtpfront-echo smtpfront-qmail qmqpfront-qmail qmqpfront-echo

protocol-qmqp.so: makeso protocol-qmqp.c mailfront.h responses.h constants.h qmtp.h qmtp-respond.c netstring.c
	./makeso protocol-qmqp.c qmtp-respond.c netstring.c -lbg -lbg-sysdeps 

protocol-qmtp.so: makeso protocol-qmtp.c mailfront.h responses.h constants.h qmtp.h qmtp-respond.c netstring.c
	./makeso protocol-qmtp.c qmtp-respond.c netstring.c -lbg -lbg-sysdeps 

protocol-smtp.so: makeso protocol-smtp.c mailfront.h responses.h constants.h
	./makeso protocol-smtp.c  -lcvm-sasl -lcvm-v2client -lbg -lbg-sysdeps 

qmqpfront-echo: warn-auto.sh qmqpfront-echo.sh
	cat warn-auto.sh qmqpfront-echo.sh >qmqpfront-echo
	chmod 755 qmqpfront-echo

qmqpfront-qmail: warn-auto.sh qmqpfront-qmail.sh
	cat warn-auto.sh qmqpfront-qmail.sh >qmqpfront-qmail
	chmod 755 qmqpfront-qmail

qmtpfront-echo: warn-auto.sh qmtpfront-echo.sh
	cat warn-auto.sh qmtpfront-echo.sh >qmtpfront-echo
	chmod 755 qmtpfront-echo

qmtpfront-qmail: warn-auto.sh qmtpfront-qmail.sh
	cat warn-auto.sh qmtpfront-qmail.sh >qmtpfront-qmail
	chmod 755 qmtpfront-qmail

responses.o: compile responses.c responses.h
	./compile responses.c

session.o: compile session.c mailfront-internal.h mailfront.h responses.h constants.h
	./compile session.c

smtpfront-echo: warn-auto.sh smtpfront-echo.sh
	cat warn-auto.sh smtpfront-echo.sh >smtpfront-echo
	chmod 755 smtpfront-echo

smtpfront-qmail: warn-auto.sh smtpfront-qmail.sh
	cat warn-auto.sh smtpfront-qmail.sh >smtpfront-qmail
	chmod 755 smtpfront-qmail

socket.lib: compile load
	@echo -n 'Checking for socket libraries: '
	@echo 'main() { ; }' >trylib-lsocket.c
	@{ ./compile trylib-lsocket.c && ./load trylib-lsocket -lsocket -lnsl; } >/dev/null 2>&1 \
	  && { echo -lsocket -lnsl >socket.lib; echo -lsocket -lnsl; } \
	  || { : >socket.lib; echo no; }
	@rm -f trylib-lsocket.c trylib-lsocket.o trylib-lsocket

timeout.o: compile timeout.c
	./compile timeout.c

