#############################################################################
#
#	Makefile for building C++ Masters Project Program
#
#############################################################################

ifeq ($(DEBUG),y)
	CFLAGS += -O -g		# -O is need to expand inlines
else
	CFLAGS += -O2
endif

# change the TARGET variable to the file name you want to compile
TARGET	= testSensorServoMotor1

GUMSTIX_BUILDROOT   = $(PWD)/../../../gumstix-buildroot
BUILD_ARM           = $(wildcard $(GUMSTIX_BUILDROOT)/build_arm*)
CROSS_COMPILE       = $(patsubst %g++, %, $(wildcard $(BUILD_ARM)/staging_dir/bin/arm-linux-uclibc*-g++))

ifeq ($(strip $(CROSS_COMPILE)),)
$(error Unable to detect C++ Cross Compiler)
endif

TARGET_ARCH=-Os -march=armv5te -mtune=xscale -Wa,-mcpu=xscale
CC  = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++

#
# If you need additional serch paths for include files, then use the -I flag
# and add them to the CPPFLAGS variable
#

# CPPFLAGS += -I somedir

#
# If you need to add C language specific flags, then add them to the CFLAGS variable
#
# If you need to add C++ language specific flags, then add them to the CXXFLAGS variable
#

#
# If you need addional search paths for library files, then use the -L flag
# and add them to LDFLAGS.
#

# LDFLAGS += -L somedir

#
# If you need additional libraries, then use -lxxx to search for libxxx.a
#

# LDLIBS += -lxxx

#
# By default, LINK.o is set to 
#
#     $(CC) $(LDFLAGS) $(TARGET_ARCH)
#
# however, when linking C++ files, we want to use g++ rather than gcc in
# order to get the correct C++ libraries linked in.
#
										
LINK.o = $(CXX) $(LDFLAGS) $(TARGET_ARCH)

.PHONY: all

all:	depend $(TARGET)

#
# You can change the $(TARGET).c if that's not your main file and you can
# add additional .o files to the end of the line
#

C_SRCS		=
CPP_SRCS	= $(TARGET).cpp Cmps03.cpp Srf10.cpp I2cPWM.cpp Servo.cpp Motor.cpp RSnsr.cpp 

OBJS		= $(CPP_SRCS:.cpp=.o) $(C_SRCS:.c=.o)
		     
$(TARGET) : $(OBJS)

clean:
	rm -rf $(OBJS) core .depend $(TARGET)

depend .depend dep:
	rm -f .depend
ifneq ($(CPP_SRCS),)
	$(CXX) $(CXXFLAGS) $(CPPFLAGS) -M $(CPP_SRCS) >> .depend
endif
ifneq ($(C_SRCS),)
	$(CC) $(CFLAGS) $(CPPFLAGS) -M $(C_SRCS) >> .depend
endif

ifeq (.depend,$(wildcard .depend))
include .depend
endif
