# /************************************************************ 
# Copyright (C) 1995-2006 Pumpkin, Inc. and its
# Licensor(s). Freely distributable.
# 
# $Source: C:\\RCS\\D\\Pumpkin\\Salvo\\Examples\\ARM\\Luminary_LM3S1XX\\Luminary_DK-LM3S1XX\\GCCARM\\Tut\\Tut5\\tut5.c,v $
# $Author: aek $
# $Revision: 3.2 $
# $Date: 2006-05-16 22:31:36-07 $
# 
# Makefile for tutorial program Tut5. 
# 
# ************************************************************/

#
# Define locations where the DriverLib headers and library can be found
# Change this as needed on your system.
#
DRIVERLIB_ROOT=C:/src/DriverLib
DRIVERLIB_HWINC=${DRIVERLIB_ROOT}
DRIVERLIB_INC=${DRIVERLIB_ROOT}/src
DRIVERLIB_LIB=${DRIVERLIB_ROOT}/src/gcc/libdriver.a

# Salvo library
SALVOLIB=../../../../../../../../Lib/GCCARM/libsalvofgccarmcm3t.a

# paths to source files
VPATH=${RTOS_SOURCE_DIR}:${RTOS_SOURCE_DIR}/GCCARM:${COMPILER_SOURCE_DIR}:${DEMO_SOURCE_DIR}:${PLATFORM_SRC_DIR}

# user & Salvo object modules
OBJ= startup.o \
     tut5.o \
     timer.o \
     osram96x16.o \
     salvohook_interrupt_cm3.o \
	 salvomem.o     

#
# Compiler prefix
#
PREF=arm-stellaris-eabi

#
# The command for calling the compiler.
#
CC=${PREF}-gcc

#
# The flags passed to the assembler.
#
AFLAGS=-mthumb        \
       -mcpu=cortex-m3 \
       -MD

#
# The flags passed to the compiler.
#
CFLAGS=-mthumb        \
       -mcpu=cortex-m3 \
       -mno-thumb-interwork \
       -MD \
       -Dgcc

#
# normally turn off compiler optimize if DEBUG is defined, however
# if OPTIMIZE is explicity defined, then turn on opt even if DEBUG
# is defined
#
ifdef DEBUG
ifdef OPTIMIZE
CFLAGS += -O2
else
CFLAGS += -O0
endif
else
CFLAGS += -O2
endif

#
# The command for calling the library archiver.
#
AR=${PREF}-ar

#
# The command for calling the linker.
#
LD=${PREF}-ld

#
# The flags passed to the linker.
#
LDFLAGS=

#
# Get the location of libgcc.a from the GCC front-end.
#
LIBGCC=${shell ${CC} -mthumb -march=armv6t2 -print-libgcc-file-name}

#
# Get the location of libc.a from the GCC front-end.
#
LIBC=${shell ${CC} -mthumb -march=armv6t2 -print-file-name=libc.a}

#
# The command for extracting images from the linked executables.
#
OBJCOPY=${PREF}-objcopy

#******************************************************************************
#
# Tell the compiler to include debugging information if the DEBUG environment
# variable is set.
#
#******************************************************************************
ifdef DEBUG
CFLAGS += -g
endif

RTOS_SOURCE_DIR=../../../../../../../../Src
RTOS_INC_DIR=../../../../../../../../Inc
PLATFORM_SRC_DIR=../../../..
PLATFORM_INC_DIR=../../../..
COMPILER_SOURCE_DIR=../../..
DEMO_SOURCE_DIR=../

SCATTER_tut5=${COMPILER_SOURCE_DIR}/standalone.ld
ENTRY_tut5=ResetISR

CFLAGS+=-I . -I ${RTOS_INC_DIR} -I ${RTOS_INC_DIR}/GCCARM -I ${PLATFORM_INC_DIR} -I ${DRIVERLIB_HWINC} -I ${DRIVERLIB_INC}

tut5.axf: ${OBJ}

clean:
	@rm -f ${wildcard *.o} ${wildcard *.d} ${wildcard *~}    \
	 tut5.axf tut5.bin tut5.map

#******************************************************************************
#
# The rule for building the object file from each C source file.
#
#******************************************************************************
%.o: %.c
	@if [ 'x${VERBOSE}' = x ];                               \
	 then                                                    \
	     echo "  CC    ${<}";                                \
	 else                                                    \
	     echo ${CC} ${CFLAGS} -o ${@} -c ${<}; \
	 fi
	@${CC} ${CFLAGS} -o ${@} -c ${<}

#******************************************************************************
#
# The rule for building the object file from each assembly source file.
#
#******************************************************************************
%.o: %.S
	@if [ 'x${VERBOSE}' = x ];                               \
	 then                                                    \
	     echo "  CC    ${<}";                                \
	 else                                                    \
	     echo ${CC} ${AFLAGS} -o ${@} -c ${<}; \
	 fi
	@${CC} ${AFLAGS} -o ${@} -c ${<}

#******************************************************************************
#
# The rule for creating an object library.
#
#******************************************************************************
%.a:
	@if [ 'x${VERBOSE}' = x ];     \
	 then                          \
	     echo "  AR    ${@}";      \
	 else                          \
	     echo ${AR} -cr ${@} ${^}; \
	 fi
	@${AR} -cr ${@} ${^}

#******************************************************************************
#
# The rule for linking the application.
#
#******************************************************************************
%.axf:
	@if [ 'x${VERBOSE}' = x ]; \
	 then                      \
	     echo "  LD    ${@}";  \
	 fi
	@if [ 'x${VERBOSE}' != x ];                           \
	 then                                                 \
	     echo ${LD} -T ${SCATTER_${notdir ${@:.axf=}}}    \
	                --entry ${ENTRY_${notdir ${@:.axf=}}} \
	                ${LDFLAGSgcc_${notdir ${@:.axf=}}}    \
	                ${LDFLAGS} -Map ${notdir ${@:.axf=.map}} -o ${@} ${^} \
	                ${DRIVERLIB_LIB} ${SALVOLIB} '${LIBC}' '${LIBGCC}';                \
	 fi
	@${LD} -T ${SCATTER_${notdir ${@:.axf=}}}    \
	       --entry ${ENTRY_${notdir ${@:.axf=}}} \
	       ${LDFLAGSgcc_${notdir ${@:.axf=}}}    \
	       ${LDFLAGS} -Map ${notdir ${@:.axf=.map}} -o ${@} ${^} \
	       ${DRIVERLIB_LIB} ${SALVOLIB} '${LIBC}' '${LIBGCC}'
	@${OBJCOPY} -O binary ${@} ${@:.axf=.bin}
