######################################################################
# Makfile                                                  August 2005
#
# KSSLD: An implementation of SSL/TLS in the Linux Kernel
# Copyright (C) 2005  NTT COMWARE Corporation.
#
# This file based in part on code from LVS www.linuxvirtualserver.org
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
######################################################################

include ../Makefile.base

SUBDIRS =

CFLAGS		= $(KCFLAGS) -I../include/kssl -I../asym \
		  -DCONFIG_KSSL_DEBUG #-DKSSL_ALLOC_DEBUG

KSSLD		= kssld.o
KSSLD_OBJS	= aep.o alert.o app_data.o conn.o conn_list.o core.o    \
		  css.o  daemon.o handshake.o kssl_alloc.o kssl_asym.o  \
		  kssl_proc.o  message.o message_mask.o prf.o           \
		  record.o record_list.o session.o socket.o sockopt.o	\
		  kssl_alloc.o util.o

KSSLD_SRCS	= aep.c aep.h alert.c alert.h app_data.c app_data.h \
		  conn.c conn.h conn_list.c conn_list.h core.c \
		  css.c css.h daemon.c daemon.h handshake.c handshake.h \
		  kssl_alloc.c kssl_alloc.h kssl_asym.c kssl_asym.h \
		  kssl_proc.c kssl_proc.h log.h message.c message.h \
		  message_mask.c message_mask.h prf.c prf.h \
		  record.c record.h record_list.c record_list.h \
		  session.c session.h socket.c socket.h sockopt.c sockopt.h \
		  util.c util.h

#KSSL_TEST	= kssl_test.o
#KSSL_TEST_OBJS	= session.o session_test.o util.o

DISTFILE	= Makefile $(KSSLD_SRCS)
DISTPROG	= kssld_start kssld_start.aep_user kssld_start.software

.PHONY: 	all install modules_install unintall modules_uninstall clean \
		distclean dist

all:		$(KSSLD)
		@for i in $(SUBDIRS); do $(MAKE) -C $$i all || exit 1; done

kssld:		$(KSSLD)

$(KSSLD):	$(KSSLD_OBJS)
		$(LD) -r $^ -o $@

#$(KSSL_TEST):	$(KSSL_TEST_OBJS)
#		$(LD) -r $^ -o $@

install:	modules_install
		@for i in $(SUBDIRS); do $(MAKE) -C $$i install || exit 1; done

modules_install:
		if [ ! -d "$(MODLIB)" ]; then mkdir -p "$(MODLIB)"; fi
		install -m 600 -c $(KSSLD) $(SCHEDULERS) $(APPMODS) "$(MODLIB)"
		#depmod -ae -F $(KERNELSYMS) $(DEPMOD_OPTS) $(KERNELRELEASE)
		depmod -ae

uninstall:	modules_uninstall
		@for i in $(SUBDIRS); do $(MAKE) -C $$i uninstall || exit 1; \
		done

modules_uninstall:
		(cd "$(MODLIB)"; rm -f $(KSSLD) $(SCHEDULERS) $(APPMODS))
		rmdir "$(MODLIB)"

clean:
		rm -f *.o *~ *.bak *.orig *.rej
		@for i in $(SUBDIRS); do $(MAKE) -C $$i clean || exit 1; done

distclean:	clean
		rm -rf kssld-$(VERSION)/ kssld-$(VERSION).tar.gz

dist:
		mkdir $(DISTDIR)/
		@for i in $(SUBDIRS); do \
			$(MAKE) DISTDIR="../$(DISTDIR)/$$i" -C $$i dist \
				|| exit 1; done
		install -m 644 $(DISTFILE) $(DISTDIR)   
		install -m 755 $(DISTPROG) $(DISTDIR)   
