#! /bin/sh
#***************************************************************************
#                                  _   _ ____  _
#  Project                     ___| | | |  _ \| |
#                             / __| | | | |_) | |
#                            | (__| |_| |  _ <| |___
#                             \___|\___/|_| \_\_____|
#
# Copyright (C) 2001 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at https://curl.haxx.se/docs/copyright.html.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
###########################################################################

prefix=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr
exec_prefix=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr
includedir=FIXMESTAGINGDIRTARGET/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/include
cppflag_curl_staticlib=

usage()
{
    cat <<EOF
Usage: curl-config [OPTION]

Available values for OPTION include:

  --built-shared says 'yes' if libcurl was built shared
  --ca        ca bundle install path
  --cc        compiler
  --cflags    pre-processor and compiler flags
  --checkfor [version] check for (lib)curl of the specified version
  --configure the arguments given to configure when building curl
  --features  newline separated list of enabled features
  --help      display this help and exit
  --libs      library linking information
  --prefix    curl install prefix
  --protocols newline separated list of enabled protocols
  --ssl-backends output the SSL backends libcurl was built to support
  --static-libs static libcurl library linking information
  --version   output version information
  --vernum    output the version information as a number (hexadecimal)
EOF

    exit $1
}

if test $# -eq 0; then
    usage 1
fi

