Link against glib statically on Darwin

This is needed to allow building a redistributable QEMU package.
Note that we cannot use -Bstatic/-Bdynamic options as these are not
support by ld64 on Darwin and hence we need to specify the full path
to the static libraries.

Change-Id: I9737efb2427fb977d6146ba678cbbe79a4c88ff4
diff --git a/configure b/configure
index 23b5e93..fc40c89 100755
--- a/configure
+++ b/configure
@@ -3803,7 +3803,27 @@
 for i in $glib_modules; do
     if $pkg_config --atleast-version=$glib_req_ver $i; then
         glib_cflags=$($pkg_config --cflags $i)
-        glib_libs=$($pkg_config --libs $i)
+        if test "$darwin" = "yes"; then
+          libdirs=()
+          glib_libs=()
+          for l in $(pkg-config --static --libs $i); do
+            case "${l}" in
+              -L*) libdirs+=("-B${l#-L}") ;;
+              -l*)
+                lib="$($cc ${libdirs[@]} -print-file-name=lib${l#-l}.a)"
+                if [[ -f ${lib} ]]; then
+                  glib_libs+=("${lib}")
+                else
+                 glib_libs+=("${l}")
+                fi
+                ;;
+              *) glib_libs+=("${l}")
+            esac
+          done
+          glib_libs="${glib_libs[@]}"
+        else
+          glib_libs=$($pkg_config --libs $i)
+        fi
         QEMU_CFLAGS="$glib_cflags $QEMU_CFLAGS"
         LIBS="$glib_libs $LIBS"
         libs_qga="$glib_libs $libs_qga"