# This program was created by AXELL CORPORATION.
# Copyright (C) 2015 AXELL CORPORATION, all rights reserved.

# Build switch definition
#-------------------------------------------------------------------------------
SUPPORT_FILESYSTEM		=	yes
BUILD_USECASE_SAMPLE	=	no

# Build path definition
#-------------------------------------------------------------------------------
BUILD_ROOT			=	$(shell pwd)/..
BUILD_PATH			=	$(BUILD_ROOT)/build
LIB_PATH			=	$(BUILD_ROOT)/lib
INC_PATH			=	$(BUILD_ROOT)/include
OS_PATH				=	$(BUILD_ROOT)/os
SAMPLE_PATH			=	$(BUILD_ROOT)/sample
PLATFORM_PATH		=	$(SAMPLE_PATH)/platform/os

ifeq ($(EXEGCC), ON)
PLATFORM			=	iTRON/uC3_exeGCC
else
PLATFORM			=	iTRON/uC3
endif

export BUILD_ROOT
export BUILD_PATH
export LIB_PATH
export INC_PATH
export OS_PATH
export PLATFORM
export SAMPLE_PATH
export PLATFORM_PATH

# Exclude Samples
#-------------------------------------------------------------------------------
FILTER				=	platform pgp
ifeq ($(SUPPORT_FILESYSTEM), no)
FILTER				+=	bmu dsp jpg osp ssp gvd mps
endif
ifeq ($(BUILD_USECASE_SAMPLE), no)
FILTER				+=	cap mps mtx
endif

OPTIONS				=	SUPPORT_FILESYSTEM=$(SUPPORT_FILESYSTEM)	\
						BUILD_USECASE_SAMPLE=$(BUILD_USECASE_SAMPLE)

# To build and follow the hierarchy
#-------------------------------------------------------------------------------
MAKE_DIRS			=	$(filter-out $(addprefix ./,$(FILTER)), $(shell find . -mindepth 1 -maxdepth 1 -type d))

.PHONY: all sample clean depend

all: sample
	$(MAKE) -C ../os
	$(MAKE) -C platform/os $(OPTIONS)

sample:
	@for subdir in $(MAKE_DIRS) ; do \
		$(MAKE) -C $$subdir $(OPTIONS) ; \
	done

clean:
	@for subdir in $(MAKE_DIRS) ; do \
		$(MAKE) -C $$subdir clean ; \
	done

	$(MAKE) -C ../os clean
	$(MAKE) -C platform/os clean

depend:
	@for subdir in $(MAKE_DIRS) ; do \
		$(MAKE) -C $$subdir depend ; \
	done

	$(MAKE) -C ../os depend
	$(MAKE) -C platform/os depend
