SHELL	= /bin/sh
SRCS	= postmap.c 
OBJS	= postmap.o
HDRS	= 
TESTSRC	= 
DEFS	= -I. -I$(INC_DIR) -D$(SYSTYPE)
CFLAGS	= $(DEBUG) $(OPT) $(DEFS)
TESTPROG= 
PROG	= postmap
INC_DIR	= ../../include
LIBS	= ../../lib/lib$(LIB_PREFIX)global$(LIB_SUFFIX) \
	../../lib/lib$(LIB_PREFIX)util$(LIB_SUFFIX)
NOSLEEP = LD_PRELOAD=../../lib/nosleep.so

.c.o:;	$(CC) $(CFLAGS) -c $*.c

$(PROG):	$(OBJS) $(LIBS)
	$(CC) $(CFLAGS) $(SHLIB_RPATH) -o $@ $(OBJS) $(LIBS) $(SYSLIBS)

$(OBJS): ../../conf/makedefs.out

Makefile: Makefile.in
	cat ../../conf/makedefs.out $? >$@

update: ../../bin/$(PROG)

../../bin/$(PROG): $(PROG)
	cp $(PROG) ../../bin

tests:	test1 test2 fail_test quote_test file_test lmdb_abb_test \
	lmdb_bulk_test lmdb_incr_test cdb_bulk_test mode_conflict_test

root_tests:

test1:	$(PROG) map.in map-abc1.ref map-ghi1.ref map-uABC1.ref
	rm -f main.cf
	touch -t 197101010000 main.cf
	$(SHLIB_ENV) $(VALGRIND) ./$(PROG) -c . map.in
	for key in abc ghi; \
	do \
	    $(SHLIB_ENV) $(VALGRIND) ./$(PROG) -c . -q $${key} map.in | diff map-$${key}1.ref -; \
	done
	$(SHLIB_ENV) $(VALGRIND) ./$(PROG) -c . -f map.in
	for key in ABC; \
	do \
	    $(SHLIB_ENV) $(VALGRIND) ./$(PROG) -c . -fq $${key} map.in | diff map-u$${key}1.ref -; \
	done
	rm -f map.in.db main.cf

test2:	$(PROG) map.in map-abc2.ref map-ghi2.ref map-uABC2.ref
	rm -f main.cf
	touch -t 197101010000 main.cf
	$(SHLIB_ENV) $(VALGRIND) ./$(PROG) -c . map.in
	for key in abc ghi; \
	do \
	    echo $${key} | $(SHLIB_ENV) $(VALGRIND) ./$(PROG) -c . -q - map.in | diff map-$${key}2.ref -; \
	done
	$(SHLIB_ENV) $(VALGRIND) ./$(PROG) -c . -f map.in
	for key in ABC; \
	do \
	    echo $${key} | $(SHLIB_ENV) $(VALGRIND) ./$(PROG) -c . -fq - map.in | diff map-u$${key}2.ref -; \
	done
	rm -f map.in.db main.cf

fail_test: $(PROG) aliases fail_test.in fail_test.ref
	rm -f main.cf
	touch -t 197101010000 main.cf
	-($(SHLIB_ENV) MAIL_CONFIG=. $(NOSLEEP) sh fail_test.in || exit 0) >fail_test.tmp 2>&1
	diff fail_test.ref fail_test.tmp
	rm -f fail_test.tmp main.cf

quote_test: $(PROG) aliases quote_test.in quote_test.ref
	rm -f main.cf
	touch -t 197101010000 main.cf
	rm -f quote_test_map.*
	$(SHLIB_ENV) MAIL_CONFIG=. sh quote_test.in >quote_test.tmp 2>&1
	diff quote_test.ref quote_test.tmp
	rm -f quote_test.tmp quote_test_map.* main.cf

file_test: $(PROG) file_test.in file_test.ref
	rm -f main.cf
	touch -t 197101010000 main.cf
	rm -f file_test_map.* postmap-file-1 postmap-file-2
	$(SHLIB_ENV) MAIL_CONFIG=. $(NOSLEEP) sh file_test.in >file_test.tmp 2>&1
	diff file_test.ref file_test.tmp
	rm -f file_test.tmp file_test_map.* postmap-file-1 postmap-file-2 \
	    main.cf

mode_conflict_test: $(PROG) mode_conflict_test.in mode_conflict_test.ref
	rm -f main.cf
	touch -t 197101010000 main.cf
	$(SHLIB_ENV) MAIL_CONFIG=. $(NOSLEEP) sh -x mode_conflict_test.in >mode_conflict_test.tmp 2>&1
	diff mode_conflict_test.ref mode_conflict_test.tmp
	rm -f mode_conflict_test.tmp main.cf

