# Makefile for xmlsec, specific for Windows, MSVC and NMAKE.
#
# Take a look at the beginning and modify the variables to suit your
# environment. Having done that, you can do a
#
# nmake [all]     to build the xmlsec and the accompanying utilities.
# nmake clean     to remove all compiler output files and return to a
#                 clean state.
# nmake rebuild   to rebuild everything from scratch. This basically does
#                 a 'nmake clean' and then a 'nmake all'.
# nmake install   to install the library and its header files.
#
# March 2002, Igor Zlatkovic <igor@stud.fh-frankfurt.de>
#	Created for LibXML and LibXSLT
# April 2002, Aleksey Sanin <aleksey@aleksey.com>
#	Modified for XMLSec Libary
#

AUTOCONF = .\configure.txt

# If you cannot run the configuration script, which would take the burden of
# editing this file from your back, then remove the following line...
!include $(AUTOCONF)
# ...and enable the following lines and adapt them to your environment.
#BASEDIR = ..
#XMLSEC_SRCDIR = $(BASEDIR)\src
#APPS_SRCDIR = $(BASEDIR)\apps
#BINDIR = binaries
#XMLSEC_MAJOR_VERSION = 0 # set this to the right value.
#XMLSEC_MINOR_VERSION = 0 # set this to the right value.
#XMLSEC_MICRO_VERSION = 0 # set this to the right value.
#WITH_XMLSEC_DEBUG = 1
#UNICODE = 1
#DEBUG = 0
#WITH_CRYPTO=openssl
#WITH_DEFAULT_CRYPTO=openssl
#WITH_OPENSSL=1
#WITH_OPENSSL_VERSION=
#WITH_OPENSSL3_ENGINES=0
#WITH_NSS=0
#WITH_MSCRYPTO=0
#WITH_MSCNG=0
#WITH_LIBXSLT=1
#STATIC = 0
#WITH_DL = 1
#WERROR = 0
#PEDANTIC = 1
#PREFIX = . # set this to the right value.
#BINPREFIX = $(PREFIX)\bin
#INCPREFIX = $(PREFIX)\include
#LIBPREFIX = $(PREFIX)\lib
#SOPREFIX = $(PREFIX)\bin
#INCLUDE = $(INCLUDE);$(INCPREFIX)
#LIB = $(LIB);$(LIBPREFIX)

# There should never be a need to modify anything below this line.
# ----------------------------------------------------------------

#
# Names of various input and output components.
#
!if "$(WITH_DL)" == "1"
APP_NAME 		= xmlsec.exe
!else
APP_NAME 		= xmlseca.exe
!endif
APP_NAME_MANIFEST	= $(APP_NAME).manifest

XMLSEC_NAME 		= xmlsec
XMLSEC_BASENAME 	= lib$(XMLSEC_NAME)
XMLSEC_SO 		= $(XMLSEC_BASENAME).dll
XMLSEC_SO_MANIFEST	= $(XMLSEC_BASENAME).dll.manifest
XMLSEC_PDB 		= $(XMLSEC_BASENAME).pdb
XMLSEC_IMP 		= $(XMLSEC_BASENAME).lib
XMLSEC_A 		= $(XMLSEC_BASENAME)_a.lib

XMLSEC_OPENSSL_NAME 	= $(XMLSEC_NAME)-openssl
XMLSEC_OPENSSL_BASENAME = lib$(XMLSEC_OPENSSL_NAME)
XMLSEC_OPENSSL_SO 	= $(XMLSEC_OPENSSL_BASENAME).dll
XMLSEC_OPENSSL_SO_MANIFEST = $(XMLSEC_OPENSSL_BASENAME).dll.manifest
XMLSEC_OPENSSL_PDB 	= $(XMLSEC_OPENSSL_BASENAME).pdb
XMLSEC_OPENSSL_IMP 	= $(XMLSEC_OPENSSL_BASENAME).lib
XMLSEC_OPENSSL_A 	= $(XMLSEC_OPENSSL_BASENAME)_a.lib

XMLSEC_NSS_NAME 	= $(XMLSEC_NAME)-nss
XMLSEC_NSS_BASENAME 	= lib$(XMLSEC_NSS_NAME)
XMLSEC_NSS_SO 		= $(XMLSEC_NSS_BASENAME).dll
XMLSEC_NSS_SO_MANIFEST	= $(XMLSEC_NSS_BASENAME).dll.manifest
XMLSEC_NSS_PDB 		= $(XMLSEC_NSS_BASENAME).pdb
XMLSEC_NSS_IMP 		= $(XMLSEC_NSS_BASENAME).lib
XMLSEC_NSS_A 		= $(XMLSEC_NSS_BASENAME)_a.lib

XMLSEC_MSCRYPTO_NAME 	= $(XMLSEC_NAME)-mscrypto
XMLSEC_MSCRYPTO_BASENAME= lib$(XMLSEC_MSCRYPTO_NAME)
XMLSEC_MSCRYPTO_SO 	= $(XMLSEC_MSCRYPTO_BASENAME).dll
XMLSEC_MSCRYPTO_SO_MANIFEST = $(XMLSEC_MSCRYPTO_BASENAME).dll.manifest
XMLSEC_MSCRYPTO_PDB 	= $(XMLSEC_MSCRYPTO_BASENAME).pdb
XMLSEC_MSCRYPTO_IMP 	= $(XMLSEC_MSCRYPTO_BASENAME).lib
XMLSEC_MSCRYPTO_A 	= $(XMLSEC_MSCRYPTO_BASENAME)_a.lib

XMLSEC_MSCNG_NAME 	= $(XMLSEC_NAME)-mscng
XMLSEC_MSCNG_BASENAME= lib$(XMLSEC_MSCNG_NAME)
XMLSEC_MSCNG_SO 	= $(XMLSEC_MSCNG_BASENAME).dll
XMLSEC_MSCNG_SO_MANIFEST = $(XMLSEC_MSCNG_BASENAME).dll.manifest
XMLSEC_MSCNG_PDB 	= $(XMLSEC_MSCNG_BASENAME).pdb
XMLSEC_MSCNG_IMP 	= $(XMLSEC_MSCNG_BASENAME).lib
XMLSEC_MSCNG_A 		= $(XMLSEC_MSCNG_BASENAME)_a.lib

#
# Places where intermediate files produced by the compiler go
#
XMLSEC_APPS_INTDIR      = apps.int
XMLSEC_APPS_INTDIR_A    = apps_a.int

XMLSEC_INTDIR           = $(XMLSEC_BASENAME).int
XMLSEC_INTDIR_A         = $(XMLSEC_BASENAME)_a.int

XMLSEC_OPENSSL_INTDIR   = $(XMLSEC_BASENAME)_openssl.int
XMLSEC_OPENSSL_INTDIR_A = $(XMLSEC_BASENAME)_openssl_a.int

XMLSEC_NSS_INTDIR       = $(XMLSEC_BASENAME)_nss.int
XMLSEC_NSS_INTDIR_A     = $(XMLSEC_BASENAME)_nss_a.int

XMLSEC_MSCRYPTO_INTDIR  = $(XMLSEC_BASENAME)_mscrypto.int
XMLSEC_MSCRYPTO_INTDIR_A= $(XMLSEC_BASENAME)_mscrypto_a.int

XMLSEC_MSCNG_INTDIR  = $(XMLSEC_BASENAME)_mscng.int
XMLSEC_MSCNG_INTDIR_A= $(XMLSEC_BASENAME)_mscng_a.int

#
# Source folders
#
XMLSEC_OPENSSL_SRCDIR   = $(XMLSEC_SRCDIR)\openssl
XMLSEC_NSS_SRCDIR   	= $(XMLSEC_SRCDIR)\nss
XMLSEC_MSCRYPTO_SRCDIR  = $(XMLSEC_SRCDIR)\mscrypto
XMLSEC_MSCNG_SRCDIR  = $(XMLSEC_SRCDIR)\mscng

#
# Object files for libraries and apps.
#
XMLSEC_APPS_OBJS = \
	$(XMLSEC_APPS_INTDIR)\crypto.obj\
	$(XMLSEC_APPS_INTDIR)\cmdline.obj\
	$(XMLSEC_APPS_INTDIR)\xmlsec.obj
XMLSEC_APPS_OBJS_A = \
	$(XMLSEC_APPS_INTDIR_A)\crypto.obj\
	$(XMLSEC_APPS_INTDIR_A)\cmdline.obj\
	$(XMLSEC_APPS_INTDIR_A)\xmlsec.obj

