# Simple Ada Example Makefile
#   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
#   Written by Stephane Carrez (stcarrez@nerim.fr)	
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version.
# 
# In addition to the permissions in the GNU General Public License, the
# Free Software Foundation gives you unlimited permission to link the
# compiled version of this file with other programs, and to distribute
# those programs without any restriction coming from the use of this
# file.  (The General Public License restrictions do apply in other
# respects; for example, they cover modification of the file, and
# distribution when not linked into another program.)
# 
# This file is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.  If not, write to
# the Free Software Foundation, 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#

DEVC_PREFIX=m6811-elf-
CC=$(DEVC_PREFIX)gcc
AS=$(DEVC_PREFIX)as
AR=$(DEVC_PREFIX)ar
SIZE=$(DEVC_PREFIX)size
OBJCOPY=$(DEVC_PREFIX)objcopy
GNATBIND=$(DEVC_PREFIX)gnatbind

TARGET_PROC=68hc11
AINCLUDES=-Ignat
ADAFLAGS=$(AINCLUDES)
ADAFLAGS+=-m$(TARGET_PROC)
ADAFLAGS+=-mrelax -ffunction-sections -fdata-sections -mshort -Os
ADAFLAGS+=-msoft-reg-count=0 -fomit-frame-pointer

LDSCRIPT=-Wl,-m,m$(TARGET_PROC)elfb
LDFLAGS+=-Wl,-relax -Wl,--gc-sections
LDFLAGS+=-Wl,-defsym,_io_ports=0x1000
LDFLAGS+=$(LDSCRIPT)

OBJCOPY_FLAGS=--only-section=.text \
              --only-section=.rodata \
	      --only-section=.vectors \
	      --only-section=.data

#
# .elf is for the simulator and gdb
# .s19 is for some downloader and the simulator
# .b   is a binary dump
#
.SUFFIXES: .ads .adb .elf .s19 .b

OBJS=hello.o bsp.o bsp-io.o bsp-param.o bsp-sio.o system.o

PROGS=hello.elf

all::	$(PROGS) hello.s19 hello.b

hello.elf:	$(OBJS)
	$(CC) $(ADAFLAGS) $(LDFLAGS) -o $@ $(OBJS)

# gnatbind is not used but here is how it can be called
b-hello.adb:  $(OBJS)
	$(GNATBIND) -o $@ hello $(AINCLUDES)

# Compile Ada definitions with -gnatg
system.o:	gnat/system.ads
	$(CC) -c -gnatg $(ADAFLAGS) gnat/system.ads

bsp.o:	bsp.ads
	$(CC) -c $(ADAFLAGS) bsp.ads

bsp-io.o:     bsp-io.ads
	$(CC) -c $(ADAFLAGS) $<

bsp-param.o:     bsp-param.ads
	$(CC) -c $(ADAFLAGS) $<

.adb.o:
	$(CC) -c $(ADAFLAGS) $<

#
# Rule to create an S19 file from an ELF file.
#
.elf.s19:
	$(OBJCOPY) --output-target=srec $(OBJCOPY_FLAGS) $< $*.s19

#
# Rule to create an binary dump from an ELF file.
#
.elf.b:
	$(OBJCOPY) --output-target=binary --gap-fill=255 \
		--only-section=.data $(OBJCOPY_FLAGS) $< $*.b

clean::
	$(RM) b-hello.adb b-hello.ads *.ali *.o *.elf

