xref: /freebsd/contrib/libfido2/windows/cygwin.ps1 (revision 2ccfa855b2fc331819953e3de1b1c15ce5b95a7e)
13e696dfbSEd Maste # Copyright (c) 2021 Yubico AB. All rights reserved.
23e696dfbSEd Maste # Use of this source code is governed by a BSD-style
33e696dfbSEd Maste # license that can be found in the LICENSE file.
4*2ccfa855SEd Maste # SPDX-License-Identifier: BSD-2-Clause
53e696dfbSEd Maste 
63e696dfbSEd Maste param(
73e696dfbSEd Maste 	[string]$GPGPath = "C:\Program Files (x86)\GnuPG\bin\gpg.exe",
83e696dfbSEd Maste 	[string]$Config = "Release"
93e696dfbSEd Maste )
103e696dfbSEd Maste 
113e696dfbSEd Maste $ErrorActionPreference = "Stop"
123e696dfbSEd Maste [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
133e696dfbSEd Maste 
143e696dfbSEd Maste # Cygwin coordinates.
153e696dfbSEd Maste $URL = 'https://www.cygwin.com'
163e696dfbSEd Maste $Setup = 'setup-x86_64.exe'
173e696dfbSEd Maste $Mirror = 'https://mirrors.kernel.org/sourceware/cygwin/'
183e696dfbSEd Maste $Packages = 'gcc-core,pkg-config,cmake,make,libcbor-devel,libssl-devel,zlib-devel'
193e696dfbSEd Maste 
203e696dfbSEd Maste # Work directories.
213e696dfbSEd Maste $Cygwin = "$PSScriptRoot\..\cygwin"
223e696dfbSEd Maste $Root = "${Cygwin}\root"
233e696dfbSEd Maste 
243e696dfbSEd Maste # Find GPG.
253e696dfbSEd Maste $GPG = $(Get-Command gpg -ErrorAction Ignore | `
263e696dfbSEd Maste     Select-Object -ExpandProperty Source)
273e696dfbSEd Maste if ([string]::IsNullOrEmpty($GPG)) {
283e696dfbSEd Maste 	$GPG = $GPGPath
293e696dfbSEd Maste }
303e696dfbSEd Maste if (-Not (Test-Path $GPG)) {
313e696dfbSEd Maste 	throw "Unable to find GPG at $GPG"
323e696dfbSEd Maste }
333e696dfbSEd Maste 
343e696dfbSEd Maste Write-Host "Config: $Config"
353e696dfbSEd Maste Write-Host "GPG: $GPG"
363e696dfbSEd Maste 
373e696dfbSEd Maste # Create work directories.
383e696dfbSEd Maste New-Item -Type Directory "${Cygwin}" -Force
393e696dfbSEd Maste New-Item -Type Directory "${Root}" -Force
403e696dfbSEd Maste 
413e696dfbSEd Maste # Fetch and verify Cygwin.
423e696dfbSEd Maste try {
433e696dfbSEd Maste 	if (-Not (Test-Path ${Cygwin}\${Setup} -PathType leaf)) {
443e696dfbSEd Maste 		Invoke-WebRequest ${URL}/${Setup} `
453e696dfbSEd Maste 		    -OutFile ${Cygwin}\${Setup}
463e696dfbSEd Maste 	}
473e696dfbSEd Maste 	if (-Not (Test-Path ${Cygwin}\${Setup}.sig -PathType leaf)) {
483e696dfbSEd Maste 		Invoke-WebRequest ${URL}/${Setup}.sig `
493e696dfbSEd Maste 		    -OutFile ${Cygwin}\${Setup}.sig
503e696dfbSEd Maste 	}
513e696dfbSEd Maste 	& $GPG --list-keys
523e696dfbSEd Maste 	& $GPG --quiet --no-default-keyring `
533e696dfbSEd Maste 	    --keyring ${PSScriptRoot}/cygwin.gpg `
543e696dfbSEd Maste 	    --verify ${Cygwin}\${Setup}.sig ${Cygwin}\${Setup}
553e696dfbSEd Maste 	if ($LastExitCode -ne 0) {
563e696dfbSEd Maste 		throw "GPG signature verification failed"
573e696dfbSEd Maste 	}
583e696dfbSEd Maste } catch {
593e696dfbSEd Maste 	throw "Failed to fetch and verify Cygwin"
603e696dfbSEd Maste }
613e696dfbSEd Maste 
623e696dfbSEd Maste # Bootstrap Cygwin.
633e696dfbSEd Maste Start-Process "${Cygwin}\${Setup}" -Wait -NoNewWindow `
643e696dfbSEd Maste     -ArgumentList "-dnNOqW -s ${Mirror} -R ${Root} -P ${Packages}"
653e696dfbSEd Maste 
663e696dfbSEd Maste # Build libfido2.
673e696dfbSEd Maste $Env:PATH = "${Root}\bin\;" + $Env:PATH
683e696dfbSEd Maste cmake "-DCMAKE_BUILD_TYPE=${Config}" -B "build-${Config}"
693e696dfbSEd Maste make -C "build-${Config}"
70*2ccfa855SEd Maste make -C "build-${Config}" regress
71