1@echo off 2 3setlocal enableextensions enabledelayedexpansion 4 5for /f %%v in ('git --git-dir="%~dp0..\.git" describe --tags --match "v*"') do set version=%%v 6 7if not "%version%"=="" goto :gotversion 8 9if exist "%~dp0..\version.mk" goto :getversion 10 11echo Git cannot be found, nor can version.mk. Generating unknown version. 12 13set version=unknown 14 15goto :gotversion 16 17:getversion 18 19for /f "delims== tokens=2" %%v in (%~dps0..\version.mk) do set version=%%v 20 21set version=!version:^"=! 22set version=!version: =! 23 24:gotversion 25 26set version_out=#define %~2 "%version%" 27set version_mk=%~2 = "%version%" 28 29echo %version_out%> "%~1_temp" 30 31if %version%==unknown goto :skipgenerate 32 33echo # static version string; update manually every release.> "%~dp0..\version.mk" 34echo %version_mk%>> "%~dp0..\version.mk" 35 36:skipgenerate 37 38echo n | comp "%~1_temp" "%~1" > NUL 2> NUL 39 40if not errorlevel 1 goto exit 41 42copy /y "%~1_temp" "%~1" 43 44:exit 45 46del "%~1_temp" 47