############################################################################################
#
#	Makefile For libssh2
#
#	Author: Han Chang
#	Date: 2022.04.13
#	
#	Description:
#		It will be used by xAgent implementation.
#		We will use the version curl-7.36.0 for xAgent.
#
#############################################################################################
include $(GPLTOPDIR)/config.mk
include $(GPLTOPDIR)/config.in

APP=libssh2-1.10.0
SUBDIRS := libssh2-1.10.0

CURL_DIR_PATH=$(shell pwd)

.PHONY:

all: gen_conf libssh2
	cd $(APP); make
	cd $(APP); ln -sf src/.libs lib

gen_conf:
	if [ ! -e $(APP)/Makefile.in ]; then \
    	echo "Untarring original $(APP) source"; \
	    (tar zxvf $(APP).tar.gz 2> /dev/null); \
	    (ln -sf $(APP) libssh2); \
	    (cd $(APP); \
	    ./configure --host=$(TARGET_PLATFORM_ARCH)-linux --prefix=$(TARGETDIR) \
						--disable-examples-build \
						--with-ssl=$(LIB_OPENSSLDIR) \
						--with-libssl-prefix=$(LIB_OPENSSLDIR) LDFLAGS=-Wl,-rpath-link,$(LIB_OPENSSLDIR)/lib ); \
        fi

libssh2:	
	cd $(APP); make
	cd $(APP); ln -sf src/.libs lib

clean:
	@if [ -e $(SUBDIRS)/Makefile ]; then \
    cd $(SUBDIRS); $(MAKE) distclean ; \
    fi
	-rm -rf $(SUBDIRS)
	rm -rf $(TARGETDIR)/lib/libssh2.*
	
install:
#	$(TARGET_PLATFORM_CROSS_COMPILE_USER)strip $(CURL_DIR_PATH)/binary/curl
#	rm -rf $(TARGETDIR)/bin/curl
#	rm -f $(TARGETDIR)/lib/public/libcurl.so*
#	install -d $(TARGETDIR)/sbin/
#	install -m 755 $(CURL_DIR_PATH)/binary/curl $(TARGETDIR)/sbin
	install -m 755 $(APP)/src/.libs/libssh2.so.1.0.1  $(TARGETDIR)/lib/
	ln -sf libssh2.so.1.0.1  $(TARGETDIR)/lib/libssh2.so.1
	ln -sf libssh2.so.1.0.1  $(TARGETDIR)/lib/libssh2.so

