################################################################################
SHELL = /bin/sh
################################################################################
# Automatically fetch the project name
PROJ_NAME= $(lastword $(subst /, ,$(CURDIR)))

include 1_ToolEnv/0_Build/1_Config/ConfigPrj.mk

# Check the novelty of generated make files and get the variable target name
VARIABLE_TARGET=$(call GetVarTargetValBasedOnChngsInDir,$(PROJ_DIR)/0_Src,$(MAK_CONFIG_DIR))

.PHONY:all

all: $(PROJ_FIRST_SUBMAKE)
	@echo Now Build started !!!
	@$(MAKE) $(MULTI_PROC) -f $(PROJ_FIRST_SUBMAKE) $(BUILD_TARGET)

$(PROJ_FIRST_SUBMAKE): $(VARIABLE_TARGET)
	@echo Now the make files are generated !!!
	@$(MAKE) $(MULTI_PROC) -f $(PROJ_DIR)/1_ToolEnv/0_Build/0_Utilities/MakeMaker.mk THIS_DIR_NAME=$(PROJ_DIR)/0_Src
	@echo ''

#The target "clean" will remove obj + executables
clean: 
	@-rm -rf $(OUT_DIR)/*

#The target "rmall" will remove obj + executables and also generated make files
rmall:
	@-rm -rf $(OUT_DIR)/*
	@-rm -rf $(MAK_FILE_DIR)/*

#The target "clean" will remove obj + executables + generated make files then rebuilds the whole project
rebuild: rmall all

#The target "indent" will make standard indentation and standard styling for the c and h files
indent:
	@$(MAKE) -i $(MULTI_PROC) -f $(PROJ_DIR)/1_ToolEnv/0_Build/0_Utilities/Indent.mk

#The target "doc" invokes the doxygen tool to generate the doxygen files
doc:
	@$(MAKE) $(MULTI_PROC) -f $(PROJ_DIR)/1_ToolEnv/0_Build/0_Utilities/Doxygen.mk
	
#The target "cleandoc" makes the output of documentation removed
cleandoc:
	@$(MAKE) $(MULTI_PROC) -f $(PROJ_DIR)/1_ToolEnv/0_Build/0_Utilities/Doxygen.mk clean

#The target "oscfg" generates the Erika OS configurations
oscfg:
	@$(MAKE) -f $(PROJ_DIR)/1_ToolEnv/0_Build/0_Utilities/Erika_RT_Druid.mk

#The target "help" will provide the help on this make targets	
Help:
	@echo "Important GnuWin32 tool versions"
	@make --version
	@sed --version
	@find --version
	@echo
	@echo "Usage: make -f Makefile <target>"
	@echo "following are the make targets"
	@echo  
	@echo "all: Recursive project build"
	@echo "example: make -f Makefile all"
	@echo  
	@echo "clean: removes the generated object files and executables for the configured toolchain"
	@echo "example: make -f Makefile clean"
	@echo  
	@echo "rmall: removes generated make files object files and executables. This command shall always be used when toolchain configuration changed"
	@echo "example: make -f Makefile rmall"
	@echo  
	@echo "rebuild: removes generated make files object files and executables. builds the projects"
	@echo "example: make -f Makefile rebuild"
	@echo  
	@echo "indent: Format the c and header files for non excluded part of the project. Exclude of required part shall be done with the file 1_ToolEnv/0_Build/1_Config/CfgIndent.mk"
	@echo "example: make -f Makefile indent"
	@echo  
	@echo "doc: Generate the doxygen docuement for non excluded part of the project. Exclude of required part shall be done with the file 1_ToolEnv/0_Build/1_Config/CfgDoxygen.mk"
	@echo "example: make -f Makefile indent"
	@echo  
	@echo "cleandoc: Removes generated the doxygen docuements "
	@echo "example: make -f Makefile cleandoc"
	@echo  
	@echo "oscfg: generate the configuration files for Erika OS "
	@echo "example: make -f Makefile oscfg"
	@echo 
	@echo "help: displays this help message "
	@echo "example: make -f Makefile help"
	@echo  
	
#	@hh.exe help document under development
	
	
	
	