#   ----------------------------------------------------------------------------
#   dsp_makefile
#
#   Makefile for dsplib_server.out (Debug and Release versions)
#
#   v1.00
#   ----------------------------------------------------------------------------
#   Copyright (c) Texas Instruments Incorporated 2002-2009
#
#   Use of this software is controlled by the terms and conditions found in the
#   license agreement under which this software has been supplied or provided.
#   ----------------------------------------------------------------------------
#SHELL = /bin/sh

#   ----------------------------------------------------------------------------
#   Base for TI toolchain
#   This may change depending if you are using other versions of the compiler
#   ----------------------------------------------------------------------------
BASE_TOOLCHAIN := C:/CCStudio_v3.3
BASE_COMPILER := $(BASE_TOOLCHAIN)/cg_618
BASE_SABIOS := $(BASE_TOOLCHAIN)/bios_5_33_03

#   ----------------------------------------------------------------------------
#   Name of the TI compiler and DSP/BIOS builder (Tconf)
#   This usually does not change
#   ----------------------------------------------------------------------------
CC := cl6x
TCONF := tconf

#   ----------------------------------------------------------------------------
#   Base for DSPLink
#   This may have to be changed depending on your installation paths 
#   and DSPLink version
#   ----------------------------------------------------------------------------
DSPLINK := C:/OMAPL137_dsp_1_00_00_07/dsplink-1_61-prebuilt/packages/dsplink

#   ----------------------------------------------------------------------------
#   Base for DSPLIB
#   This may have to be changed depending on your installation paths 
#   and DSPLIB version
#   ----------------------------------------------------------------------------
DSPLIB := C:/CCStudio_v3.3/c674x/dsplib_v11

#   ============================================================================
#   No changes should be necessary below this line!
#   ============================================================================

#   ----------------------------------------------------------------------------
#   Project name. 
#   This variable can be used to set all source/BIOS/object filenames
#   For clarity, in this example it sets only the .OUT .CMD and .MAP filenames
#   ----------------------------------------------------------------------------
PROJNAME := dsplib_server

#   ----------------------------------------------------------------------------
#   Global variables for building helloDSP
#   Note that common debug, compiler and linker flags are already
#   set in the lower part of this Makefile
#   CSRCS are for C-source files, ASRCS for asm and BIOSTCF is the BIOS TCF file
#   ----------------------------------------------------------------------------
DEBUG :=
CFLAGS := -i$(DSPLIB)
LDFLAGS := -i$(DSPLIB)
CSRCS := dsp_main.c dsp_interface.c
ASRCS :=
BIOSTCF := dsplib_server.tcf
OBJS :=
LIBS := -ldsplink.lib -ldsplinkpool.lib -ldsplinkmpcs.lib -ldsplinkmplist.lib -ldsplinkmsg.lib -ldsplinknotify.lib -ldsplinkringio.lib -ldsplib674x.lib
CMDS := $(PROJNAME).cmd
MAPFILE := $(PROJNAME).map
BIN := $(PROJNAME).out

#   ----------------------------------------------------------------------------
#   DSP/BIOS generated files
#   ----------------------------------------------------------------------------
BIOSSRC := $(BIOSTCF:%.tcf=%cfg.s62) $(BIOSTCF:%.tcf=%cfg_c.c)
BIOSCMD := $(BIOSTCF:%.tcf=%cfg.cmd)

#   ----------------------------------------------------------------------------
#   Adding DSP/BIOS generated files to the sources and the linker variables
#   ----------------------------------------------------------------------------
CSRCS += $(BIOSTCF:%.tcf=%cfg_c.c)
ASRCS += $(BIOSTCF:%.tcf=%cfg.s62)
CMDS += $(BIOSCMD)

