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)

.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

root_tests:

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

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

fail_test: $(PROG) aliases fail_test.in fail_test.ref
	-($(SHLIB_ENV) sh fail_test.in || exit 0) >fail_test.tmp 2>&1
	diff fail_test.ref fail_test.tmp
	rm -f fail_test.tmp

quote_test: $(PROG) aliases quote_test.in quote_test.ref
	rm -f quote_test_map.*
	$(SHLIB_ENV) sh quote_test.in >quote_test.tmp 2>&1
	diff quote_test.ref quote_test.tmp
	rm -f quote_test.tmp quote_test_map.*

file_test: $(PROG) file_test.in file_test.ref
	rm -f file_test_map.* postmap-file-1 postmap-file-2
	$(SHLIB_ENV) 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

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 -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 lmdb_abb.lmdb
	($(SHLIB_ENV) $(VALGRIND) ./postmap lmdb:lmdb_abb; \
	$(SHLIB_ENV) $(VALGRIND) ./postmap -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 -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 -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

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
