version.cmd 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. @rem Set default version in case git isn't available.
  2. set description=0.0-0-prerelease
  3. @rem Get canonical version from git tags, eg v2.21-24-g2c60e53.
  4. for /f %%v in ('git describe --tags --long') do set description=%%v
  5. @rem Strip leading v if present, eg 2.21-24-g2c60e53.
  6. set description=%description:v=%
  7. set version=%description%
  8. @rem Get the number of commits and commit hash, eg 24-g2c60e53.
  9. set n=%version:*-=%
  10. set commit=%n:*-=%
  11. call set n=%%n:%commit%=%%
  12. set n=%n:~0,-1%
  13. @rem Strip n and commit, eg 2.21.
  14. call set version=%%version:%n%-%commit%=%%
  15. set version=%version:~0,-1%
  16. @rem Find major and minor.
  17. set minor=%version:*.=%
  18. call set major=%%version:.%minor%=%%
  19. @rem Build flags.
  20. set flags=0L
  21. @rem Don't include n and commit if we match a tag exactly.
  22. if "%n%" == "0" (set description=%major%.%minor%) else set flags=VS_FF_PRERELEASE
  23. @rem Maybe we couldn't get the git tag.
  24. if "%commit%" == "prerelease" set flags=VS_FF_PRERELEASE
  25. @rem Ignore the build number if this isn't Jenkins.
  26. if "%BUILD_NUMBER%" == "" set BUILD_NUMBER=0
  27. @rem Copyright year provided by Jenkins.
  28. if "%BUILD_ID%" == "" (set year=) else (
  29. set md=%BUILD_ID:*-=%
  30. call set year=%%BUILD_ID:%md%=%%
  31. set year=%year:~0,-1%
  32. )
  33. @rem Create version.h.
  34. @echo>version.h.new #define NSSM_VERSION _T("%description%")
  35. @echo>>version.h.new #define NSSM_VERSIONINFO %major%,%minor%,%n%,%BUILD_NUMBER%
  36. @echo>>version.h.new #define NSSM_DATE _T("%DATE%")
  37. @echo>>version.h.new #define NSSM_FILEFLAGS %flags%
  38. @echo>>version.h.new #define NSSM_COPYRIGHT _T("(c) 2003-%year% Iain Patterson")
  39. fc version.h version.h.new >NUL: 2>NUL:
  40. if %ERRORLEVEL% == 0 (del version.h.new) else (move /y version.h.new version.h)