PowerShell/Scripts/build-repo.ps1

82 lines
2.4 KiB
PowerShell
Raw Normal View History

2021-04-16 20:01:38 +02:00
#!/usr/bin/pwsh
2021-04-14 17:50:35 +02:00
<#
.SYNTAX build-repo.ps1 [<repo-dir>]
2021-04-15 08:25:20 +02:00
.DESCRIPTION builds a Git repository (supporting cmake,configure,autogen,Imakefile,Makefile)
2021-04-14 17:50:35 +02:00
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
param($RepoDir = "$PWD")
try {
2021-04-15 08:41:37 +02:00
$StopWatch = [system.diagnostics.stopwatch]::startNew()
2021-04-14 19:23:34 +02:00
if (test-path "$RepoDir/CMakeLists.txt") {
2021-04-17 11:23:41 +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") {
2021-04-17 11:23:41 +02:00
"⏳ Building $RepoDir using 'configure'..."
2021-04-14 20:02:04 +02:00
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") {
2021-04-17 11:23:41 +02:00
"⏳ Building $RepoDir using 'autogen.sh'..."
2021-04-14 20:02:04 +02:00
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-15 08:25:20 +02:00
} elseif (test-path "$RepoDir/Imakefile") {
2021-04-17 11:23:41 +02:00
"⏳ Building $RepoDir using Imakefile..."
2021-04-15 08:25:20 +02:00
set-location "$RepoDir/"
& xmkmf
if ($lastExitCode -ne "0") { throw "Executing 'xmkmf' 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-17 11:23:41 +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-15 08:25:20 +02:00
} elseif (test-path "$RepoDir/attower/src/build/DevBuild/build.bat") {
2021-04-17 11:23:41 +02:00
"⏳ Building $RepoDir using build.bat..."
2021-04-14 19:23:34 +02:00
set-location "$RepoDir/attower/src/build/DevBuild/"
2021-04-15 08:25:20 +02:00
& ./build.bat build-all-release
if ($lastExitCode -ne "0") { throw "Script 'build.bat' returned error(s)" }
2021-04-14 19:23:34 +02:00
2021-04-14 17:50:35 +02:00
} else {
2021-04-17 11:23:41 +02:00
write-warning "Sorry, no rule found to build $RepoDir"
2021-04-14 19:01:47 +02:00
exit 0
2021-04-14 17:50:35 +02:00
}
2021-04-15 08:41:37 +02:00
2021-04-17 11:23:41 +02:00
write-host -foregroundColor green "✔️ Git repository $RepoDir built in $($StopWatch.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
}