TOP_DIR=../../
include $(TOP_DIR)Makefile.def

##############################################################################
# All variables here intensionally set to empty, User should not modify here

SRC =
SRC_DIR =
SUBDIR =

##############################################################################
# List of include file directories required for compilation
INCLUDES = -Iapp/\
	   -Isrc/include\
	   -Isrc/include/netif/ppp/\
	   -Isrc/include/lwip/\
	   -Isystem/arch\
	   -Itarget/\
	   -I$(TOP_DIR)/exo_stack/usb_device/app_ecm/\
	   -I$(TOP_DIR)/exo_stack/usb_device/target_ecm/\
	   -I$(TOP_DIR)/exo_stack/usb_device/stm32_usb_device_library/class/cdc/Inc/\
	   -I$(TOP_DIR)/exo_stack/usb_device/stm32_usb_device_library/class/cdc_ecm/Inc/\
	   -I$(TOP_DIR)/exo_stack/usb_device/stm32_usb_device_library/core_ecm/Inc/\
	   -I$(TOP_DIR)/exo_os/exo_ral/cpu_arch/stm32f7xx/inc/\
	   -I$(TOP_DIR)/exo_os/rtos/free_rtos/portable/GCC/ARM_CM7/r0p1/\
	   -I$(TOP_DIR)/exo_os/rtos/free_rtos/CMSIS_RTOS_V2/\
	   -I$(TOP_DIR)/exo_os/rtos/free_rtos/include/\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/common/inc\
	   -I$(TOP_DIR)/exo_os/rtos/free_rtos/CMSIS_RTOS_V2/\
	   -I$(TOP_DIR)/drivers/ut/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/rcc/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/exti/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/rtc/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/gpio/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/dma/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/cortex/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/can/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/adc/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/uart/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/i2c/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/crc/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/spi/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/usb/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/ethernet/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/tmr/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/flash/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/pwr/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/fmc/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/sdram/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/wdg/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/nor_flash/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/qspi/inc\
	   -I$(TOP_DIR)/drivers/io_drivers/io_drivers_stm32f7xx/lwip/inc\
	   -I$(TOP_DIR)/drivers/exo_hal_driver_fw/exo_io_al_driver_api/exo_io_al_common/usb/inc/\
	   -I$(TOP_DIR)/drivers/exo_hal_driver_fw/exo_io_al_driver_api/exo_io_al_common/uart/inc/\
	   -I$(TOP_DIR)/drivers/exo_hal_driver_fw/exo_io_al_driver_api/exo_io_al_common/i2c/inc/\
	   -I$(TOP_DIR)/drivers/exo_hal_driver_fw/exo_io_al_driver_api/exo_io_al_common/crc/inc/\
	   -I$(TOP_DIR)/drivers/exo_hal_driver_fw/exo_io_al_driver_api/exo_io_al_common/rtc/inc/\
	   -I$(TOP_DIR)/drivers/exo_hal_driver_fw/exo_io_al_driver_api/exo_io_al_common/spi/inc/\
	   -I$(TOP_DIR)/drivers/exo_hal_driver_fw/exo_io_al_driver_api/exo_io_al_common/ethernet/inc/\
	   -I$(TOP_DIR)/drivers/exo_hal_driver_fw/exo_io_al_driver_api/exo_io_al_common/can/inc/\
	   -I$(TOP_DIR)/drivers/exo_hal_driver_fw/exo_io_al_driver_api/exo_io_al_common/adc/inc/\
	   -I$(TOP_DIR)/drivers/exo_hal_driver_fw/exo_io_al_driver_api/exo_io_al_common/adc/inc/\
	   -I$(TOP_DIR)/drivers/exo_hal_driver_fw/exo_io_al_driver_api/exo_io_al_common/common/inc/\
	   -I$(TOP_DIR)/drivers/exo_hal_driver_fw/exo_io_al_driver_api/exo_io_al_common/fmc_nor_flash/inc/\
	   -I$(TOP_DIR)/drivers/exo_hal_driver_fw/exo_hal_fw_common/common/inc/\
	   -I$(TOP_DIR)drivers/exo_hal_driver_fw/exo_ahw_al_driver_api/exo_ahw_al_common/common/inc/\
	   -I$(TOP_DIR)/exo_os/exo_ral/cpu_arch/stm32f7xx/inc/\
	   -I$(TOP_DIR)/exo_os/rtos/free_rtos/portable/GCC/ARM_CM7/r0p1/\
	   -I$(TOP_DIR)/exo_os/rtos/free_rtos/include/\
	   -I$(TOP_DIR)/exo_os/rtos/free_rtos/CMSIS_RTOS_V2/\
	   -I$(TOP_DIR)/exo_os/ut/inc/\
	   -I$(TOP_DIR)/exo_os/exo_osal/exo_osal_common/inc/\
	   -I$(TOP_DIR)/exo_os/exo_osal/ipc_mbmr/inc/\
	   -I$(TOP_DIR)/exo_os/exo_osal/memory_management/inc/\
	   -I$(TOP_DIR)/exo_os/exo_osal/task_management/inc/\
	   -I$(TOP_DIR)/exo_os/exo_ral/exo_ral_common/inc/\
	   -I$(TOP_DIR)/includes/\

