PowerShell/Scripts/make-repo.ps1

118 lines
3.5 KiB
PowerShell
Raw Normal View History

2021-04-21 19:53:52 +02:00
<#
2021-05-17 19:53:40 +02:00
.SYNTAX make-repo.ps1 [<repo-dir>]
.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") {
2021-05-17 20:22:04 +02:00
"⏳ Building 📂$DirName using CMakeLists.txt..."
2021-05-07 15:37:04 +02:00
if (-not(test-path "$Path/BuildFiles/" -pathType container)) {
& mkdir "$Path/BuildFiles/"
2021-04-14 19:23:34 +02:00
}
2021-05-07 15:37:04 +02:00
set-location "$Path/BuildFiles/"
2021-05-10 16:21:38 +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
2021-05-22 15:51:36 +02:00
& make test
if ($lastExitCode -ne "0") { throw "Executing 'make test' has failed" }
2021-05-07 15:37:04 +02:00
} elseif (test-path "$Path/configure") {
2021-05-17 20:22:04 +02:00
"⏳ Building 📂$DirName using 'configure'..."
2021-05-07 15:37:04 +02:00
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") {
2021-05-17 20:22:04 +02:00
"⏳ Building 📂$DirName using 'autogen.sh'..."
2021-05-07 15:37:04 +02:00
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-10 16:21:38 +02:00
} elseif (test-path "$Path/build.gradle") {
2021-05-17 20:22:04 +02:00
"⏳ Building 📂$DirName using build.gradle..."
2021-05-10 16:21:38 +02:00
set-location "$Path"
& gradle build
if ($lastExitCode -ne "0") { throw "'gradle build' has failed" }
& gradle test
if ($lastExitCode -ne "0") { throw "'gradle test' has failed" }
2021-05-07 15:37:04 +02:00
} elseif (test-path "$Path/Imakefile") {
2021-05-17 20:22:04 +02:00
"⏳ 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-23 11:59:46 +02:00
} elseif (test-path "$Path/compile.sh") {
"⏳ Building 📂$DirName using 'compile.sh'..."
set-location "$Path/"
& ./compile.sh
if ($lastExitCode -ne "0") { throw "Script 'compile.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/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) {
2021-05-17 20:22:04 +02:00
"⏳ No make rule found, trying subfolder 📂$($DirName)..."
2021-05-07 15:37:04 +02:00
MakeDir "$Path/$DirName"
2021-04-14 17:50:35 +02:00
} else {
2021-05-10 16:21:38 +02:00
write-warning "Sorry, no make rule applies to: 📂$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
2021-05-10 16:21:38 +02:00
$PreviousPath = get-location
2021-05-07 15:37:04 +02:00
MakeDir "$RepoDir"
2021-05-10 16:21:38 +02:00
set-location "$PreviousPath"
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
}