# Hey Emacs, this is a -*- makefile -*-

# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make rebuild = Clean out built project files and make them again
#
# make program = rebuild the project and download it to target via avr32progam and JTAG-MKII

# Copyright (c) 2006, Atmel Corporation All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. The name of ATMEL may not be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
# SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# ********************************
#
# SETTINGS
#
# Alter the settings below to add or remove files from your project or other options
#
# ********************************

# C source files
SRC = spi.c spi_example.c

# Project name
TARGET = spi_example

# Optimization level, can be [0, 1, 2, 3, s].
OPT = 2

# Set your target processor
MCPU = ap7000

# Set your jtag mkII port. i.e USB, /dev/ttyS0
JTAG_PORT = USB

# ** ** ENVIRONMENT SETTINGS ** **
MAKE = make
CC = avr32-gcc
CFLAGS = -Wall -Werror -c -g -mcpu=$(MCPU) -O$(OPT)
LD = avr32-gcc
LDFLAGS =
OBJCOPY = avr32-objcopy
REMOVE = rm -rf
OBJ = $(SRC:.c=.o)

# ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
# USR RULES
# ** ** ** *** ** ** ** ** ** ** ** ** ** ** **

# default rule, build the project
all: gccversion build

#clean up
clean: clean_list

#rebuild project
rebuild: clean_list gccversion build

# ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
# MESSAGES DISPLAYED DURING PROCESS
# ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
MSG_BIN = Creating binary:
MSG_CLEANING = Cleaning project:
MSG_COMPILING = Compiling:
MSG_LINKING = Linking:
MSG_COPY = Copying:

# ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
# END USR RULES
# ** ** ** *** ** ** ** ** ** ** ** ** ** ** **

# ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
# COMPILATION RULES.
# ** ** ** *** ** ** ** ** ** ** ** ** ** ** **

# Link: create ELF output file from object files.
build:	$(OBJ)
	@echo $(MSG_LINKING)
	$(LD) $(OBJ) $(LDFLAGS) -o $(TARGET).elf
	@echo
	@echo $(MSG_COPY)
	$(OBJCOPY) -O binary $(TARGET).elf $(TARGET).bin
	@echo

# Compile: create object files from C source files.
%.o: %.c
	@echo $(MSG_COMPILING)
	$(CC) $(CFLAGS) -o $@ $<
	@echo

# Remove generated files
clean_list:
	@echo
	@echo $(MSG_CLEANING)
	$(REMOVE) $(TARGET).elf
	$(REMOVE) $(TARGET).bin
	$(REMOVE) $(OBJ)

#display gcc version
gccversion :
	@echo
	@$(CC) --version

# ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
# END
# ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
