CC=@CC@
CFLAGS=@CFLAGS@
LIBS=@LIBS@
LDFLAGS=@LDFLAGS@
prefix = @prefix@
exec_prefix = @exec_prefix@
datarootdir = @datarootdir@
bindir = @bindir@
mandir = @mandir@
INSTALL = @INSTALL@


all: extsmail extsmaild


EXTSMAIL_OBJS = conf_parser.tab.o conf_tokenizer.o extsmail.o common.o

extsmail: ${EXTSMAIL_OBJS}
	${CC} -o extsmail ${EXTSMAIL_OBJS} ${LDFLAGS}


EXTSMAILD_OBJS = conf_parser.tab.o conf_tokenizer.o externals_parser.tab.o \
        externals_tokenizer.o extsmaild.o common.o @COMPAT_STRTONUM@

extsmaild: ${EXTSMAILD_OBJS}
	${CC} -o extsmaild ${EXTSMAILD_OBJS} ${LDFLAGS}


conf_parser.tab.c: conf_parser.y
	yacc -p yyc -d -b conf_parser conf_parser.y


conf_tokenizer.c: conf_tokenizer.l
	lex -Pyyc -oconf_tokenizer.c conf_tokenizer.l


externals_parser.tab.c: externals_parser.y
	yacc -p yye -d -b externals_parser externals_parser.y


externals_tokenizer.c: externals_tokenizer.l
	lex -Pyye -oexternals_tokenizer.c externals_tokenizer.l


install: all
	install -d ${DESTDIR}${bindir}
	install -c -m 555 extsmail ${DESTDIR}${bindir}
	install -c -m 555 extsmaild ${DESTDIR}${bindir}
	install -d ${DESTDIR}${mandir}/man1
	install -d ${DESTDIR}${mandir}/man5
	install -c -m 444 extsmail.1 ${DESTDIR}${mandir}/man1/extsmail.1
	install -c -m 444 extsmail.conf.5 \
	  ${DESTDIR}${mandir}/man5/extsmail.conf.5
	install -c -m 444 extsmail.externals.5 \
          ${DESTDIR}${mandir}/man5/extsmail.externals.5
	install -c -m 444 extsmaild.1 ${DESTDIR}${mandir}/man1/extsmaild.1


clean:
	rm -f extsmail extsmaild ${EXTSMAIL_OBJS} ${EXTSMAILD_OBJS} \
	  conf_parser.tab.[ch] externals_parser.tab.[ch] conf_tokenizer.c \
	  externals_tokenizer.c


distclean: clean
	rm -rf configure Makefile Config.h Config.h.in autom4te.cache config.log \
	  config.status


distrib:
	${MAKE} distclean
	${MAKE} -f Makefile.bootstrap
	@read v?'extsmail version: '; mkdir extsmail-$$v; \
      cp -r `ls | grep -E -v "(autom4te.cache)|(Makefile.bootstrap)|(extsmail-$$v)"` extsmail-$$v; \
      tar cfz extsmail-$$v.tar.gz extsmail-$$v; rm -rf extsmail-$$v
