inherit qcommon qlicense qprebuilt pkgconfig

DESCRIPTION = "Qualcomm Data Configdb Module"
DEPENDS = "common dsutils diag xmllib glib-2.0"
RDEPENDS:${PN} = "diag"
PR = "r5"

EXTRA_OECONF = "--with-lib-path=${STAGING_LIBDIR} \
                --with-common-includes=${STAGING_INCDIR} \
                --with-glib \
                --with-qxdm \
                --enable-static=no \
                --with-sysroot=${STAGING_LIBDIR}/../.. \
                --disable-dependency-tracking"

EXTRA_OECONF += "PKG_CONFIG_PATH='${STAGING_LIBDIR}/pkgconfig'"

EXTRA_OECONF += "LDFLAGS='-L${STAGING_LIBDIR} -Wl,-rpath-link,${STAGING_LIBDIR}'"

S = "${UNPACKDIR}/data/configdb"
SRC_DIR = "${WORKSPACE}/data/configdb"

do_configure:prepend() {
    # wire - this is really really bad
    # new yocto doesn't copy .la anymore
    # ALSO, libglib doesn't build with autotools anymore - it uses meson
    # so, i am making a .la for it

    cp ${WORKSPACE}/poky/build/tmp-glibc/work/apq8009_robot-oe-linux-gnueabi/diag/git/sources/diag/src/libdiag.la \
        ${WORKSPACE}/poky/build/tmp-glibc/work/apq8009_robot-oe-linux-gnueabi/configdb/git/recipe-sysroot/usr/lib/

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

    mkdir -p ${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
}

INSANE_SKIP:${PN} += "ldflags"
INSANE_SKIP:${PN} += "rpaths"