XMLSEC_OBJS = \
	$(XMLSEC_INTDIR)\app.obj\
	$(XMLSEC_INTDIR)\base64.obj\
	$(XMLSEC_INTDIR)\bn.obj\
	$(XMLSEC_INTDIR)\buffer.obj \
	$(XMLSEC_INTDIR)\c14n.obj \
	$(XMLSEC_INTDIR)\dl.obj \
	$(XMLSEC_INTDIR)\enveloped.obj \
	$(XMLSEC_INTDIR)\errors.obj \
	$(XMLSEC_INTDIR)\io.obj \
	$(XMLSEC_INTDIR)\keyinfo.obj \
	$(XMLSEC_INTDIR)\keys.obj \
	$(XMLSEC_INTDIR)\keysdata.obj \
	$(XMLSEC_INTDIR)\keysmngr.obj \
	$(XMLSEC_INTDIR)\kw_aes_des.obj \
	$(XMLSEC_INTDIR)\list.obj \
	$(XMLSEC_INTDIR)\membuf.obj \
	$(XMLSEC_INTDIR)\nodeset.obj \
	$(XMLSEC_INTDIR)\parser.obj \
	$(XMLSEC_INTDIR)\relationship.obj \
	$(XMLSEC_INTDIR)\soap.obj \
	$(XMLSEC_INTDIR)\strings.obj \
	$(XMLSEC_INTDIR)\templates.obj \
	$(XMLSEC_INTDIR)\transforms.obj \
	$(XMLSEC_INTDIR)\x509.obj \
	$(XMLSEC_INTDIR)\xmldsig.obj \
	$(XMLSEC_INTDIR)\xmlenc.obj \
	$(XMLSEC_INTDIR)\xmlsec.obj \
	$(XMLSEC_INTDIR)\xmltree.obj \
	$(XMLSEC_INTDIR)\xpath.obj \
	$(XMLSEC_INTDIR)\xslt.obj
XMLSEC_OBJS_A = \
	$(XMLSEC_INTDIR_A)\app.obj\
	$(XMLSEC_INTDIR_A)\base64.obj\
	$(XMLSEC_INTDIR_A)\bn.obj\
	$(XMLSEC_INTDIR_A)\buffer.obj \
	$(XMLSEC_INTDIR_A)\c14n.obj \
	$(XMLSEC_INTDIR_A)\dl.obj \
	$(XMLSEC_INTDIR_A)\enveloped.obj \
	$(XMLSEC_INTDIR_A)\errors.obj \
	$(XMLSEC_INTDIR_A)\io.obj \
	$(XMLSEC_INTDIR_A)\keyinfo.obj \
	$(XMLSEC_INTDIR_A)\keys.obj \
	$(XMLSEC_INTDIR_A)\keysdata.obj \
	$(XMLSEC_INTDIR_A)\keysmngr.obj \
	$(XMLSEC_INTDIR_A)\kw_aes_des.obj \
	$(XMLSEC_INTDIR_A)\list.obj \
	$(XMLSEC_INTDIR_A)\membuf.obj \
	$(XMLSEC_INTDIR_A)\nodeset.obj \
	$(XMLSEC_INTDIR_A)\parser.obj \
	$(XMLSEC_INTDIR_A)\relationship.obj \
	$(XMLSEC_INTDIR_A)\soap.obj \
	$(XMLSEC_INTDIR_A)\strings.obj \
	$(XMLSEC_INTDIR_A)\templates.obj \
	$(XMLSEC_INTDIR_A)\transforms.obj \
	$(XMLSEC_INTDIR_A)\x509.obj \
	$(XMLSEC_INTDIR_A)\xmldsig.obj \
	$(XMLSEC_INTDIR_A)\xmlenc.obj \
	$(XMLSEC_INTDIR_A)\xmlsec.obj \
	$(XMLSEC_INTDIR_A)\xmltree.obj \
	$(XMLSEC_INTDIR_A)\xpath.obj \
	$(XMLSEC_INTDIR_A)\xslt.obj

XMLSEC_OPENSSL_OBJS = \
	$(XMLSEC_OPENSSL_INTDIR)\app.obj\
	$(XMLSEC_OPENSSL_INTDIR)\bn.obj \
	$(XMLSEC_OPENSSL_INTDIR)\ciphers.obj \
	$(XMLSEC_OPENSSL_INTDIR)\crypto.obj \
	$(XMLSEC_OPENSSL_INTDIR)\digests.obj \
	$(XMLSEC_OPENSSL_INTDIR)\evp.obj \
	$(XMLSEC_OPENSSL_INTDIR)\evp_signatures.obj \
	$(XMLSEC_OPENSSL_INTDIR)\hmac.obj \
	$(XMLSEC_OPENSSL_INTDIR)\kt_rsa.obj \
	$(XMLSEC_OPENSSL_INTDIR)\kw_aes.obj \
	$(XMLSEC_OPENSSL_INTDIR)\kw_des.obj \
	$(XMLSEC_OPENSSL_INTDIR)\signatures.obj \
	$(XMLSEC_OPENSSL_INTDIR)\strings.obj \
	$(XMLSEC_OPENSSL_INTDIR)\symkeys.obj \
	$(XMLSEC_OPENSSL_INTDIR)\x509.obj \
	$(XMLSEC_OPENSSL_INTDIR)\x509vfy.obj
XMLSEC_OPENSSL_OBJS_A = \
	$(XMLSEC_OPENSSL_INTDIR_A)\app.obj\
	$(XMLSEC_OPENSSL_INTDIR_A)\bn.obj \
	$(XMLSEC_OPENSSL_INTDIR_A)\ciphers.obj \
	$(XMLSEC_OPENSSL_INTDIR_A)\crypto.obj \
	$(XMLSEC_OPENSSL_INTDIR_A)\digests.obj \
	$(XMLSEC_OPENSSL_INTDIR_A)\evp.obj \
	$(XMLSEC_OPENSSL_INTDIR_A)\evp_signatures.obj \
	$(XMLSEC_OPENSSL_INTDIR_A)\hmac.obj \
	$(XMLSEC_OPENSSL_INTDIR_A)\kt_rsa.obj \
	$(XMLSEC_OPENSSL_INTDIR_A)\kw_aes.obj \
	$(XMLSEC_OPENSSL_INTDIR_A)\kw_des.obj \
	$(XMLSEC_OPENSSL_INTDIR_A)\signatures.obj \
	$(XMLSEC_OPENSSL_INTDIR_A)\strings.obj \
	$(XMLSEC_OPENSSL_INTDIR_A)\symkeys.obj \
	$(XMLSEC_OPENSSL_INTDIR_A)\x509.obj \
	$(XMLSEC_OPENSSL_INTDIR_A)\x509vfy.obj

XMLSEC_NSS_OBJS = \
	$(XMLSEC_NSS_INTDIR)\app.obj\
	$(XMLSEC_NSS_INTDIR)\bignum.obj\
	$(XMLSEC_NSS_INTDIR)\ciphers.obj \
	$(XMLSEC_NSS_INTDIR)\crypto.obj \
	$(XMLSEC_NSS_INTDIR)\digests.obj \
	$(XMLSEC_NSS_INTDIR)\hmac.obj \
	$(XMLSEC_NSS_INTDIR)\pkikeys.obj\
	$(XMLSEC_NSS_INTDIR)\signatures.obj\
	$(XMLSEC_NSS_INTDIR)\symkeys.obj \
	$(XMLSEC_NSS_INTDIR)\x509.obj\
	$(XMLSEC_NSS_INTDIR)\x509vfy.obj\
	$(XMLSEC_NSS_INTDIR)\keysstore.obj\
	$(XMLSEC_NSS_INTDIR)\keytrans.obj\
	$(XMLSEC_NSS_INTDIR)\kw_des.obj\
	$(XMLSEC_NSS_INTDIR)\kw_aes.obj\
	$(XMLSEC_NSS_INTDIR)\strings.obj
XMLSEC_NSS_OBJS_A = \
	$(XMLSEC_NSS_INTDIR_A)\app.obj\
	$(XMLSEC_NSS_INTDIR_A)\bignum.obj\
	$(XMLSEC_NSS_INTDIR_A)\ciphers.obj \
	$(XMLSEC_NSS_INTDIR_A)\crypto.obj \
	$(XMLSEC_NSS_INTDIR_A)\digests.obj \
	$(XMLSEC_NSS_INTDIR_A)\hmac.obj \
	$(XMLSEC_NSS_INTDIR_A)\pkikeys.obj\
	$(XMLSEC_NSS_INTDIR_A)\signatures.obj\
	$(XMLSEC_NSS_INTDIR_A)\symkeys.obj \
	$(XMLSEC_NSS_INTDIR_A)\x509.obj\
	$(XMLSEC_NSS_INTDIR_A)\x509vfy.obj\
	$(XMLSEC_NSS_INTDIR_A)\keysstore.obj\
	$(XMLSEC_NSS_INTDIR_A)\kt_rsa.obj\
	$(XMLSEC_NSS_INTDIR_A)\kw_des.obj\
	$(XMLSEC_NSS_INTDIR_A)\kw_aes.obj\
	$(XMLSEC_NSS_INTDIR_A)\strings.obj

