2013-06-14 03:05:02 +02:00
|
|
|
@echo off
|
2021-08-08 13:30:21 +02:00
|
|
|
setlocal enableextensions enabledelayedexpansion
|
2013-06-14 03:05:02 +02:00
|
|
|
|
2021-08-10 23:51:48 +02:00
|
|
|
REM creates or updates version_auto.h
|
|
|
|
REM params: $1=filename (usually version_auto.h), $2=VARNAME (usually VGMSTREAM_VERSION)
|
2017-01-15 23:09:37 +01:00
|
|
|
|
2013-06-14 03:05:02 +02:00
|
|
|
|
2021-08-07 17:06:45 +02:00
|
|
|
REM defaults
|
|
|
|
set VERSION_DEFAULT=unknown
|
|
|
|
set VERSION_FILE=%1
|
|
|
|
set VERSION_NAME=%2
|
2021-08-10 23:51:48 +02:00
|
|
|
if "%~1" == "" set VERSION_FILE=version_auto.h
|
2021-08-07 20:41:50 +02:00
|
|
|
if "%~2" == "" set VERSION_NAME=VGMSTREAM_VERSION
|
2015-08-31 03:43:50 +02:00
|
|
|
|
2021-08-10 23:51:48 +02:00
|
|
|
if not "%VERSION%"=="" set VERSION=!VERSION:^:=_!
|
2021-08-07 17:06:45 +02:00
|
|
|
cd /d "%~dp0"
|
2013-06-14 03:05:02 +02:00
|
|
|
|
|
|
|
|
2021-08-10 23:51:48 +02:00
|
|
|
REM try get version from Git (dynamic)
|
|
|
|
:get_version_git
|
|
|
|
for /f %%v in ('git describe --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 */
|
2021-08-11 23:57:36 +02:00
|
|
|
goto :got_version
|
2013-06-14 03:05:02 +02:00
|
|
|
|
|
|
|
|
2021-08-10 23:51:48 +02:00
|
|
|
REM try to get version from version.h (static)
|
|
|
|
:get_version_h
|
2021-08-11 23:57:36 +02:00
|
|
|
echo Git version not found, can't autogenerate version (using default)
|
2021-08-10 23:51:48 +02:00
|
|
|
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
|
|
|
|
)
|
|
|
|
)
|
2021-08-11 23:57:36 +02:00
|
|
|
goto :got_version
|
2013-06-14 03:05:02 +02:00
|
|
|
|
2021-08-11 23:57:36 +02:00
|
|
|
|
|
|
|
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%
|
|
|
|
)
|
2021-08-10 23:51:48 +02:00
|
|
|
goto :exit
|
2013-06-14 03:05:02 +02:00
|
|
|
|
2021-08-11 23:57:36 +02:00
|
|
|
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
|
2013-06-14 03:05:02 +02:00
|
|
|
|
2021-08-08 13:30:21 +02:00
|
|
|
REM done
|
2013-06-14 03:05:02 +02:00
|
|
|
:exit
|