genversion.bat 789 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. @echo off
  2. setlocal enableextensions enabledelayedexpansion
  3. for /f %%v in ('cd "%~dp0.." ^&^& git status ^>NUL 2^>NUL ^&^& git describe --tags --match "v*" --dirty 2^>NUL') do set version=%%v
  4. if not "%version%"=="" set version=!version:~1! && goto :gotversion
  5. if exist "%~dp0..\package_version" goto :getversion
  6. echo Git cannot be found, nor can package_version. Generating unknown version.
  7. set version=unknown
  8. goto :gotversion
  9. :getversion
  10. for /f "delims== tokens=2" %%v in (%~dps0..\package_version) do set version=%%v
  11. set version=!version:"=!
  12. :gotversion
  13. set version=!version: =!
  14. set version_out=#define %~2 "%version%"
  15. echo %version_out%> "%~1_temp"
  16. echo n | comp "%~1_temp" "%~1" > NUL 2> NUL
  17. if not errorlevel 1 goto exit
  18. copy /y "%~1_temp" "%~1"
  19. :exit
  20. del "%~1_temp"