#-------------------------------------------------------------------------------
#
#  $Id: makefile,v 1.6 2009/05/21 00:12:20 epasheva Exp $
#
#  Name:
#    Makefile
#
#  Description:    Makefile for sample code SwiVoiceCDMA
#
#   Usage:
#          make
#          make clean
#   
#          make CPU=arm9
#          make clean CPU=arm9
#
#          make TECHNOLOGY=ALL
#            This is when both CDMA and UMTS libraries are 
#            required by the application
#
#          make SYMBOLS=ON
#            if you want to have symbolic information compiled into the
#            objects for use with GDB debugger
#
#          Generates swicdmai386 or swivoicearm9
#          The CPU is stripped from the binary filename when copied to 
#              build/bin/$(CPU)/
#
# Copyright (c) 2008 by Sierra Wireless, Incorporated.  All Rights Reserved.
#-------------------------------------------------------------------------------
include ../../sample_rules.mak

CXX = gcc
DBGFLAGS = -g
CCFLAGS = -Wall -I../../../build/include 

LDFLAGS = -static 

#-------------------------------------------------------------------------------
# if CPU is not specified, default to i386
# otherwise, accept only i386 or arm9
#
# For arm9 download ts7800-crosstool-linux-oldabi-0.28rc39.tar.bz2
# from ftp://ftp.embeddedarm.com/ts-arm-sbc/ts-7800-linux/cross-toolchains
# Then uncompress the toolchain and 'sudo' copy /opt folder to /usr/local 
# directory of your PC.
# Tested on Ubuntu 8.04 only.
# 
#-------------------------------------------------------------------------------
ifeq ($(strip $(CPU)),)
  CPU = i386
endif
ifeq ($(CPU),i386)
  CXX = gcc
endif
ifeq ($(CPU),arm9)
  CXX=$(HOME)/toolchain/arm/bin/arm-none-linux-gnueabi-gcc
endif

#-------------------------------------------------------------------------------
# Default to including only CDMA libraries. In the event that both 
# CDMA and UMTS libraries are compiled in, we include all libraries for 
# linker symbol resolution based on additional command line option.
#
LIBS = -L../../../build/lib/$(CPU) -lswicmbasic -lswicdmabasic \
       -lswicdmainternal -lswicdmanetwork -lswicdmaiota -lswicdmalbs \
       -lswicdmaruim -lswicdmasms -lswicdmavoice -lswicmdm -lswiapi \
       -lswicore -lswicmlbs -lpthread -lrt

ifeq ($(TECHNOLOGY),ALL)
  LIBS = -L../../../build/lib/$(CPU) \
	-lswicmbasic -lswigsmbasic -lswigsmnetwork -lswigsmsim -lswigsmsms \
	-lswicdmabasic -lswicdmainternal -lswicdmanetwork \
	-lswicdmaiota -lswicdmalbs -lswicdmaruim -lswicdmasms \
	-lswicdmavoice -lswicmdm -lswicmlbs \
        -lswiapi -lswicore -lpthread -lrt
endif
     
#-------------------------------------------------------------------------------
# if SYMBOLS is set ON build the targets with the DBGFLAGS switch added to 
# the CFLAGS to generate objects compatible with GDB use
#
#-------------------------------------------------------------------------------
ifeq ($(SYMBOLS),ON)
CCFLAGS:=$(CCFLAGS) $(DBGFLAGS)
endif

#-------------------------------------------------------------------------------
# Main target
#-------------------------------------------------------------------------------       
TARGET = swivoice
SOURCE = $(TARGET).c
OBJECT = $(TARGET).o
OBJSDIR = obj$(CPU)

$(TARGET)$(CPU): $(OBJECT)
	${CXX} $(OBJSDIR)/$(OBJECT) $(LDFLAGS) $(LIBS) -g -o $(TARGET)$(CPU)  
	cp $(TARGET)$(CPU) ../../../build/bin/$(CPU)/SwiVoiceCDMA

$(OBJECT): $(SOURCE)
	${CXX} ${CCFLAGS} -c $(SOURCE)
	@if [ -d $(OBJSDIR) ] ; then echo "$(OBJDIR) exists..." ;\
	else mkdir -p $(OBJSDIR) ;\
	fi;
	mv *.o $(OBJSDIR)
#
#--------------------------------------------------------------------------------
# Clean binaries
#--------------------------------------------------------------------------------
.PHONY: clean
clean:
	@echo "Cleaning files..."    
	@-rm -f $(OBJSDIR)/$(OBJECT) $(TARGET)$(CPU) 
	@-rm -f $(OBJECT) ../../../build/bin/$(CPU)/SwiVoiceCDMA
