#requires -Version 7 # Builds the Triangle mesher into build\triangle\triangle.exe. $ErrorActionPreference = 'Stop' $Root = Resolve-Path (Join-Path $PSScriptRoot '..\..') $Build = if ($env:BUILD) { $env:BUILD } else { Join-Path $Root 'build\triangle' } New-Item -ItemType Directory -Force -Path $Build | Out-Null . (Join-Path $PSScriptRoot '_toolchain.ps1') $tc = Get-Toolchain Initialize-Toolchain $tc $buildProfile = if ($env:PROFILE) { $env:PROFILE } else { 'release' } $src = Join-Path $Root 'triangle\triangle.c' $out = Join-Path $Build 'triangle.exe' if ($tc.Kind -eq 'msvc') { $cflags = if ($buildProfile -eq 'release') { @('/nologo','/O2','/DNDEBUG','/W0') } else { @('/nologo','/Od','/Zi','/W0') } & cl.exe @cflags $src "/Fe:$out" "/Fo:$Build\" /link /SUBSYSTEM:CONSOLE if ($LASTEXITCODE -ne 0) { throw "cl.exe failed building triangle ($LASTEXITCODE)" } } elseif ($tc.Kind -eq 'clangarm64') { $cflags = if ($buildProfile -eq 'release') { @('-std=gnu89','-O3','-DNDEBUG','-w') } else { @('-std=gnu89','-O0','-g','-w') } & (Join-Path $tc.Bin 'clang.exe') @cflags -o $out $src -lm if ($LASTEXITCODE -ne 0) { throw "clang failed building triangle ($LASTEXITCODE)" } } else { $cflags = if ($buildProfile -eq 'release') { @('-std=gnu89','-O3','-DNDEBUG','-w') } else { @('-std=gnu89','-O0','-g','-w') } & gcc.exe @cflags -o $out $src -lm if ($LASTEXITCODE -ne 0) { throw "gcc failed building triangle ($LASTEXITCODE)" } } Write-Host "built: $out"