# Copyright 2010, Your File System Inc
# All rights reserved
#
# This software has been released under the terms of the BSD License
# For details, see the LICENSE file in the top level source directory

RELDIR=crypto\hcrypto
!include ..\..\config\NTMakefile.$(SYS_NAME)
!include ..\..\config\NTMakefile.version
AFSDEV_AUXCDEFINES = $(AFSDEV_AUXCDEFINES) -I$(SRC)\external\heimdal\hcrypto -DHAVE_CONFIG_H=1 -DKRB5

HCRYPTO = $(SRC)\external\heimdal\hcrypto

INCFILEDIR = $(DESTDIR)\include\hcrypto

INCFILES = \
	$(INCFILEDIR)\engine.h

HCRYPTO_INCFILES = \
        $(INCFILEDIR)\aes.h \
	$(INCFILEDIR)\des.h \
	$(INCFILEDIR)\evp.h \
	$(INCFILEDIR)\evp-hcrypto.h \
	$(INCFILEDIR)\evp-cc.h \
	$(INCFILEDIR)\hmac.h \
	$(INCFILEDIR)\md2.h \
	$(INCFILEDIR)\md4.h \
	$(INCFILEDIR)\md5.h \
	$(INCFILEDIR)\rand.h \
	$(INCFILEDIR)\rc2.h \
	$(INCFILEDIR)\rc4.h \
	$(INCFILEDIR)\sha.h \
	$(INCFILEDIR)\ui.h

LIBFILE = $(DESTDIR)\lib\afshcrypto.dll

# Object files by category.
LOCAL_OBJS = \
        $(OUT)\engine.obj

HCRYPTO_OBJS = $(OUT)\aes.obj \
        $(OUT)\camellia.obj \
        $(OUT)\camellia-ntt.obj \
        $(OUT)\des.obj \
        $(OUT)\evp.obj \
        $(OUT)\evp-hcrypto.obj \
        $(OUT)\evp-cc.obj \
        $(OUT)\hmac.obj \
        $(OUT)\md2.obj \
        $(OUT)\md4.obj \
        $(OUT)\md5.obj \
        $(OUT)\pkcs5.obj \
        $(OUT)\rand.obj \
        $(OUT)\rand-w32.obj \
        $(OUT)\rc2.obj \
        $(OUT)\rc4.obj \
        $(OUT)\rijndael-alg-fst.obj \
        $(OUT)\rnd_keys.obj \
        $(OUT)\sha.obj \
        $(OUT)\sha256.obj \
        $(OUT)\sha512.obj \
        $(OUT)\ui.obj \
        $(OUT)\validate.obj

# This is a horrible hack that is required to get
# around the fact that the OpenAFS build system copies
# its own des.h into the top-level OpenAFS include
# directory.  When the OpenAFS des implementation is
# removed, this hack can be removed as well
des.h: $(HCRYPTO)\des.h
        $(COPY) $** $@

$(HCRYPTO_OBJS):$(HCRYPTO)\$$(@B).c
	$(C2OBJ) $** -I$(HCRYPTO)

$(HCRYPTO_INCFILES):$(HCRYPTO)\$$(@B).h
	$(COPY) $** $(INCFILEDIR)

$(INCFILES):$$(@B).h
	$(COPY) $** $(INCFILEDIR)

RESFILE = $(OUT)\afshcrypto.res

$(RESFILE): afshcrypto.rc AFS_component_version_number.h

!if !defined(NMAKE)
NTMAKE = nmake /nologo /f ntmakefile
!endif

DLLLIBS = \
	$(DESTDIR)\lib\afsroken.lib

$(LIBFILE): $(LOCAL_OBJS) $(HCRYPTO_OBJS) $(RESFILE) $(DLLLIBS)
	$(DLLCONLINK) /DEF:afshcrypto.def shell32.lib
        $(_VC_MANIFEST_EMBED_DLL)
	$(DLLPREP)
        $(CODESIGN_USERLAND)
        $(SYMSTORE_IMPORT)
	$(MAKECYGLIB) --input-def afshcrypto.def

# Definitions for generating versioninfo resources
$(OUT)\afshcrypto.res: AFS_component_version_number.h

install_headers: $(INCFILES) $(HCRYPTO_INCFILES)

install: install_headers des.h $(LIBFILE)

clean::
        $(DEL) $(INCFILES)
        $(DEL) err.h des.h
	$(DEL) $(LIBFILE) $(DESTDIR)\lib\afshcrypto.lib $(DESTDIR)\lib\afshcrypto.exp
