PowerShell/Scripts/make-repo.ps1

127 lines
3.8 KiB
PowerShell
Raw Normal View History

2021-04-21 19:53:52 +02:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
make-repo.ps1 [<repo-dir>]
.DESCRIPTION
2021-08-29 17:50:03 +02:00
Builds a Git repository supporting cmake,configure,autogen,Imakefile,Makefile.
2021-07-13 21:10:02 +02:00
.EXAMPLE
PS> .\make-repo.ps1 C:\MyRepo
2021-08-29 17:50:03 +02:00
.NOTES
Author: Markus Fleschutz · License: CC0
2021-07-13 21:10:02 +02:00
.LINK
https://github.com/fleschutz/PowerShell
2021-04-14 17:50:35 +02:00
#>
2021-07-15 15:51:22 +02:00
param([string]$RepoDir = "$PWD")
2021-04-14 17:50:35 +02:00
2021-05-07 15:37:04 +02:00
function MakeDir { param($Path)
$DirName = (get-item "$Path").Name
2021-06-07 08:48:17 +02:00
if (test-path "$Path/CMakeLists.txt" -pathType leaf) {
2021-07-02 16:22:17 +02:00
"🔨 Building 📂$DirName using CMakeLists.txt to subfolder BuildFiles..."
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-06-07 08:48:17 +02:00
} elseif (test-path "$Path/configure" -pathType leaf) {
2021-07-02 16:22:17 +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
2021-07-02 17:09:52 +02:00
#if ($lastExitCode -ne "0") { throw "Script 'configure' exited with error code $lastExitCode" }
2021-04-14 20:02:04 +02:00
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
2021-07-02 17:09:52 +02:00
& make test
if ($lastExitCode -ne "0") { throw "Executing 'make test' has failed" }
2021-06-07 08:48:17 +02:00
} elseif (test-path "$Path/autogen.sh" -pathType leaf) {
2021-07-02 16:22:17 +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
2021-05-23 12:10:58 +02:00
if ($lastExitCode -ne "0") { throw "Script 'autogen.sh' exited with error code $lastExitCode" }
2021-04-14 20:02:04 +02:00
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
2021-06-07 08:48:17 +02:00
} elseif (test-path "$Path/build.gradle" -pathType leaf) {
2021-07-02 16:22:17 +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-06-07 08:48:17 +02:00
} elseif (test-path "$Path/Imakefile" -pathType leaf) {
2021-07-02 16:22:17 +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-06-07 08:48:17 +02:00
} elseif (test-path "$Path/Makefile" -pathType leaf) {
2021-07-02 16:22:17 +02:00
"🔨 Building 📂$DirName using Makefile..."
2021-05-07 15:37:04 +02:00
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-06-07 08:48:17 +02:00
} elseif (test-path "$Path/compile.sh" -pathType leaf) {
2021-07-02 16:22:17 +02:00
"🔨 Building 📂$DirName using 'compile.sh'..."
2021-05-23 11:59:46 +02:00
set-location "$Path/"
& ./compile.sh
2021-05-23 12:10:58 +02:00
if ($lastExitCode -ne "0") { throw "Script 'compile.sh' exited with error code $lastExitCode" }
2021-05-23 11:59:46 +02:00
& make -j4
if ($lastExitCode -ne "0") { throw "Executing 'make -j4' has failed" }
2021-06-07 08:48:17 +02:00
} elseif (test-path "$Path/attower/src/build/DevBuild/build.bat" -pathType leaf) {
2021-07-02 16:22:17 +02:00
"🔨 Building 📂$DirName using build.bat ..."
2021-05-07 15:37:04 +02:00
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
2021-05-23 12:10:58 +02:00
if ($lastExitCode -ne "0") { throw "Script 'build.bat' exited with error code $lastExitCode" }
2021-04-14 19:23:34 +02:00
2021-05-07 15:37:04 +02:00
} elseif (test-path "$Path/$DirName" -pathType container) {
2021-07-02 16:22:17 +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-06-07 20:06:55 +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
}