ifeq ($(BOARD),JANUS1)
    INCLUDES += \
		-I$(TOP_DIR)drivers/bsp/janus1/inc/\
		
endif

ifeq ($(BOARD),JANUS2)
    INCLUDES += \
		-I$(TOP_DIR)drivers/bsp/janus2/inc/\
		
endif

ifeq ($(BOARD),GEN2)
    INCLUDES += \
		-I$(TOP_DIR)drivers/bsp/GEN2/inc/\
		
endif

ifeq ($(BOARD),65Z)
    INCLUDES += \
           -I$(TOP_DIR)drivers/bsp/stm32f765x/inc/\
		
endif

ifeq ($(BOARD),69N)
    INCLUDES += \
           -I$(TOP_DIR)drivers/bsp/disco_f769ni/inc/\
		
endif

##############################################################################
#Current Folder target name, usually current folder name
#TARGET_LIB = target_name

# List of source files required for compilation using SRC
# mention the directory path where all C files to be compiled usig SRC_DIR
# Mention Sub director makefile compilation using SUBDIR
#SRC += src/file_name.c
#SRC_DIR += src
#SUBDIR += dir_name

SRC_DIR += app
SRC_DIR += src/core
SRC_DIR += src/core/ipv6
SRC_DIR += src/core/ipv4
SRC_DIR += src/netif
#SRC_DIR += src/netif/ppp
SRC_DIR += src/api
SRC_DIR += src/apps/mqtt
SRC_DIR += system/OS
SRC_DIR += target

##############################################################################

ifeq ($(TARGET_LIB),)
TARGET_LIB := $(shell basename `pwd`)
endif

ifneq ($(SRC_DIR),)
    SOURCES = $(foreach dir,$(SRC_DIR),$(wildcard $(dir)/*.c))
endif

SOURCES += $(SRC)

OBJS = $(foreach dir,$(patsubst %.c, %.o, $(SOURCES)), $(OBJ_DIR)/$(dir))

ifneq ($(SUBDIR),)
SUB_DIR_LIBS = $(foreach dir,$(SUBDIR), $(dir)/$(OBJ_DIR)/$(shell basename $(dir)).a)
endif

#$(info selective source files List : $(SRC))
#$(info source file directory       : $(SRC_DIR))
#$(info All source file list        : $(SOURCES))
#$(info All target object files     : $(OBJS))
#$(info All target lib files        : $(SUB_DIR_LIBS))

DEPS = $(OBJS:.o=.d)

# Command to invoke compilation in sub-directories
subdir_clean:
	$(HIDE)for i in $(SUBDIR); do \
	    $(MAKE) clean -C $$i;\
	    done
# Command to invoke compilation in sub-directories
subdir_all:
	$(HIDE)for i in $(SUBDIR); do \
	    $(MAKE) all -C $$i;\
	    done
lib: subdir_all
	$(HIDE)$(MKDIR) $(OBJ_DIR)
	$(HIDE)$(AR) $(OBJ_DIR)/$(TARGET_LIB).a $(SUB_DIR_LIBS)

# Command to compile source files to intermediate object files
all:$(OBJS)
	$(HIDE)$(MKDIR) $(OBJ_DIR)
ifneq ($(SUBDIR),)
	$(HIDE)$(MAKE) subdir_all
endif
#	$(HIDE)$(AR) $(OBJ_DIR)/$(TARGET_LIB).a $^ $(SUB_DIR_LIBS)

# Command to delete intermediate object files
clean:
ifneq ($(SUBDIR),)
	$(HIDE)$(MAKE) subdir_clean
endif
	$(HIDE)$(RM) $(OBJ_DIR)

-include $(DEPS)
