#
#  ======== makefile =======
#  GNUmake-based makefile for linuxonly rotate demo app.
#
#  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.
#

# This flag selects whether the application would use the IMGDEC interface or
# API exposed by custom stubs and skeletons
USE_CUSTOM_SS := no

ifeq ($(USE_CUSTOM_SS), no)
VARIANT = imgdec
DEFINES = 
else
VARIANT = ss
DEFINES = -D_USE_CUSTOM_SS
endif

# Root directory of this code drop
EXAMPLES_ROOTDIR = ../../../../..

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

# add the examples directory itself to the list of paths to packages
XDC_PATH := $(EXAMPLES_ROOTDIR);../../$(EXAMPLES_ROOTDIR);$(XDC_PATH)

# 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 = ./$(VARIANT)/rotate_demo.cfg
include       $(EXAMPLES_ROOTDIR)/buildutils/xdccfg_linuxarm.mak

# Augment the standard $(CPPFLAGS) variable, adding the
# $(XDC_FLAGS) variable, defined by the file above, to it.
CPPFLAGS += -I../utils/include \
	-I$(LINUXKERNEL_INSTALL_DIR)/include \
        $(XDC_FLAGS)

# Libraries needed to support simplewidget and msp430
LIBFILES = ../utils/lib/simplewidget.a \
		../utils/lib/msp430lib.a
# Source files
SOURCES = $(wildcard *.c)
SOURCES += $(wildcard $(VARIANT)/*.c)		

# Object files
OBJFILES = $(SOURCES:%.c=%.o)

#  default make
all: rotate_demo rotate.x64P

#  export
install:
	install -d $(EXEC_DIR)
	install rotate_demo $(EXEC_DIR)
	install rotate.x64P $(EXEC_DIR)
	cp -r data $(EXEC_DIR)/.
	
# "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 : $(VARIANT)/%.c
	$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
	
%.o : %.c
	$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<

# compiler and options
CC=$(MVTOOL_PREFIX)gcc \
    -g -D__DEBUG $(DEFINES) -Wall -Os  -fno-strict-aliasing

# link all the object files
# rotate_demo, in addition to its standard stuff, includes a compiled
# XDC-generated $(XDC_CFILE) and link list file $(XDC_LFILE)
rotate_demo: $(OBJFILES) $(XDC_OFILE)
	$(CC) -g -o $@ $^ $(LIBFILES) `cat $(XDC_LFILE)` -lpthread -lm -lfreetype -ljpeg -lpng

$(EXAMPLES_ROOTDIR)/ti/sdo/apps/servers/rotate/rotate.x64P:
	cd $(EXAMPLES_ROOTDIR)/ti/sdo/apps/servers/rotate; make rotate.x64P

rotate.x64P: $(EXAMPLES_ROOTDIR)/ti/sdo/apps/servers/rotate/rotate.x64P
	cp $< .
	
# clean rule; must be a :: rule because CE's xdccfg.mak defines clean::, too
clean::
	rm -f rotate_demo
	rm -f rotate.x64P
	rm -f *.o
	rm -f $(VARIANT)/*.o

