#-------------------------------------------------------------------------------
#  $Id: Makefile,v 1.4 2009/05/21 00:13:32 epasheva Exp $
#
#  Name:           Makefile
#
#  Description:    Makefile for common sample code CommonMain.c
#
#  Usage:
#          make
#          make clean
#   
#          make CPU=arm9
#          make clean CPU=arm9
#
#          make SYMBOLS=ON
#            if you want to have symbolic information compiled into the
#            objects for use with GDB debugger
#
#          Generates ../../../build/lib/$(CPU)/libCommonMain.a 
#          - see Sample code Makefiles on how to link with this library.
#
# Copyright (c) 2008 by Sierra Wireless, Incorporated.  All Rights Reserved.
#-------------------------------------------------------------------------------
include ../../sample_rules.mak

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

LIBS = -L../../../build/lib/$(CPU) -lswigsmbasic -lswiapi -lswicore -lpthread -lrt
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.
#-------------------------------------------------------------------------------
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
  AR=$(HOME)/toolchain/arm/bin/arm-none-linux-gnueabi-ar
  RANLIB=$(HOME)/toolchain/arm/bin/arm-none-linux-gnueabi-ranlib
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
#-------------------------------------------------------------------------------
LIBDIR = ../../../build/lib/$(CPU)
TARGET = $(LIBDIR)/libCommonMain.a
SOURCE = CommonMain.c  
OBJECT = $(OBJSDIR)/CommonMain.o  
OBJSDIR = obj$(CPU)

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

