# libusb makefile for Ubicom32
# ENV_PATH = /home/AthSDK , export in /home/AthSDK/Makefile
# FS_PATH = /home/AthSDK/rootfs/target , export in /home/AthSDK/Makefile

LIB_NAME = libusb
#VER = libusb-1.0.6
VER = libusb-0.1.12
BUILD_DIR = build-eagle
LIBUSB_PREFIX = $(ENV_PATH)/apps/$(LIB_NAME)
LIBUSB_INSTALL_DIR = $(FS_PATH)/lib
LIB_DL_NAME=$(shell cat $(BUILD_DIR)/lib/libusb.la  |grep dlname |sed "s/dlname='//" |sed "s/'//")


all: $(VER)/Makefile
	@echo ""
	@echo "CFLAGS = $(CFLAGS) "
	@echo "TARGET = $(TARGET) !!!!!!!!!!!"
	@echo "(FS_PATH = $(FS_PATH)  !!!!!!!!!!!"
	@echo "PWD = $(PWD)"
	$(MAKE) -C $(VER)
	$(MAKE) -C $(VER) install > install.log

$(VER)/Makefile: $(VER)/configure Makefile
	find $(VER) -type f -print0 | xargs -0 touch -r $(VER)/configure
	set -e ; \
	cd $(VER) ; \
	./configure  \
		--host=mips-linux \
		--disable-werror \
		--disable-dependency-tracking \
		--build=i386-pc-linux-gnu \
		--enable-static \
		--enable-shared \
		--disable-fast-install \
		--disable-libtool-lock \
		--disable-debug \
		--with-gnu-ld \
		--with-pic \
		--prefix=$(LIBUSB_PREFIX)/$(BUILD_DIR) ;

clean:
	rm -rf *~ install.log .sgbuilt_lib
	rm -rf build*
	-$(MAKE) -C $(VER) distclean

install:
ifeq ($(VER), libusb-1.0.6)
	cp $(BUILD_DIR)/lib/libusb-1.0.so.0.0.0 $(LIBUSB_INSTALL_DIR)/libusb-1.0.so
endif
ifeq ($(VER), libusb-0.1.12)
	#cp $(BUILD_DIR)/lib/libusb-0.1.so.4.4.4 $(LIBUSB_INSTALL_DIR)/libusb-0.1.so.4
	cp $(BUILD_DIR)/lib/libusb-0.1.so.4.4.4 $(LIBUSB_INSTALL_DIR)/$(LIB_DL_NAME)
endif


.PHONY: all clean romfs
