#/**************************************************************************
# *                                                                        *
# *         Copyright (c) 2005 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 = ../..
RTOS_DIR = threadx
WRAP_DIR = wrapper
UNIT_DIR = cunit
ROSE_DIR = ros

GOAL     = libos.a

CFLAGS += -Wall
CFLAGS += -ansi
CFLAGS += -msoft-float
CFLAGS += -I$(ROOT_DIR)/include
CFLAGS += -I$(RTOS_DIR)
CFLAGS += -I$(ROSE_DIR)
CFLAGS += -I$(UNIT_DIR)
CFLAGS += -EL
CFLAGS += -O2
CFLAGS += -G 64
CFLAGS += -Wno-uninitialized # This is only allowed for the 3rd party's S/W
CFLAGS += -DSIZE_REDUCTION

#---------------------------------------------------------------------------
# Intermediate objects
#---------------------------------------------------------------------------
#OBJS += $(RTOS_DIR)/tx_ill.o
#OBJS += $(RTOS_DIR)/tx_ill.o
#OBJS += $(RTOS_DIR)/tx_tsb.o
#OBJS += $(RTOS_DIR)/tx_ts.o
#OBJS += $(RTOS_DIR)/tx_tsr.o
#OBJS += $(RTOS_DIR)/tx_tcs.o
#OBJS += $(RTOS_DIR)/tx_tcr.o
OBJS += $(RTOS_DIR)/tx_tic.o
#OBJS += $(RTOS_DIR)/tx_timin.o
#OBJS += $(RTOS_DIR)/tx_ihl.o
#OBJS += $(RTOS_DIR)/tx_ike.o
#OBJS += $(RTOS_DIR)/tx_timi.o
#OBJS += $(RTOS_DIR)/tx_ti.o
#OBJS += $(RTOS_DIR)/tx_tse.o
#OBJS += $(RTOS_DIR)/tx_tsus.o
#OBJS += $(RTOS_DIR)/tx_tsa.o
#OBJS += $(RTOS_DIR)/tx_tra.o
#OBJS += $(RTOS_DIR)/tx_tc.o
#OBJS += $(RTOS_DIR)/tx_tr.o
#OBJS += $(RTOS_DIR)/tx_trel.o
#OBJS += $(RTOS_DIR)/tx_tts.o
#OBJS += $(RTOS_DIR)/tx_tte.o
#OBJS += $(RTOS_DIR)/tx_ta.o
#OBJS += $(RTOS_DIR)/tx_tto.o
#OBJS += $(RTOS_DIR)/tx_tsle.o
#OBJS += $(RTOS_DIR)/tx_tdel.o
#OBJS += $(RTOS_DIR)/tx_tide.o
#OBJS += $(RTOS_DIR)/tx_tpch.o
#OBJS += $(RTOS_DIR)/tx_tprch.o
#OBJS += $(RTOS_DIR)/tx_tt.o
#OBJS += $(RTOS_DIR)/tx_ttsc.o
#OBJS += $(RTOS_DIR)/tx_td.o
#OBJS += $(RTOS_DIR)/tx_timcr.o
#OBJS += $(RTOS_DIR)/tx_taa.o
#OBJS += $(RTOS_DIR)/tx_tda.o
#OBJS += $(RTOS_DIR)/tx_timch.o
#OBJS += $(RTOS_DIR)/tx_timd.o
#OBJS += $(RTOS_DIR)/tx_timeg.o
#OBJS += $(RTOS_DIR)/tx_times.o
#OBJS += $(RTOS_DIR)/tx_si.o
#OBJS += $(RTOS_DIR)/tx_sc.o
#OBJS += $(RTOS_DIR)/tx_sd.o
#OBJS += $(RTOS_DIR)/tx_sg.o
#OBJS += $(RTOS_DIR)/tx_sp.o
#OBJS += $(RTOS_DIR)/tx_scle.o
#OBJS += $(RTOS_DIR)/tx_qi.o
#OBJS += $(RTOS_DIR)/tx_qc.o
#OBJS += $(RTOS_DIR)/tx_qd.o
#OBJS += $(RTOS_DIR)/tx_qs.o
#OBJS += $(RTOS_DIR)/tx_qr.o
#OBJS += $(RTOS_DIR)/tx_qcle.o
#OBJS += $(RTOS_DIR)/tx_qf.o
#OBJS += $(RTOS_DIR)/tx_efi.o
#OBJS += $(RTOS_DIR)/tx_efc.o
#OBJS += $(RTOS_DIR)/tx_efd.o
#OBJS += $(RTOS_DIR)/tx_efg.o
#OBJS += $(RTOS_DIR)/tx_efs.o
#OBJS += $(RTOS_DIR)/tx_efcle.o
#OBJS += $(RTOS_DIR)/tx_bpi.o
#OBJS += $(RTOS_DIR)/tx_bpc.o
#OBJS += $(RTOS_DIR)/tx_bpd.o
#OBJS += $(RTOS_DIR)/tx_ba.o
#OBJS += $(RTOS_DIR)/tx_br.o
#OBJS += $(RTOS_DIR)/tx_bpcle.o
#OBJS += $(RTOS_DIR)/tx_byti.o
#OBJS += $(RTOS_DIR)/tx_bytc.o
#OBJS += $(RTOS_DIR)/tx_bytd.o
#OBJS += $(RTOS_DIR)/tx_byta.o
#OBJS += $(RTOS_DIR)/tx_bytr.o
#OBJS += $(RTOS_DIR)/tx_byts.o
#OBJS += $(RTOS_DIR)/tx_bytcl.o
#OBJS += $(RTOS_DIR)/tx_timig.o
#OBJS += $(RTOS_DIR)/tx_bpig.o
#OBJS += $(RTOS_DIR)/tx_bpp.o
#OBJS += $(RTOS_DIR)/tx_bytig.o
#OBJS += $(RTOS_DIR)/tx_bytpp.o
#OBJS += $(RTOS_DIR)/tx_efig.o
#OBJS += $(RTOS_DIR)/tx_mc.o
#OBJS += $(RTOS_DIR)/tx_mcle.o
#OBJS += $(RTOS_DIR)/tx_md.o
#OBJS += $(RTOS_DIR)/tx_mg.o
#OBJS += $(RTOS_DIR)/tx_mi.o
#OBJS += $(RTOS_DIR)/tx_mig.o
#OBJS += $(RTOS_DIR)/tx_mp.o
#OBJS += $(RTOS_DIR)/tx_mpc.o
#OBJS += $(RTOS_DIR)/tx_mpri.o
#OBJS += $(RTOS_DIR)/tx_qfs.o
#OBJS += $(RTOS_DIR)/tx_qig.o
#OBJS += $(RTOS_DIR)/tx_qp.o
#OBJS += $(RTOS_DIR)/tx_sig.o
#OBJS += $(RTOS_DIR)/tx_spri.o
#OBJS += $(RTOS_DIR)/tx_tig.o
#OBJS += $(RTOS_DIR)/tx_twa.o