XMLSEC_MSCRYPTO_OBJS = \
	$(XMLSEC_MSCRYPTO_INTDIR)\app.obj\
	$(XMLSEC_MSCRYPTO_INTDIR)\crypto.obj \
	$(XMLSEC_MSCRYPTO_INTDIR)\ciphers.obj \
	$(XMLSEC_MSCRYPTO_INTDIR)\digests.obj \
	$(XMLSEC_MSCRYPTO_INTDIR)\hmac.obj \
	$(XMLSEC_MSCRYPTO_INTDIR)\symkeys.obj \
	$(XMLSEC_MSCRYPTO_INTDIR)\kt_rsa.obj \
	$(XMLSEC_MSCRYPTO_INTDIR)\kw_aes.obj \
	$(XMLSEC_MSCRYPTO_INTDIR)\kw_des.obj \
	$(XMLSEC_MSCRYPTO_INTDIR)\strings.obj \
	$(XMLSEC_MSCRYPTO_INTDIR)\signatures.obj \
	$(XMLSEC_MSCRYPTO_INTDIR)\certkeys.obj \
	$(XMLSEC_MSCRYPTO_INTDIR)\keysstore.obj \
	$(XMLSEC_MSCRYPTO_INTDIR)\x509.obj \
	$(XMLSEC_MSCRYPTO_INTDIR)\x509vfy.obj
XMLSEC_MSCRYPTO_OBJS_A = \
	$(XMLSEC_MSCRYPTO_INTDIR_A)\app.obj\
	$(XMLSEC_MSCRYPTO_INTDIR_A)\crypto.obj \
	$(XMLSEC_MSCRYPTO_INTDIR_A)\ciphers.obj \
	$(XMLSEC_MSCRYPTO_INTDIR_A)\digests.obj \
	$(XMLSEC_MSCRYPTO_INTDIR_A)\hmac.obj \
	$(XMLSEC_MSCRYPTO_INTDIR_A)\symkeys.obj \
	$(XMLSEC_MSCRYPTO_INTDIR_A)\kt_rsa.obj \
	$(XMLSEC_MSCRYPTO_INTDIR_A)\kw_aes.obj \
	$(XMLSEC_MSCRYPTO_INTDIR_A)\kw_des.obj \
	$(XMLSEC_MSCRYPTO_INTDIR_A)\strings.obj \
	$(XMLSEC_MSCRYPTO_INTDIR_A)\signatures.obj \
	$(XMLSEC_MSCRYPTO_INTDIR_A)\certkeys.obj \
	$(XMLSEC_MSCRYPTO_INTDIR_A)\keysstore.obj \
	$(XMLSEC_MSCRYPTO_INTDIR_A)\x509.obj \
	$(XMLSEC_MSCRYPTO_INTDIR_A)\x509vfy.obj

XMLSEC_MSCNG_OBJS = \
	$(XMLSEC_MSCNG_INTDIR)\app.obj\
	$(XMLSEC_MSCNG_INTDIR)\certkeys.obj \
	$(XMLSEC_MSCNG_INTDIR)\crypto.obj\
	$(XMLSEC_MSCNG_INTDIR)\ciphers.obj \
	$(XMLSEC_MSCNG_INTDIR)\digests.obj\
	$(XMLSEC_MSCNG_INTDIR)\hmac.obj \
	$(XMLSEC_MSCNG_INTDIR)\symkeys.obj \
	$(XMLSEC_MSCNG_INTDIR)\kt_rsa.obj \
	$(XMLSEC_MSCNG_INTDIR)\kw_aes.obj \
	$(XMLSEC_MSCNG_INTDIR)\kw_des.obj \
	$(XMLSEC_MSCNG_INTDIR)\strings.obj\
	$(XMLSEC_MSCNG_INTDIR)\signatures.obj\
	$(XMLSEC_MSCNG_INTDIR)\keysstore.obj \
	$(XMLSEC_MSCNG_INTDIR)\x509.obj\
	$(XMLSEC_MSCNG_INTDIR)\x509vfy.obj
XMLSEC_MSCNG_OBJS_A = \
	$(XMLSEC_MSCNG_INTDIR_A)\app.obj\
	$(XMLSEC_MSCNG_INTDIR_A)\certkeys.obj \
	$(XMLSEC_MSCNG_INTDIR_A)\crypto.obj\
	$(XMLSEC_MSCNG_INTDIR_A)\ciphers.obj \
	$(XMLSEC_MSCNG_INTDIR_A)\digests.obj\
	$(XMLSEC_MSCNG_INTDIR_A)\hmac.obj \
	$(XMLSEC_MSCNG_INTDIR_A)\symkeys.obj \
	$(XMLSEC_MSCNG_INTDIR_A)\kt_rsa.obj \
	$(XMLSEC_MSCNG_INTDIR_A)\kw_aes.obj \
	$(XMLSEC_MSCNG_INTDIR_A)\kw_des.obj \
	$(XMLSEC_MSCNG_INTDIR_A)\strings.obj\
	$(XMLSEC_MSCNG_INTDIR_A)\signatures.obj\
	$(XMLSEC_MSCNG_INTDIR_A)\keysstore.obj \
	$(XMLSEC_MSCNG_INTDIR_A)\x509.obj\
	$(XMLSEC_MSCNG_INTDIR_A)\x509vfy.obj

#
# The preprocessor and its options.
#
CPP      = cl.exe /EP
CPPFLAGS = /nologo

#
# The compiler and its options.
#
CFLAGS = $(CFLAGS) /nologo /D "WIN32" /D "_WINDOWS" /D inline=__inline
CFLAGS = $(CFLAGS) /D "_MBCS" /D "_REENTRANT" 
CFLAGS = $(CFLAGS) /D PACKAGE=\"$(XMLSEC_NAME)\"
CFLAGS = $(CFLAGS) /D "HAVE_STDIO_H" /D "HAVE_STDLIB_H"
CFLAGS = $(CFLAGS) /D "HAVE_STRING_H" /D "HAVE_CTYPE_H"
CFLAGS = $(CFLAGS) /D "HAVE_MALLOC_H" /D "HAVE_MEMORY_H"
CFLAGS = $(CFLAGS) /D "XMLSEC_NO_GOST" /D "XMLSEC_NO_GOST2012"
CFLAGS = $(CFLAGS) /D "XMLSEC_NO_SIZE_T"
CFLAGS = $(CFLAGS) /I$(BASEDIR) /I$(BASEDIR)\include
CFLAGS = $(CFLAGS) /I$(INCPREFIX)

!if "$(PEDANTIC)" == "1"
CFLAGS = $(CFLAGS) /W4
!else
CFLAGS = $(CFLAGS) /W1
!endif

# C4127: conditional expression is constant
#     this generates a false warning inside asserts
# C4130: '!=': logical operation on address of string constant:
#     this generates a false warning inside macros
# C4152: nonstandard extension, function/data pointer conversion in expression
#     this generates a false warning for XMLSEC_PTR_TO_FUNC
# C4232: nonstandard extension, address of dllimport is not static
#     this generates a false warning for functions used in structs
CFLAGS = $(CFLAGS) /wd4127 /wd4130 /wd4152 /wd4232

!if "$(WERROR)" == "1"
CFLAGS = $(CFLAGS) /WX
!endif

!if "$(UNICODE)" == "1"
CFLAGS = $(CFLAGS) /D "UNICODE" /D "_UNICODE"
!endif

# Optimisation and debug symbols.
!if "$(DEBUG)" == "1"
CFLAGS = $(CFLAGS) /D "_DEBUG" /Od /Zi
!else
CFLAGS = $(CFLAGS) /D "NDEBUG" /O2 /Zi
!endif

CFLAGS = $(CFLAGS) $(CRUNTIME)

# configurable options
!if "$(WITH_LIBXSLT)" == "1"
!else
CFLAGS = $(CFLAGS) /DXMLSEC_NO_XSLT=1
!endif

!if "$(WITH_NT4)" == "1"
CFLAGS = $(CFLAGS) /DXMLSEC_MSCRYPTO_NT4=1
!else
!endif

CFLAGS = $(CFLAGS) /D "XMLSEC_DEFAULT_CRYPTO=\"$(XMLSEC_DEFAULT_CRYPTO)\""
!if "$(WITH_DL)" == "1"
CFLAGS = $(CFLAGS) /D "XMLSEC_DL_WIN32"
APP_CFLAGS = $(APP_CFLAGS) /D "XMLSEC_CRYPTO_DYNAMIC_LOADING"
!else
CFLAGS 	= $(CFLAGS) /D "XMLSEC_NO_CRYPTO_DYNAMIC_LOADING"
APP_CFLAGS = $(APP_CFLAGS) $(XMLSEC_CRYPTO_CFLAGS)
# this disables TEMPLATE tests and helps with missing algorithms (hmac) in mscrypto
APP_CFLAGS = $(APP_CFLAGS) /D "XMLSEC_NO_TMPL_TEST"
!endif

