########################################################################
#
# Copyright (c) 2009-2016, Secure Endpoints Inc.
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 
# - Redistributions of source code must retain the above copyright
#   notice, this list of conditions and the following disclaimer.
# 
# - 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 COPYRIGHT HOLDERS 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
# COPYRIGHT HOLDER 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.
# 

RELDIR=kdc 

!include ../windows/NTMakefile.w32 

intcflags=-I$(OBJ) -I$(SRC)\lib\gssapi -I$(OBJDIR)\lib\gssapi -I$(OBJDIR)\lib\gss_preauth -DBUILD_KDC_LIB

BINPROGRAMS=$(BINDIR)\string2key.exe

SBINPROGRAMS=$(SBINDIR)\kstash.exe

LIBEXECPROGRAMS= \
	$(LIBEXECDIR)\hprop.exe \
	$(LIBEXECDIR)\hpropd.exe \
	$(LIBEXECDIR)\kdc.exe

NOINST_PROGRAMS=$(OBJ)\kdc-replay.exe

INCFILES=\
	$(INCDIR)\kdc.h		\
	$(INCDIR)\kdc-protos.h	\
	$(INCDIR)\kdc-private.h	\
	$(INCDIR)\krb5\kdc-audit.h \
	$(INCDIR)\krb5\kdc-plugin.h \
	$(INCDIR)\krb5\kdc-accessors.h

all:: $(INCFILES) $(LIBKDC) $(BINPROGRAMS) $(SBINPROGRAMS) $(LIBEXECPROGRAMS)

clean::
	-$(RM) $(LIBKDC)
	-$(RM) $(BINPROGRAMS:.exe=.*) $(SBINPROGRAMS:.exe=.*) $(LIBEXECPROGRAMS:.exe=.*)

BIN_LIBS=\
	$(LIBHDB)	\
	$(LIBHEIMDAL)	\
	$(LIBROKEN)	\
	$(LIBVERS)

$(LIBEXECDIR)\hprop.exe: $(OBJ)\hprop.obj $(OBJ)\mit_dump.obj $(BIN_LIBS) $(OBJ)\hprop-version.res
	$(EXECONLINK)
	$(EXEPREP)

$(LIBEXECDIR)\hpropd.exe: $(OBJ)\hpropd.obj $(BIN_LIBS) $(OBJ)\hpropd-version.res
	$(EXECONLINK)
	$(EXEPREP)

$(SBINDIR)\kstash.exe: $(OBJ)\kstash.obj $(BIN_LIBS) $(OBJ)\kstash-version.res
	$(EXECONLINK)
	$(EXEPREP)

$(BINDIR)\string2key.exe: $(OBJ)\string2key.obj $(BIN_LIBS) $(OBJ)\string2key-version.res
	$(EXECONLINK)
	$(EXEPREP)

$(LIBEXECDIR)\kdc.exe: \
		$(OBJ)\connect.obj $(OBJ)\config.obj $(OBJ)\announce.obj \
		$(OBJ)\main.obj $(OBJ)\kdc-version.res \
		$(LIBKDC) $(BIN_LIBS) $(LIB_openssl_crypto)
	$(EXECONLINK)
	$(EXEPREP)

LIBKDC_OBJS=\
	$(OBJ)\default_config.obj	\
	$(OBJ)\ca.obj			\
	$(OBJ)\kx509.obj		\
	$(OBJ)\set_dbinfo.obj		\
	$(OBJ)\fast.obj			\
	$(OBJ)\kerberos5.obj		\
	$(OBJ)\krb5tgs.obj		\
	$(OBJ)\pkinit.obj		\
	$(OBJ)\mssfu.obj		\
	$(OBJ)\log.obj			\
	$(OBJ)\misc.obj			\
	$(OBJ)\kx509.obj		\
	$(OBJ)\token_validator.obj	\
	$(OBJ)\jwt_validator.obj	\
	$(OBJ)\csr_authorizer.obj	\
	$(OBJ)\process.obj		\
	$(OBJ)\kdc-plugin.obj		\
	$(OBJ)\gss_preauth.obj

LIBKDC_LIBS=\
	$(LIBHDB)		\
	$(LIBGSS_PREAUTH)	\
	$(LIBGSSAPI)		\
	$(LIBHEIMBASE)		\
	$(LIBHEIMDAL)		\
	$(LIB_openssl_crypto)	\
	$(LIBROKEN)

LIBKDCRES=$(OBJ)\libkdc-version.res

$(LIBEXECDIR)\libkdc.dll: $(LIBKDC_OBJS) $(LIBKDC_LIBS) $(LIBKDCRES)
	$(DLLGUILINK) -implib:$(LIBKDC) -def:libkdc-exports.def
	$(DLLPREP_NODIST)

$(LIBKDC): $(LIBEXECDIR)\libkdc.dll

clean::
	-$(RM) $(LIBEXECDIR)\libkdc.*

libkdc_la_SOURCES = 		\
	default_config.c 	\
	ca.c			\
	set_dbinfo.c	 	\
	fast.c			\
	kdc_locl.h		\
	kerberos5.c		\
	krb5tgs.c		\
	pkinit.c		\
	mssfu.c			\
	log.c			\
	misc.c			\
	kx509.c			\
	token_validator.c	\
	jwt_validator.c		\
	csr_authorizer.c	\
	process.c		\
	kdc-plugin.c		\
	gss_preauth.c

$(OBJ)\kdc-protos.h: $(libkdc_la_SOURCES)
	cd $(SRCDIR)
	$(PERL) ..\cf\make-proto.pl -E KDC_LIB -q -P remove -o $@ $(libkdc_la_SOURCES) \
	|| $(RM) $@

$(OBJ)\kdc-private.h: $(libkdc_la_SOURCES)
	$(PERL) ..\cf\make-proto.pl -q -P remove -p $@ $(libkdc_la_SOURCES) \
	|| $(RM) $@
