#/******************************************************************************
#*
#* Freescale Semiconductor Inc.
#* (c) Copyright 2007 Freescale Semiconductor, Inc.
#* ALL RIGHTS RESERVED.
#*
#*******************************************************************************
#*
#* $File Name:  Makefile$
#*
#* $Date: 2007/12/21 00:13:41 $
#*
#* $Version:    1.0.18.0$
#*
#* Description: MPC5516 Sample Application Makefile
#*
#******************************************************************************/

# This makefile uses VLE variable defined externally:
#   VLE = -vle, -novle    (VLE code, non VLE code)
#   If VLE variable is not defined, than -vle is used.

# specify modules which will be compiled and linked

# Tools
CC	= ccppc
AS	= asppc
LD	= ccppc

# Paths
SYSPATH	=system
BIN	=bin
DRV	=drv
 
# generate debugging information (delete if debugging info not needed)
ifndef DEBUG
  DEBUG	=-G -dual_debug
endif

IFILES = -I$ . \
         -I$(SYSPATH) \
         -I$(DRV)/src \
         -I$(DRV)/inc \

OBJFILES = $(patsubst %.c,$(BIN)/%.o,$(wildcard *.c)) \
	$(patsubst $(DRV)/src/%.c,$(BIN)/%.o,$(wildcard $(DRV)/src/*.c))

# Startup code selection
ifeq ($(VLE),-novle)
  Vector_file = Vector
  Startup_file = Startup
else
  Vector_file = Vector_vle
  Startup_file = Startup_vle
endif

# compiler options
CFLAGS  = -dwarf2 -bsp generic -cpu=ppc5516 -DAUTOSAR_OS_NOT_USED -srec -object_dir=$(BIN) --no_commons -pnone $(DEBUG) $(IFILES) $(VLE) $< -o $@ -c -nostartfiles
CFLAGS1 = -dwarf2 -bsp generic -cpu=ppc5516 -DAUTOSAR_OS_NOT_USED -srec -object_dir=$(BIN) --no_commons -pnone $(DEBUG) $(IFILES) $(VLE) $(OBJFILES) -o $@ -nostartfiles
ifeq ($(VLE),-novle)
else
  CFLAGS  += -DVLE_MODE=1
  CFLAGS1  += -DVLE_MODE=1
endif
ASFLAGS = -cpu=ppc5516 -object_dir=$(BIN) $< -o $@
#--misra_2004=1.1

#-cpu=ppc5516 -object_dir=obj -srec -ansi  -dwarf2 -$(VLETYPE) -G -dual_debug -$(VLETYPE) \
#		 --no_commons -nokeeptempfiles -pnone --incorrect_pragma_warnings \
# 		 --slash_comment $(INTRAMTYPE) $< -o $@  


# rule to make all three targets
all: $(BIN)/intflash.elf #$(BIN)/intram.elf


# rule to link each target
$(BIN)/intflash.elf: $(OBJFILES) $(BIN)/$(Vector_file).o $(BIN)/$(Startup_file).o
	$(CC) $(SYSPATH)/intflash.ld $(CFLAGS1) $(BIN)/$(Vector_file).o $(BIN)/$(Startup_file).o

$(BIN)/intram.elf: $(OBJFILES) $(BIN)/$(Vector_file).o $(BIN)/$(Startup_file)_intram.o
	$(CC) $(SYSPATH)/intram.ld $(CFLAGS1) $(BIN)/$(Vector_file).o $(BIN)/$(Startup_file)_intram.o
	
.SUFFIXES:      # Delete the default suffixes
.SUFFIXES: .c   # Define our suffix list to exlude *.h files from compiler call

# rules to compile source files to object files
$(BIN)/$(Startup_file).o: $(SYSPATH)/$(Startup_file).c
	$(CC) $(CFLAGS)

$(BIN)/$(Startup_file)_intram.o: $(SYSPATH)/$(Startup_file).c
	$(CC) $(CFLAGS) -DSINTRAM

$(BIN)/$(Vector_file).o: $(SYSPATH)/$(Vector_file).s
	$(AS) $(ASFLAGS)

$(BIN)/%.o: %.c
	$(CC) $(CFLAGS)
		
$(BIN)/%.o: $(CFGPATH)/src/%.c
	$(CC) $(CFLAGS)	
	
$(BIN)/%.o: $(DRV)/src/%.c
	$(CC) $(CFLAGS)


# delete all files
clean:
	del /f/s/q $(BIN)\*.elf
	del /f/s/q $(BIN)\*.a
	del /f/s/q $(BIN)\*.o
	del /f/s/q $(BIN)\*.dba
	del /f/s/q $(BIN)\*.dbo
	del /f/s/q $(BIN)\*.dla
	del /f/s/q $(BIN)\*.dnm
	del /f/s/q $(BIN)\*.map
	del /f/s/q $(BIN)\*.run

.PHONY clean:
