#/**************************************************************************
# *                                                                        *
# *         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:                                                               *
# *                                                                        *
# **************************************************************************/
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 = ../../..
MSDC_DIR = ./msdc
VNDR_DIR = ./vndr
SIDC_DIR = ./sidc
GOAL     = libusb.a
GOAL_MASK = libusb_mask.a

CFLAGS += -Wall
CFLAGS += -O2
CFLAGS += -G 8
CFLAGS += -ansi
CFLAGS += -msoft-float
CFLAGS += -mlong-calls
CFLAGS += -I$(ROOT_DIR)/include
CFLAGS += -I.
CFLAGS += -EL

#---------------------------------------------------------------------------
# Intermediate objects
#---------------------------------------------------------------------------
#OBJS += usb_app_if.o
#OBJS += usb_control.o
#OBJS += usb_dcl.o
#OBJS += usb_dev_app.o
#OBJS += usb_dev_req.o
#OBJS += usb_target.o
#OBJS += usb_platform.o
#OBJS += usb_utility.o

#OBJS += $(MSDC_DIR)/usb_msdc.o
#OBJS += $(MSDC_DIR)/usb_msdc_cb.o
#OBJS += $(MSDC_DIR)/usb_msdc_req.o
#OBJS += $(MSDC_DIR)/usb_scsi.o

#OBJS += $(VNDR_DIR)/usb_vndr.o
#OBJS += $(VNDR_DIR)/usb_vndr_apitest.o

#OBJS += $(SIDC_DIR)/usb_sidc.o

OBJS_MASK += usb_app_if.o
OBJS_MASK += usb_control.o
OBJS_MASK += usb_dcl.o
OBJS_MASK += usb_dev_req.o
OBJS_MASK += usb_target.o
OBJS_MASK += usb_utility.o
OBJS_MASK += usb_dev_app_mask.o
OBJS_MASK += usb_platform_mask.o
OBJS_MASK += $(VNDR_DIR)/usb_vndr_mask.o

#---------------------------------------------------------------------------
# Implicit rules
#---------------------------------------------------------------------------
%_mask.o: %.c
	@$(CC) $(CFLAGS) -MM -MT $@ -o $*_mask.d $<
	@$(ECHO) "Compiling $<..."
	@$(CC) -c $(CFLAGS) -Os -DUSB_BOOT -DUSB_VND_FRM -o $*_mask.o $<

.c.o:
	@$(CC) $(CFLAGS) -MM -MT $@ -o $*.d $<
	@$(ECHO) "Compiling $<..."
	@$(CC) -c $(CFLAGS) -DUSB_VND_FRM -DUSB_VND_APITEST -o $*.o $<

.S.o:
	@$(CC) $(CFLAGS) -MM -MT $@ -o $*.d $<
	@$(ECHO) "Compiling $<..."
	@$(CC) -c $(ASFLAGS) $(CFLAGS) -o $*.o $<

#---------------------------------------------------------------------------
# Explicit ruls
#---------------------------------------------------------------------------
all: $(GOAL) $(GOAL_MASK)

$(GOAL): $(OBJS)
	@$(AR) ru $(GOAL) $(OBJS)
	@$(ECHO) "***" $(GOAL) "is built successfully! ***"

$(GOAL_MASK): $(OBJS_MASK)
	@$(AR) ru $(GOAL_MASK) $(OBJS_MASK)
	@$(ECHO) "***" $(GOAL_MASK) "is built successfully! ***"

install: $(GOAL) $(GOAL_MASK)
	cp -u $(GOAL) $(ROOT_DIR)/lib/
	cp -u usb_api.h $(ROOT_DIR)/include/middleware/
	cp -u $(GOAL_MASK) $(ROOT_DIR)/lib/

.PHONY: clean
clean:
	rm -f $(ROOT_DIR)/lib/$(GOAL)
	rm -f $(OBJS:.o=.d) $(OBJS) $(GOAL)
	rm -f $(ROOT_DIR)/lib/$(GOAL_MASK)
	rm -f $(OBJS_MASK:_mask.o=_mask.d) $(OBJS_MASK) $(GOAL_MASK)
	
#-include $(OBJS:.o=.d)
