Created
June 1, 2024 07:48
-
-
Save t-mat/3628806a907dd4fafac8e99c1ebdd1f3 to your computer and use it in GitHub Desktop.
[Windows] Download and build NetHack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@rem Download and build script for NetHack for Windows x64 Desktop, VC++2022 | |
@echo off | |
setlocal EnableDelayedExpansion | |
set /a errorno=1 | |
for /F "delims=#" %%E in ('"prompt #$E# & for %%E in (1) do rem"') do set "esc=%%E" | |
set "ROOT=%CD%" | |
: | |
: Check prerequisites | |
: | |
where /q tar.exe || ( echo "tar.exe" command not found. & goto :ERROR ) | |
where /q curl.exe || ( echo "curl.exe" command not found. & goto :ERROR ) | |
: | |
: Setup Visual C++ | |
: https://github.com/microsoft/vswhere/wiki/Find-VC#batch | |
: | |
set "vswhere=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" | |
if not exist "%vswhere%" ( | |
echo "vswhere.exe" command not found. Please install the latest version of Visual Studio. | |
goto :ERROR | |
) | |
set "InstallDir=" | |
for /f "usebackq tokens=*" %%i in (` ^ | |
"%vswhere%" ^ | |
-latest ^ | |
-products * ^ | |
-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ^ | |
-property installationPath ^ | |
`) do ( | |
set "InstallDir=%%i" | |
) | |
if "%InstallDir%" == "" ( | |
echo Failed to find Visual C++. Please install the latest version of Visual C++. | |
goto :ERROR | |
) | |
call "%InstallDir%\VC\Auxiliary\Build\vcvars64.bat" || goto :ERROR | |
: | |
: Download and extract SDL archive | |
: | |
set "NH_VER=3.6.7" | |
if not exist "NetHack-NetHack-%NH_VER%_Released.tar.gz" ( curl.exe -LJO https://github.com/NetHack/NetHack/archive/refs/tags/NetHack-%NH_VER%_Released.tar.gz ) | |
if not exist "NetHack-NetHack-%NH_VER%_Released.tar.gz" ( echo Failed to download https://github.com/NetHack/NetHack/archive/refs/tags/NetHack-%NH_VER%_Released.tar.gz & goto :ERROR ) | |
if exist NetHack-%NH_VER% ( rmdir /Q /S NetHack-%NH_VER% ) | |
if exist NetHack-%NH_VER% ( echo Failed rmdir NetHack-%NH_VER% & goto :ERROR ) | |
tar.exe -xf NetHack-NetHack-%NH_VER%_Released.tar.gz || (echo Failed to extract NetHack-NetHack-%NH_VER%_Released.tar.gz & goto :ERROR ) | |
cd NetHack-NetHack-%NH_VER%_Released || (echo Failed to extract NetHack-NetHack-%NH_VER%_Released.tar.gz & goto :ERROR ) | |
set "NH_ROOT=%CD%" | |
: | |
: Patch and invoke the NetHack setup batch file | |
: | |
cd /d "%NH_ROOT%\sys\winnt" || goto :ERROR | |
copy /y nhsetup.bat nhsetup.old | |
powershell -Command "(gc nhsetup.old) -replace ' pause', ' echo -pause' | Out-File -encoding ASCII nhsetup.bat" | |
call .\nhsetup.bat || goto :ERROR | |
: | |
: Build NetHack | |
: | |
cd /d "%NH_ROOT%\src" || goto :ERROR | |
nmake install || goto :ERROR | |
: | |
: Show report | |
: | |
echo. | |
echo. | |
echo. | |
cd /d "%NH_ROOT%" || goto :ERROR | |
tree /A /F "%NH_ROOT%\binary\" || goto :ERROR | |
echo All artifacts are in "%NH_ROOT%\binary\" | |
echo. | |
echo Build Status -%esc%[92m SUCCEEDED %esc%[0m | |
set /a errorno=0 | |
goto :END | |
:ERROR | |
echo Abort by error. | |
echo. | |
echo Build Status -%esc%[91m ERROR %esc%[0m | |
:END | |
exit /B %errorno% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisites
Command prompt