#*******************************************************************
#* Makefile for MSII
#*
#* COPYRIGHT: Philip L Johnson 2004
#* This header must appear on all derivatives of this file.
#*
#*******************************************************************
# Extended for MS2/Extra by Ken Culver and James Murray  2006
# $Id: Makefile,v 1.4 2010-12-30 03:08:24 culverk Exp $

ifdef SYSTEMDRIVE
BINDIR = c:/usr/bin
else
BINDIR = /usr/bin
endif

CC = $(BINDIR)/m9s12x-elf-gcc
OBJCOPY = $(BINDIR)/m9s12x-elf-objcopy
OBJDUMP = $(BINDIR)/m9s12x-elf-objdump
NM      = $(BINDIR)/m9s12x-elf-nm

CFLAGS  = -g -Wall -Werror -O -fomit-frame-pointer -m68hcs12 -mshort -msoft-reg-count=5 -mauto-incdec -fsigned-char -DGCC_BUILD

LDFLAGS = -Wl,-defsym,vectors_addr=0xff80,-m,m68hc12elfb,-T,m68hc12elfb.x

CSRCS=ms2_extra_main.c premain.c sigs.c

ASRCS=msii_flash_gcc.s ms2_sermon.s \
      isr_sci.s ms2_extra_asm.s

OBJS=$(CSRCS:.c=.o)
AOBJS= $(ASRCS:.s=.o)

all:	bootstrap.dmp bootstrap.elf bootstrap.s19

#release: all
#	rm -rf release
#	mkdir release
#	cp megasquirt-ii.ini.ms2extra bootstrap.s19 copyini.bat ms2dl.exe dl release
#	# Make sure you updated sigs.c

$(AOBJS): %.o: %.s
	$(CC) $(CFLAGS) -c $<

$(OBJS): %.o: %.c hcs12def.h flash.h ms2_extra.h
	$(CC) $(CFLAGS) -c $<

bootstrap.elf:	$(OBJS)  $(AOBJS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o bootstrap.elf $(OBJS) $(AOBJS)

bootstrap.s19: bootstrap.elf
	$(OBJCOPY) --output-target=srec \
	--only-section=.text3 \
	--only-section=.rodata \
        --only-section=.vectors \
        --only-section=.eeprom \
        --only-section=.lookup \
        --only-section=.text \
	bootstrap.elf bootstrap.s19
	$(NM) bootstrap.elf | sort > bootstrap.map

bootstrap.dmp: bootstrap.elf
	 $(OBJDUMP) -Ssdp bootstrap.elf > bootstrap.dmp

.PHONY: clean
clean:
	$(RM) -f bootstrap.elf
	$(RM) -f bootstrap.s19
	$(RM) -f bootstrap.dmp
	$(RM) -f bootstrap.map
	$(RM) -f $(OBJS) $(AOBJS)
#	$(RM) -rf release
