@echo off setlocal ENABLEDELAYEDEXPANSION rem A good old 80s batch file, because it's guaranteed to always be available. rem This assumes git is in the path. for /F %%I in ('git describe --always --dirty') do set GITVER=%%I if "%GITVER%" == "" goto git_error rem Replace -dirty with -devel, to indicate builds with uncommitted changes. set GITVER=%GITVER:-dirty=-devel% goto continue :git_error rem If calling git fails for some reason, put a message in the version instead of rem letting it be blank. set GITVER=git failed :continue rem Output the current version to a temp file. set TEMP_FILE=%TEMP%\temp-SMXBuildVersion.h set OUTPUT_FILE=SMXBuildVersion.h echo // This file is auto-generated by update-build-version.bat. > %TEMP_FILE% echo. >> %TEMP_FILE% echo #ifndef SMXBuildVersion_h >> %TEMP_FILE% echo #define SMXBuildVersion_h >> %TEMP_FILE% echo. >> %TEMP_FILE% echo #define SMX_BUILD_VERSION "%GITVER%" >> %TEMP_FILE% echo. >> %TEMP_FILE% echo #endif >> %TEMP_FILE% rem Compare the temp file to any existing file. Only copy the new file over the old rem one if it's different, so we don't trigger dependency rebuilds every time. fc %TEMP_FILE% %OUTPUT_FILE% > nul if %errorlevel% == 0 goto end echo Updated to version %GITVER% copy %TEMP_FILE% %OUTPUT_FILE% > nul :end