#/**************************************************************************
# *                                                                        *
# *         Copyright (c) 2002 by Sunplus Technology Co., Ltd.             *
# *                                                                        *
# *  This software is copyrighted by and is the property of Sunplus        *
# *  Technology Co., Ltd. All rights are reserved by Sunplus Technology    *
# *  Co., Ltd. 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 Technology Co., Ltd.                       *
# *                                                                        *
# *  Sunplus Technology Co., Ltd. reserves the right to modify this        *
# *  software without notice.                                              *
# *                                                                        *
# *  Sunplus Technology Co., Ltd.                                          *
# *  19, Innovation First Road, Science-Based Industrial Park,             *
# *  Hsin-Chu, Taiwan, R.O.C.                                              *
# *                                                                        *
# *  Author: Timothy Wu                                                    *
# *                                                                        *
# **************************************************************************/
ROOT = ../../..
# Include the definition of tool chain
include $(ROOT)/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

ROOT_DIR = ../../..
GOAL     = libutil.a

CFLAGS += -Wall
CFLAGS += -ansi
CFLAGS += -msoft-float
CFLAGS += -I$(ROOT_DIR)/include
CFLAGS += -EL
CFLAGS += -O2
CFLAGS += -G 16

#---------------------------------------------------------------------------
# Intermediate objects
#---------------------------------------------------------------------------
INST_HEADER_DIR = $(ROOT_DIR)/include/middleware
APP_HEADER_DIR = $(ROOT_DIR)/app/include/middleware

INST_HEADERS_INT += mem_util.h
INST_HEADERS_INT += i2c_api.h
INST_HEADERS_INT += spi_serial_api.h
INST_HEADERS_INT += apitest_callbackfunc_api.h
INST_HEADERS_INT += sys_svclist.h
INST_HEADERS_INT += util_api.h

INST_HEADERS_EXT += pwrlog.h

#OBJS += util_ver.o
#OBJS += sw_reset.o
#OBJS += imem.o
#OBJS += i2c_serial.o
#OBJS += spi_serial.o
#OBJS += isp_imem.o
#OBJS += cpu_reset.o
#OBJS += sys_svclist.o
#OBJS += sys_sortlist.o
#OBJS += bitwidth.o
#OBJS += mul_overflow.o
#OBJS += pwr2.o
#OBJS += log2.o
#OBJS += util.o
#OBJS += dramclk_set.o
#OBJS += util_delay.o

#---------------------------------------------------------------------------
# Implicit rules
#---------------------------------------------------------------------------
.c.o:
	$(MSG_SPLIT_LINE)
	$(MSG_COMPILING)
	@$(CC) $(CFLAGS) -MM -MT $@ -o $*.d $<
	@$(CC) -c $(CFLAGS) -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)
	mkdir -p $(ROOT_DIR)/lib
	mkdir -p $(INST_HEADER_DIR)
	mkdir -p $(APP_HEADER_DIR)
	cp -u -f $(GOAL) $(ROOT_DIR)/lib/
ifdef INST_HEADERS_INT
	cp -u -f $(INST_HEADERS_INT) $(INST_HEADER_DIR)/
endif
ifdef INST_HEADERS_EXT
	cp -u -f $(INST_HEADERS_EXT) $(INST_HEADER_DIR)/
	cp -u -f $(INST_HEADERS_EXT) $(APP_HEADER_DIR)/
endif

.PHONY: clean
clean:
	$(MSG_SPLIT_LINE)
	rm -f $(ROOT_DIR)/lib/$(GOAL)
	rm -f $(OBJS:.o=.d) $(OBJS) $(GOAL)
ifdef INST_HEADERS_INT
	rm -f $(addprefix $(INST_HEADER_DIR)/,$(notdir $(INST_HEADERS_INT)))
endif
ifdef INST_HEADERS_EXT
	rm -f $(addprefix $(APP_HEADER_DIR)/,$(notdir $(INST_HEADERS_EXT)))
	rm -f $(addprefix $(INST_HEADER_DIR)/,$(notdir $(INST_HEADERS_EXT)))
endif

#mem_util.o: mem_util.c
#	$(MSG_SPLIT_LINE)
#	$(MSG_COMPILING)
#	@$(CC) $(CFLAGS) -mips16 -MM -MT mem_util.o -o mem_util.d mem_util.c
#	@$(CC) -c $(CFLAGS) -mips16 -o mem_util.o mem_util.c

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