cc := "x86_64-w64-mingw32-clang++"
cc_flags := "-Wall -Wextra -std=c++17"

windres := "x86_64-w64-mingw32-windres"

@clean:
  rm -rf build

@mkdir-build: clean
  mkdir -p build

# Locale
# ===================================================

@build-locale-ua: mkdir-build
  {{windres}} -c 65001 locale/ua/locale.rc -O coff -o build/locale-en.res
  {{cc}} {{cc_flags}} --shared -Wl,--out-implib,build/locale.lib locale/ua/locale.cpp build/locale-en.res -o build/locale-ua.dll

@build-locale-en: mkdir-build
  {{windres}} -c 65001 locale/en/locale.rc -O coff -o build/locale-en.res
  {{cc}} {{cc_flags}} --shared -Wl,--out-implib,build/locale.lib locale/en/locale.cpp build/locale-en.res -o build/locale-en.dll

@build-locale-app: build-locale-ua build-locale-en
  {{cc}} {{cc_flags}} locale/app/main.cpp -o build/locale.exe

@run-locale: build-locale-app
  wine cmd /c build/locale.exe

# Checksum
# ===================================================
@build-checksum-lib: mkdir-build
 {{cc}} {{cc_flags}} --shared checksum/lib/crc.cpp checksum/lib/crc.def -o build/crc.dll -Wl,--out-implib,build/crc.lib

@build-checksum-app: build-checksum-lib
 {{cc}} {{cc_flags}} checksum/app/main.cpp -L build -l crc -o build/checksum.exe

@checksum-append: build-checksum-app
  wine cmd /c build/checksum.exe append build/rsa.dll

@checksum-verify: build-checksum-app
  wine cmd /c build/checksum.exe verify build/rsa.dll

# Rsa Static
# ===================================================
@build-rsa-static-lib: mkdir-build build-checksum-app
 {{cc}} {{cc_flags}} -D BUILD_SHARED --shared rsa-static/lib/rsa.cpp -L build -l crc -o build/rsa.dll -Wl,--out-implib,build/rsa.lib
 wine cmd /c build/checksum.exe append build/rsa.dll

@build-rsa-static-app: build-rsa-static-lib
 {{cc}} {{cc_flags}} rsa-static/app/main.cpp -L build -l rsa -o build/rsa-static.exe

@run-rsa-static: build-rsa-static-app
  wine cmd /c build/rsa-static.exe

# Rsa Shared
# ===================================================
@build-rsa-shared-lib: mkdir-build build-checksum-app
 {{cc}} {{cc_flags}} --shared rsa-shared/lib/rsa.cpp rsa-shared/lib/rsa.def -L build -l crc -o build/rsa.dll -Wl,--out-implib,build/rsa.lib
 wine cmd /c build/checksum.exe append build/rsa.dll

@build-rsa-shared-app: build-rsa-shared-lib
 {{cc}} {{cc_flags}} rsa-shared/app/main.cpp -o build/rsa-shared.exe

@run-rsa-shared: build-rsa-shared-app
  wine cmd /c build/rsa-shared.exe
