# 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

# 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
# Uncomment one of the following lines to activate an example project
SRC = rtc_wakeup_example.c rtc.c gpio.c pm.c 
#SRC = clock_masking_example.c pm.c gpio.c 
#SRC = clock_scaling_example.c pm.c gpio.c

# Project name
TARGET = low_power_example

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

MARCH = uc

# Set your target processor
MPART = uc3a0512

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

# ** ** ENVIRONMENT SETTINGS ** **
MAKE = make
CC = avr32-gcc
INCLUDES = -I./BOARDS -I./UTILS -I./UTILS/PREPROCESSOR
CC_FLAGS = -Wall -DBOARD=EVK1100 $(INCLUDES)  -Werror -c -g -march=$(MARCH) -mpart=$(MPART) -O$(OPT) 
LD = avr32-gcc
LD_FLAGS = -march=$(ARCH) -mpart=$(MPART)
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

.PHONY: program
program: all

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

.PHONY: program
program: all
	@echo
	@echo $(MSG_PROGRAMMING)
	avr32program program -finternal@0x80000000,512Kb -e -v $(TARGET).elf

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

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

# Link: create ELF output file from object files.
build:	$(OBJ) 
	@echo $(MSG_LINKING)
	$(LD) $(OBJ) $(LD_FLAGS) -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) $(CC_FLAGS) -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
# ** ** ** *** ** ** ** ** ** ** ** ** ** ** **
