inherit qcommon qlicense qprebuilt

DESCRIPTION = "Qualcomm MSM Interface (QMI) Library"

PR = "r13"
SRC_DIR = "${WORKSPACE}/qmi"
S = "${UNPACKDIR}/qmi"

DEPENDS = "configdb diag dsutils libcutils"
RDEPENDS:${PN} = "dsutils libcutils"

CFLAGS += "-I${STAGING_INCDIR}/cutils"
CFLAGS += " -fforward-propagate"
CFLAGS += " -Wl,--verbose"
CFLAGS += "-Wno-error -Wno-implicit-function-declaration -Wno-incompatible-pointer-types"

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

do_configure:prepend() {
    export PKG_CONFIG_SYSROOT_DIR="${STAGING_LIBDIR}/../.."
    export PKG_CONFIG_LIBDIR="${STAGING_LIBDIR}/pkgconfig:${STAGING_LIBDIR}/../share/pkgconfig"

    # wire - this is really really bad

    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

    cd ${S}
    if [ -f configure.ac ]; then
        autoreconf -fiv
    fi
}

EXTRA_OECONF = "--with-qxdm \
                --with-common-includes=${STAGING_INCDIR} \
                --enable-static=no \
                --with-sysroot=${STAGING_LIBDIR}/../.."

EXTRA_OECONF:append_msm8960 = " --enable-auto-answer=yes"

INSANE_SKIP:${PN} += "rpaths"