# Makefile
#
# ============================================================================
# Copyright (c) Texas Instruments Inc 2005
#
# 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.
# ============================================================================

ROOTDIR = ../..
TARGET = $(notdir $(CURDIR))

include $(ROOTDIR)/Rules.make

XDC_PATH = $(CODEC_INSTALL_DIR)/packages;$(CE_INSTALL_DIR)/packages;$(LINK_INSTALL_DIR)/packages;$(XDAIS_INSTALL_DIR)/packages;$(CMEM_INSTALL_DIR)/packages

XDC_CFGFILE = $(TARGET).cfg

# Generates XDC_FLAGS, XDC_CFILE, XDC_OFILE, XDC_LFILE and XDC_CFGPKGDIR from
# XDC_INSTALL_DIR, XDC_PATH and XDC_CFGFILE and sets up the XDC environment.
include $(CE_INSTALL_DIR)/examples/buildutils/xdccfg_linuxarm.mak

C_FLAGS += -Wall

CPP_FLAGS += -I$(DVEVM_INSTALL_DIR)/demos/utils/include \
		-I$(LINUXKERNEL_INSTALL_DIR)/include \
		$(XDC_FLAGS)

LD_FLAGS += -lfreetype -lpng -ljpeg -lpthread

COMPILE.c = $(MVTOOL_PREFIX)gcc $(C_FLAGS) $(CPP_FLAGS) -c
LINK.c = $(MVTOOL_PREFIX)gcc $(LD_FLAGS)

DBGTARGET = debug/$(TARGET)d
RELTARGET = release/$(TARGET)

DBGCFLAGS = -g -D__DEBUG
RELCFLAGS = -O2 -fno-strict-aliasing

SOURCES = $(wildcard *.c)
HEADERS = $(wildcard *.h)

DBGOBJFILES = $(SOURCES:%.c=debug/%.o)
RELOBJFILES = $(SOURCES:%.c=release/%.o)

RELLDFLAGS = $(DVEVM_INSTALL_DIR)/demos/utils/lib/simplewidget.a \
		$(DVEVM_INSTALL_DIR)/demos/utils/lib/msp430lib.a
DBGLDFLAGS = $(DVEVM_INSTALL_DIR)/demos/utils/lib/simplewidgetd.a \
		$(DVEVM_INSTALL_DIR)/demos/utils/lib/msp430libd.a

.PHONY: clean debug release install

all:	debug release

install:
	install -d $(EXEC_DIR)
	install $(RELTARGET) $(EXEC_DIR)
	install -m 444 $(TARGET).txt $(EXEC_DIR)

release:	$(RELTARGET)

debug:		$(DBGTARGET)

$(RELTARGET):	$(XDC_OFILE) $(RELOBJFILES)
	$(LINK.c) -o $@ $^ $(RELLDFLAGS) `cat $(XDC_LFILE)`

$(DBGTARGET):	$(XDC_OFILE) $(DBGOBJFILES)
	$(LINK.c) -o $@ $^ $(DBGLDFLAGS) `cat $(XDC_LFILE)`

$(RELOBJFILES):	release/%.o: %.c $(HEADERS)
	@mkdir -p release
	$(COMPILE.c) $(RELCFLAGS) -o $@ $<

$(DBGOBJFILES):	debug/%.o: %.c $(HEADERS)
	@mkdir -p debug
	$(COMPILE.c) $(DBGCFLAGS) -o $@ $<

$(XDC_OFILE):	$(XDC_CFGPKGDIR)/$(XDC_CFILE)

clean::
	-$(RM) -rf release debug *~ *.d

