
@SET_MAKE@

DESTDIR     =
prefix      = @prefix@
exec_prefix = @exec_prefix@
bindir      = @bindir@
libdir      = @libdir@
includedir  = @includedir@
mandir      = @mandir@

CC          = @CC@
CFLAGS      = @CFLAGS@ @DEFS@
LDFLAGS     = @LDFLAGS@
LIBS        = @LIBS@

SHTOOL      = ./shtool
POD2MAN     = pod2man

PROG = lmtp2nntp
HDRS = lmtp.h nntp.h sa.h argz.h shpat_match.h msg.h trace.h
OBJS = lmtp2nntp.o lmtp.o nntp.o sa.o argz.o shpat_match.o msg.o trace.o version.o

all: lmtp2nntp lmtp2nntp.1

.c.o:
	$(CC) $(CFLAGS) -c $<

$(PROG): Makefile $(OBJS) $(HDRS)
	$(CC) $(LDFLAGS) -o $(PROG) $(OBJS) $(LIBS)

lmtp2nntp.1: lmtp2nntp.pod
	VS=`$(SHTOOL) version -lc -dshort version.c`; \
	VL=`$(SHTOOL) version -lc -dlong version.c`; \
	$(POD2MAN) --section=1 --center="mail to news gateway" \
               --release="$$VS" --date="$$VL" \
               lmtp2nntp.pod >lmtp2nntp.1 

install: all
	$(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(bindir) $(DESTDIR)$(mandir)/man1
	$(SHTOOL) install -c -s -m 755 lmtp2nntp $(DESTDIR)$(bindir)/
	$(SHTOOL) install -c -m 644 lmtp2nntp.1 $(DESTDIR)$(mandir)/man1/

clean:
	-rm -f *.core
	-rm -f dmalloc.log test/dmalloc.log
	-rm -f $(PROG)
	-rm -f $(OBJS)

distclean: clean
	-rm -f config.h config.status config.log config.cache
	-rm -f Makefile

realclean: distclean
	-rm -f lmtp2nntp.1
	-rm -f config.h.in
	-rm -f configure
	-rm -f shtool

new-version:
	$(SHTOOL) version -lc -n lmtp2nntp -p lmtp2nntp_ -e version.c

dist: distclean
	@$(SHTOOL) fixperm -v .; \
	V=`$(SHTOOL) version -lc -dshort version.c`; \
	$(SHTOOL) tarball -o lmtp2nntp-$${V}.tar.gz -d lmtp2nntp-$${V} -u ossp -g ossp \
	                  -e 'CVS,\.cvsignore,\.[ao],^\.,autogen.sh,test,*.tar.gz' -c 'gzip --best' .

check: lmtp2nntp
	@cd test && ./run.sh

