#
# $Id: makefile,v 1.1 2002/04/01 12:48:28 cjh Exp $
#
# Makefile for "timer" test program
#
# (c) Copyright 2000 Clifford Heath.
# Any use allowed provided copyright notices are retained.
#

AS	=	m6811-elf-as
LD	=	m6811-elf-ld
CC	=	m6811-elf-gcc
CFLAGS	=	-Os -fomit-frame-pointer -msoft-reg-count=0 -I.

all:	sciintr.s19 sciintr.syms
clean:
	rm -f *.o *.s19 *.bin *.boo *.lst *.elf *.map *.syms

LIBDIR	=	/usr/local/m6811/lib/
CRT0	=	$(LIBDIR)/gcc-lib/m6811-elf/3.0.4/crt1.o
LIBPATH	=	-L$(LIBDIR)/m6811-elf/3.0.4 \
		-L$(LIBDIR)/gcc-lib \
		-L$(LIBDIR)/gcc-lib/m6811-elf/3.0.4 \
		-L$(LIBDIR)/gcc-lib/m6811-elf/lib \
		-L$(LIBDIR)/lib/gcc-lib/m6811-elf/lib \
		-L$(LIBDIR)/
LD_SREC	=	--oformat srec

# Uncomment this to remove the normal C startup and just start at the first func
CRT0	=	--defsym _start=0 

#
# Make rules for assembling and linking boot blocks:
#
.SUFFIXES:	.syms
%.s: %.c
	$(CC) $(CFLAGS) -S $<

%.syms:	%.elf
	nm $< | \
		sed -n -e '/ [T?] /s/\(.*\) [T?] \(.*\)/define \2=0x\1/p' \
			-e '/ [dDbB] /s/\(.*\) . \(.*\)/define \2@0x\1/p' \
		| grep -v __ > $*.syms

# This assembly rule produces a listing file:
ASFLAGS	=	--gstabs -al
%.o: %.s
	$(AS) $(ASFLAGS) -o $@ $< > $*.lst

# These linker rules use "memory.x", which assumes you're building a 256 byte
# boot block... Beware!
%.s19: %.o memory.x
	$(LD) -m m68hc11elfb -M $(LD_SREC) -o $@ \
		$(CRT0) $(LIBPATH) $< -lgcc -lgcc > $*.map

%.bin: %.o memory.x
	$(LD) -m m68hc11elfb --oformat binary --defsym _start=0 -o $@ $<

%.elf: %.o memory.x
	$(LD) -m m68hc11elfb -M -o $@ \
		$(CRT0) $(LIBPATH) $< -lgcc -lgcc > $*.map
