PowerShell/Scripts/build-repo.ps1

71 lines
2.1 KiB
PowerShell
Raw Normal View History

2021-04-14 17:50:35 +02:00
#!/usr/bin/pwsh
<#
.SYNTAX build-repo.ps1 [<repo-dir>]
.DESCRIPTION builds the current/given Git repository
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
param($RepoDir = "$PWD")
try {
2021-04-14 20:02:04 +02:00
$StartTime = get-date
2021-04-14 19:23:34 +02:00
if (test-path "$RepoDir/CMakeLists.txt") {
2021-04-14 17:50:35 +02:00
"Building $RepoDir using CMakeLists.txt..."
2021-04-14 20:02:04 +02:00
if (-not(test-path "$RepoDir/CMakeBuild")) {
2021-04-14 19:23:34 +02:00
& mkdir "$RepoDir/CMakeBuild/"
}
set-location "$RepoDir/CMakeBuild/"
2021-04-14 17:50:35 +02:00
2021-04-14 19:01:47 +02:00
& cmake ..
if ($lastExitCode -ne "0") { throw "Executing 'cmake ..' has failed" }
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
2021-04-14 20:02:04 +02:00
} elseif (test-path "$RepoDir/configure") {
"Building $RepoDir using 'configure'..."
set-location "$RepoDir/"
& ./configure
if ($lastExitCode -ne "0") { throw "Executing 'configure' has failed" }
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
} elseif (test-path "$RepoDir/autogen.sh") {
"Building $RepoDir using 'autogen.sh'..."
set-location "$RepoDir/"
& ./autogen.sh
if ($lastExitCode -ne "0") { throw "Script 'autogen.sh' has failed" }
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
2021-04-14 19:01:47 +02:00
} elseif (test-path "$RepoDir/Makefile") {
2021-04-14 17:50:35 +02:00
"Building $RepoDir using Makefile..."
2021-04-14 19:23:34 +02:00
set-location "$RepoDir/"
2021-04-14 19:01:47 +02:00
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
2021-04-14 20:02:04 +02:00
2021-04-14 19:23:34 +02:00
} elseif (test-path "$RepoDir/attower/src/build/DevBuild/build-all-release.bat") {
"Building $RepoDir using build-all-release.bat..."
set-location "$RepoDir/attower/src/build/DevBuild/"
2021-04-14 20:02:04 +02:00
& ./build-all-release.bat
2021-04-14 19:23:34 +02:00
if ($lastExitCode -ne "0") { throw "Script 'build-all-release.bat' returned error(s)" }
2021-04-14 17:50:35 +02:00
} else {
write-warning "Sorry, no clue how to build $RepoDir"
2021-04-14 19:01:47 +02:00
exit 0
2021-04-14 17:50:35 +02:00
}
2021-04-14 20:02:04 +02:00
$Elapsed = new-timeSpan -start $StartTime -end (get-date)
write-host -foregroundColor green "OK - built Git repository $RepoDir in $($Elapsed.seconds) second(s)"
2021-04-14 17:50:35 +02:00
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}