SHELL	= /bin/sh
SRCS	= dns_lookup.c dns_rr.c dns_strerror.c dns_strtype.c dns_rr_to_pa.c \
	dns_sa_to_rr.c dns_rr_eq_sa.c dns_rr_to_sa.c
OBJS	= dns_lookup.o dns_rr.o dns_strerror.o dns_strtype.o dns_rr_to_pa.o \
	dns_sa_to_rr.o dns_rr_eq_sa.o dns_rr_to_sa.o
HDRS	= dns.h
TESTSRC	= test_dns_lookup.c test_alias_token.c
DEFS	= -I. -I$(INC_DIR) -D$(SYSTYPE)
CFLAGS	= $(DEBUG) $(OPT) $(DEFS)
INCL	=
LIB	= libdns.a
TESTPROG= test_dns_lookup dns_rr_to_pa dns_rr_to_sa dns_sa_to_rr dns_rr_eq_sa
LIBS	= ../../lib/libutil.a
LIB_DIR	= ../../lib
INC_DIR	= ../../include

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

all: $(LIB)

Makefile: Makefile.in
	(echo "# DO NOT EDIT"; tail +2 ../../conf/makedefs.out; cat $?) >$@

test:	$(TESTPROG)

tests:	test dns_rr_to_pa_test dns_rr_to_sa_test dns_sa_to_rr_test \
	dns_rr_eq_sa_test

$(LIB):	$(OBJS)
	$(AR) $(ARFL) $(LIB) $?
	$(RANLIB) $(LIB)

$(LIB_DIR)/$(LIB): $(LIB)
	cp $(LIB) $(LIB_DIR)
	$(RANLIB) $(LIB_DIR)/$(LIB)

update: $(LIB_DIR)/$(LIB) $(HDRS)
	-for i in $(HDRS); \
	do \
	  cmp -s $$i $(INC_DIR)/$$i 2>/dev/null || cp $$i $(INC_DIR); \
	done
	cd $(INC_DIR); chmod 644 $(HDRS)

test_dns_lookup: test_dns_lookup.c $(LIB) $(LIBS)
	$(CC) $(CFLAGS) -o $@ $@.c $(LIB) $(LIBS) $(SYSLIBS)

dns_rr_to_pa: $(LIB) $(LIBS)
	mv $@.o junk
	$(CC) $(CFLAGS) -DTEST -o $@ $@.c $(LIB) $(LIBS) $(SYSLIBS)
	mv junk $@.o

dns_rr_to_sa: $(LIB) $(LIBS)
	mv $@.o junk
	$(CC) $(CFLAGS) -DTEST -o $@ $@.c $(LIB) $(LIBS) $(SYSLIBS)
	mv junk $@.o

dns_sa_to_rr: $(LIB) $(LIBS)
	mv $@.o junk
	$(CC) $(CFLAGS) -DTEST -o $@ $@.c $(LIB) $(LIBS) $(SYSLIBS)
	mv junk $@.o

dns_rr_eq_sa: $(LIB) $(LIBS)
	mv $@.o junk
	$(CC) $(CFLAGS) -DTEST -o $@ $@.c $(LIB) $(LIBS) $(SYSLIBS)
	mv junk $@.o

dns_rr_to_pa_test: dns_rr_to_pa dns_rr_to_pa.in dns_rr_to_pa.ref
	./dns_rr_to_pa `cat dns_rr_to_pa.in` >dns_rr_to_pa.tmp
	diff dns_rr_to_pa.ref dns_rr_to_pa.tmp
	rm -f dns_rr_to_pa.tmp

dns_rr_to_sa_test: dns_rr_to_sa dns_rr_to_sa.in dns_rr_to_sa.ref
	./dns_rr_to_sa `cat dns_rr_to_sa.in` >dns_rr_to_sa.tmp
	diff dns_rr_to_sa.ref dns_rr_to_sa.tmp
	rm -f dns_rr_to_sa.tmp

dns_sa_to_rr_test: dns_sa_to_rr dns_sa_to_rr.in dns_sa_to_rr.ref
	./dns_sa_to_rr `cat dns_sa_to_rr.in` >dns_sa_to_rr.tmp
	diff dns_sa_to_rr.ref dns_sa_to_rr.tmp
	rm -f dns_sa_to_rr.tmp

dns_rr_eq_sa_test: dns_rr_eq_sa dns_rr_eq_sa.in dns_rr_eq_sa.ref
	./dns_rr_eq_sa `cat dns_rr_eq_sa.in` >dns_rr_eq_sa.tmp
	diff dns_rr_eq_sa.ref dns_rr_eq_sa.tmp
	rm -f dns_rr_eq_sa.tmp

