configure: add -pkg-config option to control pkg-config usage
authorGirish Ramakrishnan <girish.1.ramakrishnan@nokia.com>
Wed, 4 Apr 2012 22:02:11 +0000 (15:02 -0700)
committerQt by Nokia <qt-info@nokia.com>
Wed, 11 Apr 2012 17:14:43 +0000 (19:14 +0200)
Currently, for host builds, pkg-config usage is autodetected based
on it's availability in the mkspec or the PATH. For xcompile builds,
pkg-config is disabled unless -force-pkg-config is passed.

-force-pkg-config is poorly named since it doesn't reflect the fact
that it applies only to xplatform builds. It is in fact the only way to
enable pkg-config in xcompile builds. And when passed, it doesn't actually
force anything since all it does is check env variables. To add to the
confusion, it prints a warning even if the env variables are setup correctly.

This patch remedies the situation. It adds (-no)-pkg-config. The flag works
for both host and xcompile builds.

By default, the value is 'auto'. In this mode, it will try try to detect pkg-config
from the path. If found, it will be used. For xcompiled builds, we use some heuristics
to determine if the pkg-config is actually usable:
1. if -sysroot is not set and the environment variables PKG_CONFIG_LIBDIR or
    PKG_CONFIG_SYSROOT_DIR are not set, we disable pkg-config.
2. if -sysroot is set, then we setup PKG_CONFIG_LIBDIR and PKG_CONFIG_SYSROOT_DIR
   automatically (provided $SYSROOT/usr/lib/pkgconfig exists).

If the value is 'yes', configure will error if it's heuristics fail to detect a usable
pkg-config.

If the value is 'no', pkg-config usage is disabled.

If the value is 'force', configure will skip it's heuristics and use pkg-config anyway.
This mode is useful, for example, when compiling for 32-bit on 64-bit systems.

This change also removes references to PKG_CONFIG_SYSROOT (PKG_CONFIG_SYSROOT_DIR
is the correct environment variable).

Change-Id: I07fc8d48603c65a60de0336fc6276e90fcb41430
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
configure

index 6ed6969..0bd115e 100755 (executable)
--- a/configure
+++ b/configure
@@ -688,6 +688,7 @@ CFG_AUDIO_BACKEND=auto
 CFG_V8SNAPSHOT=auto
 CFG_QML_DEBUG=yes
 CFG_JAVASCRIPTCORE_JIT=auto
+CFG_PKGCONFIG=auto
 
 # Target architecture
 CFG_ARCH=
@@ -890,7 +891,7 @@ while [ "$#" -gt 0 ]; do
         VAL=no
         ;;
     #Qt style yes options
-    -profile|-shared|-static|-sm|-xinerama|-xshape|-xsync|-xinput|-xinput2|-egl|-reduce-exports|-pch|-separate-debug-info|-stl|-freetype|-xcursor|-xfixes|-xrandr|-xrender|-mitshm|-fontconfig|-xkb|-xcb|-eglfs|-nis|-dbus|-dbus-linked|-glib|-gstreamer|-gtkstyle|-cups|-iconv|-largefile|-h|-help|-v|-verbose|-debug|-release|-fast|-accessibility|-confirm-license|-gnumake|-framework|-debug-and-release|-exceptions|-harfbuzz|-prefix-install|-silent|-optimized-qmake|-dwarf2|-reduce-relocations|-sse|-openssl|-openssl-linked|-phonon-backend|-audio-backend|-qml-debug|-javascript-jit|-rpath|-force-pkg-config|-icu|-force-asserts|-testcocoon)
+    -profile|-shared|-static|-sm|-xinerama|-xshape|-xsync|-xinput|-xinput2|-egl|-reduce-exports|-pch|-separate-debug-info|-stl|-freetype|-xcursor|-xfixes|-xrandr|-xrender|-mitshm|-fontconfig|-xkb|-xcb|-eglfs|-nis|-dbus|-dbus-linked|-glib|-gstreamer|-gtkstyle|-cups|-iconv|-largefile|-h|-help|-v|-verbose|-debug|-release|-fast|-accessibility|-confirm-license|-gnumake|-framework|-debug-and-release|-exceptions|-harfbuzz|-prefix-install|-silent|-optimized-qmake|-dwarf2|-reduce-relocations|-sse|-openssl|-openssl-linked|-phonon-backend|-audio-backend|-qml-debug|-javascript-jit|-rpath|-pkg-config|-force-pkg-config|-icu|-force-asserts|-testcocoon)
         VAR=`echo $1 | sed "s,^-\(.*\),\1,"`
         VAL=yes
         ;;
