@echo off

rem ***************************************************************************
rem Set parameters 1 to 26
rem ***************************************************************************

set p01=%1
set p02=%2
set p03=%3
set p04=%4
set p05=%5
set p06=%6
set p07=%7
set p08=%8
set p09=%9
shift&shift&shift&shift&shift&shift&shift&shift&shift
set p10=%1
set p11=%2
set p12=%3
set p13=%4
set p14=%5
set p15=%6
set p16=%7
set p17=%8
set p18=%9
shift&shift&shift&shift&shift&shift&shift&shift&shift
set p19=%1
set p20=%2
set p21=%3
set p22=%4
set p23=%5
set p24=%6
set p25=%7
set p26=%8


rem ***************************************************************************
rem Obtain the build start time
rem ***************************************************************************

echo.
echo Get the build start time
echo The build start time is: %time%
echo.

for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
   set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
)

rem ***************************************************************************
rem Create, report and execute the build command
rem ***************************************************************************

echo.
echo The build command is:
echo %CD%\..\Build.bat %p01% %p02% %p03% %p04% %p05% %p06% %p07% %p08% %p09% %p10%
echo.

echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo.
echo The description of the build command is:
echo Build.bat  %p01% %p02% %p03% %p04% %p05% %p06% %p07% %p08% %p09% %p10%
echo.
echo %%p01: TYP_ECU:    ecu                 such as G00, G01, W00, W01, Z03...
echo %%p02: TYP_MCAL    mcal                such as CYT2_B9, STM32_F4, ...
echo %%p03: TYP_CC:     tool chain compiler such as ARM_GCC, ARM_GHS, ARM_KEIL, WIN_VC, WIN_GCC, TRICORE_TASKING ...
echo %%p04: TYP_TEST    test framework      either  CUnit or GoogleTest
echo %%p05: TYP_COVER   code coverage tool  either  CTC or GCOV
echo %%p06: TYP_CORE:   cpu core            such as M4F, M0P, X64, ...
echo %%p07: TYP_PRJ:    project             such as Ps066, Pb022, In005, ...
echo %%p08: TYP_VAR:    variant             such as App, Test, Pbl, Fbl, ...
echo %%p09: TYP_BUILD:  type                such as default        : Compile and link the project
echo                                                prepro         : Only perform compiler preprocessing (does not compile or link)
echo                                                lint           : (not yet supported) Only perform lint analysis of the project
echo                                                misra          : (not yet supported) Only perform misra analysis of the project
echo                                                Mt_CddExample  : Module test CddExample (TYP_VAR=Test)
echo %%p10: TYP_KEY:    key                 such as NonKey         : Using no key whatsoever
echo                                                HotKey         : HotKey is a key originating from a secure server
echo                                                DevKey         : DevKey is a cold development key (which can also have no value)
echo %%p11: TYP_RULE:   rule                such as all            : Build (do not rebuild) the active project configuration
echo                                                rebuild        : Rebuild the active project configuration
echo                                                clean          : (not yet supported) Clean the active project configuration
echo                                                single         : (not yet supported) Compile one single file in the active project configuration
echo.
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

set MAKEBAT=%CD%\..\Make\Make.bat
set MAKEPARAMS=%p01% %p02% %p03% %p04% %p05% %p06% %p07% %p08% %p09% %p10% %p11%

if "%p03%" NEQ "WIN_VC" (
  goto callmake
)

set VSVERSION=
set VSCOMMONTOOLS=

for /F "tokens=1,2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7"') do (
set VSVERSION=%%i
set VSCOMMONTOOLS=%%k
)

if "%VSVERSION%" lss "15.0" (
set VCVARSBAT="%VSCOMMONTOOLS%VC\bin\amd64\vcvars64.bat"
) else (
set VCVARSBAT="%VSCOMMONTOOLS%VC\Auxiliary\Build\vcvars64.bat"
)

if exist %VCVARSBAT% (
echo.
echo calling %VCVARSBAT%
call %VCVARSBAT%
) else (
echo.
echo VSCOMMONTOOLS can not be found
)

echo VSCOMMONTOOLS     : %VSCOMMONTOOLS%
echo VSVERSION         : %VSVERSION%
echo VCVARSBAT         : %VCVARSBAT%

:callmake
echo.
echo Calling: %MAKEBAT% %MAKEPARAMS%
echo.
%MAKEBAT% %MAKEPARAMS%
