builds: don't make .h when no git found, no .mk

This commit is contained in:
bnnm 2021-08-08 13:30:21 +02:00
parent d12f137470
commit 63b588709f

View File

@ -1,9 +1,9 @@
@echo off @echo off
setlocal enableextensions enabledelayedexpansion
REM creates or updates version.h REM creates or updates version.h
REM params (optional): $1=filename (usually [relpath]/version.h), $2=VARNAME (usually VGMSTREAM_VERSION) REM params: $1=filename (usually version.h), $2=VARNAME (usually VGMSTREAM_VERSION)
setlocal enableextensions enabledelayedexpansion
REM defaults REM defaults
set VERSION_DEFAULT=unknown set VERSION_DEFAULT=unknown
@ -17,44 +17,22 @@ if not "%version%"=="" set version=!version:^:=_!
cd /d "%~dp0" cd /d "%~dp0"
REM try dynamic version from git REM try get version from Git, leave original version.h untouched if not possible
for /f %%v in ('git describe --always') do set version=%%v for /f %%v in ('git describe --always') do set version=%%v
if not "%version%"=="" set version=!version:^:=_! if not "%version%"=="" set version=!version:^:=_!
if not "%version%"=="" goto :got_version if not "%version%"=="" goto :got_version
if exist "version.mk" goto :mk_version
echo Git version cannot be found, nor can version.mk. Generating unknown version. echo Git version cannot be found, can't autogenerate version.h
set version=%VERSION_DEFAULT% goto :exit
goto :got_version
REM try static version from .mk file REM overwrite version.h
:mk_version
for /f "delims== tokens=2" %%v in (version.mk) do set version=%%v
set version=!version:^"=!
set version=!version: =!
REM version found, create version.h and update .mk
:got_version :got_version
set version_out=#define %VERSION_NAME% "%version%" if %version%==%VERSION_DEFAULT% goto :exit
set version_mk=%VERSION_NAME% = "%version%"
echo %version_out%> %VERSION_FILE%_temp echo #define %VERSION_NAME% "%version%" /* autogenerated */ >> %VERSION_FILE%
if %version%==%VERSION_DEFAULT% goto :skip_generate
echo # static version string; update manually before and after every release.> "version.mk"
echo %version_mk%>> "version.mk"
:skip_generate REM done
echo n | comp %VERSION_FILE%_temp %VERSION_FILE% > NUL 2> NUL
if not errorlevel 1 goto exit
copy /y %VERSION_FILE%_temp %VERSION_FILE% > NUL 2> NUL
:exit :exit
del %VERSION_FILE%_temp