XMLSEC_OPENSSL_CFLAGS   = /D "XMLSEC_CRYPTO_OPENSSL" /D "XMLSEC_DEFAULT_CRYPTO=\"openssl\""
XMLSEC_NSS_CFLAGS   	= /D "XMLSEC_CRYPTO_NSS" /D "XMLSEC_DEFAULT_CRYPTO=\"nss\""
XMLSEC_MSCRYPTO_CFLAGS  = /D "XMLSEC_CRYPTO_MSCRYPTO" /D "XMLSEC_DEFAULT_CRYPTO=\"mscrypto\""
XMLSEC_MSCNG_CFLAGS     = /D "XMLSEC_CRYPTO_MSCNG" /D "XMLSEC_DEFAULT_CRYPTO=\"mscng\""

# Crytpo options
!if "$(WITH_OPENSSL_VERSION)" == "XMLSEC_OPENSSL_300"
!if "$(WITH_OPENSSL3_ENGINES)" == "1"
XMLSEC_OPENSSL_CFLAGS  = $(XMLSEC_OPENSSL_CFLAGS) /D "XMLSEC_OPENSSL3_ENGINES=1"
!endif
!endif

#
# The linker and its options.
#
LD 				= link.exe
LDFLAGS 		= /nologo /debug
LDFLAGS 		= $(LDFLAGS) /LIBPATH:$(BINDIR) /LIBPATH:$(LIBPREFIX)
LIBS 			=

# Optimisation and debug symbols.
!if "$(DEBUG)" == "1"
LDFLAGS 		= $(LDFLAGS) /DEBUG /OPT:ICF
!else
LDFLAGS 		= $(LDFLAGS) /OPT:REF,ICF
!endif

!if "$(PEDANTIC)" == "1"
LDFLAGS = $(LDFLAGS) /WX
!endif

SOLIBS 			= $(LIBS) libxml2.lib ws2_32.lib
ALIBS 			= $(LIBS) libxml2_a.lib ws2_32.lib

!if "$(WITH_ICONV)" == "1"
CFLAGS          = $(CFLAGS) /D "LIBXML_ICONV_ENABLED"
SOLIBS 			= $(SOLIBS) iconv.lib
ALIBS 			= $(ALIBS) iconv_a.lib
!endif

!if "$(WITH_LIBXSLT)" == "1"
SOLIBS 			= $(SOLIBS) libxslt.lib
ALIBS 			= $(ALIBS) libxslt_a.lib
!endif

!if "$(WITH_DL)" == "1"
APP_LIBS  		= $(SOLIBS) $(XMLSEC_CRYPTO_SOLIBS)
!else
APP_LIBS  		= $(ALIBS) $(XMLSEC_CRYPTO_ALIBS)
!endif

!if "$(WITH_OPENSSL_VERSION)" == "XMLSEC_OPENSSL_300"
XMLSEC_OPENSSL_SOLIBS   = libcrypto.lib wsock32.lib kernel32.lib user32.lib gdi32.lib crypt32.lib advapi32.lib ws2_32.lib
XMLSEC_OPENSSL_ALIBS    = libcrypto.lib wsock32.lib kernel32.lib user32.lib gdi32.lib crypt32.lib advapi32.lib ws2_32.lib
!elseif "$(WITH_OPENSSL_VERSION)" == "XMLSEC_OPENSSL_110"
XMLSEC_OPENSSL_SOLIBS   = libcrypto.lib wsock32.lib kernel32.lib user32.lib gdi32.lib crypt32.lib advapi32.lib ws2_32.lib
XMLSEC_OPENSSL_ALIBS    = libcrypto.lib wsock32.lib kernel32.lib user32.lib gdi32.lib crypt32.lib advapi32.lib ws2_32.lib
!else
XMLSEC_OPENSSL_SOLIBS   = libeay32.lib wsock32.lib kernel32.lib user32.lib gdi32.lib crypt32.lib advapi32.lib
XMLSEC_OPENSSL_ALIBS    = libeay32.lib wsock32.lib kernel32.lib user32.lib gdi32.lib crypt32.lib advapi32.lib
!endif

XMLSEC_NSS_SOLIBS       = smime3.lib ssl3.lib nss3.lib libnspr4.lib libplds4.lib libplc4.lib kernel32.lib user32.lib gdi32.lib
XMLSEC_NSS_ALIBS        = smime3.lib ssl3.lib nss3.lib libnspr4_s.lib libplds4_s.lib libplc4_s.lib kernel32.lib user32.lib gdi32.lib

XMLSEC_MSCRYPTO_SOLIBS  = kernel32.lib user32.lib gdi32.lib Crypt32.lib Advapi32.lib
XMLSEC_MSCRYPTO_ALIBS   = kernel32.lib user32.lib gdi32.lib Crypt32.lib Advapi32.lib

XMLSEC_MSCNG_SOLIBS  = kernel32.lib user32.lib gdi32.lib Crypt32.lib Advapi32.lib Bcrypt.lib Ncrypt.lib
XMLSEC_MSCNG_ALIBS   = kernel32.lib user32.lib gdi32.lib Crypt32.lib Advapi32.lib Bcrypt.lib Ncrypt.lib


# The archiver and its options.
AR = link.exe /lib
ARFLAGS = /nologo

!if "$(PEDANTIC)" == "1"
ARFLAGS = $(ARFLAGS) /WX
!endif

#
# xmlsec-<default-crypto> options
#
!if "$(WITH_DEFAULT_CRYPTO)" == "openssl"
XMLSEC_DEFAULT_CRYPTO   = "openssl"
XMLSEC_DEFAULT_CRYPTO_A = "openssla"
XMLSEC_CRYPTO_CFLAGS   	= $(XMLSEC_OPENSSL_CFLAGS)
XMLSEC_CRYPTO_SOLIBS  	= $(XMLSEC_OPENSSL_SOLIBS)
XMLSEC_CRYPTO_ALIBS    	= $(XMLSEC_OPENSSL_ALIBS)
XMLSEC_CRYPTO_SO        = $(XMLSEC_OPENSSL_SO)
XMLSEC_CRYPTO_IMP	    = $(XMLSEC_OPENSSL_IMP)
XMLSEC_CRYPTO_A		    = $(XMLSEC_OPENSSL_A)
!endif

!if "$(WITH_DEFAULT_CRYPTO)" == "nss"
XMLSEC_DEFAULT_CRYPTO   = "nss"
XMLSEC_DEFAULT_CRYPTO_A = "nssa"
XMLSEC_CRYPTO_CFLAGS   	= $(XMLSEC_NSS_CFLAGS)
XMLSEC_CRYPTO_SOLIBS   	= $(XMLSEC_NSS_SOLIBS)
XMLSEC_CRYPTO_ALIBS    	= $(XMLSEC_NSS_ALIBS)
XMLSEC_CRYPTO_SO        = $(XMLSEC_NSS_SO)
XMLSEC_CRYPTO_IMP	    = $(XMLSEC_NSS_IMP)
XMLSEC_CRYPTO_A		    = $(XMLSEC_NSS_A)
!endif

!if "$(WITH_DEFAULT_CRYPTO)" == "mscrypto"
XMLSEC_DEFAULT_CRYPTO  	= "mscrypto"
XMLSEC_DEFAULT_CRYPTO_A = "mscryptoa"
XMLSEC_CRYPTO_CFLAGS   	= $(XMLSEC_MSCRYPTO_CFLAGS)
XMLSEC_CRYPTO_SOLIBS   	= $(XMLSEC_MSCRYPTO_SOLIBS)
XMLSEC_CRYPTO_ALIBS    	= $(XMLSEC_MSCRYPTO_ALIBS)
XMLSEC_CRYPTO_SO        = $(XMLSEC_MSCRYPTO_SO)
XMLSEC_CRYPTO_IMP	    = $(XMLSEC_MSCRYPTO_IMP)
XMLSEC_CRYPTO_A		    = $(XMLSEC_MSCRYPTO_A)
!endif

!if "$(WITH_DEFAULT_CRYPTO)" == "mscng"
XMLSEC_DEFAULT_CRYPTO  	= "mscng"
XMLSEC_DEFAULT_CRYPTO_A = "mscnga"
XMLSEC_CRYPTO_CFLAGS   	= $(XMLSEC_MSCNG_CFLAGS)
XMLSEC_CRYPTO_SOLIBS   	= $(XMLSEC_MSCNG_SOLIBS)
XMLSEC_CRYPTO_ALIBS    	= $(XMLSEC_MSCNG_ALIBS)
XMLSEC_CRYPTO_SO        = $(XMLSEC_MSCNG_SO)
XMLSEC_CRYPTO_IMP	    = $(XMLSEC_MSCNG_IMP)
XMLSEC_CRYPTO_A		    = $(XMLSEC_MSCNG_A)
!endif


!if "$(WITH_OPENSSL_VERSION)" == "XMLSEC_OPENSSL_300"
XMLSEC_OPENSSL_TEST_CONFIG = openssl3.cnf
!else
XMLSEC_OPENSSL_TEST_CONFIG =
!endif

!if "$(STATIC)" == "1"
EXTRA_ALL_TARGETS=xmlseca
EXTRA_OPENSSL_TARGETS=openssla
EXTRA_NSS_TARGETS=nssa
EXTRA_MSCRYPTO_TARGETS=mscryptoa
EXTRA_MSCNG_TARGETS=mscnga
!else
EXTRA_ALL_TARGETS=
EXTRA_OPENSSL_TARGETS=
EXTRA_NSS_TARGETS=
EXTRA_MSCRYPTO_TARGETS=
EXTRA_MSCNG_TARGETS=
!endif

#
# Build rules
#

all: apps $(EXTRA_ALL_TARGETS)

apps: $(BINDIR)\$(APP_NAME)

xmlseca:  $(XMLSEC_APPS_INTDIR_A) $(BINDIR)\$(XMLSEC_A) $(XMLSEC_DEFAULT_CRYPTO_A)
xmlsec: $(XMLSEC_APPS_INTDIR) $(BINDIR)\$(XMLSEC_SO) $(XMLSEC_DEFAULT_CRYPTO)

openssla: $(BINDIR)\$(XMLSEC_OPENSSL_A)
openssl: $(BINDIR)\$(XMLSEC_OPENSSL_SO) $(EXTRA_OPENSSL_TARGETS)

nssa: $(BINDIR)\$(XMLSEC_NSS_A)
nss: $(BINDIR)\$(XMLSEC_NSS_SO) $(EXTRA_NSS_TARGETS)

mscryptoa: $(BINDIR)\$(XMLSEC_MSCRYPTO_A)
mscrypto: $(BINDIR)\$(XMLSEC_MSCRYPTO_SO) $(EXTRA_MSCRYPTO_TARGETS)

mscnga: $(BINDIR)\$(XMLSEC_MSCNG_A)
mscng: $(BINDIR)\$(XMLSEC_MSCNG_SO) $(EXTRA_MSCNG_TARGETS)

check : check-keys check-dsig check-enc

check-keys : $(BINDIR)\$(APP_NAME)
	cd ..
	if not exist %MAKEDIR%\tmp mkdir %MAKEDIR%\tmp
	set TMPFOLDER=%MAKEDIR%\tmp
	set XMLSEC_OPENSSL_TEST_CONFIG=$(XMLSEC_OPENSSL_TEST_CONFIG)
	sh ./tests/testrun.sh ./tests/testKeys.sh "$(WITH_DEFAULT_CRYPTO)" ./tests win32/$(BINDIR)/$(APP_NAME) der
	cd win32

check-dsig : $(BINDIR)\$(APP_NAME)
	cd ..
	if not exist %MAKEDIR%\tmp mkdir %MAKEDIR%\tmp
	set TMPFOLDER=%MAKEDIR%\tmp
	set XMLSEC_OPENSSL_TEST_CONFIG=$(XMLSEC_OPENSSL_TEST_CONFIG)
	sh ./tests/testrun.sh ./tests/testDSig.sh "$(WITH_DEFAULT_CRYPTO)" ./tests win32/$(BINDIR)/$(APP_NAME) der
	cd win32

check-enc : $(BINDIR)\$(APP_NAME)
	cd ..
	if not exist %MAKEDIR%\tmp mkdir %MAKEDIR%\tmp
	set TMPFOLDER=%MAKEDIR%\tmp
	set XMLSEC_OPENSSL_TEST_CONFIG=$(XMLSEC_OPENSSL_TEST_CONFIG)
	sh ./tests/testrun.sh ./tests/testEnc.sh "$(WITH_DEFAULT_CRYPTO)" ./tests win32/$(BINDIR)/$(APP_NAME) der
	cd win32

clean :
	if exist $(XMLSEC_INTDIR) rmdir /S /Q $(XMLSEC_INTDIR)
	if exist $(XMLSEC_INTDIR_A) rmdir /S /Q $(XMLSEC_INTDIR_A)
	if exist $(XMLSEC_OPENSSL_INTDIR) rmdir /S /Q $(XMLSEC_OPENSSL_INTDIR)
	if exist $(XMLSEC_OPENSSL_INTDIR_A) rmdir /S /Q $(XMLSEC_OPENSSL_INTDIR_A)
	if exist $(XMLSEC_NSS_INTDIR) rmdir /S /Q $(XMLSEC_NSS_INTDIR)
	if exist $(XMLSEC_NSS_INTDIR_A) rmdir /S /Q $(XMLSEC_NSS_INTDIR_A)
	if exist $(XMLSEC_MSCRYPTO_INTDIR) rmdir /S /Q $(XMLSEC_MSCRYPTO_INTDIR)
	if exist $(XMLSEC_MSCRYPTO_INTDIR_A) rmdir /S /Q $(XMLSEC_MSCRYPTO_INTDIR_A)
	if exist $(XMLSEC_MSCNG_INTDIR) rmdir /S /Q $(XMLSEC_MSCNG_INTDIR)
	if exist $(XMLSEC_MSCNG_INTDIR_A) rmdir /S /Q $(XMLSEC_MSCNG_INTDIR_A)
	if exist $(XMLSEC_APPS_INTDIR) rmdir /S /Q $(XMLSEC_APPS_INTDIR)
	if exist $(XMLSEC_APPS_INTDIR_A) rmdir /S /Q $(XMLSEC_APPS_INTDIR_A)
	if exist $(BINDIR) rmdir /S /Q $(BINDIR)

rebuild : clean all