OBJS += $(WRAP_DIR)/os_wrap_irq.o
#OBJS += $(WRAP_DIR)/os_wrap_mem.o
#OBJS += $(WRAP_DIR)/os_wrap_mem_reduce.o
#OBJS += $(WRAP_DIR)/os_wrap_info.o
#OBJS += $(WRAP_DIR)/os_wrap_syscall.o
#OBJS += $(WRAP_DIR)/os_wrap_isrun.o
#OBJS += $(WRAP_DIR)/os_wrap_isirq.o
#OBJS += $(WRAP_DIR)/os_wrap_isnblk.o
#OBJS += $(WRAP_DIR)/os_bmap_idx.o
#OBJS += $(WRAP_DIR)/os_bmap_lsb.o
#OBJS += $(WRAP_DIR)/os_bmap_msb.o
OBJS += $(WRAP_DIR)/cpu_dcache.o
#OBJS += os_ver.o

#------------------------------------------------
# CUnit
#------------------------------------------------
#OBJS += $(UNIT_DIR)/Basic.o
#OBJS += $(UNIT_DIR)/Console.o
#OBJS += $(UNIT_DIR)/CUError.o
#OBJS += $(UNIT_DIR)/MyMem.o
##OBJS += $(UNIT_DIR)/test_cunit.o
#OBJS += $(UNIT_DIR)/TestDB.o
#OBJS += $(UNIT_DIR)/TestRun.o
#OBJS += $(UNIT_DIR)/Util.o
#OBJS += $(UNIT_DIR)/cunit_api.o

#------------------------------------------------
# BIST of CUnit
#------------------------------------------------
#OBJS += $(UNIT_DIR)/ExampleTests.o
#OBJS += $(UNIT_DIR)/BasicTest.o

#------------------------------------------------
# ROSE
#------------------------------------------------
#OBJS += $(ROSE_DIR)/ros_init.o
##OBJS += $(ROSE_DIR)/ros_mem.o
#OBJS += $(ROSE_DIR)/ros_bk.o
#OBJS += $(ROSE_DIR)/ros_thread.o
#OBJS += $(ROSE_DIR)/ros_thread_sus.o
#OBJS += $(ROSE_DIR)/ros_que.o
#OBJS += $(ROSE_DIR)/ros_semaphore.o
#OBJS += $(ROSE_DIR)/ros_event_flag.o
#OBJS += $(ROSE_DIR)/ros_timer.o
#OBJS += $(ROSE_DIR)/ros_unit.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 $(ROSE_DIR)/ros_api.h $(ROOT_DIR)/include/os/
	cp -u $(UNIT_DIR)/cunit_api.h $(ROOT_DIR)/include/os/
	cp -u $(RTOS_DIR)/os_api.h  $(ROOT_DIR)/include/os/
	cp -u $(RTOS_DIR)/tx_api.h  $(ROOT_DIR)/include/os/
	cp -u $(RTOS_DIR)/tx_port.h $(ROOT_DIR)/include/os/
	cp -u $(WRAP_DIR)/os_bmap.h $(ROOT_DIR)/include/os/

$(WRAP_DIR)/os_wrap_info.o: $(WRAP_DIR)/os_wrap_info.c
	$(MSG_SPLIT_LINE)
	$(MSG_COMPILING)
	@$(CC) $(CFLAGS) -MM -MT $@ -o $(WRAP_DIR)/os_wrap_info.d $(WRAP_DIR)/os_wrap_info.c
	@$(CC) -c $(CFLAGS) -Os -mips16 -o $(WRAP_DIR)/os_wrap_info.o $(WRAP_DIR)/os_wrap_info.c


.PHONY: clean
clean:
	$(MSG_SPLIT_LINE)
	rm -f $(ROOT_DIR)/lib/$(GOAL)
	rm -f $(OBJS:.o=.d) $(OBJS) $(GOAL)
	rm -f $(ROOT_DIR)/include/os/os_api.h
	rm -f $(ROOT_DIR)/include/os/tx_api.h
	rm -f $(ROOT_DIR)/include/os/tx_port.h
	rm -f $(ROOT_DIR)/include/os/os_bmap.h

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