From e0eb2b8a31acd66f13e9cb43f837248e4ddea694 Mon Sep 17 00:00:00 2001
From: orbea <ovariegata@yahoo.com>
Date: Sat, 25 Nov 2017 13:12:31 -0800
Subject: [PATCH] qb: Add $PKG_CONF_USED to the check_lib function to help
 avoid undefined referenecs.

---
 qb/config.libs.sh |  8 --------
 qb/qb.libs.sh     | 11 ++++++-----
 2 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/qb/config.libs.sh b/qb/config.libs.sh
index e438351d8b..70a9b864ea 100644
--- a/qb/config.libs.sh
+++ b/qb/config.libs.sh
@@ -123,7 +123,6 @@ if [ "$HAVE_EGL" != "no" ] && [ "$OS" != 'Win32' ]; then
       HAVE_EGL=auto; check_lib '' EGL "-l${VC_PREFIX}EGL $EXTRA_GL_LIBS"
       if [ "$HAVE_EGL" = "yes" ]; then
          EGL_LIBS="-l${VC_PREFIX}EGL $EXTRA_GL_LIBS"
-         PKG_CONF_USED="$PKG_CONF_USED EGL"
       fi
    else
       EGL_LIBS="$EGL_LIBS $EXTRA_GL_LIBS"
@@ -316,9 +315,6 @@ if [ "$HAVE_OPENGL" != 'no' ] && [ "$HAVE_OPENGLES" != 'yes' ]; then
          [ "$HAVE_CG" = 'yes' ] && CG_LIBS='-lCg -lCgGL'
       fi
 
-      # fix undefined variables
-      PKG_CONF_USED="$PKG_CONF_USED CG"
-
       check_pkgconf OSMESA osmesa
    else
       die : 'Notice: Ignoring Cg. Desktop OpenGL is not enabled.'
@@ -410,7 +406,6 @@ if [ "$HAVE_X11" = "no" ] && [ "$OS" != 'Darwin' ]; then
    HAVE_X11=auto; check_lib '' X11 -lX11
    if [ "$HAVE_X11" = "yes" ]; then
       X11_LIBS="-lX11"
-      PKG_CONF_USED="$PKG_CONF_USED X11"
    fi
 fi
 
@@ -427,7 +422,6 @@ if [ "$HAVE_X11" != "no" ]; then
       HAVE_XEXT=auto; check_lib '' XEXT -lXext
       if [ "$HAVE_XEXT" = "yes" ]; then
          XEXT_LIBS="-lXext"
-         PKG_CONF_USED="$PKG_CONF_USED XEXT"
       fi
    fi
 
@@ -435,7 +429,6 @@ if [ "$HAVE_X11" != "no" ]; then
       HAVE_XF86VM=auto; check_lib '' XF86VM -lXxf86vm
       if [ "$HAVE_XF86VM" = "yes" ]; then
          XF86VM_LIBS="-lXxf86vm"
-         PKG_CONF_USED="$PKG_CONF_USED XF86VM"
       fi
    fi
 else
@@ -457,7 +450,6 @@ if [ "$HAVE_UDEV" != "no" ]; then
       HAVE_UDEV=auto; check_lib '' UDEV "-ludev"
       if [ "$HAVE_UDEV" = "yes" ]; then
          UDEV_LIBS='-ludev'
-         PKG_CONF_USED="$PKG_CONF_USED UDEV"
       fi
    fi
 fi
diff --git a/qb/qb.libs.sh b/qb/qb.libs.sh
index 994d2c31ba..5f96629486 100644
--- a/qb/qb.libs.sh
+++ b/qb/qb.libs.sh
@@ -58,13 +58,14 @@ check_lib() # $1 = language  $2 = HAVE_$2  $3 = lib  $4 = function in lib  $5 =
 	printf %s\\n "$ECHOBUF ... $answer"
 	rm -f -- "$TEMP_CODE" "$TEMP_EXE"
 
-	[ "$answer" = 'no' ] && {
+	if [ "$answer" = 'no' ]; then
 		[ "$7" ] && die 1 "$7"
 		[ "$tmpval" = 'yes' ] && {
 			die 1 "Forced to build with library $3, but cannot locate. Exiting ..."
 		}
-
-	}
+	else
+		PKG_CONF_USED="$PKG_CONF_USED $2"
+	fi
 
 	return 0
 }
@@ -219,8 +220,8 @@ create_config_make()
 				*$1*)
 					FLAGS="$(eval "printf %s \"\$$1_CFLAGS\"")"
 					LIBS="$(eval "printf %s \"\$$1_LIBS\"")"
-					printf %s\\n "$1_CFLAGS = ${FLAGS%"${FLAGS##*[! ]}"}" \
-						"$1_LIBS = ${LIBS%"${LIBS##*[! ]}"}"
+					[ "${FLAGS}" ] && printf %s\\n "$1_CFLAGS = ${FLAGS%"${FLAGS##*[! ]}"}"
+					[ "${LIBS}" ] && printf %s\\n "$1_LIBS = ${LIBS%"${LIBS##*[! ]}"}"
 				;;
 			esac
 			shift