#/**************************************************************************
# *                                                                        *
# *         Copyright (c) 2004 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: Matt Wang                                                     *
# *                                                                        *
# **************************************************************************/
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 = ../../..
ifeq ($(dbg), 1)
GOAL = global_d.a
CFLAGS += -DDBG_FUNC_TRACE_EXT_EN=1
CFLAGS += -DDBG_ASSERT_EXT_EN=1
CFLAGS += -DDBG_PRINT_EXT_EN=1
else
ifeq ($(dbg), 2)
GOAL = global.a
CFLAGS += -DDBG_FUNC_TRACE_EXT_EN=1
CFLAGS += -DDBG_ASSERT_EXT_EN=1
CFLAGS += -DDBG_PRINT_EXT_EN=1
else
GOAL = global.a
CFLAGS += -DDBG_FUNC_TRACE_EXT_EN=0
CFLAGS += -DDBG_ASSERT_EXT_EN=0
CFLAGS += -DDBG_PRINT_EXT_EN=0
endif
endif

CFLAGS += -Wall
CFLAGS += -Os
CFLAGS += -G 0
CFLAGS += -ansi
CFLAGS += -msoft-float
CFLAGS += -I$(ROOT_DIR)/include
CFLAGS += -I.
CFLAGS += -EL

#---------------------------------------------------------------------------
# Intermediate objects
#---------------------------------------------------------------------------
OBJS += gpio.o
OBJS += time.o
OBJS += global_ver.o
#OBJS += pwr_ctrl.o
#OBJS += pwr_ctrl_get.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 -f $(GOAL) $(ROOT_DIR)/lib/
	cp -u -f global_api.h $(ROOT_DIR)/include/middleware/
	cp -u -f global_def.h $(ROOT_DIR)/include/middleware/
	cp -u -f global_def.h $(ROOT_DIR)/app/include/middleware/

.PHONY: clean
clean:
	$(MSG_SPLIT_LINE)
	rm -f $(ROOT_DIR)/lib/$(GOAL)
	rm -f $(OBJS:.o=.d) $(OBJS) $(GOAL)
	rm -f $(ROOT_DIR)/include/middleware/global_api.h
	rm -f $(ROOT_DIR)/include/middleware/global_def.h
	rm -f $(ROOT_DIR)/app/include/middleware/global_def.h

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