# Copyright (c) 1996-1997 WIDE Project. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modifications, are permitted provided that the above copyright notice
# and this paragraph are duplicated in all such forms and that any
# documentation, advertising materials, and other materials related to
# such distribution and use acknowledge that the software was developed
# by the WIDE Project, Japan. The name of the Project may not be used to
# endorse or promote products derived from this software without
# specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS''
# AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
# LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE.

.if exists(${.CURDIR}/Makefile.opsys)
.include "${.CURDIR}/Makefile.opsys"
.endif

# must build libinet6 and libipsec first!
.if ((${OPSYS} == "FreeBSD" && (${OPREL} == "2.2.8-RELEASE" || ${OPREL} == "2.2.8-STABLE")) || ${OPSYS} == "BSD/OS" || (${OPSYS} == "NetBSD" && ${OPREL} == "1.4"))
SUBDIR=	libinet6 libipsec setkey
.else
SUBDIR=	libinet6
.endif
SUBDIR+=cksum6 gifconfig icmp6dump inet6d mld6query ndp ping6 \
	prefix route6d rrenumd rtadvd rtsol rtsold faith faithd \
	traceroute6 pim6dd send-pr mcastread
SUBDIR+=	hroute6d
# pma: just for KAME/BSDI and KAME/FreeBSD-2.2.8
.if (${OPSYS} == "BSD/OS") || (${OPSYS} == "FreeBSD" && (${OPREL} == "2.2.8-RELEASE" || ${OPREL} == "2.2.8-STABLE"))
SUBDIR+=	pma
.endif

CONFIGURE_SUBDIR=	v6test bgpd libpcap tcpdump traceroute

all:
	for i in $(SUBDIR); do\
		(cd $$i; $(MAKE)); \
	done
	(cd v6test; \
		[ -f Makefile ] || ./configure; $(MAKE))
	(cd bgpd; \
		[ -f Makefile ] || \
		./configure --prefix=/usr/local/v6; \
		$(MAKE))
	(cd v6p; $(MAKE))
	(cd libpcap; \
		[ -f Makefile ] || \
		./configure --enable-ipv6 --prefix=/usr/local/v6; \
		$(MAKE))
	(cd tcpdump; \
		[ -f Makefile ] || \
		./configure --enable-ipv6 --prefix=/usr/local/v6; \
		$(MAKE))
	(cd traceroute; \
		[ -f Makefile ] || \
		./configure --prefix=/usr/local/v6; \
		$(MAKE))
.if (${OPSYS} == "FreeBSD" || ${OPSYS} == "NetBSD")
	(cd dtcp; $(MAKE))
	(cd man; $(MAKE))
.endif

install:
	for i in $(SUBDIR); do\
		(cd $$i; $(MAKE) install); \
	done
	(cd v6test; \
		[ -f Makefile ] || ./configure; $(MAKE) install)
	(cd bgpd; \
		[ -f Makefile ] || \
		./configure --prefix=/usr/local/v6; \
		$(MAKE) install)
	(cd v6p; $(MAKE) install)
	(cd libpcap; \
		[ -f Makefile ] || \
		./configure --enable-ipv6 --prefix=/usr/local/v6; \
		$(MAKE) install)
	(cd tcpdump; \
		[ -f Makefile ] || \
		./configure --enable-ipv6 --prefix=/usr/local/v6; \
		$(MAKE) install install-man)
	(cd traceroute; \
		[ -f Makefile ] || \
		./configure --prefix=/usr/local/v6; \
		$(MAKE) install install-man)
	(cd dtcp; $(MAKE) install)
	(cd man; $(MAKE) install)

clean:
	for i in $(SUBDIR); do\
		(cd $$i; $(MAKE) clean); \
	done
	(for i in $(CONFIGURE_SUBDIR); do \
		if [ -f $$i/Makefile ]; then \
			(cd $$i; $(MAKE) distclean) \
		else \
			(cd $$i; /bin/rm -f *.o */*.o) \
		fi \
	done)
.if (${OPSYS} == "FreeBSD" || ${OPSYS} == "NetBSD")
	(cd dtcp; $(MAKE) clean)
.endif
