inherit autotools-brokensep pkgconfig

DESCRIPTION = "Bluetooth Vendor Library"
HOMEPAGE = "http://codeaurora.org/"
LICENSE = "Apache-2.0"

LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/\
${LICENSE};md5=89aea4e17d99a7cacdbeed46a0096b10"

DEPENDS = "common system-core glib-2.0 hci-qcomm-init"

RDEPENDS_${PN} = "libcutils"

FILESPATH =+ "${WORKSPACE}:"
SRC_URI = "file://hardware/qcom/bt/libbt-vendor/"

S = "${UNPACKDIR}/hardware/qcom/bt/libbt-vendor"

CFLAGS:append = " -DUSE_ANDROID_LOGGING -Wno-implicit-function-declaration -Wno-return-mismatch -fno-strict-aliasing -fno-tree-vectorize"
LDFLAGS:append = " -llog "

BASEPRODUCT = "${@d.getVar('PRODUCT', False)}"

EXTRA_OECONF = "--with-common-includes="${WORKSPACE}/vendor/qcom/opensource/bluetooth/hal/include/" \
                --with-lib-path=${STAGING_LIBDIR} \
                --enable-target=${BASEMACHINE} \
                --enable-static=no \
                --with-sysroot=${STAGING_LIBDIR}/../.. \
                --enable-rome=${BASEPRODUCT} \
                --with-glib \
               "

# TODO - XXX - WIRE - THIS IS NOT FUTURE-PROOF - THIS IS REALLY FUCKING BAD, AT LEAST USE STAGING_LIBDIR + RELATIVITY
do_compile:prepend() {
    rm -f ${WORKSPACE}/poky/build/tmp-glibc/work/apq8009_robot-oe-linux-gnueabi/hci-qcomm-init/git/recipe-sysroot/usr/lib/libc.so
    ln -s libc.so.6 ${WORKSPACE}/poky/build/tmp-glibc/work/apq8009_robot-oe-linux-gnueabi/hci-qcomm-init/git/recipe-sysroot/usr/lib/libc.so
}

do_configure:prepend() {
    # wire - this is really really bad

    # btnv
    cp ${WORKSPACE}/poky/build/tmp-glibc/work/apq8009_robot-oe-linux-gnueabi/hci-qcomm-init/git/sources/vendor/qcom/proprietary/bt/hci_qcomm_init/libbtnv.la ${STAGING_LIBDIR}/

    # qmi
    cp ${WORKSPACE}/poky/build/tmp-glibc/work/apq8009_robot-oe-linux-gnueabi/qmi/git/sources/qmi/services/libqmiservices.la \
        ${STAGING_LIBDIR}/
    cp ${WORKSPACE}/poky/build/tmp-glibc/work/apq8009_robot-oe-linux-gnueabi/qmi/git/sources/qmi/src/libqmi.la \
        ${STAGING_LIBDIR}/
    cp ${WORKSPACE}/poky/build/tmp-glibc/work/apq8009_robot-oe-linux-gnueabi/qmi-framework/git/sources/qmi-framework/qcci/src/libqmi_cci.la  ${STAGING_LIBDIR}/
    cp ${WORKSPACE}/poky/build/tmp-glibc/work/apq8009_robot-oe-linux-gnueabi/qmi-framework/git/sources/qmi-framework/common/src/libqmi_common_so.la  ${STAGING_LIBDIR}/
    cp ${WORKSPACE}/poky/build/tmp-glibc/work/apq8009_robot-oe-linux-gnueabi/qmi-framework/git/sources/qmi-framework/qcsi/src/libqmi_csi.la  ${STAGING_LIBDIR}/
    cp ${WORKSPACE}/poky/build/tmp-glibc/work/apq8009_robot-oe-linux-gnueabi/qmi/git/sources/qmi/qmi_client_qmux/libqmi_client_qmux.la  ${STAGING_LIBDIR}/

    # diag
    cp ${WORKSPACE}/poky/build/tmp-glibc/work/apq8009_robot-oe-linux-gnueabi/diag/git/sources/diag/src/libdiag.la \
        ${STAGING_LIBDIR}/

    cp ${WORKSPACE}/poky/build/tmp-glibc/work/apq8009_robot-oe-linux-gnueabi/time-genoff/git/sources/time-services/time-genoff/libtime_genoff.la \
        ${STAGING_LIBDIR}/

    cp ${WORKSPACE}/poky/build/tmp-glibc/work/apq8009_robot-oe-linux-gnueabi/configdb/git/sources/data/configdb/src/libconfigdb.la \
        ${STAGING_LIBDIR}/

    if [ ! -f ${STAGING_LIBDIR}/libglib-2.0.la ]; then
        cat > ${STAGING_LIBDIR}/libglib-2.0.la << 'EOF'
# libglib-2.0.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4.6
#
# Please DO NOT delete this file!
# It is necessary for linking the library.

# The name that we can dlopen(3).
dlname='libglib-2.0.so.0'

# Names of this library.
library_names='libglib-2.0.so.0.7800.0 libglib-2.0.so.0 libglib-2.0.so'

# The name of the static archive.
old_library=''

# Linker flags that cannot be derived automatically.
inherited_linker_flags=''

# Libraries that this one depends upon.
dependency_libs=' -lpcre2-8 -lm'

# Names of additional weak libraries provided by this library
weak_library_names=''

# Version information for libglib-2.0.
current=7800
age=7800
revision=0

# Is this an already installed library?
installed=yes

# Should we warn about portability when linking against -modules?
shouldnotlink=no

# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''

# Directory that this library needs to be installed in:
libdir='${STAGING_LIBDIR}'
EOF
    fi
    
    if [ ! -f ${STAGING_LIBDIR}/libgthread-2.0.la ]; then
        cat > ${STAGING_LIBDIR}/libgthread-2.0.la << 'EOF'
# libgthread-2.0.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4.6
#
# Please DO NOT delete this file!
# It is necessary for linking the library.

# The name that we can dlopen(3).
dlname='libgthread-2.0.so.0'

# Names of this library.
library_names='libgthread-2.0.so.0.7800.0 libgthread-2.0.so.0 libgthread-2.0.so'

# The name of the static archive.
old_library=''

# Linker flags that cannot be derived automatically.
inherited_linker_flags=''

# Libraries that this one depends upon.
dependency_libs=' -lglib-2.0 -lpthread'

# Names of additional weak libraries provided by this library
weak_library_names=''

# Version information for libgthread-2.0.
current=7800
age=7800
revision=0

# Is this an already installed library?
installed=yes

# Should we warn about portability when linking against -modules?
shouldnotlink=no

# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''

# Directory that this library needs to be installed in:
libdir='${STAGING_LIBDIR}'
EOF
    fi
}

FILES:${PN} += "/misc/bluetooth/*"

do_install:append () {
    install -d ${D}/misc/bluetooth
    install -m 755 ${S}/init.msm.bt.sh ${D}/misc/bluetooth/
}

INSANE_SKIP:${PN} += "rpaths"
INSANE_SKIP:${PN} += "already-stripped"
INSANE_SKIP:${PN} += "ldflags"
