# Copyright (C) @BABOLO  2010 http://www.babolo.ru/
# 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 AUTHORS ``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 REGENTS 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.
#
# $Id: Makefile,v 1.2 2010/10/18 16:51:36 babolo Exp $

PKG	= tund
VMAJOR	= 0
VMINOR	= 22
PREFIX	?= /usr/local

SUBDIR	= helpers
PROG	= ${PKG}
INCS	= ${PKG}
INCI	=
CSRC	= main secur scb utils md5 alarm cipher search

#SHLIB	= ${CSRC}
#STLIB	= ${CSRC}
CONF	= ${PKG}.conf
MISC	+= ${INCH}
DATAMODE=0600
VARDIR	?= /var/net/conf
BINOVER	= ${PREFIX}/sbin
CONG	= tund.rsa.key tund.hosts.key
CLEAN	+= tund.seed.rng
REQUIRED= babolo-libmake:2.14

EXTRA_SSL_LIBS	?=
OPENSSL_CFLAGS	?=
OPENSSLINC	?= /usr/include
OPENSSLLIB	?= /usr/lib
RSA_KEY_LENGTH	= 1024

LDFLAGS		+= -L${OPENSSLLIB} -lmd -lcrypto ${EXTRA_SSL_LIBS}
DEBUG_FLAGS	+= -g -DDEBUG
DEBUG_FLAGS	+= -Wall
CFLAGSPLUS	+= ${DEBUG_FLAGS} -I${OPENSSLINC} ${OPENSSL_CFLAGS}

postinstall: ${CONG}
	${MKDIR} -p ${VARDIR}
	if  [ ! -e ${VARDIR}/tund.seed.rng ]; then\
            ${INSTALL_DATA} tund.seed.rng ${VARDIR}/tund.seed.rng;\
        fi
	if  [ ! -e ${CONFDIR}/tund.seed.rng ]; then\
            ${LN} -fs ${VARDIR}/tund.seed.rng ${CONFDIR}/tund.seed.rng;\
        fi

tund.rsa.key::
	@helpers/rsa_kg ${RSA_KEY_LENGTH}

tund.hosts.key::
	@helpers/pkey_gen tund.rsa.key
	${MV} rsa_pub.key ${.TARGET}

BUILDINCLUDEDIR	= ${PREFIX}/include/babolo
.include <${BUILDINCLUDEDIR}/define.make>
.include <${BUILDINCLUDEDIR}/common.make>
