#
# Copyright (C) 2008-Present      Sigma Designs
#
# Sigma Designs
# 1778 McCarthy BLVD
# Milpitas CA 95035, USA
#
#############################################################
#############################################################
#
# CONFIGURE LIBCURL
#
#############################################################
TARGETS+=libcurl
ifeq ($(strip $(BR2_PACKAGE_LIBCURL)),y)
SUBDIR:=package/$(TARGETS)
BUILD_DIR:=$(BASE_DIR)/$(SUBDIR)
VERSION:=$(strip $(subst ",, $(BR2_LIBCURL_VERSION)))
#"))
SOURCE = curl-$(VERSION).tar.bz2
UNZIP:=$(TAR)
UNZIP_OPTIONS:=$(BZ2_EXT)
ifeq ($(strip $(DOWNLOAD_SITE_PUBLIC)),y)
SITE =  http://curl.haxx.se/download
else
SITE := $(DOWNLOAD_SITE)
endif
SOURCE_DIR:=$(BUILD_DIR)/curl-$(VERSION)
SOURCE_LIBS:= $(SOURCE_DIR)/lib/.libs/$(TARGETS).so
STAGING_LIBS:= $(STAGING_DIR)/lib/$(TARGETS).so
TARGET_LIBS:= $(TARGET_DIR)/lib/$(TARGETS).so
CONFIG_ARGS:=Y
LD_FLAGS:=Y
EXTRA_INSTALL:=Y
EXTRA_RM:=Y
NNAME:=$(TARGETS).la
TARGET_CFLAGS:=-fPIC $(TARGET_CFLAGS)
-include $(BASE_DIR)/makefile.newrules
LIBCURL_CONF_OPT = --disable-verbose --disable-manual --enable-hidden-symbols \
		   $(DISABLE_IPV6)

ifeq ($(BR2_PACKAGE_OPENSSL),y)
LIBCURL_DEPENDENCIES += openssl
LIBCURL_CONF_ENV += ac_cv_lib_crypto_CRYPTO_lock=yes
# configure adds the cross openssl dir to LD_LIBRARY_PATH which screws up
# native stuff during the rest of configure when target == host.
# Fix it by setting LD_LIBRARY_PATH to something sensible so those libs
# are found first.
LIBCURL_CONF_ENV += LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:/lib:/usr/lib
LIBCURL_CONF_OPT += --enable-shared --with-random=/dev/urandom --with-ssl=$(STAGING_DIR)
endif

ifeq ($(BR2_PACKAGE_LIBIDN),y)
LIBCURL_DEPENDENCIES += libidn
LIBCURL_CONF_OPT += --with-idn=$(STAGING_DIR)
endif

CONFIGURE:=(cd $(SOURCE_DIR); rm -rf config.cache; \
		$(TARGET_CONFIGURE_ARGS) \
		$(TARGET_CONFIGURE_OPTS) \
		CFLAGS="$(TARGET_CFLAGS)" \
		LDFLAGS="$(TARGET_LDFLAGS)" \
		$(LIBCURL_CONF_ENV) \
		./configure \
		--target=$(GNU_TARGET_NAME) \
		--host=$(GNU_TARGET_NAME) \
		--build=$(GNU_HOST_NAME) \
		--sysconfdir=/etc \
		--enable-shared \
		--prefix= \
		--enable-threaded-resolver \
		--disable-ares \
		--without-gnutls \
		--without-nss \
		--without-libssh2 \
		--disable-ftp \
		--disable-ldap \
		--disable-ldaps \
		--disable-dict \
		--disable-telnet \
		--disable-tftp \
		--disable-sspi \
		--with-zlib=$(SMP86XX_ROOTFS_PATH)/cross_rootfs \
		$(LIBCURL_CONF_OPT); \
		sed -i -e "s|^link_all_deplibs=.*|link_all_deplibs=yes|" libtool \
	)
extra-operations: extra-install
	@cp -f $(SOURCE_DIR)/lib/.libs/$(TARGETS).la $(ROOTFS_TMP_DIR)/lib/$(TARGETS).la
	@$(SED) "s,^libdir=.*,libdir=\'$(ROOTFS_TMP_DIR)/lib\',g" $(ROOTFS_TMP_DIR)/lib/$(TARGETS).la
else
$(error Please use "make menuconfig" to enable $(TARGETS))
endif