install : all
	if not exist $(INCPREFIX)\$(XMLSEC_NAME) mkdir $(INCPREFIX)\$(XMLSEC_NAME)
	if not exist $(BINPREFIX) mkdir $(BINPREFIX)
	if not exist $(LIBPREFIX) mkdir $(LIBPREFIX)
	if exist $(BINDIR)\$(XMLSEC_OPENSSL_SO) if not exist $(INCPREFIX)\$(XMLSEC_NAME)\openssl mkdir $(INCPREFIX)\$(XMLSEC_NAME)\openssl
	if exist $(BINDIR)\$(XMLSEC_NSS_SO) if not exist $(INCPREFIX)\$(XMLSEC_NAME)\nss mkdir $(INCPREFIX)\$(XMLSEC_NAME)\nss
	if exist $(BINDIR)\$(XMLSEC_MSCRYPTO_SO) if not exist $(INCPREFIX)\$(XMLSEC_NAME)\mscrypto mkdir $(INCPREFIX)\$(XMLSEC_NAME)\mscrypto
	if exist $(BINDIR)\$(XMLSEC_MSCNG_SO) if not exist $(INCPREFIX)\$(XMLSEC_NAME)\mscng mkdir $(INCPREFIX)\$(XMLSEC_NAME)\mscng
	if exist $(BASEDIR)\include\$(XMLSEC_NAME) copy $(BASEDIR)\include\$(XMLSEC_NAME)\*.h $(INCPREFIX)\$(XMLSEC_NAME)
	if exist $(BINDIR)\$(XMLSEC_OPENSSL_SO) copy $(BASEDIR)\include\$(XMLSEC_NAME)\openssl\*.h $(INCPREFIX)\$(XMLSEC_NAME)\openssl
	if exist $(BINDIR)\$(XMLSEC_NSS_SO) copy $(BASEDIR)\include\$(XMLSEC_NAME)\nss\*.h $(INCPREFIX)\$(XMLSEC_NAME)\nss
	if exist $(BINDIR)\$(XMLSEC_MSCRYPTO_SO) copy $(BASEDIR)\include\$(XMLSEC_NAME)\mscrypto\*.h $(INCPREFIX)\$(XMLSEC_NAME)\mscrypto
	if exist $(BINDIR)\$(XMLSEC_MSCNG_SO) copy $(BASEDIR)\include\$(XMLSEC_NAME)\mscng\*.h $(INCPREFIX)\$(XMLSEC_NAME)\mscng
	if exist $(BINDIR)\$(XMLSEC_SO) copy $(BINDIR)\$(XMLSEC_SO) $(SOPREFIX)
	if exist $(BINDIR)\$(XMLSEC_SO_MANIFEST) copy $(BINDIR)\$(XMLSEC_SO_MANIFEST) $(SOPREFIX)
	if exist $(BINDIR)\$(XMLSEC_PDB) copy $(BINDIR)\$(XMLSEC_PDB) $(SOPREFIX)
	if exist $(BINDIR)\$(XMLSEC_A) copy $(BINDIR)\$(XMLSEC_A) $(LIBPREFIX)
	if exist $(BINDIR)\$(XMLSEC_IMP) copy $(BINDIR)\$(XMLSEC_IMP) $(LIBPREFIX)
	if exist $(BINDIR)\$(XMLSEC_OPENSSL_SO) copy $(BINDIR)\$(XMLSEC_OPENSSL_SO) $(SOPREFIX)
	if exist $(BINDIR)\$(XMLSEC_OPENSSL_SO_MANIFEST) copy $(BINDIR)\$(XMLSEC_OPENSSL_SO_MANIFEST) $(SOPREFIX)
	if exist $(BINDIR)\$(XMLSEC_OPENSSL_PDB) copy $(BINDIR)\$(XMLSEC_OPENSSL_PDB) $(SOPREFIX)
	if exist $(BINDIR)\$(XMLSEC_OPENSSL_A) copy $(BINDIR)\$(XMLSEC_OPENSSL_A) $(LIBPREFIX)
	if exist $(BINDIR)\$(XMLSEC_OPENSSL_IMP) copy $(BINDIR)\$(XMLSEC_OPENSSL_IMP) $(LIBPREFIX)
	if exist $(BINDIR)\$(XMLSEC_NSS_SO) copy $(BINDIR)\$(XMLSEC_NSS_SO) $(SOPREFIX)
	if exist $(BINDIR)\$(XMLSEC_NSS_SO_MANIFEST) copy $(BINDIR)\$(XMLSEC_NSS_SO_MANIFEST) $(SOPREFIX)
	if exist $(BINDIR)\$(XMLSEC_NSS_PDB) copy $(BINDIR)\$(XMLSEC_NSS_PDB) $(SOPREFIX)
	if exist $(BINDIR)\$(XMLSEC_NSS_A) copy $(BINDIR)\$(XMLSEC_NSS_A) $(LIBPREFIX)
	if exist $(BINDIR)\$(XMLSEC_NSS_IMP) copy $(BINDIR)\$(XMLSEC_NSS_IMP) $(LIBPREFIX)
	if exist $(BINDIR)\$(XMLSEC_MSCRYPTO_SO) copy $(BINDIR)\$(XMLSEC_MSCRYPTO_SO) $(SOPREFIX)
	if exist $(BINDIR)\$(XMLSEC_MSCRYPTO_SO_MANIFEST) copy $(BINDIR)\$(XMLSEC_MSCRYPTO_SO_MANIFEST) $(SOPREFIX)
	if exist $(BINDIR)\$(XMLSEC_MSCRYPTO_PDB) copy $(BINDIR)\$(XMLSEC_MSCRYPTO_PDB) $(SOPREFIX)
	if exist $(BINDIR)\$(XMLSEC_MSCRYPTO_A) copy $(BINDIR)\$(XMLSEC_MSCRYPTO_A) $(LIBPREFIX)
	if exist $(BINDIR)\$(XMLSEC_MSCRYPTO_IMP) copy $(BINDIR)\$(XMLSEC_MSCRYPTO_IMP) $(LIBPREFIX)
	if exist $(BINDIR)\$(XMLSEC_MSCNG_SO) copy $(BINDIR)\$(XMLSEC_MSCNG_SO) $(SOPREFIX)
	if exist $(BINDIR)\$(XMLSEC_MSCNG_SO_MANIFEST) copy $(BINDIR)\$(XMLSEC_MSCNG_SO_MANIFEST) $(SOPREFIX)
	if exist $(BINDIR)\$(XMLSEC_MSCNG_PDB) copy $(BINDIR)\$(XMLSEC_MSCNG_PDB) $(SOPREFIX)
	if exist $(BINDIR)\$(XMLSEC_MSCNG_A) copy $(BINDIR)\$(XMLSEC_MSCNG_A) $(LIBPREFIX)
	if exist $(BINDIR)\$(XMLSEC_MSCNG_IMP) copy $(BINDIR)\$(XMLSEC_MSCNG_IMP) $(LIBPREFIX)
	if exist $(BINDIR)\$(APP_NAME) copy $(BINDIR)\$(APP_NAME) $(BINPREFIX)
	if exist $(BINDIR)\$(APP_NAME_MANIFEST) copy $(BINDIR)\$(APP_NAME_MANIFEST) $(BINPREFIX)

uninstall :
	if exist $(INCPREFIX)\$(XMLSEC_NAME) rmdir /S /Q $(INCPREFIX)\$(XMLSEC_NAME)
	if exist $(SOPREFIX)\$(XMLSEC_SO) del /F /S /Q $(SOPREFIX)\$(XMLSEC_SO)
	if exist $(SOPREFIX)\$(XMLSEC_SO_MANIFEST) del /F /S /Q $(SOPREFIX)\$(XMLSEC_SO)
	if exist $(SOPREFIX)\$(XMLSEC_PDB) del /F /S /Q $(SOPREFIX)\$(XMLSEC_PDB)
	if exist $(LIBPREFIX)\$(XMLSEC_A) del /F /S /Q $(LIBPREFIX)\$(XMLSEC_A)
	if exist $(LIBPREFIX)\$(XMLSEC_IMP) del /F /S /Q $(LIBPREFIX)\$(XMLSEC_IMP)
	if exist $(SOPREFIX)\$(XMLSEC_OPENSSL_SO) del /F /S /Q $(SOPREFIX)\$(XMLSEC_OPENSSL_SO)
	if exist $(SOPREFIX)\$(XMLSEC_OPENSSL_SO_MANIFEST) del /F /S /Q $(SOPREFIX)\$(XMLSEC_OPENSSL_SO)
	if exist $(SOPREFIX)\$(XMLSEC_OPENSSL_PDB) del /F /S /Q $(SOPREFIX)\$(XMLSEC_OPENSSL_PDB)
	if exist $(LIBPREFIX)\$(XMLSEC_OPENSSL_A) del /F /S /Q $(LIBPREFIX)\$(XMLSEC_OPENSSL_A)
	if exist $(LIBPREFIX)\$(XMLSEC_OPENSSL_IMP) del /F /S /Q $(LIBPREFIX)\$(XMLSEC_OPENSSL_IMP)
	if exist $(SOPREFIX)\$(XMLSEC_NSS_SO) del /F /S /Q $(SOPREFIX)\$(XMLSEC_NSS_SO)
	if exist $(SOPREFIX)\$(XMLSEC_NSS_SO_MANIFEST) del /F /S /Q $(SOPREFIX)\$(XMLSEC_NSS_SO)
	if exist $(SOPREFIX)\$(XMLSEC_NSS_PDB) del /F /S /Q $(SOPREFIX)\$(XMLSEC_NSS_PDB)
	if exist $(LIBPREFIX)\$(XMLSEC_NSS_A) del /F /S /Q $(LIBPREFIX)\$(XMLSEC_NSS_A)
	if exist $(LIBPREFIX)\$(XMLSEC_NSS_IMP) del /F /S /Q $(LIBPREFIX)\$(XMLSEC_NSS_IMP)
	if exist $(SOPREFIX)\$(XMLSEC_MSCRYPTO_SO) del /F /S /Q $(SOPREFIX)\$(XMLSEC_MSCRYPTO_SO)
	if exist $(SOPREFIX)\$(XMLSEC_MSCRYPTO_SO_MANIFEST) del /F /S /Q $(SOPREFIX)\$(XMLSEC_MSCRYPTO_SO)
	if exist $(SOPREFIX)\$(XMLSEC_MSCRYPTO_PDB) del /F /S /Q $(SOPREFIX)\$(XMLSEC_MSCRYPTO_PDB)
	if exist $(LIBPREFIX)\$(XMLSEC_MSCRYPTO_A) del /F /S /Q $(LIBPREFIX)\$(XMLSEC_MSCRYPTO_A)
	if exist $(LIBPREFIX)\$(XMLSEC_MSCRYPTO_IMP) del /F /S /Q $(LIBPREFIX)\$(XMLSEC_MSCRYPTO_IMP)
	if exist $(SOPREFIX)\$(XMLSEC_MSCNG_SO) del /F /S /Q $(SOPREFIX)\$(XMLSEC_MSCNG_SO)
	if exist $(SOPREFIX)\$(XMLSEC_MSCNG_SO_MANIFEST) del /F /S /Q $(SOPREFIX)\$(XMLSEC_MSCNG_SO)
	if exist $(SOPREFIX)\$(XMLSEC_MSCNG_PDB) del /F /S /Q $(SOPREFIX)\$(XMLSEC_MSCNG_PDB)
	if exist $(LIBPREFIX)\$(XMLSEC_MSCNG_A) del /F /S /Q $(LIBPREFIX)\$(XMLSEC_MSCNG_A)
	if exist $(LIBPREFIX)\$(XMLSEC_MSCNG_IMP) del /F /S /Q $(LIBPREFIX)\$(XMLSEC_MSCNG_IMP)
	if exist $(BINPREFIX)\$(APP_NAME) del /F /S /Q $(BINPREFIX)\$(APP_NAME)
	if exist $(BINPREFIX)\$(APP_NAME_MANIFEST) del /F /S /Q $(BINPREFIX)\$(APP_NAME_MANIFEST)

