#/**************************************************************************
# *                                                                        *
# *         Copyright (c) 2008 by Sunplus mMedia Inc.                      *
# *                                                                        *
# *  This software is copyrighted by and is the property of Sunplus        *
# *  mMedia Ltd. All rights are reserved by Sunplus mMedia Inc.            *
# *  This software may only be used in accordance with the                 *
# *  corresponding license agreement. Any unauthorized use, duplication,   *
# *  distribution, or disclosure of this software is expressly forbidden.  *
# *                                                                        *
# *  This Copyright notice MUST not be removed or modified without prior   *
# *  written consent of Sunplus mMedia Inc.                                *
# *                                                                        *
# *  Sunplus mMedia Inc. reserves the right to modify this software        *
# *  without notice.                                                       *
# *                                                                        *
# *  Sunplus mMedia Inc.                                                   *
# *  19, Innovation First Road, Science-Based Industrial Park,             *
# *  Hsin-Chu, Taiwan, R.O.C.                                              *
# *                                                                        *
# *                                                                        *
# **************************************************************************/
ROOT_DIR = ../../..
# Include the definition of tool chain
include $(ROOT_DIR)/tool_chain.def

#---------------------------------------------------------------------------
# Variable definition:
#   1. Cross-compling tools
#   2. Linker script file
#   3. C complier options
#   4. Assembly compiler options
#   5. Linker options
#---------------------------------------------------------------------------
CC      = $(PREFIX)/gcc
AR      = $(PREFIX)/ar
ECHO    = echo
SVN     = svn

GOAL    = libmem.a


CFLAGS += -Wall
CFLAGS += -ansi
CFLAGS += -msoft-float
CFLAGS += -I$(ROOT_DIR)/inc
CFLAGS += -I$(ROOT_DIR)/include/os
CFLAGS += -I$(ROOT_DIR)/include
CFLAGS += -EL
CFLAGS += -G 16
ifeq ($(gdb), 1)
CFLAGS += -g
else
CFLAGS += -O2
endif

#---------------------------------------------------------------------------
# Intermediate objects
#---------------------------------------------------------------------------
#OBJS += mem.o
OBJS += buddymem.o


#---------------------------------------------------------------------------
# Implicit rules
#---------------------------------------------------------------------------
.c.o:
	$(MSG_SPLIT_LINE)
	$(MSG_COMPILING)
	@$(CC) $(CFLAGS) -MM -MT $@ -o $*.d $<
	@$(CC) -c $(CFLAGS) -mips16 -o $*.o $<

.S.o:
	$(MSG_SPLIT_LINE)
	$(MSG_COMPILING)
	@$(CC) $(CFLAGS) -MM -MT $@ -o $*.d $<
	@$(CC) -c $(ASFLAGS) $(CFLAGS) -o $*.o $<

#---------------------------------------------------------------------------
# Explicit ruls
#---------------------------------------------------------------------------
all: $(GOAL)

$(GOAL): $(OBJS)
	$(MSG_SPLIT_LINE)
	@$(AR) ru $(GOAL) $(OBJS)
	$(MSG_GOAL_OK)

install: $(GOAL)
	$(MSG_SPLIT_LINE)
	cp -f $(GOAL) $(ROOT_DIR)/lib/

.PHONY: clean
clean:
	$(MSG_SPLIT_LINE)
	rm -f $(ROOT_DIR)/lib/$(GOAL)
	rm -f $(OBJS:.o=.d) $(OBJS) $(GOAL)
	rm -f core/ver.cfg

.PHONY: release
release:

.PHONY: core/ver.cfg
core/ver.cfg:
	@$(ECHO) "#define SPGUI_REVISION \\" > core/ver.cfg
	@$(SVN) info .@BASE | grep Revision | sed -e 's/Revision: //' - >> core/ver.cfg || $(ECHO) 0 >> core/ver.cfg

core/ver.o: core/ver.c core/ver.cfg
	$(MSG_SPLIT_LINE)
	$(MSG_COMPILING)
	@$(CC) $(CFLAGS) -MM -MT $@ -o $*.d $<
	@$(CC) -c $(CFLAGS) -o $*.o $<

-include $(OBJS:.o=.d)