@@ -1080,8 +1081,15 @@ while [ "$#" -gt 0 ]; do
     hostbindir)
         QT_HOST_BINS="$VAL"
         ;;
+    pkg-config)
+        if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
+            CFG_PKGCONFIG="$VAL"
+        else
+            UNKNOWN_OPT=yes
+        fi
+        ;;
     force-pkg-config)
-        QT_FORCE_PKGCONFIG=yes
+        CFG_PKGCONFIG="force"
         ;;
     docdir)
         QT_INSTALL_DOCS="$VAL"
@@ -2465,50 +2473,6 @@ if [ "$CFG_DEBUG_RELEASE" = "yes" ]; then
     QT_CONFIG="$QT_CONFIG build_all"
 fi
 
-if [ -z "$PKG_CONFIG" ]; then
-    # See if PKG_CONFIG is set in the mkspec:
-    PKG_CONFIG=`getXQMakeConf PKG_CONFIG`
-fi
-if [ -z "$PKG_CONFIG" ]; then
-    PKG_CONFIG=`"$WHICH" pkg-config 2>/dev/null`
-fi
-
-# Work out if we can use pkg-config
-if [ "$QT_CROSS_COMPILE" = "yes" ]; then
-    if [ "$QT_FORCE_PKGCONFIG" = "yes" ]; then
-        echo >&2 ""
-        echo >&2 "You have asked to use pkg-config and are cross-compiling."
-        echo >&2 "Please make sure you have a correctly set-up pkg-config"
-        echo >&2 "environment!"
-        echo >&2 ""
-        if [ -z "$PKG_CONFIG_LIBDIR" ]; then
-            echo >&2 ""
-            echo >&2 "Warning: PKG_CONFIG_LIBDIR has not been set.  This could mean"
-            echo >&2 "the host's .pc files will be used (even if you set PKG_CONFIG_PATH)."
-            echo >&2 "This is probably not what you want."
-            echo >&2 ""
-        elif [ -z "$PKG_CONFIG_SYSROOT" ] && [ -z "$PKG_CONFIG_SYSROOT_DIR" ]; then
-            echo >&2 ""
-            echo >&2 "Warning: PKG_CONFIG_SYSROOT/PKG_CONFIG_SYSROOT_DIR has not"
-            echo >&2 "been set. This means your toolchain's .pc files must contain"
-            echo >&2 "the paths to the toolchain's libraries & headers. If configure"
-            echo >&2 "tests are failing, please check these files."
-            echo >&2 ""
-        fi
-    else
-        echo >&2 ""
-        echo >&2 "You have not explicitly asked to use pkg-config and are cross-compiling."
-        echo >&2 "pkg-config will not be used to automatically query cflag/lib parameters for"
-        echo >&2 "dependencies"
-        echo >&2 ""
-        PKG_CONFIG=""
-    fi
-fi
-
-if [ ! -n "$PKG_CONFIG" ]; then
-    QT_CONFIG="$QT_CONFIG no-pkg-config"
-fi
-
 # pass on $CFG_SDK to the configure tests.
 if [ '!' -z "$CFG_SDK" ]; then
     MAC_CONFIG_TEST_COMMANDLINE="$MAC_CONFIG_TEST_COMMANDLINE -sdk $CFG_SDK"
@@ -3072,6 +3036,13 @@ Configure options:
     -I <string> ........ Add an explicit include path.
     -L <string> ........ Add an explicit library path.
 
+ +  -pkg-config ........ Use pkg-config to detect include and library paths. By default,
+                         configure determines whether to use pkg-config or not with
+                         some heuristics such as checking the environment variables.
+    -no-pkg-config ..... Disable use of pkg-config.
+    -force-pkg-config .. Force usage of pkg-config (skips pkg-config usability
+                         detection heuristic).
+
     -help, -h .......... Display this information.
 
 Third Party Libraries:
@@ -3644,6 +3615,70 @@ if true; then ###[ '!' -f "$outpath/bin/qmake" ];
 fi # Build qmake
 
 #-------------------------------------------------------------------------------
