PowerShell/Scripts/build-repo.ps1

87 lines
2.6 KiB
PowerShell
Raw Normal View History

2021-04-21 19:53:52 +02:00
<#
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-21 12:22:41 +02:00
$RepoDir = resolve-path "$RepoDir"
2021-04-21 12:05:53 +02:00
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
2021-04-14 19:23:34 +02:00
if (test-path "$RepoDir/CMakeLists.txt") {
2021-04-21 12:05:53 +02:00
"⏳ Building 📂$RepoDir using CMakeLists.txt ..."
2021-04-21 12:22:41 +02:00
if (-not(test-path "$RepoDir/BuildFiles/" -pathType container)) {
& mkdir "$RepoDir/BuildFiles/"
2021-04-14 19:23:34 +02:00
}
2021-04-14 17:50:35 +02:00
2021-04-21 12:22:41 +02:00
set-location "$RepoDir/BuildFiles/"
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
2021-04-21 12:22:41 +02:00
set-location ".."
2021-04-14 20:02:04 +02:00
} elseif (test-path "$RepoDir/configure") {
2021-04-21 12:05:53 +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-21 12:05:53 +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-21 12:05:53 +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-21 12:05:53 +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-21 12:05:53 +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-21 12:05:53 +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-21 16:43:08 +02:00
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
2021-04-21 16:20:49 +02:00
"✔️ built Git repository 📂$RepoDir in $Elapsed sec."
2021-04-14 17:50:35 +02:00
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}