diff --git a/GlitchyEngineHelper/.gitignore b/GlitchyEngineHelper/.gitignore new file mode 100644 index 0000000..57bd3d0 --- /dev/null +++ b/GlitchyEngineHelper/.gitignore @@ -0,0 +1,2 @@ +vendor/mono/lib/ +vendor/mono/repo/ diff --git a/GlitchyEngineHelper/BeefProj.toml b/GlitchyEngineHelper/BeefProj.toml index b474d02..8a3950f 100644 --- a/GlitchyEngineHelper/BeefProj.toml +++ b/GlitchyEngineHelper/BeefProj.toml @@ -10,10 +10,10 @@ StartupObject = "GlitchyEngineHelper.Program" BuildCommandsOnCompile = "IfFilesChanged" BuildCommandsOnRun = "IfFilesChanged" LibPaths = ["$(ProjectDir)/out/build/x64-debug/GlitchyEngineHelper.lib", "$(ProjectDir)/vendor/mono/lib/Windows/Debug/libmono-static-sgen.lib", "$(ProjectDir)/vendor/mono/lib/Windows/Debug/libmonoutils.lib", "$(ProjectDir)/vendor/mono/lib/Windows/Debug/libmonoruntime-sgen.lib", "ws2_32.lib", "Winmm.lib", "OleAut32.lib", "Bcrypt.lib"] -PreBuildCmds = ["$(ProjectDir)/../bin/vscmake.bat x64 $(ProjectDir) x64-debug"] +PreBuildCmds = ["$(ProjectDir)/../bin/vscmake.bat x64 $(ProjectDir) x64-debug", "powershell $(ProjectDir)/Build_Mono.ps1"] [Configs.Release.Win64] BuildCommandsOnCompile = "IfFilesChanged" BuildCommandsOnRun = "IfFilesChanged" LibPaths = ["$(ProjectDir)/out/build/x64-release/GlitchyEngineHelper.lib"] -PreBuildCmds = ["$(ProjectDir)/../bin/vscmake.bat x64 $(ProjectDir) x64-release"] +PreBuildCmds = ["$(ProjectDir)/../bin/vscmake.bat x64 $(ProjectDir) x64-release", "powershell $(ProjectDir)/Build_Mono.ps1"] diff --git a/GlitchyEngineHelper/Build_Mono.ps1 b/GlitchyEngineHelper/Build_Mono.ps1 new file mode 100644 index 0000000..affd402 --- /dev/null +++ b/GlitchyEngineHelper/Build_Mono.ps1 @@ -0,0 +1,99 @@ +param( + [switch] $UpdateRepo, + [switch] $CleanBuild, + [switch] $Rebuild +) + +$RepositoryPath = "./vendor/mono/repo" +# Directory which will contain the final build output +$TargetDirectory = Join-Path $PSScriptRoot "vendor/mono/lib/Windows" + +if ((-Not $UpdateRepo) -and (-Not $CleanBuild) -and (-Not $Rebuild)) { + $DebugLibMono = Join-Path $TargetDirectory "Debug/libmono-static-sgen.lib"; + $ReleaseLibMono = Join-Path $TargetDirectory "Release/libmono-static-sgen.lib"; + + # We assume, that everything exists, when libmono-static-sgen.lib exists and don't invoke devenv + # because devenv is slow as heck! + # Updates/Rebuilds and Cleans will issue a build + if ((Test-Path $DebugLibMono) -and (Test-Path $ReleaseLibMono)) { + Write-Output "Mono already build and ready." + exit + } +} + +function Clone-GitRepoIfDestEmpty { + $RepoUrl = "https://github.com/mono/mono.git" + + # Check if the destination directory is empty or does not exist + if ((-Not (Test-Path $RepositoryPath)) -or ((Get-ChildItem $RepositoryPath).Count -eq 0)) { + # If the directory does not exist or is empty, clone the repository + git clone $RepoUrl $RepositoryPath + } else { + Write-Output "Destination directory is not empty. Git repository will not be cloned." + } +} + +function Update-GitRepo { + # Call Update-GitRepo function only if -Update switch is provided + if (-Not $UpdateRepo) { + Write-Output "Repository will not be updated. (Use -UpdateRepo if you want to update the repository)" + return + } + + Write-Output "Pulling repository..." + git pull +} + +function Patch-Mono { + # applies the patch that sets mono to statically link the clib + Write-Output "Patching..." + git apply ../patch.txt +} + +function Build-Mono { + if ($CleanBuild) { + Write-Output "Cleaning Debug..." + devenv msvc/mono.sln /Clean "Debug|x64" + Write-Output "Cleaning Release..." + devenv msvc/mono.sln /Clean "Release|x64" + } + + $BuildOption = if ($Rebuild) { "/Rebuild" } else { "/Build" } + + Write-Output "Building Debug..." + devenv msvc/mono.sln $BuildOption "Debug|x64" /Project "libmono-static" + #Write-Output "Building Release..." + #devenv msvc/mono.sln $BuildOption "Release|x64" /Project "libmono-static" +} + +function Copy-BuildResults { + $SourceDirectory = "msvc/build/sgen/x64/lib" + + # Create the target directory if it does not exist + if (-Not (Test-Path $TargetDirectory)) { + New-Item -ItemType Directory -Force -Path $TargetDirectory + } + + # Copy all files from source to target directory + Copy-Item -Path "$SourceDirectory\*" -Destination $TargetDirectory -Force -Recurse +} + +# Switch working directory to directory containing the script (allows calling the script from anywhere) +Push-Location $PSScriptRoot + +# Clone the git-repository, if necessary. +Clone-GitRepoIfDestEmpty + +# Change into repository +Set-Location $RepositoryPath + +Update-GitRepo + +Patch-Mono + +Build-Mono + +Copy-BuildResults + +# Return to the original directory +Pop-Location diff --git a/GlitchyEngineHelper/vendor/mono/patch.txt b/GlitchyEngineHelper/vendor/mono/patch.txt new file mode 100644 index 0000000..7f8daf7 --- /dev/null +++ b/GlitchyEngineHelper/vendor/mono/patch.txt @@ -0,0 +1,16 @@ +diff --git a/msvc/mono.props b/msvc/mono.props +index 4aa149a7ab5..f9824d3020c 100644 +--- a/msvc/mono.props ++++ b/msvc/mono.props +@@ -12,9 +12,9 @@ + + true + +- false ++ true + +- false ++ true + + false +