version.cmd 1.1 KB

123456789101112131415161718192021222324252627282930313233
  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 Don't include n and commit if we match a tag exactly.
  20. if "%n%" == "0" set description=%major%.%minor%
  21. @rem Ignore the build number if this isn't Jenkins.
  22. if "%BUILD_NUMBER%" == "" set BUILD_NUMBER=0
  23. @rem Create version.h.
  24. @echo>version.h #define NSSM_VERSION _T("%description%")
  25. @echo>>version.h #define NSSM_VERSIONINFO %major%,%minor%,%n%,%BUILD_NUMBER%
  26. @echo>>version.h #define NSSM_DATE _T("%DATE%")