#/**************************************************************************
# *                                                                        *
# *         Copyright (c) 2006 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_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

STDIO_DIR = stdio
TIME_DIR = time
MISC_DIR = misc
BENCH_DIR = benchmark

GOAL     = libc_ex.a

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

#---------------------------------------------------------------------------
# Intermediate objects
#---------------------------------------------------------------------------
OBJS += $(STDIO_DIR)/stdio_no_float.o
OBJS += $(TIME_DIR)/time.o
OBJS += $(TIME_DIR)/mktime.o
OBJS += $(TIME_DIR)/gmtime.o

OBJS += $(MISC_DIR)/bit_dump.o
OBJS += $(MISC_DIR)/bit_op.o
OBJS += $(MISC_DIR)/bitfields.o
OBJS += $(MISC_DIR)/dump.o
OBJS += $(MISC_DIR)/list.o
OBJS += $(MISC_DIR)/ltoa.o
OBJS += $(MISC_DIR)/single_list.o
OBJS += $(MISC_DIR)/mem_util.o
OBJS += $(MISC_DIR)/qtable.o
OBJS += $(MISC_DIR)/misc_unit.o

OBJS += $(BENCH_DIR)/dhry_1.o
OBJS += $(BENCH_DIR)/dhry_2.o
OBJS += $(BENCH_DIR)/dhry_port.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)
	cp -u $(GOAL) $(ROOT_DIR)/lib/
	cp -u $(MISC_DIR)/slist.h $(ROOT_DIR)/include/middleware/

$(BENCH_DIR)/dhry_1.o: $(BENCH_DIR)/dhry_1.c
	$(MSG_COMPILING)
	@$(CC) $(CFLAGS) -MM -MT $*.o -o $*.d $*.c
	@$(CC) -c $(CFLAGS) -O3 -o $*.o $*.c

$(BENCH_DIR)/dhry_2.o: $(BENCH_DIR)/dhry_2.c
	$(MSG_COMPILING)
	@$(CC) $(CFLAGS) -MM -MT $*.o -o $*.d $*.c
	@$(CC) -c $(CFLAGS) -O3 -o $*.o $*.c

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

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