# 
#******************************************************************************
#
#  HDVICP2.0 Based H.264 HP Encoder
# 
# "HDVICP2.0 Based H.264 HP Encoder" is software module developed on TI's 
#  HDVICP2 based SOCs. This module is capable of compressing a 4:2:0 Raw 
#  video into a high/main/baseline profile bit-stream. Based on ISO/IEC      
#  14496-10." 
# Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 
# ALL RIGHTS RESERVED 
#******************************************************************************
# 

#  
#******************************************************************************
# @file makefile
#                                       
# @brief This file contains all make rules required for compiling/building
#        M3 lib file
#   
# @author: Kumar Desappan (kumar.desappan@ti.com)
#
# @version 0.0 (May 2010) : Base version created
# @version 0.1 (April 2011) : Fix for the Debug list accountation in building
#
#*****************************************************************************
# 

#-----------------------------------------------------------------------------#
# Install directires of all thecomponants required for building the           #
# M3 lib software. These can either from environment variables      #
# or the absolute paths                                                              #
#-----------------------------------------------------------------------------#
HDVICP_DIR = %HDVICP2_INSTALL_DIR%
CSP_DIR  = %CSP_INSTALL_DIR%
FC_DIR = %FC_INSTALL_DIR%
CG_TOOL = D:\ccsV4\ccsv4\tools\compiler\tms470_493
#CG_TOOL = D:\ccsV4\ccsv4\tools\compiler\CGT_4_5_1

#-----------------------------------------------------------------------------#
# Creating a common root to access all the files in the entire code basse     #
#-----------------------------------------------------------------------------#
ROOT_DIR = .


#-----------------------------------------------------------------------------#
# List of C source files needs to be compiled                                 #
#-----------------------------------------------------------------------------#
C_SRCS += \
$(ROOT_DIR)\library.c

#-----------------------------------------------------------------------------#
# List of C source files needs to be compiled with special compile options    #
# Depending on the requirement more number of groups also can be created      #
#-----------------------------------------------------------------------------#
DEBUG_C_SRCS += \


#-----------------------------------------------------------------------------#
# Final target lib file                                                       #
#-----------------------------------------------------------------------------#
LIB_FILE += \
.\libsamplelib.a

#-----------------------------------------------------------------------------#
# Object file directory                                                       #
#-----------------------------------------------------------------------------#
OBJ_DIR += $(ROOT_DIR)

#-----------------------------------------------------------------------------#
# Deriving OBJ and PPA(dependecies list file) files list for C source list    #
#-----------------------------------------------------------------------------#
C_OBJS      = $(C_SRCS:.c=.obj)
C_PPS       = $(C_SRCS:.c=.PP)
#-----------------------------------------------------------------------------#
# Extracting the file name alone (removing the directry name from the list)   #
#-----------------------------------------------------------------------------#
C_OBJS_FILE_TEMP = $(notdir $(C_OBJS))
C_PPS_FILE  = $(notdir $(C_PPS))
C_OBJS_FILE = $(addprefix $(OBJ_DIR)\,$(C_OBJS_FILE_TEMP))

#-----------------------------------------------------------------------------#
# Deriving OBJ and PPA(dependecies list file) files list for C source list    #
#-----------------------------------------------------------------------------#
DEBUG_C_OBJS      = $(DEBUG_C_SRCS:.c=.obj)
DEBUG_C_PPS       = $(DEBUG_C_SRCS:.c=.PP)
#-----------------------------------------------------------------------------#
# Extracting the file name alone (removing the directry name from the list)   #
#-----------------------------------------------------------------------------#
DEBUG_C_OBJS_FILE_TEMP = $(notdir $(DEBUG_C_OBJS))
DEBUG_C_PPS_FILE  = $(notdir $(DEBUG_C_PPS))
DEBUG_C_OBJS_FILE = $(addprefix $(OBJ_DIR)\,$(DEBUG_C_OBJS_FILE_TEMP))

#-----------------------------------------------------------------------------#
# Definin RM as force delete. This is used while target clean                 #
#-----------------------------------------------------------------------------#
RM := del /f

#-----------------------------------------------------------------------------#
# Compiler executable                                                         #
#-----------------------------------------------------------------------------#
CC     = $(CG_TOOL)\bin\cl470
#-----------------------------------------------------------------------------#
# Executable for generating lib                                               #
#-----------------------------------------------------------------------------#
AR     = "$(CG_TOOL)\bin\ar470"

