2018-01-20 03:55:39 +01:00
|
|
|
[CmdletBinding()]
|
|
|
|
Param(
|
|
|
|
[Parameter(Position=0, mandatory=$true)]
|
2021-08-13 23:52:26 +02:00
|
|
|
[ValidateSet("Init", "Build", "Rebuild", "Clean", "Package", "PackageTmp")]
|
2018-01-20 03:55:39 +01:00
|
|
|
[string]$Task
|
|
|
|
)
|
|
|
|
|
2021-08-07 17:04:48 +02:00
|
|
|
###############################################################################
|
2022-05-01 18:07:53 +02:00
|
|
|
# CONFIG
|
2021-08-07 17:04:48 +02:00
|
|
|
# set these vars to override project defaults
|
2021-08-08 13:31:11 +02:00
|
|
|
# can also create a mssvc-build.config.ps1 with those
|
2021-08-07 17:04:48 +02:00
|
|
|
###############################################################################
|
2021-08-08 13:31:11 +02:00
|
|
|
$config_file = ".\msvc-build.config.ps1"
|
|
|
|
if((Test-Path $config_file)) { . $config_file }
|
|
|
|
|
|
|
|
# - toolsets: "" (default), "v140" (MSVC 2015), "v141" (MSVC 2017), "v141_xp" (XP support), "v142" (MSVC 2019), etc
|
|
|
|
if (!$toolset) { $toolset = "" }
|
2021-09-04 20:25:36 +02:00
|
|
|
|
2021-08-08 13:31:11 +02:00
|
|
|
# - sdks: "" (default), "7.0" (Win7 SDK), "8.1" (Win8 SDK), "10.0" (Win10 SDK), etc
|
|
|
|
if (!$sdk) { $sdk = "" }
|
2021-09-04 20:25:36 +02:00
|
|
|
|
2021-08-08 13:31:11 +02:00
|
|
|
# - platforms: "" (default), "Win32"
|
|
|
|
if (!$platform) { $platform = "" }
|
2021-09-04 20:25:36 +02:00
|
|
|
|
2021-08-13 22:35:14 +02:00
|
|
|
# print compilation log
|
|
|
|
#$log = 1
|
2021-09-04 20:25:36 +02:00
|
|
|
|
|
|
|
# Debug or Release, usually
|
|
|
|
if (!$configuration) { $configuration = "Release" }
|
|
|
|
|
2021-08-07 17:04:48 +02:00
|
|
|
###############################################################################
|
2018-06-22 03:59:27 +02:00
|
|
|
|
2018-01-20 03:55:39 +01:00
|
|
|
$solution = "vgmstream_full.sln"
|
2021-08-07 17:04:48 +02:00
|
|
|
$dependencies = "dependencies"
|
|
|
|
$vswhere = "$dependencies/vswhere.exe"
|
2021-09-04 20:25:36 +02:00
|
|
|
$config = "/p:Configuration=" + $configuration
|
2021-08-07 17:04:48 +02:00
|
|
|
# not used ATM
|
|
|
|
$enable_aac = 0
|
2018-01-20 03:55:39 +01:00
|
|
|
|
2021-08-07 17:04:48 +02:00
|
|
|
if ($platform) { $platform = "/p:Platform=" + $platform }
|
|
|
|
if ($toolset) { $toolset = "/p:PlatformToolset=" + $toolset }
|
|
|
|
if ($sdk) { $sdk = "/p:WindowsTargetPlatformVersion=" + $sdk }
|
|
|
|
|
|
|
|
# https://stackoverflow.com/a/41618979/9919772
|
|
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|
|
|
|
|
|
|
# helper
|
2018-01-20 03:55:39 +01:00
|
|
|
function Unzip
|
|
|
|
{
|
|
|
|
param([string]$zipfile, [string]$outpath)
|
|
|
|
Write-Output "Extracting $zipfile"
|
|
|
|
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
|
|
|
|
}
|
|
|
|
|
2021-08-07 17:04:48 +02:00
|
|
|
# helper
|
2018-01-20 03:55:39 +01:00
|
|
|
function Download
|
|
|
|
{
|
|
|
|
param([string]$uri, [string]$outfile)
|
|
|
|
Write-Output "Downloading $uri"
|
|
|
|
$wc = New-Object net.webclient
|
|
|
|
$wc.Downloadfile($uri, $outfile)
|
|
|
|
}
|
|
|
|
|
2021-08-07 17:04:48 +02:00
|
|
|
# download and unzip dependencies
|
2018-01-20 03:55:39 +01:00
|
|
|
function Init
|
|
|
|
{
|
|
|
|
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
|
|
|
|
2021-08-07 17:04:48 +02:00
|
|
|
Remove-Item -Path "$dependencies" -Recurse -ErrorAction Ignore
|
|
|
|
New-Item "$dependencies" -Type directory -Force | out-null
|
|
|
|
|
|
|
|
# vswhere: MSBuild locator
|
|
|
|
# may already be in %ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe
|
|
|
|
# so could test that and skip this step
|
|
|
|
Download "https://github.com/Microsoft/vswhere/releases/download/2.6.7/vswhere.exe" "$dependencies\vswhere.exe"
|
|
|
|
|
|
|
|
# foobar: wtl
|
2022-05-01 18:07:53 +02:00
|
|
|
Download "https://www.nuget.org/api/v2/package/wtl/10.0.10320" "$dependencies\wtl.zip"
|
2021-08-07 17:04:48 +02:00
|
|
|
Unzip "$dependencies\wtl.zip" "$dependencies\wtl_tmp"
|
|
|
|
Move-Item "$dependencies\wtl_tmp\lib\native" "$dependencies\wtl"
|
|
|
|
Remove-Item -Path "$dependencies\wtl_tmp" -Recurse
|
|
|
|
|
|
|
|
# foobar: sdk anti-hotlink (random link) defeater
|
|
|
|
#Download "https://www.foobar2000.org/SDK" "$dependencies\SDK"
|
|
|
|
#$key = (Select-String -Path $dependencies\SDK -Pattern "\/([a-f0-9]+)\/SDK-2018-01-11\.zip").matches.groups[1]
|
|
|
|
#Remove-Item -Path "$dependencies\SDK"
|
|
|
|
#Download "https://www.foobar2000.org/files/$key/SDK-2018-01-11.zip" "$dependencies\foobar.zip"
|
|
|
|
|
|
|
|
# foobar: sdk direct link, but 2019< sdks gone ATM
|
|
|
|
#Download "https://www.foobar2000.org/files/SDK-2018-01-11.zip" "$dependencies\foobar.zip"
|
|
|
|
|
|
|
|
# foobar: sdk static mirror
|
2022-05-01 18:07:53 +02:00
|
|
|
Download "https://github.com/vgmstream/vgmstream-deps/raw/master/foobar2000/SDK-2022-01-04.zip" "$dependencies\foobar.zip"
|
2021-08-07 17:04:48 +02:00
|
|
|
Unzip "$dependencies\foobar.zip" "$dependencies\foobar"
|
|
|
|
|
|
|
|
# foobar: aac (not used ATM)
|
|
|
|
if ($enable_aac)
|
|
|
|
{
|
|
|
|
Download "https://github.com/kode54/fdk-aac/archive/master.zip" "$dependencies\fdk-aac.zip"
|
|
|
|
Download "https://github.com/kode54/qaac/archive/master.zip" "$dependencies\qaac.zip"
|
|
|
|
Unzip "$dependencies\fdk-aac.zip" "$dependencies\fdk-aac_tmp"
|
|
|
|
Unzip "$dependencies\qaac.zip" "$dependencies\qaac_tmp"
|
|
|
|
Move-Item "$dependencies\fdk-aac_tmp\fdk-aac-master" "$dependencies\fdk-aac"
|
|
|
|
Move-Item "$dependencies\qaac_tmp\qaac-master" "$dependencies\qaac"
|
|
|
|
Remove-Item -Path "$dependencies\fdk-aac_tmp" -Recurse
|
|
|
|
Remove-Item -Path "$dependencies\qaac_tmp" -Recurse
|
|
|
|
}
|
2018-01-20 03:55:39 +01:00
|
|
|
|
2021-08-07 17:04:48 +02:00
|
|
|
# open foobar sdk project and modify WTL path
|
|
|
|
# (maybe should just pass include to CL envvar: set CL=/I"(path)\WTL\Include")
|
2022-05-01 18:07:53 +02:00
|
|
|
[xml]$proj = Get-Content $dependencies\foobar\foobar2000\helpers\foobar2000_sdk_helpers.vcxproj
|
2018-01-20 03:55:39 +01:00
|
|
|
$proj.project.ItemDefinitionGroup | ForEach-Object {
|
2022-05-01 18:07:53 +02:00
|
|
|
$_.ClCompile.AdditionalIncludeDirectories += ";../../../wtl/include"
|
2018-01-20 03:55:39 +01:00
|
|
|
}
|
2022-05-01 18:07:53 +02:00
|
|
|
$proj.Save("$dependencies\foobar\foobar2000\helpers\foobar2000_sdk_helpers.vcxproj")
|
|
|
|
|
|
|
|
[xml]$proj = Get-Content $dependencies\foobar\libPPUI\libPPUI.vcxproj
|
|
|
|
$proj.project.ItemDefinitionGroup | ForEach-Object {
|
|
|
|
$_.ClCompile.AdditionalIncludeDirectories += ";../../wtl/include"
|
|
|
|
}
|
|
|
|
$proj.Save("$dependencies\foobar\libPPUI\libPPUI.vcxproj")
|
2018-01-20 03:55:39 +01:00
|
|
|
}
|
|
|
|
|
2021-08-07 17:04:48 +02:00
|
|
|
# main build
|
|
|
|
function CallMsbuild
|
2018-01-20 03:55:39 +01:00
|
|
|
{
|
2021-08-07 17:04:48 +02:00
|
|
|
param([string]$target)
|
|
|
|
if ($target) { $target = "/t:" + $target }
|
|
|
|
|
|
|
|
# download dependencies if needed
|
2018-01-20 03:55:39 +01:00
|
|
|
if(!(Test-Path $vswhere)) { Init }
|
|
|
|
|
2021-08-07 17:04:48 +02:00
|
|
|
|
|
|
|
# autolocate MSBuild path
|
2019-05-11 08:12:07 +02:00
|
|
|
$msbuild = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe
|
2018-01-20 03:55:39 +01:00
|
|
|
|
|
|
|
if(!($msbuild -and $(Test-Path $msbuild))) {
|
2022-05-01 18:08:08 +02:00
|
|
|
throw "Unable to find MSBuild. Is Visual Studio installed?"
|
2018-01-20 03:55:39 +01:00
|
|
|
}
|
|
|
|
|
2021-08-07 17:04:48 +02:00
|
|
|
# main build (pass config separate and not as a single string)
|
2021-08-13 22:35:14 +02:00
|
|
|
if (!$log) {
|
|
|
|
& $msbuild $solution $config $platform $toolset $sdk $target /m
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
& $msbuild $solution $config $platform $toolset $sdk $target /m > "msvc-build.log"
|
|
|
|
}
|
2022-05-01 18:08:08 +02:00
|
|
|
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
|
|
throw "MSBuild failed with error code $LASTEXITCODE"
|
|
|
|
}
|
2021-08-07 17:04:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function Build
|
|
|
|
{
|
|
|
|
CallMsbuild "Build"
|
|
|
|
}
|
|
|
|
|
|
|
|
function Rebuild
|
|
|
|
{
|
|
|
|
CallMsbuild "Rebuild"
|
|
|
|
}
|
2021-08-13 23:52:26 +02:00
|
|
|
|
2021-08-07 17:04:48 +02:00
|
|
|
function Clean
|
|
|
|
{
|
|
|
|
CallMsbuild "Clean"
|
|
|
|
# todo fix the above, for now:
|
|
|
|
#Remove-Item -Path "$dependencies" -Recurse -ErrorAction Ignore
|
|
|
|
Remove-Item -Path "cli/Debug" -Recurse -ErrorAction Ignore
|
|
|
|
Remove-Item -Path "cli/Release" -Recurse -ErrorAction Ignore
|
|
|
|
Remove-Item -Path "ext_libs/Debug" -Recurse -ErrorAction Ignore
|
|
|
|
Remove-Item -Path "ext_libs/Release" -Recurse -ErrorAction Ignore
|
2021-09-04 20:25:36 +02:00
|
|
|
Remove-Item -Path "ext_libs/Getopt/Debug" -Recurse -ErrorAction Ignore
|
2021-08-07 17:04:48 +02:00
|
|
|
Remove-Item -Path "ext_libs/Getopt/Release" -Recurse -ErrorAction Ignore
|
|
|
|
Remove-Item -Path "fb2k/Debug" -Recurse -ErrorAction Ignore
|
|
|
|
Remove-Item -Path "fb2k/Release" -Recurse -ErrorAction Ignore
|
|
|
|
Remove-Item -Path "src/Debug" -Recurse -ErrorAction Ignore
|
|
|
|
Remove-Item -Path "src/Release" -Recurse -ErrorAction Ignore
|
|
|
|
Remove-Item -Path "winamp/Debug" -Recurse -ErrorAction Ignore
|
|
|
|
Remove-Item -Path "winamp/Release" -Recurse -ErrorAction Ignore
|
|
|
|
Remove-Item -Path "xmplay/Debug" -Recurse -ErrorAction Ignore
|
|
|
|
Remove-Item -Path "xmplay/Release" -Recurse -ErrorAction Ignore
|
|
|
|
Remove-Item -Path "Debug" -Recurse -ErrorAction Ignore
|
|
|
|
Remove-Item -Path "Release" -Recurse -ErrorAction Ignore
|
2021-08-13 23:52:26 +02:00
|
|
|
Remove-Item -Path "bin" -Recurse -ErrorAction Ignore
|
|
|
|
Remove-Item -Path "tmp" -Recurse -ErrorAction Ignore
|
2021-09-26 19:34:12 +02:00
|
|
|
|
|
|
|
Remove-Item "msvc-build.log" -ErrorAction Ignore
|
2018-01-20 03:55:39 +01:00
|
|
|
}
|
|
|
|
|
2021-08-13 23:52:26 +02:00
|
|
|
$fb2kFiles = @(
|
|
|
|
"ext_libs/*.dll",
|
2021-09-04 20:25:36 +02:00
|
|
|
"$configuration/foo_input_vgmstream.dll",
|
2021-08-13 23:52:26 +02:00
|
|
|
"README.md"
|
2021-09-11 17:19:10 +02:00
|
|
|
"doc/USAGE.md"
|
2021-08-13 23:52:26 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
$cliFiles = @(
|
|
|
|
"ext_libs/*.dll",
|
2021-09-04 20:25:36 +02:00
|
|
|
"$configuration/in_vgmstream.dll",
|
2023-01-15 18:24:41 +01:00
|
|
|
"$configuration/vgmstream-cli.exe",
|
2021-09-04 20:25:36 +02:00
|
|
|
"$configuration/xmp-vgmstream.dll",
|
2021-08-13 23:52:26 +02:00
|
|
|
"COPYING",
|
|
|
|
"README.md"
|
2021-09-11 17:19:10 +02:00
|
|
|
"doc/USAGE.md"
|
2021-08-13 23:52:26 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
$fb2kPdbFiles = @(
|
2021-09-04 20:25:36 +02:00
|
|
|
"$configuration/foo_input_vgmstream.pdb"
|
2021-08-13 23:52:26 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
$cliPdbFiles = @(
|
2021-09-04 20:25:36 +02:00
|
|
|
"$configuration/in_vgmstream.pdb",
|
2023-01-15 22:44:52 +01:00
|
|
|
"$configuration/vgmstream-cli.pdb",
|
2021-09-04 20:25:36 +02:00
|
|
|
"$configuration/xmp-vgmstream.pdb"
|
2021-08-13 23:52:26 +02:00
|
|
|
)
|
|
|
|
|
2021-09-26 19:34:12 +02:00
|
|
|
function MakePackage
|
2021-08-13 23:52:26 +02:00
|
|
|
{
|
2021-08-27 22:21:04 +02:00
|
|
|
Build
|
2021-08-13 23:52:26 +02:00
|
|
|
|
2023-01-15 18:24:41 +01:00
|
|
|
if(!(Test-Path "$configuration/vgmstream-cli.exe")) {
|
2021-08-13 23:52:26 +02:00
|
|
|
Write-Error "Unable to find binaries, check for compilation errors"
|
2022-05-01 18:08:08 +02:00
|
|
|
return
|
2021-08-13 23:52:26 +02:00
|
|
|
}
|
|
|
|
|
2021-09-04 20:25:36 +02:00
|
|
|
Compress-Archive $cliFiles $configuration/vgmstream-win.zip -Force
|
|
|
|
Compress-Archive $fb2kFiles $configuration/foo_input_vgmstream.zip -Force
|
|
|
|
Compress-Archive $cliPdbFiles $configuration/vgmstream-win.pdb.zip -Force
|
|
|
|
Compress-Archive $fb2kPdbFiles $configuration/foo_input_vgmstream.pdb.zip -Force
|
2021-08-13 23:52:26 +02:00
|
|
|
|
|
|
|
md -Force bin
|
2021-09-04 20:25:36 +02:00
|
|
|
Move-Item $configuration/vgmstream-win.zip bin/vgmstream-win.zip -Force
|
|
|
|
Move-Item $configuration/foo_input_vgmstream.zip bin/foo_input_vgmstream.fb2k-component -Force
|
|
|
|
Move-Item $configuration/vgmstream-win.pdb.zip bin/vgmstream-win.pdb.zip -Force
|
|
|
|
Move-Item $configuration/foo_input_vgmstream.pdb.zip bin/foo_input_vgmstream.pdb.zip -Force
|
2021-08-13 23:52:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# for github actions/artifact uploads, that use a dir with files
|
2021-09-26 19:34:12 +02:00
|
|
|
function MakePackageTmp
|
2021-08-13 23:52:26 +02:00
|
|
|
{
|
2021-09-26 19:34:12 +02:00
|
|
|
MakePackage
|
2021-08-13 23:52:26 +02:00
|
|
|
|
|
|
|
md -Force tmp/cli
|
|
|
|
md -Force tmp/fb2k
|
|
|
|
md -Force tmp/cli-p
|
|
|
|
md -Force tmp/fb2k-p
|
|
|
|
|
|
|
|
Copy-Item $cliFiles tmp/cli/ -Recurse -Force
|
|
|
|
Copy-Item $fb2kFiles tmp/fb2k/ -Recurse -Force
|
|
|
|
Copy-Item $cliPdbFiles tmp/cli-p/ -Recurse -Force
|
|
|
|
Copy-Item $fb2kPdbFiles tmp/fb2k-p/ -Recurse -Force
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-20 03:55:39 +01:00
|
|
|
switch ($Task)
|
|
|
|
{
|
|
|
|
"Init" { Init }
|
|
|
|
"Build" { Build }
|
2021-08-07 17:04:48 +02:00
|
|
|
"Rebuild" { Rebuild }
|
|
|
|
"Clean" { Clean }
|
2021-09-26 19:34:12 +02:00
|
|
|
"Package" { MakePackage }
|
|
|
|
"PackageTmp" { MakePackageTmp }
|
2018-01-20 03:55:39 +01:00
|
|
|
}
|