#
# Copyright (c) 2004 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/GNUmakefile,v 1.2 2005/12/28 08:56:36 ume Exp $
#

# Get the architecture
ARCH=		$(shell uname -m)

# Get the operationg system type
OPSYS=		$(shell uname -s)

# Get the operationg system version
OPREL=		$(shell uname -r)

PREFIX?=	/usr/local

BINDIR=		$(PREFIX)/sbin

MANDIR=		$(PREFIX)/man/man
MAN=		dtcps.8 dtcpc.8 dtcpauth.8

ifeq ($(OPSYS),NetBSD)
RUBY?=		/usr/pkg/bin/ruby
POPAUTHDB?=	/usr/pkg/etc/apop.auth
DTCPS_TUNIF?=	gif0
DTCPC_TUNIF?=	gif0
else
ifeq ($(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
endif

CFLAGS?=	-O -Wall
CPPFLAGS=	-DPREFIX=\"$(PREFIX)\"

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

BINOWN=		root
BINGRP=		wheel

INSTALL=	install
COPY=		-c

all:		dtcps dtcpc dtcpauth dtcps.8 dtcpc.8 dtcpauth.8

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

install:
	$(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
	$(INSTALL) $(COPY) -o $(BINOWN) -g $(BINGRP) -m 444 $(MAN) $(MANDIR)8

clean:
	$(RM) -f $(CLEANFILES)

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}