+# Detect pkg-config
+#-------------------------------------------------------------------------------
+if [ -z "$PKG_CONFIG" ]; then
+    # See if PKG_CONFIG is set in the mkspec:
+    PKG_CONFIG=`getXQMakeConf PKG_CONFIG`
+fi
+if [ -z "$PKG_CONFIG" ]; then
+    PKG_CONFIG=`"$WHICH" pkg-config 2>/dev/null`
+fi
+
+if [ "$CFG_PKGCONFIG" = "no" ]; then
+    PKG_CONFIG=
+elif [ "$CFG_PKGCONFIG" = "force" ]; then
+    echo >&2 ""
+    echo >&2 "You have asked to use pkg-config. Please make sure you have"
+    echo >&2 "a correctly setup pkg-config environment!"
+    echo >&2 ""
+elif [ -n "$PKG_CONFIG" ]; then
+    # found a pkg-config
+    if [ "$QT_CROSS_COMPILE" = "yes" ]; then
+        # when xcompiling, check environment to see if it's actually usable
+        if [ -z "$PKG_CONFIG_LIBDIR" ]; then
+            if [ -n "$CFG_SYSROOT" ] && [ -d "$CFG_SYSROOT/usr/lib/pkgconfig" ]; then
+                PKG_CONFIG_LIBDIR=$CFG_SYSROOT/usr/lib/pkgconfig:$CFG_SYSROOT/usr/share/pkgconfig
+                export PKG_CONFIG_LIBDIR
+                echo >&2 "Note: PKG_CONFIG_LIBDIR automatically set to $PKG_CONFIG_LIBDIR"
+            elif [ "$CFG_PKGCONFIG" = "yes" ]; then
+                echo >&2 "Error: PKG_CONFIG_LIBDIR has not been set. This could mean"
+                echo >&2 "the host's .pc files will be used (even if you set PKG_CONFIG_PATH)."
+                echo >&2 "Set this variable to the directory that contains target .pc files"
+                echo >&2 "for pkg-config to function correctly when cross-compiling or"
+                echo >&2 "use -force-pkg-config to override this test."
+                exit 101
+            else
+                PKG_CONFIG=
+                echo >&2 "Warning: Disabling pkg-config since PKG_CONFIG_LIBDIR is not set."
+            fi
+        fi
+        if [ -z "$PKG_CONFIG_SYSROOT_DIR" ]; then
+            if [ -n "$CFG_SYSROOT" ]; then
+                PKG_CONFIG_SYSROOT_DIR=$CFG_SYSROOT
+                export PKG_CONFIG_SYSROOT_DIR
+                echo >&2 "Note: PKG_CONFIG_SYSROOT_DIR automatically set to $PKG_CONFIG_SYSROOT_DIR"
+            elif [ "$CFG_PKGCONFIG" = "yes" ]; then
+                echo >&2 "Error: PKG_CONFIG_SYSROOT_DIR has not been set. Set this variable"
+                echo >&2 "to your sysroot for pkg-config to function correctly when cross-compiling"
+                echo >&2 "or use -force-pkg-config to override this test."
+                exit 101
+            else
+                PKG_CONFIG=
+                echo >&2 "Warning: Disabling pkg-config since PKG_CONFIG_SYSROOT_DIR is not set."
+            fi
+        fi
+    fi
+elif [ "$CFG_PKGCONFIG" = "yes" ]; then
+    echo >&2 "Could not detect pkg-config from mkspec or PATH."
+    exit 101
+fi
+
+if [ -z "$PKG_CONFIG" ]; then
+    QT_CONFIG="$QT_CONFIG no-pkg-config"
+fi
+
+#-------------------------------------------------------------------------------
 # tests that need qmake
 #-------------------------------------------------------------------------------
 
@@ -5914,6 +5949,11 @@ if [ "$CFG_DEBUG_RELEASE" = "yes" ]; then
 else
    echo "Debug .................. $CFG_DEBUG"
 fi
+if [ -n "$PKG_CONFIG" ]; then
+    echo "pkg-config ............. yes"
+else
+    echo "pkg-config ............. no"
+fi
 [ "$CFG_DBUS" = "no" ]     && echo "QtDBus module .......... no"
 [ "$CFG_DBUS" = "yes" ]    && echo "QtDBus module .......... yes (run-time)"
 [ "$CFG_DBUS" = "linked" ] && echo "QtDBus module .......... yes (linked)"