cdb_bulk_test: $(PROG)
	rm -f cdb_bulk.cdb main.cf
	tr A-Z a-z < /usr/share/dict/words| \
	    sed -e 's/.*/&	&/' -e 10000q| LANG=C sort -u >cdb_bulk
	touch -t 197101010000 main.cf
	($(SHLIB_ENV) $(VALGRIND) ./postmap -c . cdb:cdb_bulk; \
	$(SHLIB_ENV) $(VALGRIND) ./postmap -c . -s cdb:cdb_bulk | \
	    LANG=C sort > cdb_bulk.tmp)
	cmp cdb_bulk cdb_bulk.tmp
	rm -f cdb_bulk cdb_bulk.tmp cdb_bulk.cdb main.cf

lmdb_abb_test: $(PROG) lmdb_abb lmdb_abb.ref
	rm -f main.cf
	touch -t 197101010000 main.cf
	rm -f lmdb_abb.lmdb
	($(SHLIB_ENV) $(VALGRIND) ./postmap -c . lmdb:lmdb_abb; \
	$(SHLIB_ENV) $(VALGRIND) ./postmap -c . -s lmdb:lmdb_abb | sort) >lmdb_abb.tmp 2>&1
	diff lmdb_abb.ref lmdb_abb.tmp
	rm -f lmdb_abb.tmp lmdb_abb.lmdb

lmdb_bulk_test: $(PROG)
	rm -f lmdb_retry.lmdb main.cf
	tr A-Z a-z < /usr/share/dict/words| \
	    sed -e 's/.*/&	&/' -e 10000q| LANG=C sort -u >lmdb_retry
	echo lmdb_map_size=10240 >main.cf
	touch -t 197101010000 main.cf
	($(SHLIB_ENV) $(VALGRIND) ./postmap -c . lmdb:lmdb_retry; \
	$(SHLIB_ENV) $(VALGRIND) ./postmap -c . -s lmdb:lmdb_retry | \
	    LANG=C sort > lmdb_retry.tmp)
	cmp lmdb_retry lmdb_retry.tmp
	rm -f lmdb_retry lmdb_retry.tmp lmdb_retry.lmdb main.cf

lmdb_incr_test: $(PROG)
	rm -f lmdb_retry.lmdb main.cf
	tr A-Z a-z < /usr/share/dict/words| \
	    sed -e 's/.*/&	&/' -e 1000q| LANG=C sort -u >lmdb_retry
	echo lmdb_map_size=10240 >main.cf
	touch -t 197101010000 main.cf
	($(SHLIB_ENV) $(VALGRIND) ./postmap -ic . lmdb:lmdb_retry <lmdb_retry; \
	$(SHLIB_ENV) $(VALGRIND) ./postmap -c . -s lmdb:lmdb_retry | \
	    LANG=C sort > lmdb_retry.tmp)
	cmp lmdb_retry lmdb_retry.tmp
	rm -f lmdb_retry lmdb_retry.tmp lmdb_retry.lmdb main.cf

clean:
	rm -f *.o *core $(PROG) $(TESTPROG) *.tmp junk *.db main.cf master.cf

tidy:	clean

depend: $(MAKES)
	(sed '1,/^# do not edit/!d' Makefile.in; \
	set -e; for i in [a-z][a-z0-9]*.c; do \
	    $(CC) -E $(DEFS) $(INCL) $$i | grep -v '[<>]' | sed -n -e '/^# *1 *"\([^"]*\)".*/{' \
	    -e 's//'`echo $$i|sed 's/c$$/o/'`': \1/' \
	    -e 's/o: \.\//o: /' -e p -e '}' ; \
	done | LANG=C sort -u) | grep -v '[.][o][:][ ][/]' >$$$$ && mv $$$$ Makefile.in
	@$(EXPORT) make -f Makefile.in Makefile 1>&2

# do not edit below this line - it is generated by 'make depend'
postmap.o: ../../include/argv.h
postmap.o: ../../include/check_arg.h
postmap.o: ../../include/clean_env.h
postmap.o: ../../include/dict.h
postmap.o: ../../include/dict_db.h
postmap.o: ../../include/dict_proxy.h
postmap.o: ../../include/header_opts.h
postmap.o: ../../include/mail_conf.h
postmap.o: ../../include/mail_dict.h
postmap.o: ../../include/mail_params.h
postmap.o: ../../include/mail_parm_split.h
postmap.o: ../../include/mail_task.h
postmap.o: ../../include/mail_version.h
postmap.o: ../../include/maillog_client.h
postmap.o: ../../include/mime_state.h
postmap.o: ../../include/mkmap.h
postmap.o: ../../include/msg.h
postmap.o: ../../include/msg_vstream.h
postmap.o: ../../include/myflock.h
postmap.o: ../../include/mymalloc.h
postmap.o: ../../include/readlline.h
postmap.o: ../../include/rec_type.h
postmap.o: ../../include/set_eugid.h
postmap.o: ../../include/split_at.h
postmap.o: ../../include/stringops.h
postmap.o: ../../include/sys_defs.h
postmap.o: ../../include/vbuf.h
postmap.o: ../../include/vstream.h
postmap.o: ../../include/vstring.h
postmap.o: ../../include/vstring_vstream.h
postmap.o: ../../include/warn_stat.h
postmap.o: postmap.c