#-----------------------------------------------------------------------------#
# List of folder needs to be searched for a included header file              #
#-----------------------------------------------------------------------------#
INCDIR = --include_path="$(CG_TOOL)\include" \
         --include_path="$(HDVICP_DIR)\inc" \
		 --include_path="$(CSP_DIR)\csl_soc" \
		 --include_path="$(CSP_DIR)\csl_ivahd" \
         --include_path="$(FC_DIR)\fctools\packages" \
		 --include_path="$(FC_DIR)\packages" \
		 --include_path="$(ROOT_DIR)\inc" \
		 --include_path="$(ROOT_DIR)\algsrc\inc" 

#-----------------------------------------------------------------------------#
# Common compile flags                                                        #
#-----------------------------------------------------------------------------#
CFLAGS = -@ $(ROOT_DIR)\diag.txt \
         -mv7M3 -O3 --define="ARM9" \
         --define="ICONT_SEPERATE" --define="HOST_M3" --diag_warning=225 \
		 -me --enum_type=packed --elf --gen_func_subsections --abi=eabi \
		 --signed_chars --auto_inline=200 --obj_directory="$(OBJ_DIR)"

#-----------------------------------------------------------------------------#
# Final target needs to be build                                              #
#-----------------------------------------------------------------------------#
all: $(LIB_FILE)

#-----------------------------------------------------------------------------#
# Rules to build the target. Here $(C_OBJS_FILE) $(DEBUG_C_OBJS_FILE)         #
# $(ASM_OBJS_FILE) are pre requisite files. Target wil be                     #
# remade only if there is any change (time stamp) in these file               #
#-----------------------------------------------------------------------------#
$(LIB_FILE) : $(C_OBJS_FILE) $(DEBUG_C_OBJS_FILE)
	echo Archiving .....
	$(AR) -r $(LIB_FILE) $(C_OBJS_FILE) $(DEBUG_C_OBJS_FILE)
	echo Archiving Completed----------------------------------------------
	
#-----------------------------------------------------------------------------#
# Each source file can have list of header files includes. If there is any    #
# change in any of the header files then the corresponding C files needs to   #
# be remade. To get this dependecy, the compile can invoked with "-ppd" otion #
# for this corresponding depency file. This dependency file needs to added to #
# the reules while making the "all" targets                                   #
#-----------------------------------------------------------------------------#
ifeq ($(MAKECMDGOALS),all)
ifneq ($(strip $(C_PPS_FILE)),)
-include $(C_PPS_FILE)
endif
ifneq ($(strip $(DEBUG_C_PPS_FILE)),)
-include $(DEBUG_C_PPS_FILE)
endif

#-----------------------------------------------------------------------------#
# Compiling the C source files to get the corresponding object files          #
#-----------------------------------------------------------------------------#
$(C_OBJS_FILE) : 
	echo Compiling  $(<)
	$(CC) $(<) --symdebug:skeletal $(CFLAGS) $(INCDIR)
	echo Finished
	
#-----------------------------------------------------------------------------#
# Compiling the C source files to get the corresponding object files          #
# with special compile otption                                                #
#-----------------------------------------------------------------------------#
$(DEBUG_C_OBJS_FILE) :
	echo Compiling  $(<)
	$(CC) $(<) $(CFLAGS) $(INCDIR) -g
	echo Finished

endif

#-----------------------------------------------------------------------------#
# Creating all the required dependency file for OBJ file. Also creating the   #
# dependency for target file on library sources                               #
#-----------------------------------------------------------------------------#
deps:
	echo Scaning dependencies...
	$(CC) $(C_SRCS) $(DEBUG_C_SRCS) -ppd $(CFLAGS) $(INCDIR) 
	echo echo OFF > temp_pps.bat
	FOR %%i IN ($(C_PPS)) DO echo move %%i >> temp_pps.bat
	FOR %%i IN ($(DEBUG_C_PPS)) DO echo move %%i >> temp_pps.bat
	echo echo ON >> temp_pps.bat
	temp_pps.bat
	-$(RM) temp_pps.bat

#-----------------------------------------------------------------------------#
# List of .PHONY (just rules not the actual files) available in this makefile #
#-----------------------------------------------------------------------------#
.PHONY: clean all deps
#-----------------------------------------------------------------------------#
# List rule for removing all the intermidaitre file created during            #
# build of the target                                                         #
#-----------------------------------------------------------------------------#
clean :
	-$(RM) $(C_PPS_FILE) $(DEBUG_C_PPS_FILE) $(C_OBJS_FILE) \
	$(DEBUG_C_OBJS_FILE) $(LIB_FILE)
#-----------------------------------------------------------------------------#
# End of the file                                                             #
#-----------------------------------------------------------------------------#

