#
# Copyright (c) 2004-2013 Hajimu UMEMOTO <ume@mahoroba.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $Mahoroba: src/dtcp/Makefile,v 1.14 2013/06/02 14:07:08 ume Exp $

# Get the architecture
ARCH!=		uname -m

# Get the operationg system type
OPSYS!=		uname -s

# Get the operationg system version
OPREL!=		uname -r

PREFIX?=	/usr/local

BINDIR=		$(PREFIX)/sbin

.if (${OPSYS} == "NetBSD")
MANDIR=		$(PREFIX)/man
.else
MANDIR=		$(PREFIX)/man/man
.endif
MAN=		dtcps.8 dtcpc.8 dtcpauth.8

.if (${OPSYS} == "NetBSD")
RUBY?=		/usr/pkg/bin/ruby
POPAUTHDB?=	/usr/pkg/etc/apop.auth
DTCPS_TUNIF?=	gif0
DTCPC_TUNIF?=	gif0
.elif (${OPSYS} == "FreeBSD")
RUBY?=		/usr/local/bin/ruby
POPAUTHDB?=	/usr/local/etc/qpopper/pop.auth
DTCPS_TUNIF?=	gif0
DTCPC_TUNIF?=	gif
.else
RUBY?=		/usr/local/bin/ruby
POPAUTHDB?=	/usr/local/etc/pop.auth
DTCPS_TUNIF?=	gif0
DTCPC_TUNIF?=	gif0
.endif

CLEANFILES+=	dtcps dtcpc dtcpauth dtcps.8 dtcpc.8 dtcpauth.8

all:		dtcps dtcpc dtcpauth

dtcps:		dtcps.rb
	sed -e 's#@RUBY@#${RUBY}#' -e 's#@PREFIX@#${PREFIX}#' \
		-e 's#@POPAUTHDB@#${POPAUTHDB}#' \
		-e 's#@DTCPS_TUNIF@#${DTCPS_TUNIF}#' \
		< dtcps.rb > dtcps
dtcpc:		dtcpc.rb
	sed -e 's#@RUBY@#${RUBY}#' -e 's#@PREFIX@#${PREFIX}#' \
		-e 's#@DTCPC_TUNIF@#${DTCPC_TUNIF}#' \
		< dtcpc.rb > dtcpc
dtcpauth:	dtcpauth.rb
	sed -e 's#@RUBY@#${RUBY}#' -e 's#@PREFIX@#${PREFIX}#' \
		-e 's#@POPAUTHDB@#${POPAUTHDB}#' \
		< dtcpauth.rb > dtcpauth

dtcps.8:	dtcps.8.in
	sed -e 's#@PREFIX@#${PREFIX}#' -e 's#@POPAUTHDB@#${POPAUTHDB}#' \
		< dtcps.8.in > dtcps.8

dtcpc.8:	dtcpc.8.in
	sed -e 's#@PREFIX@#${PREFIX}#' -e 's#@POPAUTHDB@#${POPAUTHDB}#' \
		< dtcpc.8.in > dtcpc.8

dtcpauth.8:	dtcpauth.8.in
	sed -e 's#@PREFIX@#${PREFIX}#' -e 's#@POPAUTHDB@#${POPAUTHDB}#' \
		< dtcpauth.8.in > dtcpauth.8

realinstall:
	${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m 555 dtcps \
		${BINDIR}/dtcps
	${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m 555 dtcpc \
		${BINDIR}/dtcpc
	${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m 555 dtcpauth \
		${BINDIR}/dtcpauth

dist:
	@data=`date +%Y%m%d`; \
	rm -rf dtcp-$${data}; \
	mkdir dtcp-$${data}; \
	cp -p ChangeLog GNUmakefile Makefile dtcpauth.8.in dtcpauth.rb \
		dtcpc.8.in dtcpc.rb dtcpc.sh dtcps.8.in dtcps.rb dtcps.sh \
		dtcp-$${data}; \
	tar cvzf dtcp-$${data}.tar.gz dtcp-$${data}; \
	rm -rf dtcp-$${data}

.include <bsd.prog.mk>