#   ----------------------------------------------------------------------------
#   DSP/BIOS common flags
#   ----------------------------------------------------------------------------
BFLAGS := -Dconfig.importPath="$(BASE_SABIOS)/packages; \
          $(BASE_SABIOS)/packages/ti/bios;              \
          $(DSPLINK)/dsp/inc/DspBios;                   \
          $(DSPLINK)/dsp/inc/DspBios/5.XX/OMAPL1XXGEM;  \
          $(DSPLINK)/dsp/inc/DspBios/5.XX;./"
# BIOS 6 ONLY
# -I$(DSPLINK)/dsp/inc/DspBios/6.XX/DA8XXGEM 

#   ----------------------------------------------------------------------------
#   All common compiler and linker flags
#   ----------------------------------------------------------------------------
ALL_CFLAGS := -q -pdr -pdv -pden -ml3 -mv6400+ --disable:sploop $(CFLAGS)
ALL_LDFLAGS := -z -c -q -x $(LDFLAGS)

#   ----------------------------------------------------------------------------
#   Compiler and Linker options for Debug
#   ----------------------------------------------------------------------------
CFLAGS_D := -g -d"_DEBUG" --no_compress $(DEBUG) $(ALL_CFLAGS)
OBJDIR_D := Debug
BINDIR_D := $(OBJDIR_D)
OBJS_D := $(CSRCS:%.c=$(OBJDIR_D)/%.obj) $(ASRCS:%.s62=$(OBJDIR_D)/%.obj)
LIBS_D := $(LIBS)
MAPFILE_D := $(OBJDIR_D)/$(MAPFILE)

#   ----------------------------------------------------------------------------
#   Compiler and Linker options for Release
#   ----------------------------------------------------------------------------
CFLAGS_R := -o3 $(ALL_CFLAGS)
OBJDIR_R := Release
BINDIR_R := $(OBJDIR_R)
OBJS_R := $(CSRCS:%.c=$(OBJDIR_R)/%.obj) $(ASRCS:%.s62=$(OBJDIR_R)/%.obj)
LIBS_R := $(LIBS)
MAPFILE_R := $(OBJDIR_R)/$(MAPFILE)

#   ----------------------------------------------------------------------------
#   Compiler common include directories 
#   ----------------------------------------------------------------------------
CINCLUDES := -I$(DSPLINK)/dsp/inc                             \
             -I$(DSPLINK)/dsp/inc/DspBios                     \
             -I$(DSPLINK)/dsp/inc/DspBios/5.XX                \
             -I$(DSPLINK)/dsp/inc/DspBios/5.XX/OMAPL1XXGEM    \
             -I$(DSPLINK)/dsp/inc/C64XX                       \
             -I$(BASE_SABIOS)/packages/ti/bios/include        \
             -I$(BASE_COMPILER)/include                       \
             -I$(BASE_SABIOS)/packages/ti/rtdx/include/c6000  \
             -I$(BASE_SABIOS)/packages/ti/psl/include         \
             -I$(DSPLINK)/dsp/export/INCLUDE/DspBios/OMAPL1XX \
             -I./

#   ----------------------------------------------------------------------------
#   Compiler common symbol definitions 
#   ----------------------------------------------------------------------------
DEFS :=        -dMAX_DSPS=1          \
               -dMAX_PROCESSORS=2    \
               -dID_GPP=1            \
               -dOMAPL1XX            \
               -dPROC_COMPONENT      \
               -dPOOL_COMPONENT      \
               -dNOTIFY_COMPONENT    \
               -dMPCS_COMPONENT      \
               -dRINGIO_COMPONENT    \
               -dMPLIST_COMPONENT    \
               -dMSGQ_COMPONENT      \
               -dMSGQ_ZCPY_LINK      \
               -dCHNL_COMPONENT      \
               -dCHNL_ZCPY_LINK      \
               -dZCPY_LINK           \
               -dPROCID=0            \
               -dDA8XXGEM            \
               -DOS_LINUX            \
               -dDA8XXGEM_INTERFACE=SHMEM_INTERFACE \
               -dPHYINTERFACE=SHMEM_INTERFACE

