################################################################################
#
# makefile - application specific makefile
#
# Renesas Electronics America
# Version 0.4, 7 June 2023
#
# Description:
# Automates build of software
# Calls generic makefile for most actions
# 
# Invocation (from a DOS command line):
# make [<target>] [micro=<micro>] [comp=<compiler>]
#
#	<target>: makefile target (see below)
#	This is an optional argument and defaults to the default target.
#		default: make a .elf and .s19 file
#		clean: delete all generated output files and directories
#		test: print out makefile variables
#		format: invokes code beautification utilities
#		bridgeway: displays usage screen
#
#	<micro>: selects micro core instruction set and memory to be used
#	This is optional and defaults to U2A.
#		2z19:  (U2A)       default
#       2z32:  (U2C)
#
#	<compiler>: selects compiler to be used for build
#	This is an optional argument and defaults to WR
#		WR: WindRiver Diab compiler (default)
#		GHS: GreenHills compiler
#		CS/CS+: Renesas CS+ compiler - not yet supported
#
#	FIXME: How is GTM supported?
#
# Dependencies:
# DOS has no 'make' command, nor other related useful commands.
# Therefore, this makefile depends on GnuWin32 CoreUtils-5.3.0 and
# GnuWin32 Make-3.81. These can be downloaded from
# website: gnuwin32.sourceforge.net/packages.html.
# Install them by running the downloaded executable.
# Manuals are here: www.gnu.org/manual/
# Add the installed path (C:\Program Files (x86)\GnuWin32\bin, default)
# to the PATH environment variable.
#
################################################################################
# File Name   : makefile
# Device(s)   : RH850
# Description : MAKE build for EvbSchd App 
################################################################################

################################################################################
# Target check
################################################################################

#if user does not specify the target (micro) 
# use this as the default
ifndef micro
   micro = U2B6
endif
	
################################################################################
# Application Directories
################################################################################

# The application/project directory
PROJ_DIR := $(shell pwd)


# Here specify all directories for all source files for this application.
#
# The current directory (.) is the location of the Makefile, which
# should be in an individual application directory.
#
# IMPORTANT: to reference a target specific folder in SRC_DIRS you can
# substitute such a folder name with $(DEVICENUM). This requires that target
# specific folder names are valid $(DEVICENUM) names. See 
# makefile.generic.target for the list of valid $(DEVICENUM) names.
#
# If valid DEVICENUM folder names are used then they do not have to be 
# listed below (the script will find them).
#
#
SRC_DIRS = ./ana \
           ./can \
           ./cfg \
		   ./display \
           ./ecm_module \
		   ./enc \
		   ./ethernet \
		   ./ethernet/lwip/include \
		   ./ethernet/lwip/core \
		   ./ethernet/lwip/netif \
		   ./ethernet/lwip/include/netif \
		   ./ethernet/lwip/core/ipv4 \
		   ./ethernet/lwip/arch \
		   ./ethernet/http \
		   ./ethernet/http/website \
		   ./ethernet/lwip \
		   ./led \
           ./pmic \
		   ./rlinDriver \
           ./rlinModule \
           ./shell \
		   ./spi \
           ./src \
		   ./standby \
		   ./sysTimer \
           ./uart \
		   ./userinput \
		   ../../drivers/ETH \
		   ../../drivers/ETND \
		   ./ana \
		   ./standby \
		   ./systemTest \
           ../../Drivers/RH850 \
           ../../Drivers/ESH \
           ../../Drivers/ESH/lib/printf 

# target evaluation logic
# 1) "micro" variable is used by the included make file to generate variables
#    DEVICENUM and MICRO (variable names are case sensitive).
# 2) "SRC_DIRS" and "DEVICENUM" variables are used by the included make file to 
#    find subdirectories with name /DEVICENUM and appended to SRC_DIRS
include ./../../make/generic/makefile.generic.target

EXTRA_DEFINES = -DMICRO=$(micro) -DCOMP=$(comp)


################################################################################
# Tools
################################################################################

# User Note: Suggest use of environment variable to define path to compiler. 
#            Alternately edit the path below per your computer installation.
# if environment variable is set, use that for compiler path
ifdef WR_COMPILER
    COMPILER_PATH_WR = ${WR_COMPILER}
else
    COMPILER_PATH_WR = c:/windriver/5.9.6.1
endif
# user can specify flags to use for this app
# if nothing is listed, then the default flags will be used
COMPILER_FLAGS_WR = 
ASSEMBLER_FLAGS_WR = 
LINKER_FLAGS_WR = 

# User Note: Suggest use of environment variable to define path to compiler. 
#            Alternately edit the path below per your computer installation.
# if environment variable is set, use that for compiler path
ifdef GHS_COMPILER
    COMPILER_PATH_GHS = ${GHS_COMPILER}
else
    COMPILER_PATH_GHS = C:\ghs\comp_202414
endif
# user can specify flags to use for this app
# if nothing is listed, then the default flags will be used
COMPILER_FLAGS_GHS =-cpu=rh850g4mh -rh850_fxu -list -bsp=generic \
	                 -large_sda -shorten_loads -dwarf2 -prepare_dispose \
	                 --no_commons -ffunctions --bool -g -Mx -O -Olink -Omaxdebug \
	                 -nofloatsingle --ghstd=none \
	                 -nostartfiles -noobj -notda -passsource -inline_prologue \
	                 --switch_table -C99 -dual_debug \
	                 -preprocess_assembly_files  \
					--no_wrap_diagnostics \
					--brief_diagnostics
#	                 --diag_suppress=32  
ASSEMBLER_FLAGS_GHS = 
LINKER_FLAGS_GHS =  -Olink -Omaxdebug -nostartfiles -noobj -map -minlib -lstartup \
	               -lsys -lcrt0.o -lansi -lmath_sngl -lutf8_u16 -lind_fp -notda \
	               -e _g4mh_rbase

# User Note: Suggest use of environment variable to define path to compiler.
#            Alternately edit the path below per your computer installation.
# if environment variable is set, use that for compiler path
COMPILER_PATH_CS =
ifdef CS_COMPILER
	COMPILER_PATH_CS = ${CS_COMPILER}
else
	COMPILER_PATH_CS = \
	        C:\Program Files (x86)\Renesas Electronics\CS+\CC\CC-RH\V2.07.00
endif
# user can specify flags to use for this app
# if nothing is listed, then the default flags will be used
COMPILER_FLAGS_CS = 
ASSEMBLER_FLAGS_CS = 
LINKER_FLAGS_CS = 

# all the variables in this makefile will be exported to the shell
# used by the generic makefile
export

################################################################################
# Invocation of generic makefile
################################################################################
.PHONY: default
default:
	${MAKE} ${MAKECMDGOALS} -f ../../Make/Generic/makefile.generic 

.PHONY: test
test:
	${MAKE} ${MAKECMDGOALS} -f ../../Make/Generic/makefile.generic 
	
.PHONY: clean
clean:
	${MAKE} ${MAKECMDGOALS} -f ../../Make/Generic/makefile.generic 	

.PHONY: format
format:
	${MAKE} ${MAKECMDGOALS} -f ../../Make/Generic/makefile.generic

.PHONY: bridgeway
bridgeway:
	${MAKE} ${MAKECMDGOALS} -f ../../Make/Generic/makefile.generic
