1*0afa8e06SEd Maste param( 2*0afa8e06SEd Maste [string]$CMakePath = "C:\Program Files\CMake\bin\cmake.exe", 3*0afa8e06SEd Maste [string]$GitPath = "C:\Program Files\Git\bin\git.exe", 4*0afa8e06SEd Maste [string]$SevenZPath = "C:\Program Files\7-Zip\7z.exe", 5*0afa8e06SEd Maste [string]$GPGPath = "C:\Program Files (x86)\GnuPG\bin\gpg.exe", 6*0afa8e06SEd Maste [string]$WinSDK = "", 7*0afa8e06SEd Maste [string]$Fido2Flags = "" 8*0afa8e06SEd Maste ) 9*0afa8e06SEd Maste 10*0afa8e06SEd Maste $ErrorActionPreference = "Continue" 11*0afa8e06SEd Maste 12*0afa8e06SEd Maste [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 13*0afa8e06SEd Maste 14*0afa8e06SEd Maste # LibreSSL coordinates. 15*0afa8e06SEd Maste New-Variable -Name 'LIBRESSL_URL' ` 16*0afa8e06SEd Maste -Value 'https://fastly.cdn.openbsd.org/pub/OpenBSD/LibreSSL' -Option Constant 17*0afa8e06SEd Maste New-Variable -Name 'LIBRESSL' -Value 'libressl-3.2.5' -Option Constant 18*0afa8e06SEd Maste 19*0afa8e06SEd Maste # libcbor coordinates. 20*0afa8e06SEd Maste New-Variable -Name 'LIBCBOR' -Value 'libcbor-0.8.0' -Option Constant 21*0afa8e06SEd Maste New-Variable -Name 'LIBCBOR_BRANCH' -Value 'v0.8.0' -Option Constant 22*0afa8e06SEd Maste New-Variable -Name 'LIBCBOR_GIT' -Value 'https://github.com/pjk/libcbor' ` 23*0afa8e06SEd Maste -Option Constant 24*0afa8e06SEd Maste 25*0afa8e06SEd Maste # zlib coordinates. 26*0afa8e06SEd Maste New-Variable -Name 'ZLIB' -Value 'zlib-1.2.11' -Option Constant 27*0afa8e06SEd Maste New-Variable -Name 'ZLIB_BRANCH' -Value 'v1.2.11' -Option Constant 28*0afa8e06SEd Maste New-Variable -Name 'ZLIB_GIT' -Value 'https://github.com/madler/zlib' ` 29*0afa8e06SEd Maste -Option Constant 30*0afa8e06SEd Maste 31*0afa8e06SEd Maste # Work directories. 32*0afa8e06SEd Maste New-Variable -Name 'BUILD' -Value "$PSScriptRoot\..\build" -Option Constant 33*0afa8e06SEd Maste New-Variable -Name 'OUTPUT' -Value "$PSScriptRoot\..\output" -Option Constant 34*0afa8e06SEd Maste 35*0afa8e06SEd Maste # Find CMake. 36*0afa8e06SEd Maste $CMake = $(Get-Command cmake -ErrorAction Ignore | Select-Object -ExpandProperty Source) 37*0afa8e06SEd Maste if([string]::IsNullOrEmpty($CMake)) { 38*0afa8e06SEd Maste $CMake = $CMakePath 39*0afa8e06SEd Maste } 40*0afa8e06SEd Maste 41*0afa8e06SEd Maste # Find Git. 42*0afa8e06SEd Maste $Git = $(Get-Command git -ErrorAction Ignore | Select-Object -ExpandProperty Source) 43*0afa8e06SEd Maste if([string]::IsNullOrEmpty($Git)) { 44*0afa8e06SEd Maste $Git = $GitPath 45*0afa8e06SEd Maste } 46*0afa8e06SEd Maste 47*0afa8e06SEd Maste # Find 7z. 48*0afa8e06SEd Maste $SevenZ = $(Get-Command 7z -ErrorAction Ignore | Select-Object -ExpandProperty Source) 49*0afa8e06SEd Maste if([string]::IsNullOrEmpty($SevenZ)) { 50*0afa8e06SEd Maste $SevenZ = $SevenZPath 51*0afa8e06SEd Maste } 52*0afa8e06SEd Maste 53*0afa8e06SEd Maste # Find GPG. 54*0afa8e06SEd Maste $GPG = $(Get-Command gpg -ErrorAction Ignore | Select-Object -ExpandProperty Source) 55*0afa8e06SEd Maste if([string]::IsNullOrEmpty($GPG)) { 56*0afa8e06SEd Maste $GPG = $GPGPath 57*0afa8e06SEd Maste } 58*0afa8e06SEd Maste 59*0afa8e06SEd Maste # Override CMAKE_SYSTEM_VERSION if $WinSDK is set. 60*0afa8e06SEd Maste if(-Not ([string]::IsNullOrEmpty($WinSDK))) { 61*0afa8e06SEd Maste $CMAKE_SYSTEM_VERSION = "-DCMAKE_SYSTEM_VERSION='$WinSDK'" 62*0afa8e06SEd Maste } else { 63*0afa8e06SEd Maste $CMAKE_SYSTEM_VERSION = '' 64*0afa8e06SEd Maste } 65*0afa8e06SEd Maste 66*0afa8e06SEd Maste if(-Not (Test-Path $CMake)) { 67*0afa8e06SEd Maste throw "Unable to find CMake at $CMake" 68*0afa8e06SEd Maste } 69*0afa8e06SEd Maste 70*0afa8e06SEd Maste if(-Not (Test-Path $Git)) { 71*0afa8e06SEd Maste throw "Unable to find Git at $Git" 72*0afa8e06SEd Maste } 73*0afa8e06SEd Maste 74*0afa8e06SEd Maste if(-Not (Test-Path $SevenZ)) { 75*0afa8e06SEd Maste throw "Unable to find 7z at $SevenZ" 76*0afa8e06SEd Maste } 77*0afa8e06SEd Maste 78*0afa8e06SEd Maste if(-Not (Test-Path $GPG)) { 79*0afa8e06SEd Maste throw "Unable to find GPG at $GPG" 80*0afa8e06SEd Maste } 81*0afa8e06SEd Maste 82*0afa8e06SEd Maste Write-Host "Git: $Git" 83*0afa8e06SEd Maste Write-Host "CMake: $CMake" 84*0afa8e06SEd Maste Write-Host "7z: $SevenZ" 85*0afa8e06SEd Maste Write-Host "GPG: $GPG" 86*0afa8e06SEd Maste 87*0afa8e06SEd Maste New-Item -Type Directory ${BUILD} 88*0afa8e06SEd Maste New-Item -Type Directory ${BUILD}\32 89*0afa8e06SEd Maste New-Item -Type Directory ${BUILD}\32\dynamic 90*0afa8e06SEd Maste New-Item -Type Directory ${BUILD}\32\static 91*0afa8e06SEd Maste New-Item -Type Directory ${BUILD}\64 92*0afa8e06SEd Maste New-Item -Type Directory ${BUILD}\64\dynamic 93*0afa8e06SEd Maste New-Item -Type Directory ${BUILD}\64\static 94*0afa8e06SEd Maste New-Item -Type Directory ${OUTPUT} 95*0afa8e06SEd Maste New-Item -Type Directory ${OUTPUT}\pkg\Win64\Release\v142\dynamic 96*0afa8e06SEd Maste New-Item -Type Directory ${OUTPUT}\pkg\Win32\Release\v142\dynamic 97*0afa8e06SEd Maste New-Item -Type Directory ${OUTPUT}\pkg\Win64\Release\v142\static 98*0afa8e06SEd Maste New-Item -Type Directory ${OUTPUT}\pkg\Win32\Release\v142\static 99*0afa8e06SEd Maste 100*0afa8e06SEd Maste Push-Location ${BUILD} 101*0afa8e06SEd Maste 102*0afa8e06SEd Maste try { 103*0afa8e06SEd Maste if (Test-Path .\${LIBRESSL}) { 104*0afa8e06SEd Maste Remove-Item .\${LIBRESSL} -Recurse -ErrorAction Stop 105*0afa8e06SEd Maste } 106*0afa8e06SEd Maste 107*0afa8e06SEd Maste if(-Not (Test-Path .\${LIBRESSL}.tar.gz -PathType leaf)) { 108*0afa8e06SEd Maste Invoke-WebRequest ${LIBRESSL_URL}/${LIBRESSL}.tar.gz ` 109*0afa8e06SEd Maste -OutFile .\${LIBRESSL}.tar.gz 110*0afa8e06SEd Maste } 111*0afa8e06SEd Maste if(-Not (Test-Path .\${LIBRESSL}.tar.gz.asc -PathType leaf)) { 112*0afa8e06SEd Maste Invoke-WebRequest ${LIBRESSL_URL}/${LIBRESSL}.tar.gz.asc ` 113*0afa8e06SEd Maste -OutFile .\${LIBRESSL}.tar.gz.asc 114*0afa8e06SEd Maste } 115*0afa8e06SEd Maste 116*0afa8e06SEd Maste Copy-Item "$PSScriptRoot\libressl.gpg" -Destination "${BUILD}" 117*0afa8e06SEd Maste & $GPG --list-keys 118*0afa8e06SEd Maste & $GPG -v --no-default-keyring --keyring ./libressl.gpg ` 119*0afa8e06SEd Maste --verify .\${LIBRESSL}.tar.gz.asc .\${LIBRESSL}.tar.gz 120*0afa8e06SEd Maste if ($LastExitCode -ne 0) { 121*0afa8e06SEd Maste throw "GPG signature verification failed" 122*0afa8e06SEd Maste } 123*0afa8e06SEd Maste 124*0afa8e06SEd Maste & $SevenZ e .\${LIBRESSL}.tar.gz 125*0afa8e06SEd Maste & $SevenZ x .\${LIBRESSL}.tar 126*0afa8e06SEd Maste Remove-Item -Force .\${LIBRESSL}.tar 127*0afa8e06SEd Maste 128*0afa8e06SEd Maste if(-Not (Test-Path .\${LIBCBOR})) { 129*0afa8e06SEd Maste Write-Host "Cloning ${LIBCBOR}..." 130*0afa8e06SEd Maste & $Git clone --branch ${LIBCBOR_BRANCH} ${LIBCBOR_GIT} ` 131*0afa8e06SEd Maste .\${LIBCBOR} 132*0afa8e06SEd Maste } 133*0afa8e06SEd Maste 134*0afa8e06SEd Maste if(-Not (Test-Path .\${ZLIB})) { 135*0afa8e06SEd Maste Write-Host "Cloning ${ZLIB}..." 136*0afa8e06SEd Maste & $Git clone --branch ${ZLIB_BRANCH} ${ZLIB_GIT} ` 137*0afa8e06SEd Maste .\${ZLIB} 138*0afa8e06SEd Maste } 139*0afa8e06SEd Maste } catch { 140*0afa8e06SEd Maste throw "Failed to fetch and verify dependencies" 141*0afa8e06SEd Maste } finally { 142*0afa8e06SEd Maste Pop-Location 143*0afa8e06SEd Maste } 144*0afa8e06SEd Maste 145*0afa8e06SEd Maste Function Build(${OUTPUT}, ${GENERATOR}, ${ARCH}, ${SHARED}, ${FLAGS}) { 146*0afa8e06SEd Maste if (-Not (Test-Path .\${LIBRESSL})) { 147*0afa8e06SEd Maste New-Item -Type Directory .\${LIBRESSL} -ErrorAction Stop 148*0afa8e06SEd Maste } 149*0afa8e06SEd Maste 150*0afa8e06SEd Maste Push-Location .\${LIBRESSL} 151*0afa8e06SEd Maste & $CMake ..\..\..\${LIBRESSL} -G "${GENERATOR}" -A "${ARCH}" ` 152*0afa8e06SEd Maste -DBUILD_SHARED_LIBS="${SHARED}" -DLIBRESSL_TESTS=OFF ` 153*0afa8e06SEd Maste -DCMAKE_C_FLAGS_RELEASE="${FLAGS} /Zi /guard:cf /sdl" ` 154*0afa8e06SEd Maste -DCMAKE_INSTALL_PREFIX="${OUTPUT}" "${CMAKE_SYSTEM_VERSION}" 155*0afa8e06SEd Maste & $CMake --build . --config Release --verbose 156*0afa8e06SEd Maste & $CMake --build . --config Release --target install --verbose 157*0afa8e06SEd Maste Pop-Location 158*0afa8e06SEd Maste 159*0afa8e06SEd Maste if (-Not (Test-Path .\${LIBCBOR})) { 160*0afa8e06SEd Maste New-Item -Type Directory .\${LIBCBOR} -ErrorAction Stop 161*0afa8e06SEd Maste } 162*0afa8e06SEd Maste 163*0afa8e06SEd Maste Push-Location .\${LIBCBOR} 164*0afa8e06SEd Maste & $CMake ..\..\..\${LIBCBOR} -G "${GENERATOR}" -A "${ARCH}" ` 165*0afa8e06SEd Maste -DBUILD_SHARED_LIBS="${SHARED}" ` 166*0afa8e06SEd Maste -DCMAKE_C_FLAGS_RELEASE="${FLAGS} /Zi /guard:cf /sdl" ` 167*0afa8e06SEd Maste -DCMAKE_INSTALL_PREFIX="${OUTPUT}" "${CMAKE_SYSTEM_VERSION}" 168*0afa8e06SEd Maste & $CMake --build . --config Release --verbose 169*0afa8e06SEd Maste & $CMake --build . --config Release --target install --verbose 170*0afa8e06SEd Maste Pop-Location 171*0afa8e06SEd Maste 172*0afa8e06SEd Maste if(-Not (Test-Path .\${ZLIB})) { 173*0afa8e06SEd Maste New-Item -Type Directory .\${ZLIB} -ErrorAction Stop 174*0afa8e06SEd Maste } 175*0afa8e06SEd Maste 176*0afa8e06SEd Maste Push-Location .\${ZLIB} 177*0afa8e06SEd Maste & $CMake ..\..\..\${ZLIB} -G "${GENERATOR}" -A "${ARCH}" ` 178*0afa8e06SEd Maste -DBUILD_SHARED_LIBS="${SHARED}" ` 179*0afa8e06SEd Maste -DCMAKE_C_FLAGS_RELEASE="${FLAGS} /Zi /guard:cf /sdl" ` 180*0afa8e06SEd Maste -DCMAKE_INSTALL_PREFIX="${OUTPUT}" "${CMAKE_SYSTEM_VERSION}" 181*0afa8e06SEd Maste & $CMake --build . --config Release --verbose 182*0afa8e06SEd Maste & $CMake --build . --config Release --target install --verbose 183*0afa8e06SEd Maste Pop-Location 184*0afa8e06SEd Maste 185*0afa8e06SEd Maste & $CMake ..\..\.. -G "${GENERATOR}" -A "${ARCH}" ` 186*0afa8e06SEd Maste -DBUILD_SHARED_LIBS="${SHARED}" ` 187*0afa8e06SEd Maste -DCBOR_INCLUDE_DIRS="${OUTPUT}\include" ` 188*0afa8e06SEd Maste -DCBOR_LIBRARY_DIRS="${OUTPUT}\lib" ` 189*0afa8e06SEd Maste -DZLIB_INCLUDE_DIRS="${OUTPUT}\include" ` 190*0afa8e06SEd Maste -DZLIB_LIBRARY_DIRS="${OUTPUT}\lib" ` 191*0afa8e06SEd Maste -DCRYPTO_INCLUDE_DIRS="${OUTPUT}\include" ` 192*0afa8e06SEd Maste -DCRYPTO_LIBRARY_DIRS="${OUTPUT}\lib" ` 193*0afa8e06SEd Maste -DCMAKE_C_FLAGS_RELEASE="${FLAGS} /Zi /guard:cf /sdl ${Fido2Flags}" ` 194*0afa8e06SEd Maste -DCMAKE_INSTALL_PREFIX="${OUTPUT}" "${CMAKE_SYSTEM_VERSION}" 195*0afa8e06SEd Maste & $CMake --build . --config Release --verbose 196*0afa8e06SEd Maste & $CMake --build . --config Release --target install --verbose 197*0afa8e06SEd Maste if ("${SHARED}" -eq "ON") { 198*0afa8e06SEd Maste "cbor.dll", "crypto-46.dll", "zlib1.dll" | %{ Copy-Item "${OUTPUT}\bin\$_" ` 199*0afa8e06SEd Maste -Destination "examples\Release" } 200*0afa8e06SEd Maste } 201*0afa8e06SEd Maste } 202*0afa8e06SEd Maste 203*0afa8e06SEd Maste Function Package-Headers() { 204*0afa8e06SEd Maste Copy-Item "${OUTPUT}\64\dynamic\include" -Destination "${OUTPUT}\pkg" ` 205*0afa8e06SEd Maste -Recurse -ErrorAction Stop 206*0afa8e06SEd Maste } 207*0afa8e06SEd Maste 208*0afa8e06SEd Maste Function Package-Dynamic(${SRC}, ${DEST}) { 209*0afa8e06SEd Maste Copy-Item "${SRC}\bin\cbor.dll" "${DEST}" -ErrorAction Stop 210*0afa8e06SEd Maste Copy-Item "${SRC}\lib\cbor.lib" "${DEST}" -ErrorAction Stop 211*0afa8e06SEd Maste Copy-Item "${SRC}\bin\zlib1.dll" "${DEST}" -ErrorAction Stop 212*0afa8e06SEd Maste Copy-Item "${SRC}\lib\zlib.lib" "${DEST}" -ErrorAction Stop 213*0afa8e06SEd Maste Copy-Item "${SRC}\bin\crypto-46.dll" "${DEST}" -ErrorAction Stop 214*0afa8e06SEd Maste Copy-Item "${SRC}\lib\crypto-46.lib" "${DEST}" -ErrorAction Stop 215*0afa8e06SEd Maste Copy-Item "${SRC}\bin\fido2.dll" "${DEST}" -ErrorAction Stop 216*0afa8e06SEd Maste Copy-Item "${SRC}\lib\fido2.lib" "${DEST}" -ErrorAction Stop 217*0afa8e06SEd Maste } 218*0afa8e06SEd Maste 219*0afa8e06SEd Maste Function Package-Static(${SRC}, ${DEST}) { 220*0afa8e06SEd Maste Copy-Item "${SRC}/lib/cbor.lib" "${DEST}" -ErrorAction Stop 221*0afa8e06SEd Maste Copy-Item "${SRC}/lib/zlib.lib" "${DEST}" -ErrorAction Stop 222*0afa8e06SEd Maste Copy-Item "${SRC}/lib/crypto-46.lib" "${DEST}" -ErrorAction Stop 223*0afa8e06SEd Maste Copy-Item "${SRC}/lib/fido2_static.lib" "${DEST}/fido2.lib" ` 224*0afa8e06SEd Maste -ErrorAction Stop 225*0afa8e06SEd Maste } 226*0afa8e06SEd Maste 227*0afa8e06SEd Maste Function Package-PDBs(${SRC}, ${DEST}) { 228*0afa8e06SEd Maste Copy-Item "${SRC}\${LIBRESSL}\crypto\crypto.dir\Release\vc142.pdb" ` 229*0afa8e06SEd Maste "${DEST}\crypto-46.pdb" -ErrorAction Stop 230*0afa8e06SEd Maste Copy-Item "${SRC}\${LIBCBOR}\src\cbor.dir\Release\vc142.pdb" ` 231*0afa8e06SEd Maste "${DEST}\cbor.pdb" -ErrorAction Stop 232*0afa8e06SEd Maste Copy-Item "${SRC}\${ZLIB}\zlib.dir\Release\vc142.pdb" ` 233*0afa8e06SEd Maste "${DEST}\zlib.pdb" -ErrorAction Stop 234*0afa8e06SEd Maste Copy-Item "${SRC}\src\fido2_shared.dir\Release\vc142.pdb" ` 235*0afa8e06SEd Maste "${DEST}\fido2.pdb" -ErrorAction Stop 236*0afa8e06SEd Maste } 237*0afa8e06SEd Maste 238*0afa8e06SEd Maste Function Package-Tools(${SRC}, ${DEST}) { 239*0afa8e06SEd Maste Copy-Item "${SRC}\tools\Release\fido2-assert.exe" ` 240*0afa8e06SEd Maste "${DEST}\fido2-assert.exe" -ErrorAction stop 241*0afa8e06SEd Maste Copy-Item "${SRC}\tools\Release\fido2-cred.exe" ` 242*0afa8e06SEd Maste "${DEST}\fido2-cred.exe" -ErrorAction stop 243*0afa8e06SEd Maste Copy-Item "${SRC}\tools\Release\fido2-token.exe" ` 244*0afa8e06SEd Maste "${DEST}\fido2-token.exe" -ErrorAction stop 245*0afa8e06SEd Maste } 246*0afa8e06SEd Maste 247*0afa8e06SEd Maste Push-Location ${BUILD}\64\dynamic 248*0afa8e06SEd Maste Build ${OUTPUT}\64\dynamic "Visual Studio 16 2019" "x64" "ON" "/MD" 249*0afa8e06SEd Maste Pop-Location 250*0afa8e06SEd Maste Push-Location ${BUILD}\32\dynamic 251*0afa8e06SEd Maste Build ${OUTPUT}\32\dynamic "Visual Studio 16 2019" "Win32" "ON" "/MD" 252*0afa8e06SEd Maste Pop-Location 253*0afa8e06SEd Maste 254*0afa8e06SEd Maste Push-Location ${BUILD}\64\static 255*0afa8e06SEd Maste Build ${OUTPUT}\64\static "Visual Studio 16 2019" "x64" "OFF" "/MT" 256*0afa8e06SEd Maste Pop-Location 257*0afa8e06SEd Maste Push-Location ${BUILD}\32\static 258*0afa8e06SEd Maste Build ${OUTPUT}\32\static "Visual Studio 16 2019" "Win32" "OFF" "/MT" 259*0afa8e06SEd Maste Pop-Location 260*0afa8e06SEd Maste 261*0afa8e06SEd Maste Package-Headers 262*0afa8e06SEd Maste 263*0afa8e06SEd Maste Package-Dynamic ${OUTPUT}\64\dynamic ${OUTPUT}\pkg\Win64\Release\v142\dynamic 264*0afa8e06SEd Maste Package-PDBs ${BUILD}\64\dynamic ${OUTPUT}\pkg\Win64\Release\v142\dynamic 265*0afa8e06SEd Maste Package-Tools ${BUILD}\64\dynamic ${OUTPUT}\pkg\Win64\Release\v142\dynamic 266*0afa8e06SEd Maste 267*0afa8e06SEd Maste Package-Dynamic ${OUTPUT}\32\dynamic ${OUTPUT}\pkg\Win32\Release\v142\dynamic 268*0afa8e06SEd Maste Package-PDBs ${BUILD}\32\dynamic ${OUTPUT}\pkg\Win32\Release\v142\dynamic 269*0afa8e06SEd Maste Package-Tools ${BUILD}\32\dynamic ${OUTPUT}\pkg\Win32\Release\v142\dynamic 270*0afa8e06SEd Maste 271*0afa8e06SEd Maste Package-Static ${OUTPUT}\64\static ${OUTPUT}\pkg\Win64\Release\v142\static 272*0afa8e06SEd Maste Package-Static ${OUTPUT}\32\static ${OUTPUT}\pkg\Win32\Release\v142\static 273