forked from vgmstream/vgmstream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version-make.bat
66 lines (56 loc) · 1.98 KB
/
version-make.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
@echo off
setlocal enableextensions enabledelayedexpansion
REM creates or updates version_auto.h
set VERSION_EMPTY=%1
set VERSION_FILE=%2
set VERSION_NAME=%3
if "%~1" == "" set VERSION_EMPTY=false
if "%~2" == "" set VERSION_FILE=version_auto.h
if "%~3" == "" set VERSION_NAME=VGMSTREAM_VERSION
set VERSION_DEFAULT=unknown
if not "%VERSION%"=="" set VERSION=!VERSION:^:=_!
cd /d "%~dp0"
REM try get version from Git (dynamic), including lightweight tags
:get_version_git
for /f %%v in ('git describe --tags --always') do set VERSION=%%v
if not "%VERSION%"=="" set VERSION=!VERSION:^:=_!
if "%VERSION%"=="" goto :get_version_h
if %VERSION%==%VERSION_DEFAULT% goto :get_version_h
set LINE=#define %VERSION_NAME% "%VERSION%" /* autogenerated */
goto :got_version
REM try to get version from version.h (static)
:get_version_h
echo Git version not found, can't autogenerate version (using default)
REM option to output empty line instead of default version, so plugins can detect git-less builds
if "%VERSION_EMPTY%"=="true" (
set LINE=/* ignored */
) else (
set LINE=#define %VERSION_NAME% "%VERSION_DEFAULT%" /* autogenerated */
if exist "version.h" (
for /F "tokens=*" %%v in (version.h) do (
set TOKEN=%%v
REM set COMP=#define %VERSION_NAME% #todo
if /i "!TOKEN:~0,25!"=="#define VGMSTREAM_VERSION" set LINE=%%v /* default */
)
)
)
goto :got_version
REM avoid overwritting if contents are the same, as some systems rebuild on timestamp
:got_version
set LINE_ORIGINAL=none
if exist %VERSION_FILE% set /p LINE_ORIGINAL=<%VERSION_FILE%
if not "%LINE%"=="%LINE_ORIGINAL%" (
REM no spaces!
echo %LINE%>%VERSION_FILE%
)
goto :exit
REM * alt full file comp test
REM echo %LINE% > %VERSION_FILE%_temp
REM echo n | comp %VERSION_FILE%_temp %VERSION_FILE% > NUL 2> NUL
REM if not errorlevel 1 goto :got_version_done
REM copy /y %VERSION_FILE%_temp %VERSION_FILE% > NUL 2> NUL
REM :got_version_done
REM del %VERSION_FILE%_temp
REM :exit
REM done
:exit