#
# 	Makefile for AAC Microtec OpenRISC Fault Tolerant based products products
#	using newlib bare metal toolchain
# 	Copyright (c) AAC Microtec AB 2012.
#	Copyright (c) Stefan Kristiansson 2011.
#
#	version 1.0. March 4th 2012, <fredrik.bruhn@aacmicrotec.com>
#
#	Usage. make clean; make BOARD=<product>
#
#	<product> = {
#
#	obc-lite-521
#	obc-lite-522
#	rtu-lite-511
#	rtu-lite-512
#	urtu-311
#	urtu-312
#
#	}
#
#	Additional support can be found at AAC WIKI, http://wiki.aacmicrotec.com
#
#	-----------------------------------------------------------
#	How-to add a new board with newlib
#
# 	or32-aac-elf-gcc -c newboard.S
#
#	copy newboard.o to directory
#	/opt/aac-ria/gcc-bare/or32-aac-elf/lib/boards/
#
#	compile with this makefile or directly with
#	or32-aac-elf-gcc -mboard=newboard main.c -o myprog
#	-----------------------------------------------------------
#

# Project Output filename
OUT = dhry
# Specify this project Sources Content
TARGET = dhry.c
INCLUDES =

# Define default board configuration if not specified.
BOARD ?=obc-lite-521

# Compiler Command definitions
# C
CC = or32-aac-elf-gcc
# C++
CPP = or32-aac-elf-g++
# 
OBJCOPY = or32-aac-elf-objcopy
OBJDUMP = or32-aac-elf-objdump

# Compiler flags
CFLAGS = -c -Wall -std=c99 -O2 -mhard-mul -mhard-div -mhard-float

# Linker flags
LDFLAGS = -mboard=$(BOARD) -e 256

SRC = $(TARGET)
INCLUDE_FLAGS = $(addprefix -I, $(INCLUDES))
CFLAGS += $(INCLUDE_FLAGS)


#
# General functions
#

# Define remove command for make clean
REMOVE = rm -rf

# Object defines
COBJ = $(SRC:.c=.o)

all: $(SRC) $(OUT) $(OUT).bin

$(OUT).bin: $(OUT)
	$(OBJCOPY) -O binary $< $@

$(OUT): $(COBJ)
	$(CC) $(LDFLAGS) $(COBJ) -o $@

$(COBJ) : %.o : %.c
	$(CC) $(CFLAGS) $< -o $@

clean: 
	$(REMOVE) $(COBJ) $(OUT) $(OUT).bin

