#!/bin/sh
#
# Script to import symcrypt
#
# Run from the top of the Wine source dir
#

tag=v103.11.0

set -e

cd libs/symcrypt

# update files
if test "$1" = "-u"
then
    test -d SymCrypt/.git || git clone https://github.com/microsoft/SymCrypt.git

    (cd SymCrypt
     git checkout $tag
     python3 scripts/version.py -b
     sed -i 's!#define SYMCRYPT_BUILD_INFO_TIMESTAMP .*!#define SYMCRYPT_BUILD_INFO_TIMESTAMP ""!' inc/buildInfo.h)

    for i in $(git ls-files inc lib)
    do
        test -f SymCrypt/$i || continue
        sed -e 's!\r!!' -e 's!  *$!!' SymCrypt/$i >$i
    done
fi

for i in \
	aesasm \
	fdef369_asm \
	fdef_asm \
	fdef_mulx \
	sha256xmm_asm \
	wipe
do
    if test -f lib/amd64/$i.symcryptasm
    then
        python3 scripts/symcryptasm_processor.py gas-pe amd64 msft lib/amd64/$i.symcryptasm lib/amd64/$i.S
    fi
    if test -f lib/arm64/$i.symcryptasm
    then
        python3 scripts/symcryptasm_processor.py gas-pe arm64 aapcs64 lib/arm64/$i.symcryptasm lib/arm64/$i.S
        python3 scripts/symcryptasm_processor.py gas-pe arm64 arm64ec lib/arm64/$i.symcryptasm lib/arm64ec/$i.S
    fi
    if test -f lib/arm/$i.symcryptasm
    then
        python3 scripts/symcryptasm_processor.py gas-pe arm aapcs32 lib/arm/$i.symcryptasm lib/arm/$i.S
    fi
done

exit 0
