inherit autotools qcommon qlicense

DESCRIPTION = "Bluetooth BT Vendor Filters"
PR = "r0"
DEPENDS = "common qmi qmi-framework glib-2.0"

RDEPENDS:${PN} = "libcutils"

FILESPATH =+ "${WORKSPACE}:"
SRC_URI = "file://vendor/qcom/proprietary/bt/hci_qcomm_init/"
SRC_DIR = "${WORKSPACE}/vendor/qcom/proprietary/bt/hci_qcomm_init/"
S = "${UNPACKDIR}/vendor/qcom/proprietary/bt/hci_qcomm_init"

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

EXTRA_OECONF = "--with-lib-path=${STAGING_LIBDIR} \
                --with-glib \
                --enable-target=${BASEMACHINE} \
                --enable-static=no \
                --with-sysroot=${STAGING_LIBDIR}/../.. \
                --enable-rome=${BASEPRODUCT} \
               "

CFLAGS:append = " -DUSE_ANDROID_LOGGING -Wno-implicit-function-declaration \
                  -Wno-incompatible-pointer-types -Wno-implicit-int -fno-strict-aliasing -fno-tree-vectorize"
LDFLAGS:append = " -llog -Wl,--allow-multiple-definition"

do_compile:prepend() {
    rm -f ${WORKSPACE}/poky/build/tmp-glibc/work/apq8009_robot-oe-linux-gnueabi/qmi-framework/git/recipe-sysroot/usr/lib/libc.so
    ln -s libc.so.6 ${WORKSPACE}/poky/build/tmp-glibc/work/apq8009_robot-oe-linux-gnueabi/qmi-framework/git/recipe-sysroot/usr/lib/libc.so
}

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

    # 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
}

do_install:append () {
    if [ -d "${SRC_DIR}" ]; then
        install -d ${D}${includedir}
        install -m 644 ${S}/bt_nv.h ${D}${includedir}
        install -m 644 ${S}/btqsocnvm.h ${D}${includedir}
        install -m 644 ${S}/btqsocnvmutils.h ${D}${includedir}
    fi
    install -d ${D}/usr/bin
    rm -f ${D}/usr/bin/hci_qcomm_init
    install -m 755 ${S}/hci_qcomm_init_49 ${D}/usr/bin/hci_qcomm_init
}

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