diff --git a/generate.bat b/generate.bat index 23b7b3d3..1b7ddd5a 100644 --- a/generate.bat +++ b/generate.bat @@ -1,6 +1,62 @@ @echo off +set PREMAKE_URL="https://github.com/premake/premake-core/releases/download/v5.0.0-beta4/premake-5.0.0-beta4-windows.zip" +set PREMAKE_HASH="12d741d3b70445b025c03e26148e2d129801041fa5ddde61b4ac888a76017395" + +goto start + +:downloadpremake + +if not exist "build" mkdir "build" + +powershell -Command "Invoke-WebRequest %PREMAKE_URL% -OutFile build/premake.zip" +IF %ERRORLEVEL% NEQ 0 ( + echo Download failed >&2 + exit 2 +) + +powershell -Command "Expand-Archive -LiteralPath build/premake.zip -DestinationPath build" +IF %ERRORLEVEL% NEQ 0 ( + echo Extraction failed >&2 + exit 2 +) + +rm build/premake.zip + +powershell -Command "if ((Get-FileHash -LiteralPath build/premake5.exe -Algorithm SHA256).Hash -eq \"%PREMAKE_HASH%\") { exit 0 } else { exit 1 }" +IF %ERRORLEVEL% NEQ 0 ( + echo Hash verification failed >&2 + rm build/premake5.exe + exit 2 +) + +exit /B 0 + cd %~dp0 +:start +where /q "premake5.exe" +IF %ERRORLEVEL% EQU 0 ( + set PREMAKE_BIN="premake5.exe" + goto runpremake +) + +IF EXIST build/premake5.exe ( + set PREMAKE_BIN="build/premake5.exe" + goto runpremake +) + +echo Could not find premake5. You can either install it yourself or this script download it for you. +set /p choice="Do you wish to download it automatically? [y/N]> " +if /i "%choice%"=="y" ( + call:downloadpremake + set PREMAKE_BIN="build/premake5.exe" + goto runpremake +) + +echo Please install premake5 and try again +exit 1 + +:runpremake git submodule update --init --recursive -tools\premake5.exe %* vs2022 \ No newline at end of file +%PREMAKE_BIN% %* vs2022 diff --git a/generate.sh b/generate.sh index c298574e..1b1770bd 100755 --- a/generate.sh +++ b/generate.sh @@ -1,7 +1,71 @@ #!/bin/bash +PREMAKE_URL='https://github.com/premake/premake-core/releases/download/v5.0.0-beta4/premake-5.0.0-beta4-linux.tar.gz' +PREMAKE_HASH='4356ab7cdec6085183d68fb240089376eacdc2fb751ffbd8063d797ae43abeb3' + +function install_premake { + if [[ ! -x "$(command -v wget)" ]]; then + echo "Failed: Installation requires wget" >&2 + exit 2 + fi + if [[ ! -x "$(command -v tar)" ]]; then + echo "Failed: Installation requires tar" >&2 + exit 2 + fi + if [[ ! -x "$(command -v sha256sum)" ]]; then + echo "Failed: Installation requires sha256sum" >&2 + exit 2 + fi + + mkdir -p build + wget -nd -O build/premake.tar.gz "$PREMAKE_URL" + if [[ $? -ne 0 ]]; then + echo "Download failed" >&2 + exit 2 + fi + + tar -xf build/premake.tar.gz -C build + if [[ $? -ne 0 ]]; then + echo "Extraction failed" >&2 + exit 2 + fi + + rm build/premake.tar.gz + + echo "${PREMAKE_HASH} build/premake5" | sha256sum -c + if [[ $? -ne 0 ]]; then + echo "Hash verification failed" >&2 + rm build/premake5 + exit 2 + fi + + chmod +x build/premake5 +} + # Go to repository root cd "$(dirname "$0")" || exit 2 +if [[ ! -d ".git" ]]; then + echo "You must clone the OpenAssetTools repository using 'git clone'. Please read README.md." >&2 + exit 1 +fi + +PREMAKE_BIN='' +if [[ -x "$(command -v premake5)" ]]; then + PREMAKE_BIN='premake5' +elif [[ -x "$(command -v build/premake5)" ]]; then + PREMAKE_BIN='build/premake5' +else + echo "Could not find premake5. You can either install it yourself or this script download it for you." + if [[ "$(read -e -p 'Do you wish to download it automatically? [y/N]> '; echo $REPLY)" == [Yy]* ]]; then + echo "Installing premake" + install_premake + PREMAKE_BIN='build/premake5' + else + echo "Please install premake5 and try again" + exit 1 + fi +fi + git submodule update --init --recursive -tools/premake5 $@ gmake2 \ No newline at end of file +$PREMAKE_BIN $@ gmake2 diff --git a/premake5.lua b/premake5.lua index b3962cbf..359134fd 100644 --- a/premake5.lua +++ b/premake5.lua @@ -1,3 +1,5 @@ +require("premake", ">=5.0.0-beta4") + include "tools/scripts/folders.lua" include "tools/scripts/including.lua" include "tools/scripts/linking.lua" diff --git a/tools/premake5 b/tools/premake5 deleted file mode 100755 index 3d2f8f32..00000000 Binary files a/tools/premake5 and /dev/null differ diff --git a/tools/premake5.exe b/tools/premake5.exe deleted file mode 100644 index c73da1fb..00000000 Binary files a/tools/premake5.exe and /dev/null differ