prebuild.bat:
@echo off
setlocal
rem Uncomment line below for use another dir
rem cd ..\..\
for /F "usebackq" %%f in (`cd`) do set CURR_DIR=%%f
rem Define build data and time constants
set CURR_DATA=%DATE%
set CURR_TIME=%TIME%
echo #define BUILD_DATA_STR "%CURR_DATA:~0,10%" > %CURR_DIR%\build_param.h
echo #define BUILD_TIME_STR "%CURR_TIME:~0,8%" >> %CURR_DIR%\build_param.h
echo #define BUILD_DATA_YEAR %CURR_DATA:~6,4% >> %CURR_DIR%\build_param.h
if "%CURR_DATA:~3,1%" == "0" (
echo #define BUILD_DATA_MONTH %CURR_DATA:~4,1% >> %CURR_DIR%\build_param.h
) else (
echo #define BUILD_DATA_MONTH %CURR_DATA:~3,2% >> %CURR_DIR%\build_param.h
)
if "%CURR_DATA:~0,1%" == "0" (
echo #define BUILD_DATA_DAY %CURR_DATA:~1,1% >> %CURR_DIR%\build_param.h
) else (
echo #define BUILD_DATA_DAY %CURR_DATA:~0,2% >> %CURR_DIR%\build_param.h
)
if "%CURR_TIME:~0,1%" == "0" (
echo #define BUILD_DATA_HOUR %CURR_TIME:~1,1% >> %CURR_DIR%\build_param.h
) else (
echo #define BUILD_DATA_HOUR %CURR_TIME:~0,2% >> %CURR_DIR%\build_param.h
)
if "%CURR_TIME:~3,1%" == "0" (
echo #define BUILD_DATA_MIN %CURR_TIME:~4,1% >> %CURR_DIR%\build_param.h
) else (
echo #define BUILD_DATA_MIN %CURR_TIME:~3,2% >> %CURR_DIR%\build_param.h
)
if "%CURR_TIME:~6,1%" == "0" (
echo #define BUILD_DATA_SEC %CURR_TIME:~7,1% >> %CURR_DIR%\build_param.h
) else (
echo #define BUILD_DATA_SEC %CURR_TIME:~6,2% >> %CURR_DIR%\build_param.h
)
rem Define build revision number from mercurial repository
hg summary | find /I "parent:" > %CURR_DIR%\tmpfile
for /F "usebackq tokens=2,3 delims=:" %%A in ("tmpfile") do set REV_NUM=%%A&set REV_HASH=%%B
echo #define BUILD_REV_NUM %REV_NUM%U >> %CURR_DIR%\build_param.h
echo #define BUILD_REV_NUM_STR "%REV_NUM%" >> %CURR_DIR%\build_param.h
echo #define BUILD_REV_HASH 0x%REV_HASH:~0,12%ULL >> %CURR_DIR%\build_param.h
echo #define BUILD_REV_HASH_STR "%REV_HASH:~0,12%" >> %CURR_DIR%\build_param.h
del %CURR_DIR%\tmpfile >nul
endlocal
Результирующий файл build_param.h:
#define BUILD_DATA_STR "05.02.2024"
#define BUILD_TIME_STR "19:33:00"
#define BUILD_DATA_YEAR 2024
#define BUILD_DATA_MONTH 2
#define BUILD_DATA_DAY 5
#define BUILD_DATA_HOUR 19
#define BUILD_DATA_MIN 33
#define BUILD_DATA_SEC 0
#define BUILD_REV_NUM 2330U
#define BUILD_REV_NUM_STR " 2330"
#define BUILD_REV_HASH 0x81bd30a4816fULL
#define BUILD_REV_HASH_STR "81bd30a4816f"