#   ----------------------------------------------------------------------------
#   Linker common library search path
#   ----------------------------------------------------------------------------
LDINCLUDES := -i$(BASE_COMPILER)/lib                      \
              -i$(BASE_SABIOS)/packages/ti/bios/lib       \
              -i$(BASE_SABIOS)/packages/ti/rtdx/lib/c6000 \
              -i$(BASE_SABIOS)/packages/ti/psl/lib

#   ----------------------------------------------------------------------------
#   Linker library search path for Debug
#   ----------------------------------------------------------------------------
LDINCLUDES_D := $(LDINCLUDES) -i$(DSPLINK)/dsp/export/BIN/DspBios/OMAPL1XX/OMAPL1XXGEM_0/DEBUG/

#   ----------------------------------------------------------------------------
#   Linker library search path for Release
#   ----------------------------------------------------------------------------
LDINCLUDES_R := $(LDINCLUDES) -i$(DSPLINK)/dsp/export/BIN/DspBios/OMAPL1XX/OMAPL1XXGEM_0/RELEASE/

#   ----------------------------------------------------------------------------
#   Compiler and Linker procedure
#   From this point and on changes are highly unlikely.
#   - Be careful if changing the order of the linker object and library files
#   - The DSP/BIOS TCONF build needs to come before everything else
#   - The clean rule also removes all DSP/BIOS generated files
#   ----------------------------------------------------------------------------
.PHONY: all
all: $(BIOSSRC) Debug Release

$(BIOSSRC): $(BIOSTCF)
	@echo Building DSP/BIOS file...
	@$(BASE_SABIOS)/xdctools/$(TCONF) $(BFLAGS) $< 0

#   ----------------------------------------------------------------------------
#   Building Debug... 
#   ----------------------------------------------------------------------------
.PHONY: Debug
Debug: $(BINDIR_D)/$(BIN)

$(BINDIR_D)/$(BIN) : $(OBJS_D)
	@echo Compiling Debug...
	@$(BASE_COMPILER)/bin/$(CC) $(ALL_LDFLAGS) $(LDINCLUDES_D) -o$@ $? $(LIBS_D) -m$(MAPFILE_D) $(CMDS)

$(OBJDIR_D)/%.obj : %.c
	@$(BASE_COMPILER)/bin/$(CC) $(ALL_DEBUG) $(DEFS) $(CFLAGS_D) $(CINCLUDES) -fr$(OBJDIR_D) $<

$(OBJDIR_D)/%.obj : %.s62
	@$(BASE_COMPILER)/bin/$(CC) $(ALL_DEBUG) $(DEFS) $(CFLAGS_D) $(CINCLUDES) -fr$(OBJDIR_D) $<

#   ----------------------------------------------------------------------------
#   Building Release... 
#   ----------------------------------------------------------------------------
.PHONY: Release
Release: $(BINDIR_R)/$(BIN)

$(BINDIR_R)/$(BIN) : $(OBJS_R)
	@echo Compiling Release...
	@$(BASE_COMPILER)/bin/$(CC) $(ALL_LDFLAGS) $(LDINCLUDES_R) -o$@ $? $(LIBS_R) -m$(MAPFILE_R) $(CMDS)

$(OBJDIR_R)/%.obj : %.c
	@$(BASE_COMPILER)/bin/$(CC) $(DEFS) $(CFLAGS_R) $(CINCLUDES) -fr$(OBJDIR_R) $<

$(OBJDIR_R)/%.obj : %.s62
	@$(BASE_COMPILER)/bin/$(CC) $(DEFS) $(CFLAGS_R) $(CINCLUDES) -fr$(OBJDIR_R) $<

.PHONY: clean
clean:
	@rm -f *.cdb
	@rm -f *cfg.*
	@rm -f *cfg_c.*
	@rm -f ./$(OBJDIR_D)/*
	@rm -f ./$(OBJDIR_R)/*



