########################################################################
#
# Copyright (c) 2009-2017, 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=lib\hx509
intcflags=-I$(OBJ)
localcflags=-DASN1_LIB

!include ../../windows/NTMakefile.w32

libhx509_la_OBJS =			\
	$(OBJ)\ca.obj			\
	$(OBJ)\cert.obj			\
	$(OBJ)\cms.obj			\
	$(OBJ)\collector.obj		\
	$(OBJ)\crypto.obj		\
	$(OBJ)\crypto-ec.obj		\
	$(OBJ)\error.obj		\
	$(OBJ)\env.obj			\
	$(OBJ)\file.obj			\
	$(OBJ)\hx509_err.obj		\
	$(OBJ)\sel.obj			\
	$(OBJ)\sel-gram.obj		\
	$(OBJ)\sel-lex.obj		\
	$(OBJ)\keyset.obj		\
	$(OBJ)\ks_dir.obj		\
	$(OBJ)\ks_file.obj		\
	$(OBJ)\ks_mem.obj		\
	$(OBJ)\ks_null.obj		\
	$(OBJ)\ks_p11.obj		\
	$(OBJ)\ks_p12.obj		\
	$(OBJ)\ks_keychain.obj		\
	$(OBJ)\lock.obj			\
	$(OBJ)\name.obj			\
	$(OBJ)\peer.obj			\
	$(OBJ)\print.obj		\
	$(OBJ)\softp11.obj		\
	$(OBJ)\req.obj			\
	$(OBJ)\revoke.obj		\
	$(OBJ)\jose.obj

$(LIBHX509): $(libhx509_la_OBJS)
	$(LIBCON)

dist_libhx509_la_SOURCES =	\
	$(SRCDIR)\ca.c		\
	$(SRCDIR)\cert.c	\
	$(SRCDIR)\cms.c		\
	$(SRCDIR)\collector.c	\
	$(SRCDIR)\crypto.c	\
	$(SRCDIR)\crypto-ec.c	\
	$(SRCDIR)\doxygen.c	\
	$(SRCDIR)\error.c	\
	$(SRCDIR)\env.c		\
	$(SRCDIR)\file.c	\
	$(SRCDIR)\hx509.h	\
	$(SRCDIR)\hx_locl.h	\
	$(SRCDIR)\sel.c		\
	$(SRCDIR)\sel.h		\
	$(SRCDIR)\sel-gram.y	\
	$(SRCDIR)\sel-lex.l	\
	$(SRCDIR)\keyset.c	\
	$(SRCDIR)\ks_dir.c	\
	$(SRCDIR)\ks_file.c	\
	$(SRCDIR)\ks_mem.c	\
	$(SRCDIR)\ks_null.c	\
	$(SRCDIR)\ks_p11.c	\
	$(SRCDIR)\ks_p12.c	\
	$(SRCDIR)\ks_keychain.c \
	$(SRCDIR)\lock.c	\
	$(SRCDIR)\name.c	\
	$(SRCDIR)\peer.c	\
	$(SRCDIR)\print.c	\
	$(SRCDIR)\softp11.c	\
	$(SRCDIR)\ref\pkcs11.h	\
	$(SRCDIR)\req.c		\
	$(SRCDIR)\revoke.c	\
	$(SRCDIR)\jose.c

{}.c{$(OBJ)}.obj::
	$(C2OBJ_P) -DBUILD_HX509_LIB -DASN1_LIB

{$(OBJ)}.c{$(OBJ)}.obj::
	$(C2OBJ_P) -DBUILD_HX509_LIB -DASN1_LIB

asn1_compile=$(BINDIR)\asn1_compile.exe

INCFILES=			    \
	$(INCDIR)\hx509.h	    \
	$(INCDIR)\hx509-protos.h    \
	$(INCDIR)\hx509-private.h   \
	$(INCDIR)\hx509_err.h

hxtool.c: $(OBJ)\hxtool-commands.h

SLC=$(BINDIR)\slc.exe

$(OBJ)\hxtool-commands.c $(OBJ)\hxtool-commands.h: hxtool-commands.in $(SLC)
	cd $(OBJ)
	$(CP) $(SRCDIR)\hxtool-commands.in $(OBJ)\hxtool-commands.in
	$(SLC) hxtool-commands.in
	cd $(SRCDIR)

$(BINDIR)\hxtool.exe: $(OBJ)\tool\hxtool.obj $(OBJ)\tool\hxtool-commands.obj $(LIBHEIMDAL) $(OBJ)\hxtool-version.res
	$(EXECONLINK) $(LIBHEIMDAL) $(LIBHEIMBASE) $(LIBROKEN) $(LIBSL) $(LIBVERS) $(LIBCOMERR) $(LIB_openssl_crypto)
	$(EXEPREP)

$(OBJ)\hx509-protos.h:
	cd $(OBJ)
	$(PERL) $(SRCDIR)\..\..\cf\make-proto.pl -R "^(_|^C)" -E HX509_LIB -q -P remove -o hx509-protos.h $(dist_libhx509_la_SOURCES) || $(RM) -f hx509-protos.h
	cd $(SRCDIR)

$(OBJ)\hx509-private.h:
	cd $(OBJ)
	$(PERL) $(SRCDIR)\..\..\cf\make-proto.pl -q -P remove -p hx509-private.h $(dist_libhx509_la_SOURCES) || $(RM) -f hx509-private.h
	cd $(SRCDIR)

$(OBJ)\hx509_err.c $(OBJ)\hx509_err.h: hx509_err.et
	cd $(OBJ)
	$(BINDIR)\compile_et.exe $(SRCDIR)\hx509_err.et
	cd $(SRCDIR)

$(OBJ)\sel-gram.obj: $(OBJ)\sel-gram.c
	$(C2OBJ) -I$(SRCDIR)

$(OBJ)\sel-lex.obj: $(OBJ)\sel-lex.c
	$(C2OBJ) -I$(SRCDIR) -I$(OBJ) -DYY_NO_UNISTD_H

$(OBJ)\sel-gram.c: sel-gram.y
	$(YACC) -o $@ --defines=$(OBJ)\sel-gram.h sel-gram.y

$(OBJ)\sel-lex.c: sel-lex.l
	$(LEX) -P_hx509_sel_yy -o$@ sel-lex.l

all:: $(INCFILES) $(LIBHX509)

prep:: mktooldir

mktooldir:
!  if !exist($(OBJ)\tool)
	$(MKDIR) $(OBJ)\tool
!  endif

all-tools:: $(BINDIR)\hxtool.exe

clean::
	-$(RM) $(BINDIR)\hxtool.*
	-$(RM) $(OBJ)\tool\*.*

{}.c{$(OBJ)\tool}.obj::
	$(C2OBJ_C) /Fd$(OBJ)\tool\ /Fo$(OBJ)\tool\ $(MPOPT) /UASN1_LIB $<

{$(OBJ)}.c{$(OBJ)\tool}.obj::
	$(C2OBJ_C) /Fd$(OBJ)\tool\ /Fo$(OBJ)\tool\ $(MPOPT) /UASN1_LIB $<

