@echo off
set PATH=%~dp0mingw64\bin;%~dp0python3;%~dp0PortableGit\bin
:: Changes slashes
set "SLASHPATH=%~dp0"
set "SLASHPATH=%SLASHPATH:\=/%"

rem Give python the correct paths
rem Other methods don't work reliably (like setting parameters)
echo python313.zip                                   > %~dp0python3\python313._pth
echo .                                              >> %~dp0python3\python313._pth
echo %~dp0open62541/tools                           >> %~dp0python3\python313._pth
echo %~dp0open62541/tools/nodeset_compiler          >> %~dp0python3\python313._pth


@rem Now the building
cd open62541
rd /s /q build 2>nul
mkdir build
cd build

:: Run the CMake configuration with all features enabled
set CFLAGS=-Wno-redundant-decls
cmake -G "MinGW Makefiles" ^
      -Wno-dev ^
      -DCMAKE_SHARED_LINKER_FLAGS="-static -static-libgcc" ^
      -DBUILD_SHARED_LIBS=ON ^
      -DCMAKE_BUILD_TYPE=Release ^
      -DUA_NAMESPACE_ZERO=FULL ^
      -DUA_ENABLE_DISCOVERY_MULTICAST=OFF ^
      -DUA_ENABLE_ENCRYPTION=MBEDTLS ^
      -DMBEDTLS_INCLUDE_DIRS=%SLASHPATH%mbedtls/build/include;%SLASHPATH%mbedtls/include ^
      -DMBEDTLS_LIBRARY=%SLASHPATH%mbedtls/build/library/libmbedtls.a ^
      -DMBEDX509_LIBRARY=%SLASHPATH%mbedtls/build/library/libmbedx509.a ^
      -DMBEDCRYPTO_LIBRARY=%SLASHPATH%mbedtls/build/library/libmbedcrypto.a ^
      ..

:: -DUA_ENABLE_DISCOVERY_MULTICAST=MDNSD ^
:: -DCMAKE_SHARED_LINKER_FLAGS="-static-libgcc -static-libstdc++ -Wl,-Bstatic -lwinpthread -Wl,-Bdynamic" ^


:: Compile the configuration
cmake --build . --config Release

copy bin\libopen62541.dll ..\..\Delphi

cd ..
cd ..


