@ECHO OFF

: Removes a regenerates any local MK in the [SKD]\kernels\mk folder using as reference all the .tm files found.
:: This script is supposed to be at .git\hooks folder of the SKD
SET "SCRIPT_PATH=%~dp0"
cd %SCRIPT_PATH%

cd ..
cd ..

SET "SKD_PATH=%cd%
SET "KERNELS_PATH=%SKD_PATH%\kernels"
SET "MKS_PATH=%KERNELS_PATH%\mk"

:: Go to MK folder
if exist %MKS_PATH% (

  :: Goto MKs folder
  cd %MKS_PATH%

  echo Removing old local Meta-Kernels...
  del *_local.tm

  echo Creating updated local Meta-Kernels...
  for /r "%MKS_PATH%" %%f in (*.tm) do (
    %SCRIPT_PATH%update_local_mk.bat %%~nxf %KERNELS_PATH% %%~nf_local.tm
  )

  del *_local_local.tm

  cd %SCRIPT_PATH%

  echo Local Meta-Kernels updated successfully...
  :: pause
  :: exit 0

) else (
  echo "Invalid path: %MKS_PATH% , aborted."
  :: pause
  :: exit 1
)
