#
#  ======== makefile =======
#  GNUmake-based makefile for linuxonly speech sample app.
#
#! Revision History
#! ================
#! 2005-Oct-06 cring:  Better documentation and default values.
#

# This file simulates the build for a generic Linux application that
# happens to use Codec Engine. This makefile has special sections to
# accomodate inclusion of the codec engine, while the rest is standard.
# Codec Engine-specific additions are marked with the [CE] tag.

# [CE] define EXAMPLES_ROOTDIR to point to root of <CE/examples> directory
EXAMPLES_ROOTDIR := $(CURDIR)/../../..

# [CE] include the file that defines paths to XDC packages and XDC tools
include $(EXAMPLES_ROOTDIR)/xdcpaths.mak

# [CE] add the examples directory itself to the list of paths to packages
XDC_PATH := $(EXAMPLES_ROOTDIR);$(XDC_PATH)

# [CE] include the makefile that rus XDC configuration step for our
# program configuration script.
#
# Input:
# XDC_CFGFILE: location of the program configuration script (if in different
#              directory, include the relative path to the file)
# Implicit input: XDC_ROOT and XDC_PATH defined by the xdcpaths.mak above
#
# Output:
# XDC_FLAGS:   additional compiler flags that must be added to existing 
#              CFLAGS or CPPFLAGS
# XDC_CFILE:   name of the XDC-generated C file; usually does not need to be
#              used explicitly, the existing .c->.o rules will take care of it
# XDC_OFILE:   name of object file produced by compiling XDC-generated C file;
#              must be linked with the user's application
# XDC_LFILE:   list of Codec Engine libraries that must be supplied to the
#              linker (usually as `cat $(XDC_LFILE)`)
# Implicit output: rule that generates .c file from the program configuration
#              script (XDC_CFGFILE); rule to generate dummy package one dir.
#              level below the script; rule that cleans generated files
XDC_CFGFILE = ./ceapp.cfg
include       $(EXAMPLES_ROOTDIR)/buildutils/xdccfg_linuxarm.mak

# [CE] Augment the standard $(CPPFLAGS) variable, adding the
# $(XDC_FLAGS) variable, defined by the file above, to it.
CPPFLAGS += $(XDC_FLAGS)


# "normal" makefile settings and rules follow, with some additions for CE
# This app consists of the main, codec-engine unrelated main.c file, and
# the codec-engine-using app.c file.

%.o : %.c
	$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<

# compiler (do we need -MD for dependencies?)
CC=/db/toolsrc/library/vendors2005/mvl/arm/mvl4.0/Linux/montavista/pro/devkit/arm/v5t_le/armv5tl-montavista-linuxeabi/bin/gcc \
    -g -Wall -Os

# link all the object files
# [CE] app.out, in addition to its standard stuff, includes a compiled
# XDC-generated $(XDC_CFILE) and link list file $(XDC_LFILE)
app.out: app.o ceapp.o $(XDC_OFILE)
	$(CC) -g -o $@ $^ `cat $(XDC_LFILE)` -lpthread

all: app.out
	
# clean rule; must be a :: rule because CE's xdccfg.mak defines clean::, too
clean::
	rm -rf app.out *.o testruns

# test rule: run automated test
test: app.out
	@$(CE_INSTALL_DIR)/packages/ti/platforms/evmDM6446/testrunner.sh \
	--toTargetFile ../../../servers/video_copy/video_copy.x64P \
	--toTargetFile in.dat \
	--fromTargetFile out.dat \
	--copyLocalFile in.dat --diffFiles in.dat out.dat \
	app.out

