###############################################################################
#
#       COPYRIGHT (c) 2003 MOTOROLA INC.
#       ALL RIGHTS RESERVED
#
# Filename:     Makefile
# Author:       Mark Jonas
# Revision:     1.0
#
# History:      2003-May-30: First release.
#
# Description:  The Makefile.
#
# Notes:        
#
###############################################################################

###############################################################################
#
# Source Files
#

SRCS	= vectors.S	\
	  init.S	\
	  main.c	\
	  stdlib.c	\
	  printk.c	\
	  core.S	\
	  freq.c	\
	  time.c	\
	  pscuart.c

OBJS	= $(patsubst %.c, %.o, \
	  $(patsubst %.s, %.o, \
	  $(patsubst %.S, %.o, $(SRCS))))

###############################################################################
#
# Tools
#

CC	= powerpc-eabi-gcc
LD	= powerpc-eabi-ld
OC	= powerpc-eabi-objcopy
MKDEP	= powerpc-eabi-gcc -MM
RM	= rm -rf

###############################################################################
#
# Compiler settings
#

# Generate code for 603e, big endian, ABI calling convention, EABI extensions
CFLAGS = -mcpu=603e -mbig -mcall-sysv -meabi \
	   -Wall -W -Wtraditional -Wundef -Wshadow -Wpointer-arith -Winline \
	   -gdwarf-2 \
	   -Iinclude

# Generate code for 603, big endian, allow symbolic register names,
# do not generate code for Solaris
ASFLAGS =  -m603 -mbig -mregnames -mno-solaris

###############################################################################
#
# Rules
#

%.mot: %.elf
	$(OC) -v -O srec $^ $@

%.bin: %.elf
	$(OC) -v -O binary $^ $@

###############################################################################
#
# Targets
#

all: mpc5200startup.elf mpc5200startup.mot mpc5200startup.bin

clean:
	$(RM) *.o *.elf *.mot *.bin *.map

depend: $(SRCS)
	@ echo '# Auto-generated dependency file, do not edit.' >$@
	@ echo >>$@
	$(CC) -MM $(CFLAGS) $(SRCS) >>$@

mpc5200startup.elf: $(OBJS)
	$(LD) -T linkerscript.lds -Map $(basename $@).map -o $@ $^

.PHONY: all clean

###############################################################################
#
# Dependencies
#

include depend