while test $# -gt 0; do
    case "$1" in
    # this deals with options in the style
    # --option=value and extracts the value part
    # [not currently used]
    -*=*) value=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
    *) value= ;;
    esac

    case "$1" in
    --built-shared)
        echo yes
        ;;

    --ca)
        echo "/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/etc/ssl/certs/ca-certificates.crt"
        ;;

    --cc)
        echo "x86_64-petalinux-linux-gcc  --sysroot=FIXMESTAGINGDIRTARGET"
        ;;

    --prefix)
        echo "$prefix"
        ;;

    --feature|--features)
        for feature in AsynchDNS HTTPS-proxy IPv6 NTLM SSL TLS-SRP UnixSockets libz ""; do
            test -n "$feature" && echo "$feature"
        done
        ;;

    --protocols)
        for protocol in FILE FTP FTPS HTTP HTTPS; do
            echo "$protocol"
        done
        ;;

    --version)
        echo libcurl 7.72.0
        exit 0
        ;;

    --checkfor)
        checkfor=$2
        cmajor=`echo $checkfor | cut -d. -f1`
        cminor=`echo $checkfor | cut -d. -f2`
        # when extracting the patch part we strip off everything after a
        # dash as that's used for things like version 1.2.3-CVS
        cpatch=`echo $checkfor | cut -d. -f3 | cut -d- -f1`

        vmajor=`echo 7.72.0 | cut -d. -f1`
        vminor=`echo 7.72.0 | cut -d. -f2`
        # when extracting the patch part we strip off everything after a
        # dash as that's used for things like version 1.2.3-CVS
        vpatch=`echo 7.72.0 | cut -d. -f3 | cut -d- -f1`

        if test "$vmajor" -gt "$cmajor"; then
            exit 0;
        fi
        if test "$vmajor" -eq "$cmajor"; then
            if test "$vminor" -gt "$cminor"; then
                exit 0
            fi
            if test "$vminor" -eq "$cminor"; then
                if test "$cpatch" -le "$vpatch"; then
                    exit 0
                fi
            fi
        fi

        echo "requested version $checkfor is newer than existing 7.72.0"
        exit 1
        ;;

    --vernum)
        echo 074800
        exit 0
        ;;

    --help)
        usage 0
        ;;

    --cflags)
        if test "X$cppflag_curl_staticlib" = "X-DCURL_STATICLIB"; then
          CPPFLAG_CURL_STATICLIB="-DCURL_STATICLIB "
        else
          CPPFLAG_CURL_STATICLIB=""
        fi
        if test "X/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/include" = "X/usr/include"; then
          echo "$CPPFLAG_CURL_STATICLIB"
        else
          echo "${CPPFLAG_CURL_STATICLIB}-IFIXMESTAGINGDIRTARGET/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/include"
        fi
        ;;

    --libs)
        if test "X/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/lib" != "X/usr/lib" -a "X/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/lib" != "X/usr/lib64"; then
           CURLLIBDIR="-LFIXMESTAGINGDIRTARGET/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/lib "
        else
           CURLLIBDIR=""
        fi
        if test "Xyes" = "Xno"; then
          echo ${CURLLIBDIR}-lcurl -lssl -lcrypto -lz
        else
          echo ${CURLLIBDIR}-lcurl
        fi
        ;;
    --ssl-backends)
        echo "OpenSSL"
        ;;

    --static-libs)
        if test "Xno" != "Xno" ; then
          echo /opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/lib/libcurl.a -Wl,-O1 -LFIXMESTAGINGDIRTARGET/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/lib/recipe-sysroot/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/lib/..//lib -lssl -lcrypto -lz
        else
          echo "curl was built with static libraries disabled" >&2
          exit 1
        fi
        ;;

    --configure)
        echo " '--build=x86_64-linux' '--host=x86_64-petalinux-linux' '--target=x86_64-petalinux-linux' '--prefix=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr' '--exec_prefix=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr' '--bindir=FIXMESTAGINGDIRTARGET/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/bin' '--sbindir=FIXMESTAGINGDIRTARGET/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/bin' '--libexecdir=FIXMESTAGINGDIRTARGET/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/libexec' '--datadir=FIXMESTAGINGDIRTARGET/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/share' '--sysconfdir=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/etc' '--sharedstatedir=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/com' '--localstatedir=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/var' '--libdir=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/lib' '--includedir=FIXMESTAGINGDIRTARGET/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/include' '--oldincludedir=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/include' '--infodir=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/share/info' '--mandir=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/share/man' '--disable-silent-rules' '--disable-dependency-tracking' '--with-libtool-sysroot=FIXMESTAGINGDIRTARGET' '--disable-libcurl-option' '--disable-ntlm-wb' '--enable-crypto-auth' '--with-ca-bundle=/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/etc/ssl/certs/ca-certificates.crt' '--without-libmetalink' '--without-libpsl' '--enable-debug' '--enable-optimize' '--disable-curldebug' '--disable-static' '--disable-ares' '--without-brotli' '--disable-manual' '--disable-dict' '--without-gnutls' '--disable-gopher' '--disable-imap' '--enable-ipv6' '--without-gssapi' '--disable-ldap' '--disable-ldaps' '--without-libidn2' '--without-libssh2' '--without-mbedtls' '--disable-mqtt' '--without-nghttp2' '--without-nss' '--disable-pop3' '--enable-proxy' '--without-librtmp' '--disable-rtsp' '--disable-smb' '--disable-smtp' '--with-ssl' '--with-random=/dev/urandom' '--disable-telnet' '--disable-tftp' '--enable-threaded-resolver' '--enable-verbose' '--with-zlib=FIXMESTAGINGDIRTARGET/opt/petalinux/2021.2/sysroots/x86_64-petalinux-linux/usr/lib/../' 'build_alias=x86_64-linux' 'host_alias=x86_64-petalinux-linux' 'target_alias=x86_64-petalinux-linux' 'CC=x86_64-petalinux-linux-gcc  --sysroot=FIXMESTAGINGDIRTARGET' 'CFLAGS= -O2 -pipe -fmacro-prefix-map=/scratch/jenkins-BUILDS-eSDK-2021.2_stable-pipeline-build-89_ZynqFull/build/tmp/work/x86_64-nativesdk-petalinux-linux/nativesdk-curl/7.72.0-r0=/usr/src/debug/nativesdk-curl/7.72.0-r0                      -fdebug-prefix-map=/scratch/jenkins-BUILDS-eSDK-2021.2_stable-pipeline-build-89_ZynqFull/build/tmp/work/x86_64-nativesdk-petalinux-linux/nativesdk-curl/7.72.0-r0=/usr/src/debug/nativesdk-curl/7.72.0-r0                      -fdebug-prefix-map=FIXMESTAGINGDIRTARGET=                      -fdebug-prefix-map=FIXMESTAGINGDIRHOST= ' 'LDFLAGS=-Wl,-O1' 'CPPFLAGS=' 'CPP=x86_64-petalinux-linux-gcc -E --sysroot=FIXMESTAGINGDIRTARGET '"
        ;;

    *)
        echo "unknown option: $1"
        usage 1
        ;;
    esac
    shift
done

exit 0