#
# Makes the compiler output directory.
#
$(BINDIR) :
	if not exist $(BINDIR) mkdir $(BINDIR)

#
# Makes intermediate directories.
#
$(XMLSEC_APPS_INTDIR) :
	if not exist $(XMLSEC_APPS_INTDIR) mkdir $(XMLSEC_APPS_INTDIR)
$(XMLSEC_APPS_INTDIR_A) :
	if not exist $(XMLSEC_APPS_INTDIR_A) mkdir $(XMLSEC_APPS_INTDIR_A)

$(XMLSEC_INTDIR) :
	if not exist $(XMLSEC_INTDIR) mkdir $(XMLSEC_INTDIR)
$(XMLSEC_INTDIR_A) :
	if not exist $(XMLSEC_INTDIR_A) mkdir $(XMLSEC_INTDIR_A)

$(XMLSEC_OPENSSL_INTDIR) :
	if not exist $(XMLSEC_OPENSSL_INTDIR) mkdir $(XMLSEC_OPENSSL_INTDIR)
$(XMLSEC_OPENSSL_INTDIR_A) :
	if not exist $(XMLSEC_OPENSSL_INTDIR_A) mkdir $(XMLSEC_OPENSSL_INTDIR_A)

$(XMLSEC_NSS_INTDIR) :
	if not exist $(XMLSEC_NSS_INTDIR) mkdir $(XMLSEC_NSS_INTDIR)
$(XMLSEC_NSS_INTDIR_A) :
	if not exist $(XMLSEC_NSS_INTDIR_A) mkdir $(XMLSEC_NSS_INTDIR_A)

$(XMLSEC_MSCRYPTO_INTDIR) :
	if not exist $(XMLSEC_MSCRYPTO_INTDIR) mkdir $(XMLSEC_MSCRYPTO_INTDIR)
$(XMLSEC_MSCRYPTO_INTDIR_A) :
	if not exist $(XMLSEC_MSCRYPTO_INTDIR_A) mkdir $(XMLSEC_MSCRYPTO_INTDIR_A)

$(XMLSEC_MSCNG_INTDIR) :
	if not exist $(XMLSEC_MSCNG_INTDIR) mkdir $(XMLSEC_MSCNG_INTDIR)
$(XMLSEC_MSCNG_INTDIR_A) :
	if not exist $(XMLSEC_MSCNG_INTDIR_A) mkdir $(XMLSEC_MSCNG_INTDIR_A)

#
# An implicit rule for xmlsec compilation.
#
{$(APPS_SRCDIR)}.c{$(XMLSEC_APPS_INTDIR)}.obj::
	$(CC) $(CFLAGS) $(APP_CFLAGS) /Fo$(XMLSEC_APPS_INTDIR)\ /c $<

{$(XMLSEC_SRCDIR)}.c{$(XMLSEC_INTDIR)}.obj::
	$(CC) $(CFLAGS) /Fo$(XMLSEC_INTDIR)\ /c $<

{$(XMLSEC_SRCDIR)}.c{$(XMLSEC_OPENSSL_INTDIR)}.obj::
	$(CC) $(CFLAGS) $(XMLSEC_OPENSSL_CFLAGS) /Fo$(XMLSEC_OPENSSL_INTDIR)\ /c $<
{$(XMLSEC_OPENSSL_SRCDIR)}.c{$(XMLSEC_OPENSSL_INTDIR)}.obj::
	$(CC) $(CFLAGS) $(XMLSEC_OPENSSL_CFLAGS) /Fo$(XMLSEC_OPENSSL_INTDIR)\ /c $<

{$(XMLSEC_SRCDIR)}.c{$(XMLSEC_NSS_INTDIR)}.obj::
	$(CC) $(CFLAGS) $(XMLSEC_NSS_CFLAGS) /Fo$(XMLSEC_NSS_INTDIR)\ /c $<
{$(XMLSEC_NSS_SRCDIR)}.c{$(XMLSEC_NSS_INTDIR)}.obj::
	$(CC) $(CFLAGS) $(XMLSEC_NSS_CFLAGS) /Fo$(XMLSEC_NSS_INTDIR)\ /c $<

{$(XMLSEC_SRCDIR)}.c{$(XMLSEC_MSCRYPTO_INTDIR)}.obj::
	$(CC) $(CFLAGS) $(XMLSEC_MSCRYPTO_CFLAGS) /Fo$(XMLSEC_MSCRYPTO_INTDIR)\ /c $<
{$(XMLSEC_MSCRYPTO_SRCDIR)}.c{$(XMLSEC_MSCRYPTO_INTDIR)}.obj::
	$(CC) $(CFLAGS) $(XMLSEC_MSCRYPTO_CFLAGS) /Fo$(XMLSEC_MSCRYPTO_INTDIR)\ /c $<

{$(XMLSEC_SRCDIR)}.c{$(XMLSEC_MSCNG_INTDIR)}.obj::
	$(CC) $(CFLAGS) $(XMLSEC_MSCNG_CFLAGS) /Fo$(XMLSEC_MSCNG_INTDIR)\ /c $<
{$(XMLSEC_MSCNG_SRCDIR)}.c{$(XMLSEC_MSCNG_INTDIR)}.obj::
	$(CC) $(CFLAGS) $(XMLSEC_MSCNG_CFLAGS) /Fo$(XMLSEC_MSCNG_INTDIR)\ /c $<

#
# An implicit rule for static xmlsec compilation.
#
{$(APPS_SRCDIR)}.c{$(XMLSEC_APPS_INTDIR_A)}.obj::
	$(CC) /D "LIBXML_STATIC" /D "LIBXSLT_STATIC" /D "XMLSEC_STATIC" \
		$(CFLAGS) $(APP_CFLAGS) /Fo$(XMLSEC_APPS_INTDIR_A)\ /c $<

{$(XMLSEC_SRCDIR)}.c{$(XMLSEC_INTDIR_A)}.obj::
	$(CC) /D "LIBXML_STATIC" /D "LIBXSLT_STATIC" /D "XMLSEC_STATIC" \
		$(CFLAGS) /Fo$(XMLSEC_INTDIR_A)\ /c $<

{$(XMLSEC_SRCDIR)}.c{$(XMLSEC_OPENSSL_INTDIR_A)}.obj::
	$(CC) /D "LIBXML_STATIC" /D "LIBXSLT_STATIC" /D "XMLSEC_STATIC" \
		$(CFLAGS) $(XMLSEC_OPENSSL_CFLAGS) /Fo$(XMLSEC_OPENSSL_INTDIR_A)\ /c $<
{$(XMLSEC_OPENSSL_SRCDIR)}.c{$(XMLSEC_OPENSSL_INTDIR_A)}.obj::
	$(CC) /D "LIBXML_STATIC" /D "LIBXSLT_STATIC" /D "XMLSEC_STATIC" \
		$(CFLAGS)  $(XMLSEC_OPENSSL_CFLAGS) /Fo$(XMLSEC_OPENSSL_INTDIR_A)\ /c $<

{$(XMLSEC_SRCDIR)}.c{$(XMLSEC_NSS_INTDIR_A)}.obj::
	$(CC) /D "LIBXML_STATIC" /D "LIBXSLT_STATIC" /D "XMLSEC_STATIC" \
		$(CFLAGS) $(XMLSEC_NSS_CFLAGS) /Fo$(XMLSEC_NSS_INTDIR_A)\ /c $<
{$(XMLSEC_NSS_SRCDIR)}.c{$(XMLSEC_NSS_INTDIR_A)}.obj::
	$(CC) /D "LIBXML_STATIC" /D "LIBXSLT_STATIC" /D "XMLSEC_STATIC" \
		$(CFLAGS) $(XMLSEC_NSS_CFLAGS) /Fo$(XMLSEC_NSS_INTDIR_A)\ /c $<