printfck: $(OBJS) $(PROG)
	rm -rf printfck
	mkdir printfck
	cp *.h printfck
	sed '1,/^# do not edit/!d' Makefile >printfck/Makefile
	set -e; for i in *.c; do printfck -f .printfck $$i >printfck/$$i; done
	cd printfck; make "INC_DIR=../../../include" `cd ..; ls *.o`

lint:
	lint $(DEFS) $(SRCS) $(LINTFIX)

clean:
	rm -f *.o $(LIB) *core $(TESTPROG) junk
	rm -rf printfck

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 'p' -e '}'; \
	done) | 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'
dns_lookup.o: dns_lookup.c
dns_lookup.o: ../../include/sys_defs.h
dns_lookup.o: ../../include/mymalloc.h
dns_lookup.o: ../../include/vstring.h
dns_lookup.o: ../../include/vbuf.h
dns_lookup.o: ../../include/msg.h
dns_lookup.o: ../../include/valid_hostname.h
dns_lookup.o: ../../include/stringops.h
dns_lookup.o: dns.h
dns_lookup.o: ../../include/sock_addr.h
dns_lookup.o: ../../include/myaddrinfo.h
dns_rr.o: dns_rr.c
dns_rr.o: ../../include/sys_defs.h
dns_rr.o: ../../include/msg.h
dns_rr.o: ../../include/mymalloc.h
dns_rr.o: ../../include/myrand.h
dns_rr.o: dns.h
dns_rr.o: ../../include/vstring.h
dns_rr.o: ../../include/vbuf.h
dns_rr.o: ../../include/sock_addr.h
dns_rr.o: ../../include/myaddrinfo.h
dns_rr_eq_sa.o: dns_rr_eq_sa.c
dns_rr_eq_sa.o: ../../include/sys_defs.h
dns_rr_eq_sa.o: ../../include/msg.h
dns_rr_eq_sa.o: ../../include/sock_addr.h
dns_rr_eq_sa.o: dns.h
dns_rr_eq_sa.o: ../../include/vstring.h
dns_rr_eq_sa.o: ../../include/vbuf.h
dns_rr_eq_sa.o: ../../include/myaddrinfo.h
dns_rr_to_pa.o: dns_rr_to_pa.c
dns_rr_to_pa.o: ../../include/sys_defs.h
dns_rr_to_pa.o: ../../include/msg.h
dns_rr_to_pa.o: dns.h
dns_rr_to_pa.o: ../../include/vstring.h
dns_rr_to_pa.o: ../../include/vbuf.h
dns_rr_to_pa.o: ../../include/sock_addr.h
dns_rr_to_pa.o: ../../include/myaddrinfo.h
dns_rr_to_sa.o: dns_rr_to_sa.c
dns_rr_to_sa.o: ../../include/sys_defs.h
dns_rr_to_sa.o: ../../include/msg.h
dns_rr_to_sa.o: dns.h
dns_rr_to_sa.o: ../../include/vstring.h
dns_rr_to_sa.o: ../../include/vbuf.h
dns_rr_to_sa.o: ../../include/sock_addr.h
dns_rr_to_sa.o: ../../include/myaddrinfo.h
dns_sa_to_rr.o: dns_sa_to_rr.c
dns_sa_to_rr.o: ../../include/sys_defs.h
dns_sa_to_rr.o: ../../include/msg.h
dns_sa_to_rr.o: dns.h
dns_sa_to_rr.o: ../../include/vstring.h
dns_sa_to_rr.o: ../../include/vbuf.h
dns_sa_to_rr.o: ../../include/sock_addr.h
dns_sa_to_rr.o: ../../include/myaddrinfo.h
dns_strerror.o: dns_strerror.c
dns_strerror.o: ../../include/sys_defs.h
dns_strerror.o: ../../include/vstring.h
dns_strerror.o: ../../include/vbuf.h
dns_strerror.o: dns.h
dns_strerror.o: ../../include/sock_addr.h
dns_strerror.o: ../../include/myaddrinfo.h
dns_strtype.o: dns_strtype.c
dns_strtype.o: ../../include/sys_defs.h
dns_strtype.o: ../../include/vstring.h
dns_strtype.o: ../../include/vbuf.h
dns_strtype.o: dns.h
dns_strtype.o: ../../include/sock_addr.h
dns_strtype.o: ../../include/myaddrinfo.h
test_dns_lookup.o: test_dns_lookup.c
test_dns_lookup.o: ../../include/sys_defs.h
test_dns_lookup.o: ../../include/vstring.h
test_dns_lookup.o: ../../include/vbuf.h
test_dns_lookup.o: ../../include/msg.h
test_dns_lookup.o: ../../include/msg_vstream.h
test_dns_lookup.o: ../../include/vstream.h
test_dns_lookup.o: ../../include/mymalloc.h
test_dns_lookup.o: ../../include/argv.h
test_dns_lookup.o: dns.h
test_dns_lookup.o: ../../include/sock_addr.h
test_dns_lookup.o: ../../include/myaddrinfo.h
