Generate version information as part of the build.
[nssm.git] / version.cmd
1 @rem Set default version in case git isn't available.\r
2 set description=0.0-0-prerelease\r
3 @rem Get canonical version from git tags, eg v2.21-24-g2c60e53.\r
4 for /f %%v in ('git describe --tags --long') do set description=%%v\r
5 \r
6 @rem Strip leading v if present, eg 2.21-24-g2c60e53.\r
7 set description=%description:v=%\r
8 set version=%description%\r
9 \r
10 @rem Get the number of commits and commit hash, eg 24-g2c60e53.\r
11 set n=%version:*-=%\r
12 set commit=%n:*-=%\r
13 call set n=%%n:%commit%=%%\r
14 set n=%n:~0,-1%\r
15 \r
16 @rem Strip n and commit, eg 2.21.\r
17 call set version=%%version:%n%-%commit%=%%\r
18 set version=%version:~0,-1%\r
19 \r
20 @rem Find major and minor.\r
21 set minor=%version:*.=%\r
22 call set major=%%version:.%minor%=%%\r
23 \r
24 @rem Don't include n and commit if we match a tag exactly.\r
25 if "%n%" == "0" set description=%major%.%minor%\r
26 \r
27 @rem Ignore the build number if this isn't Jenkins.\r
28 if "%BUILD_NUMBER%" == "" set BUILD_NUMBER=0\r
29 \r
30 @rem Create version.h.\r
31 @echo>version.h #define NSSM_VERSION _T("%description%")\r
32 @echo>>version.h #define NSSM_VERSIONINFO %major%,%minor%,%n%,%BUILD_NUMBER%\r
33 @echo>>version.h #define NSSM_DATE _T("%DATE%")\r