{$(XMLSEC_SRCDIR)}.c{$(XMLSEC_MSCRYPTO_INTDIR_A)}.obj::
	$(CC) /D "LIBXML_STATIC" /D "LIBXSLT_STATIC" /D "XMLSEC_STATIC" \
		$(CFLAGS) $(XMLSEC_MSCRYPTO_CFLAGS) /Fo$(XMLSEC_MSCRYPTO_INTDIR_A)\ /c $<
{$(XMLSEC_MSCRYPTO_SRCDIR)}.c{$(XMLSEC_MSCRYPTO_INTDIR_A)}.obj::
	$(CC) /D "LIBXML_STATIC" /D "LIBXSLT_STATIC" /D "XMLSEC_STATIC" \
		$(CFLAGS) $(XMLSEC_MSCRYPTO_CFLAGS) /Fo$(XMLSEC_MSCRYPTO_INTDIR_A)\ /c $<

{$(XMLSEC_SRCDIR)}.c{$(XMLSEC_MSCNG_INTDIR_A)}.obj::
	$(CC) /D "LIBXML_STATIC" /D "LIBXSLT_STATIC" /D "XMLSEC_STATIC" \
		$(CFLAGS) $(XMLSEC_MSCNG_CFLAGS) /Fo$(XMLSEC_MSCNG_INTDIR_A)\ /c $<
{$(XMLSEC_MSCNG_SRCDIR)}.c{$(XMLSEC_MSCNG_INTDIR_A)}.obj::
	$(CC) /D "LIBXML_STATIC" /D "LIBXSLT_STATIC" /D "XMLSEC_STATIC" \
		$(CFLAGS) $(XMLSEC_MSCNG_CFLAGS) /Fo$(XMLSEC_MSCNG_INTDIR_A)\ /c $<

#
# Compiles xmlsec source. Uses the implicit rule for commands.
#
$(XMLSEC_OBJS) : $(XMLSEC_INTDIR)
$(XMLSEC_OBJS_A) : $(XMLSEC_INTDIR_A)

$(XMLSEC_OPENSSL_OBJS) : $(XMLSEC_OPENSSL_INTDIR)
$(XMLSEC_OPENSSL_OBJS_A) : $(XMLSEC_OPENSSL_INTDIR_A)

$(XMLSEC_NSS_OBJS) : $(XMLSEC_NSS_INTDIR)
$(XMLSEC_NSS_OBJS_A) : $(XMLSEC_NSS_INTDIR_A)

$(XMLSEC_MSCRYPTO_OBJS) : $(XMLSEC_MSCRYPTO_INTDIR)
$(XMLSEC_MSCRYPTO_OBJS_A) : $(XMLSEC_MSCRYPTO_INTDIR_A)

$(XMLSEC_MSCNG_OBJS) : $(XMLSEC_MSCNG_INTDIR)
$(XMLSEC_MSCNG_OBJS_A) : $(XMLSEC_MSCNG_INTDIR_A)

#
# Creates the shared objects and archives.
#
$(BINDIR)\$(XMLSEC_SO) : $(BINDIR) $(XMLSEC_OBJS)
	$(LD) $(LDFLAGS) /DLL /VERSION:$(XMLSEC_VERSION_MAJOR).$(XMLSEC_VERSION_MINOR) \
		/IMPLIB:$(BINDIR)\$(XMLSEC_IMP) /OUT:$(BINDIR)\$(XMLSEC_SO) \
		$(XMLSEC_OBJS) $(SOLIBS)
$(BINDIR)\$(XMLSEC_A) : $(BINDIR) $(XMLSEC_OBJS_A)
	$(AR) $(ARFLAGS) /OUT:$(BINDIR)\$(XMLSEC_A) $(XMLSEC_OBJS_A)

$(BINDIR)\$(XMLSEC_OPENSSL_SO) : $(BINDIR) $(XMLSEC_OPENSSL_OBJS)
	$(LD) $(LDFLAGS) /DLL /VERSION:$(XMLSEC_VERSION_MAJOR).$(XMLSEC_VERSION_MINOR) \
		/IMPLIB:$(BINDIR)\$(XMLSEC_OPENSSL_IMP) /OUT:$(BINDIR)\$(XMLSEC_OPENSSL_SO) \
		$(XMLSEC_OPENSSL_OBJS) $(XMLSEC_IMP) $(SOLIBS) $(XMLSEC_OPENSSL_SOLIBS)
$(BINDIR)\$(XMLSEC_OPENSSL_A) : $(BINDIR) $(XMLSEC_OPENSSL_OBJS_A)
	$(AR) $(ARFLAGS) /OUT:$(BINDIR)\$(XMLSEC_OPENSSL_A) $(XMLSEC_OPENSSL_OBJS_A)

$(BINDIR)\$(XMLSEC_NSS_SO) : $(BINDIR) $(XMLSEC_NSS_OBJS)
	$(LD) $(LDFLAGS) /DLL /VERSION:$(XMLSEC_VERSION_MAJOR).$(XMLSEC_VERSION_MINOR) \
		/IMPLIB:$(BINDIR)\$(XMLSEC_NSS_IMP) /OUT:$(BINDIR)\$(XMLSEC_NSS_SO) \
		$(XMLSEC_NSS_OBJS) $(XMLSEC_IMP) $(SOLIBS) $(XMLSEC_NSS_SOLIBS)
$(BINDIR)\$(XMLSEC_NSS_A) : $(BINDIR) $(XMLSEC_NSS_OBJS_A)
	$(AR) $(ARFLAGS) /OUT:$(BINDIR)\$(XMLSEC_NSS_A) $(XMLSEC_NSS_OBJS_A)

$(BINDIR)\$(XMLSEC_MSCRYPTO_SO) : $(BINDIR) $(XMLSEC_MSCRYPTO_OBJS)
	$(LD) $(LDFLAGS) /DLL /VERSION:$(XMLSEC_VERSION_MAJOR).$(XMLSEC_VERSION_MINOR) \
		/IMPLIB:$(BINDIR)\$(XMLSEC_MSCRYPTO_IMP) /OUT:$(BINDIR)\$(XMLSEC_MSCRYPTO_SO) \
		$(XMLSEC_MSCRYPTO_OBJS) $(XMLSEC_IMP) $(SOLIBS) $(XMLSEC_MSCRYPTO_SOLIBS)
$(BINDIR)\$(XMLSEC_MSCRYPTO_A) : $(BINDIR) $(XMLSEC_MSCRYPTO_OBJS_A)
	$(AR) $(ARFLAGS) /OUT:$(BINDIR)\$(XMLSEC_MSCRYPTO_A) $(XMLSEC_MSCRYPTO_OBJS_A)

$(BINDIR)\$(XMLSEC_MSCNG_SO) : $(BINDIR) $(XMLSEC_MSCNG_OBJS)
	$(LD) $(LDFLAGS) /DLL /VERSION:$(XMLSEC_VERSION_MAJOR).$(XMLSEC_VERSION_MINOR) \
		/IMPLIB:$(BINDIR)\$(XMLSEC_MSCNG_IMP) /OUT:$(BINDIR)\$(XMLSEC_MSCNG_SO) \
		$(XMLSEC_MSCNG_OBJS) $(XMLSEC_IMP) $(SOLIBS) $(XMLSEC_MSCNG_SOLIBS)
$(BINDIR)\$(XMLSEC_MSCNG_A) : $(BINDIR) $(XMLSEC_MSCNG_OBJS_A)
	$(AR) $(ARFLAGS) /OUT:$(BINDIR)\$(XMLSEC_MSCNG_A) $(XMLSEC_MSCNG_OBJS_A)

#
# An implicit rule for xmlsec command line tool
#
$(BINDIR)\xmlseca.exe: xmlseca $(BINDIR) $(XMLSEC_APPS_OBJS_A)
	$(LD) $(LDFLAGS) /OUT:$@ $(XMLSEC_A) $(XMLSEC_CRYPTO_A) $(APP_LIBS) $(XMLSEC_APPS_OBJS_A)
$(BINDIR)\xmlsec.exe: xmlsec $(BINDIR) $(XMLSEC_APPS_OBJS)
	$(LD) $(LDFLAGS) /OUT:$@ $(XMLSEC_IMP) $(XMLSEC_CRYPTO_IMP) $(APP_LIBS) $(XMLSEC_APPS_OBJS)


# This is a target for me, to make a binary distribution. Not for the public use,
# keep your hands off :-)
BDVERSION = $(XMLSEC_VERSION_MAJOR).$(XMLSEC_VERSION_MINOR).$(XMLSEC_VERSION_SUBMINOR)
BDPREFIX = $(XMLSEC_BASENAME)-$(BDVERSION).win32
bindist : all
	$(MAKE) /nologo PREFIX=$(BDPREFIX) SOPREFIX=$(BDPREFIX)\bin install
	cscript //NoLogo configure.js genreadme $(XMLSEC_BASENAME) $(BDVERSION) $(BDPREFIX)\readme.txt
