################################################################################
################################################################################
##
## Makefile -- project specific makefile to build an executable
##
## (C) Copyright 2006-2010 by Fujitsu Microelectronics Europe GmbH
## (C) Copyright 2010 by Fujitsu Semiconductor Europe GmbH
##
## Version: $Id: Makefile 6733 2010-08-11 07:55:18Z rseng $
##
## Mandatory settings:
##
## o TOPDIR    = the toplevel directory (using slashes as path separator)
## o TARGET    = the machine qualifier to generate code for
## o SOURCES   = the list of source files to compile
## o STARTUP   = the name of the (assembler) startup file to use
## o HEADERS   = the list of local header files to install
## o PROGRAM   = the name of the executable to generate (without extension)
## o LIBRARIES = the list of library files to be linked
##
################################################################################
################################################################################

  TOPDIR = ../..
  SUBDIR = applications/c202_h60

include $(TOPDIR)/env/make/Makefile.config

################################################################################
# Default parameters for bootable image
#
# BOOTER_SLOT_NAME       - image name string
# BOOTER_IMGVENDOR       - image manufacturer identification string
# BOOTER_SLOT_VERSION    - image version number
# BOOTER_SLOT_INDEX      - image slot number (BOOTER_SLOT_0,BOOTER_SLOT_1)
#
# NOTE: These defaults may be overridden
#       in the application-specific makefile $(APPPATH)/makefile.app.
################################################################################

BOOTER_SLOT_NAME     = "av_demo"
BOOTER_SLOT_0        = 1
BOOTER_SLOT_1        = 2
BOOTER_IMGVENDOR     = "fme"
BOOTER_SLOT_VERSION  = 1
BOOTER_SLOT_INDEX    = BOOTER_SLOT_0
BOOTER_SLOT_COMPRESS = on
BOOTER_SLOT_IMAGE    = build/bslotimg.bin
BOOTER_SLOT_OFFSETS  = 0x00140000 0x00520000
BOOTER_SLOT_OFFSET   = $(word $($(BOOTER_SLOT_INDEX)),$(BOOTER_SLOT_OFFSETS))

################################################################################
# Please note to update the flash contents
# after having changed the value of the following *FIRMWARE* variables
#
#  VIDEO_FIRMWARE_USE_EMBEDDED decides whether the video firmware is stored
#                              embedded or in either RBL or booter slot
#  AUDIO_FIRMWARE_USE_EMBEDDED decides whether the audio firmware is stored
#                              embedded or in either RBL or booter slot
#  AUDIO_FIRMWARE_USE_FLASHMEM decides whether the audio firmware is stored
#                              in flash or will be loaded via 'executer'
################################################################################

  VIDEO_FIRMWARE_USE_EMBEDDED = 1
  AUDIO_FIRMWARE_USE_EMBEDDED = 1
  AUDIO_FIRMWARE_USE_FLASHMEM = 0

-include ./Makefile.${USERNAME}

################################################################################
# The macro FLASH_INCLUDE_APPLICATION is required only during "make flash"
# it decides whether to burn the application as well or the firmware files
# only.
################################################################################

  FLASH_INCLUDE_APPLICATION = 1

################################################################################
# Please note to recompile/relink the entire application
# after having changed the value of OSD_USE_FREETYPE or OSD_DRAW_ROUND_CORNERS
#   make clean build
# Also, make sure the you have the freetype library in your install tree
################################################################################

  OSD_USE_FREETYPE = 0
  OSD_DRAW_ROUND_CORNERS = 0

################################################################################
# Please note to recompile/relink the entire application
# after having changed the value of RTOS_USE_FAMOS
#   make clean build
################################################################################

  RTOS_USE_FAMOS = 1

################################################################################
# Please note to recompile/relink the entire application
# after having changed the value of VIDEO_USE_VAL
#   make clean build
#
#   VIDEO_USE_VAL     decides whether to use VAL or by default VCL video layer 
#
################################################################################

  VIDEO_USE_VAL = 1
  AUDIO_USE_AAL = 1
  
################################################################################
# project specific settings
################################################################################

  SOURCES += src/main.c
ifeq ($(AUDIO_USE_AAL),1)
  SOURCES += src/av/av_video.c
  SOURCES += src/av/av_audio.c
  SOURCES += src/av/av_app.c
  SOURCES += src/av/settings.c
  SOURCES += src/av/av_debug.c
else
  SOURCES += src/tsd.c
  SOURCES += src/audio.c
  SOURCES += src/sync.c
  SOURCES += src/hdmi_cec.c
endif
  SOURCES += src/fpga_ram.c
#  SOURCES += src/adv7171.c
#  SOURCES += src/pcm1742.c
  SOURCES += src/gs1531.c
  SOURCES += src/cs8406.c
  SOURCES += src/CCaption.c
  HEADERS =
  PROGRAM = c202_h60
ifeq ($(RTOS_USE_FAMOS),1)
  LIBRARIES += famos
else
  LIBRARIES += rtosstub
endif
  LIBRARIES += booter
ifeq ($(AUDIO_FIRMWARE_USE_EMBEDDED),1)
  LIBRARIES += firmwareaudio
else
  LIBRARIES += firmwareaudiostub
endif
ifeq ($(VIDEO_FIRMWARE_USE_EMBEDDED),1)
  LIBRARIES += firmwarevideo
else
  LIBRARIES += firmwarevideostub
endif
  LIBRARIES += fapisys
  LIBRARIES += fapidrv
  LIBRARIES += fapireg
ifeq ($(VIDEO_USE_VAL),1)
  LIBRARIES += val
else
  LIBRARIES += vcl
