#
# Copyright (c) 2003-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/dtcpclient/GNUmakefile,v 1.6 2005/12/28 07:29:24 ume Exp $
#

OPSYS=		$(shell uname -s)

PREFIX?=	/usr/local

PROG=		dtcpclient
MAN=		dtcpclient.8

BINDIR=		$(PREFIX)/sbin
SCRIPTSDIR=	$(PREFIX)/etc
EXAMPLESDIR=	$(PREFIX)/share/examples/dtcpclient

MANDIR=		$(PREFIX)/man/man

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

ifeq ($(OPSYS),FreeBSD)
LDLIBS=		-lmd
HAVE_MD5=	1
endif
ifeq ($(OPSYS),NetBSD)
HAVE_MD5=	1
endif
ifeq ($(OPSYS),OpenBSD)
HAVE_MD5=	1
endif
ifeq ($(HAVE_MD5),1)
CPPFLAGS+=	-DHAVE_MD5
else
LDLIBS=		-lcrypto
endif

BINOWN=		root
BINGRP=		wheel

INSTALL=	install
COPY=		-c

all:		$(PROG)

dtcpclient:	dtcpclient.o

install:
	$(INSTALL) -s $(COPY) -o $(BINOWN) -g $(BINGRP) -m 555 \
		dtcpclient $(BINDIR)/dtcpclient
	$(INSTALL) -d $(EXAMPLESDIR)
	$(INSTALL) $(COPY) -o $(BINOWN) -g $(BINGRP) -m 555 \
		dtcpclient.script $(EXAMPLESDIR)/dtcpclient.script
	if [ ! -f $(SCRIPTSDIR)/dtcpclient.script ]; then \
		cp -p $(EXAMPLESDIR)/dtcpclient.script $(SCRIPTSDIR)/; \
	fi
	$(INSTALL) $(COPY) -o $(BINOWN) -g $(BINGRP) -m 444 $(MAN) $(MANDIR)8

clean:
	$(RM) -f dtcpclient dtcpclient.o dtcpclient.8.gz dtcpclient.8.cat.gz

dist:
	@data=`date +%Y%m%d`; \
	$(RM) -rf dtcpclient-$${data}; \
	mkdir dtcpclient-$${data}; \
	cp -p ChangeLog GNUmakefile Makefile dtcpclient.8 dtcpclient.c \
		dtcpclient.script dtcpclient.sh dtcpclient-$${data}; \
	tar cvzf dtcpclient-$${data}.tar.gz dtcpclient-$${data}; \
	$(RM) -rf dtcpclient-$${data}
