#/**************************************************************************
# *                                                                        *
# *         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 = hal.a

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

#---------------------------------------------------------------------------
# Intermediate objects
#---------------------------------------------------------------------------
#OBJS += hal_scale.o
#OBJS += hal_gpe/hal_gpe.o
#OBJS += hal_aud/hal_aud.o

#OBJS += hal_cdsp/hal_cdsp.o
#OBJS += hal_cdsp/hal_cdsp_isr.o

#OBJS += hal_cpu/hal_basic_cunit.o
#OBJS += hal_cpu/hal_cpu.o
OBJS += hal_cpu/hal_dma.o
#OBJS += hal_cpu/hal_rtc.o
#OBJS += hal_cpu/hal_sram.o
#OBJS += hal_cpu/hal_tmr.o
OBJS += hal_cpu/hal_uart.o

#OBJS += hal_disp/hal_disp.o
#OBJS += hal_disp/hal_disp_bg_color.o
#OBJS += hal_disp/hal_disp_scale.o
#OBJS += hal_disp/hal_osd.o

#OBJS += hal_dram/hal_dram.o

OBJS += hal_flash/hal_flash.o
OBJS += hal_flash/hal_nand.o
OBJS += hal_flash/hal_sd.o
OBJS += hal_flash/hal_spi.o

#OBJS += hal_front/hal_front.o
#OBJS += hal_front/hal_front_test.o #kept for obsolete coding style
#OBJS += hal_front/hal_front_int_en.o
#OBJS += hal_front/hal_front_int_reg.o

#OBJS += hal_jpeg/hal_jpeg.o
#OBJS += hal_jpeg/hal_jpeg_scale.o

OBJS += hal_gpio/hal_aud_gpio.o
OBJS += hal_gpio/hal_disp_gpio.o
OBJS += hal_gpio/hal_fm_gpio.o
OBJS += hal_gpio/hal_gen_gpio.o
#OBJS += hal_adc/hal_adc.o
#OBJS += hal_pwr/hal_reset.o
OBJS += hal_usb/hal_usb.o
#OBJS += hal_ver.o

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

.S.o:
	$(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)

hal_cpu/hal_basic_cunit.o: hal_cpu/hal_basic_cunit.c
	$(MSG_COMPILING)
	@$(CC) $(CFLAGS) -MM -MT $*.o -o $*.d $*.c
	@$(CC) -c $(CFLAGS) -O2 -mlong-calls -o $*.o $*.c

install: $(GOAL)
	$(MSG_SPLIT_LINE)
	cp -f $(GOAL) $(ROOT_DIR)/lib/
	cp -u -f hal_cpu/hal_cpu.h $(ROOT_DIR)/include/hal/
	cp -u -f hal_cpu/hal_rtc.h $(ROOT_DIR)/include/hal/
	cp -u -f hal_flash/hal_sd.h $(ROOT_DIR)/include/hal/
	cp -u -f hal_flash/hal_nand.h $(ROOT_DIR)/include/hal/
	cp -u -f hal_flash/hal_flash.h $(ROOT_DIR)/include/hal/
	cp -u -f hal_flash/hal_spi.h $(ROOT_DIR)/include/hal/
	cp -u -f hal_dram/hal_dram.h $(ROOT_DIR)/include/hal/
	cp -u -f hal_peripherals.h $(ROOT_DIR)/include/hal/
#	cp -u -f hal_glob/hal_glob.h $(ROOT_DIR)/include/hal/
	cp -u -f hal_ptngen/hal_ptngen.h $(ROOT_DIR)/include/hal/
	cp -u -f hal_gpio/hal_gpio.h $(ROOT_DIR)/include/hal/
	cp -u -f hal_cntr/hal_cntr.h $(ROOT_DIR)/include/hal/
	cp -u -f hal_usb/hal_usb.h $(ROOT_DIR)/include/hal/
	cp -u -f hal_isp.h $(ROOT_DIR)/include/hal/

.PHONY: clean
clean:
	$(MSG_SPLIT_LINE)
	rm -f $(ROOT_DIR)/lib/$(GOAL)
	rm -f $(OBJS:.o=.d) $(OBJS) $(GOAL)
	rm -f $(ROOT_DIR)/include/hal/hal_cpu.h
	rm -f $(ROOT_DIR)/include/hal/hal_pll.h
	rm -f $(ROOT_DIR)/include/hal/hal_aud.h
	rm -f $(ROOT_DIR)/include/hal/hal_sd.h
	rm -f $(ROOT_DIR)/include/hal/hal_cf.h
	rm -f $(ROOT_DIR)/include/hal/hal_smc.h
	rm -f $(ROOT_DIR)/include/hal/hal_flash.h
	rm -f $(ROOT_DIR)/include/hal/hal_ms.h
	rm -f $(ROOT_DIR)/include/hal/hal_spi.h
	rm -f $(ROOT_DIR)/include/hal/hal_front.h
	rm -f $(ROOT_DIR)/include/hal/hal_cdsp.h
	rm -f $(ROOT_DIR)/include/hal/hal_dram.h
	rm -f $(ROOT_DIR)/include/hal/hal_mpeg.h
	rm -f $(ROOT_DIR)/include/hal/hal_peripherals.h
	rm -f $(ROOT_DIR)/include/hal/hal_disp.h
	rm -f $(ROOT_DIR)/include/hal/hal_glob.h
	rm -f $(ROOT_DIR)/include/hal/hal_ptngen.h
	rm -f $(ROOT_DIR)/include/hal/hal_gpio.h
	rm -f $(ROOT_DIR)/include/hal/hal_adc.h
	rm -f $(ROOT_DIR)/include/hal/hal_cntr.h
	rm -f $(ROOT_DIR)/include/hal/hal_rtc.h
	rm -f $(ROOT_DIR)/include/hal/hal_usb.h
	rm -f $(ROOT_DIR)/include/hal/hal_jpeg.h
	rm -f $(ROOT_DIR)/include/hal/hal_gprm.h
	rm -f $(ROOT_DIR)/include/hal/hal_isp.h
	rm -f $(ROOT_DIR)/include/hal/hal_pwr.h

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