PowerShell/Scripts/build-repo.ps1

95 lines
2.8 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")
2021-05-07 15:37:04 +02:00
function MakeDir { param($Path)
$DirName = (get-item "$Path").Name
if (test-path "$Path/CMakeLists.txt") {
"⏳ Building 📂$DirName using CMakeLists.txt ..."
if (-not(test-path "$Path/BuildFiles/" -pathType container)) {
& mkdir "$Path/BuildFiles/"
2021-04-14 19:23:34 +02:00
}
2021-04-14 17:50:35 +02:00
2021-05-07 15:37:04 +02:00
set-location "$Path/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-05-06 19:24:05 +02:00
set-location ..
2021-04-21 12:22:41 +02:00
2021-05-07 15:37:04 +02:00
} elseif (test-path "$Path/configure") {
"⏳ Building 📂$DirName using 'configure' ..."
set-location "$Path/"
2021-04-14 20:02:04 +02:00
& ./configure
if ($lastExitCode -ne "0") { throw "Executing 'configure' has failed" }
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
2021-05-07 15:37:04 +02:00
} elseif (test-path "$Path/autogen.sh") {
"⏳ Building 📂$DirName using 'autogen.sh' ..."
set-location "$Path/"
2021-04-14 20:02:04 +02:00
& ./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-05-07 15:37:04 +02:00
} elseif (test-path "$Path/Imakefile") {
"⏳ Building 📂$DirName 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-05-07 15:37:04 +02:00
} elseif (test-path "$Path/Makefile") {
"⏳ Building 📂$DirName using Makefile..."
set-location "$Path"
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-05-07 15:37:04 +02:00
} elseif (test-path "$Path/attower/src/build/DevBuild/build.bat") {
"⏳ Building 📂$DirName using build.bat ..."
set-location "$Path/attower/src/build/DevBuild/"
2021-04-14 19:23:34 +02:00
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-05-07 15:37:04 +02:00
} elseif (test-path "$Path/$DirName" -pathType container) {
"⏳ No make rule found, but trying the subdirectory 📂$DirName ..."
MakeDir "$Path/$DirName"
2021-04-14 17:50:35 +02:00
} else {
2021-05-07 15:37:04 +02:00
write-warning "Sorry, no make rule found in 📂$DirName"
2021-04-14 19:01:47 +02:00
exit 0
2021-04-14 17:50:35 +02:00
}
2021-05-07 15:37:04 +02:00
}
try {
$StopWatch = [system.diagnostics.stopwatch]::startNew()
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
$RepoDirName = (get-item "$RepoDir").Name
MakeDir "$RepoDir"
2021-04-15 08:41:37 +02:00
2021-04-21 16:43:08 +02:00
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
2021-05-06 19:24:05 +02:00
"✔️ built Git repository 📂$RepoDirName in $Elapsed sec."
2021-04-14 17:50:35 +02:00
exit 0
} catch {
2021-05-02 21:30:48 +02:00
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2021-04-14 17:50:35 +02:00
exit 1
}