@echo off

set defines=-D"STM32F407xx" -D"USE_HAL_DRIVER"^
 -D"MATLAB"^
 -D"__sizeof_ptr=8"
:: -------------------------USERS PATHS AND CODE---------------------------
::-----------заголовочные файлы---------------
:: не добавлять CMSIS и HAL, они кастомные
set includes_user= -I".\Core\Inc"

::-----------исходный код---------------
set code_import=.\Core\Src\main.c^
 .\Core\Src\tim.c^
 .\Core\Src\gpio.c^
 .\Core\Src\stm32f4xx_it.c^
 .\Core\Src\system_stm32f4xx.c

:: .\Core\Src\stm32f4xx_hal_msp.c^
::-------------------------------------------------------------------------


:: -----------------------MCU LIBRARIES & SIMULATOR------------------------
:: -------MCU INCLUDED PATHS-------
set includes_MCU= -I"."^
 -I".\MCU_STM32F407_Matlab"^
 -I".\MCU_STM32F407_Matlab\Drivers\STM32F4xx_SIMULINK"^
 -I".\MCU_STM32F407_Matlab\Drivers\CMSIS"^
 -I".\MCU_STM32F407_Matlab\Drivers\STM32F4xx_HAL_Driver\Inc"^
 -I".\MCU_STM32F407_Matlab\Drivers\STM32F4xx_HAL_Driver\Inc\Legacy"

:: --------MCU SIMULATOR-------
:: код, которая будет симулировать перефирию МК в симулинке
set mcu_sim= .\MCU_STM32F407_Matlab\Drivers\CMSIS\stm32f407xx_matlab.c^
 .\MCU_STM32F407_Matlab\STM32F407xx.c^
 .\MCU_STM32F407_Matlab\Drivers\STM32F4xx_SIMULINK\stm32f4xx_matlab_tim.c
  
:: ---------HAL CODE----------
set code_hal=.\MCU_STM32F407_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim.c^
 .\MCU_STM32F407_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim_ex.c^
 .\MCU_STM32F407_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc.c^
 .\MCU_STM32F407_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash.c^
 .\MCU_STM32F407_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ex.c^
 .\MCU_STM32F407_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ramfunc.c^
 .\MCU_STM32F407_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_gpio.c^
 .\MCU_STM32F407_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma.c^
 .\MCU_STM32F407_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr.c^
 .\MCU_STM32F407_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr_ex.c^
 .\MCU_STM32F407_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cortex.c^
 .\MCU_STM32F407_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal.c^
 .\MCU_STM32F407_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_exti.c
: .\MCU_STM32F407_Matlab\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc_ex.c^



:: --------SHELL CODE----------
:: оболочка, которая будет моделировать работу МК в симулинке
set code_shell= .\MCU_Simulink\MCU.c^
 .\MCU_Simulink\controller.c^
 .\MCU_Simulink\Output\asmjmp.obj

:: оболочка, которая будет моделировать работу МК в симулинке
set includes_shell= -I".\MCU_Simulink"






:: ---------LIBRARIES---------
:: set params_obj=..\device_support_ml\source\C28x_FPU_FastRTS.obj ..\device_support_ml\source\DSP2833x_GlobalVariableDefs.obj


:: ---------------------SET PARAMS FOR MEX COMPILING-----------------------
:: -------OUTPUT FOLDER--------
set output=-outdir "."

:: если нужен дебаг, до запускаем run mex с припиской debug
IF [%1]==[debug] (set debug= -g)

::------START COMPILING-------
set command= mex %output% %debug% %defines% %includes_shell% %includes_MCU% %includes_user% %code_shell% %mcu_sim% %code_hal% %code_import% %params_obj%

echo %command%
%command%
::-------------------------------------------------------------------------