endif
ifeq ($(AUDIO_USE_AAL),1)
  LIBRARIES += aal
endif
  LIBRARIES += osdhandler
  LIBRARIES += fontserver
  LIBRARIES += fontserver_engine_fbf
  LIBRARIES += fbf
ifeq ($(OSD_USE_FREETYPE),1)
  LIBRARIES += fontserver_engine_ft
  LIBRARIES += ftf
  LIBRARIES += freetype2
endif
ifeq ($(OSD_DRAW_ROUND_CORNERS),1)
  LIBRARIES += draw
  LIBRARIES += z
  LIBRARIES += png
endif
  LIBRARIES += fatfs
  LIBRARIES += musb
  LIBRARIES += feall
  LIBRARIES += fapiboard
  LIBRARIES += h60boards

  CCFLAGS_USER += -DRTOS_USE_FAMOS=$(RTOS_USE_FAMOS)
  CCFLAGS_USER += -DOSD_USE_FREETYPE=$(OSD_USE_FREETYPE)
  CCFLAGS_USER += -DOSD_DRAW_ROUND_CORNERS=$(OSD_DRAW_ROUND_CORNERS)
ifeq ($(AUDIO_FIRMWARE_USE_EMBEDDED),1)
  CCFLAGS_USER += -DAUDIO_REBOOT_ENABLED=1
endif
ifeq ($(AUDIO_FIRMWARE_USE_FLASHMEM),1)
  CCFLAGS_USER += -DAUDIO_REBOOT_ENABLED=1
endif
  CCFLAGS_USER += -DVIDEO_USE_VAL=$(VIDEO_USE_VAL)

  LINTFLAGS_USER += -e923
  MISRA = 1

################################################################################
# define user targets
################################################################################

default: build

clean: clean-objects clean-program

build: build-objects build-program

headers:

install: build

all: clean build

flash: clean-flash-image build-flash-image burn-flash-image

flash-booterslot: build                    \
                  clean-booter-slot-image  \
                  build-booter-slot-image  \
                  burn-booter-slot-image   \

flash-booter: force
	@$(NEWLINE)
	@$(ECHO) $(ECHOPREFIX) Re-building/flashing [booter] application
	@$(SUBMAKE) -C $(TOPDIR)/applications/booter build flash

################################################################################
# include internal definitions and rules
################################################################################

  RELEASE_SUBDIR = $(SUBDIR)
  RELEASE_FILES += $(SOURCES)
  RELEASE_FILES += $(wildcard src/*.h)
  RELEASE_FILES += Makefile

  LINTFLAGS_USER += -e923
  MISRA = 1

release: release-files

doc:

include $(TOPDIR)/env/make/Makefile.rules

################################################################################
# override the internal FLIMGEN defaults
#
# The following statements force the flash image generator 'flimgen' to
# generate a flash image which contains the 6 video firmware files only.
# The video firmware file references will be taken from the makefile in
# the directory "<fapi_topdir>/applications/system/" in order to share
# the firmware file versioning.
# The final flash image which will be generated here will neither contain
# any register/value setting (to configure the memory interface), nor
# the audio firmware, nor the 'av_demo' application itself.
#
# To run the 'av_demo' you should perform the following steps:
#
# 'make flash'      to burn the video firmware file into flash memory
#                   (this is MANDATORY!)
# 'make run'        to upload and execute the audio firmware and the
#                   'av_demo' application
# 'make debug'      to upload and execute the audio firmware and to upload
#                   and debug the 'av_demo' application
################################################################################

  FLIMGEN_RVS_FILE  := -reg=$(RVSFILE)
  FLIMGEN_ELF_FILES :=
  FLIMGEN_BIN_FILES :=

ifeq ($(FLASH_INCLUDE_APPLICATION),1)
  FLIMGEN_ELF_FILES := -elf=$(TOPDIR)/$(SUBDIR)/$(BUILD_PROGRAM)
endif

ifneq ($(AUDIO_FIRMWARE_USE_EMBEDDED),1)
  ifeq ($(AUDIO_FIRMWARE_USE_FLASHMEM),1)
    FLIMGEN_BIN_FILES += $(shell $(SUBMAKE) -C ../system plain-macro MACRO=FIRMWARE_AUDIO_FILES)
  endif
endif

ifneq ($(VIDEO_FIRMWARE_USE_EMBEDDED),1)
  FLIMGEN_BIN_FILES += $(shell $(SUBMAKE) -C ../system plain-macro MACRO=FIRMWARE_VIDEO_FILES)
endif

ifneq ($(AUDIO_FIRMWARE_USE_EMBEDDED),1)
  ifneq ($(AUDIO_FIRMWARE_USE_FLASHMEM),1)
    EXECUTE_ADD_FILES += $(shell $(SUBMAKE) -C ../system plain-macro MACRO=FIRMWARE_AUDIO_FILES)
  endif
endif

################################################################################
# override the internal BIMGEN defaults
#
# The following statements force the booter image generator 'bimgen' to
# generate a flash slot image which contains
# - the register/value setup
# - the application image
# - audio firmware image
# - video firmware images
################################################################################

  BIMGEN_IMAGE_FILE     := $(BOOTER_SLOT_IMAGE)
  BIMGEN_IMAGE_NAME     := $(BOOTER_SLOT_NAME)
  BIMGEN_IMAGE_FILES    := $(FLIMGEN_BIN_FILES) $(FLIMGEN_ELF_FILES)
  BIMGEN_IMAGE_COMPRESS := $(BOOTER_SLOT_COMPRESS)
  BIMGEN_IMAGE_VERSION  := $(BOOTER_SLOT_VERSION)
