changeset 2748:d8db838d5616

Rewrite the configure GTK and WebKitGTK test section. The old code was way too confusing and complicated with nested ifs. Simplify the code with a primary and alternate webkit package. Display the selected GTK version and WebKit package during configure. This change removed a "WebKitGtk" package, which I am not sure what it was from... but if it causes problems revisit later. --with-gtk4 will override --with-gtk2 now and will always default to GTK3. If --with-gtk2 is used with no GTK2 installed or --with-gtk4 is used with no GTK4 installed use GTK3. Then in a second pass we check the package we have selected and add any necessary defines so the correct code paths are followed during compile.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 28 Dec 2021 11:00:26 +0000
parents c83d6261ce3e
children 1f2c4f7aca4b
files configure configure.in
diffstat 2 files changed, 101 insertions(+), 103 deletions(-) [+]
line wrap: on
line diff
--- a/configure	Mon Dec 27 14:03:33 2021 +0000
+++ b/configure	Tue Dec 28 11:00:26 2021 +0000
@@ -5479,16 +5479,13 @@
 
 
    if test x"$PKG_CFG" != x; then
+      # Figure out the best available GTK packages...
+      # Preference order GTK3>GTK4>GTK2, WebKit2>WebKit1.1>WebKit1.0>WebKit
       GTK_LIBS=""
-      if test $with_gtk2 = "yes"; then
-         DW_DIR=gtk
-         GTK_PACKAGES="gtk+-2.0 gthread-2.0"
-         GTK_LIBS=`$PKG_CFG --silence-errors --libs $GTK_PACKAGES`
-      fi
-      # Default WebKitGTK test is 4.0 for GTK3
-      WEBKIT_PKG="webkit2gtk-4.0"
+      GTK_PACKAGES=""
+      WEBKIT_PKG=""
+      WEBKIT_ALT_PKG=""
       if test $with_gtk4 = "yes"; then
-         DW_DIR=gtk4
          # First try the X11 version so we can call Xlib directly
          # to fill in the holes not available with Wayland
          GTK_PACKAGES="gtk4-x11"
@@ -5497,58 +5494,59 @@
             GTK_PACKAGES="gtk4"
             GTK_LIBS=`$PKG_CFG --silence-errors --libs $GTK_PACKAGES`
          fi
-         # WebKitGTK built for GTK4 becomes 5.0
-         WEBKIT_PKG="webkitgtk-5.0"
+         if test x"$GTK_LIBS" != x; then
+            DW_DIR=gtk4
+            # WebKit2GTK built for GTK4 becomes 5.0
+            WEBKIT_PKG="webkit2gtk-5.0"
+         fi
+      else
+         # Put the GTK2 test here since --with-gtk2 is mutually
+         # exclusive with --with-gtk4
+         if test $with_gtk2 = "yes"; then
+            GTK_PACKAGES="gtk+-2.0 gthread-2.0"
+            GTK_LIBS=`$PKG_CFG --silence-errors --libs $GTK_PACKAGES`
+            if test x"$GTK_LIBS" != x; then
+               DW_DIR=gtk
+               WEBKIT_PKG="webkit-1.1"
+               WEBKIT_ALT_PKG="webkit-1.0"
+            fi
+         fi
       fi
+      # We did not successfully find a GTK installation after
+      # handling --with-gtk2 and --with-gtk4 so try GTK3
       if test x"$GTK_LIBS" = x; then
+         # GTK3 Defaults section
          GTK_PACKAGES="gtk+-3.0"
          GTK_LIBS=`$PKG_CFG --silence-errors --libs $GTK_PACKAGES`
-      else
-         WEBKIT_PKG="webkit-1.1"
+         WEBKIT_PKG="webkit2gtk-4.0"
+         WEBKIT_ALT_PKG="webkitgtk-3.0"
       fi
-      # test for webkit2gtk or webkitgtk packages
-      WEBKIT_CFLAGS=`$PKG_CFG --silence-errors --cflags $WEBKIT_PKG`
-      if test x"$WEBKIT_CFLAGS" = x; then
-         # no webkit2gtk-4.0 or webkitgtk-1.1
-         if test $DW_DIR = "gtk"; then
-            WEBKIT_PKG="webkit-1.0"
-            WEBKIT_CFLAGS=`$PKG_CFG --silence-errors --cflags $WEBKIT_PKG`
-            if test x"$WEBKIT_CFLAGS" = x; then
-               WEBKIT_PKG="WebKitGtk"
-               WEBKIT_CFLAGS=`$PKG_CFG --silence-errors --cflags $WEBKIT_PKG`
-               if test x"$WEBKIT_CFLAGS" = x; then
-                  WEBKIT_LIBS=`$PKG_CFG --silence-errors --libs $WEBKIT_PKG`
-               fi
-            else
-               $as_echo "#define USE_WEBKIT10 1" >>confdefs.h
-
-               WEBKIT_LIBS=`$PKG_CFG --silence-errors --libs $WEBKIT_PKG`
-            fi
-         else
-            if test $DW_DIR = "gtk3"; then
-               WEBKIT_PKG="webkitgtk-3.0"
-               WEBKIT_CFLAGS=`$PKG_CFG --silence-errors --cflags $WEBKIT_PKG`
-               if test x"$WEBKIT_CFLAGS" = x; then
-                  WEBKIT_PKG="webkitgtk-1.0"
-                  WEBKIT_CFLAGS=`$PKG_CFG --silence-errors --cflags $WEBKIT_PKG`
-                  if test x"$WEBKIT_CFLAGS" = x; then
-                     $as_echo "#define USE_WEBKIT10 1" >>confdefs.h
-
-                     WEBKIT_LIBS=`$PKG_CFG --silence-errors --libs $WEBKIT_PKG`
-                  fi
-               else
-                  $as_echo "#define USE_WEBKIT11 1" >>confdefs.h
-
-                  WEBKIT_LIBS=`$PKG_CFG --silence-errors --libs $WEBKIT_PKG`
-               fi
+      echo "checking for GTK version: $DW_DIR"
+      # Test for the preferred WebKit package
+      WEBKIT_LIBS=`$PKG_CFG --silence-errors --libs $WEBKIT_PKG`
+      if test x"$WEBKIT_LIBS" = x; then
+         # Preferred package is not available, try the alternate if defined
+         if test x"$WEBKIT_ALT_PKG" != x; then
+            WEBKIT_LIBS=`$PKG_CFG --silence-errors --libs $WEBKIT_ALT_PKG`
+            if test x"$WEBKIT_LIBS" != x; then
+               WEBKIT_PKG=$WEBKIT_ALT_PKG
             fi
          fi
-      else
-         WEBKIT_LIBS=`$PKG_CFG --silence-errors --libs $WEBKIT_PKG`
-         if test $with_gtk2 = "yes"; then
+      fi
+      echo "checking for WebKit package: $WEBKIT_PKG"
+      WEBKIT_CFLAGS=`$PKG_CFG --silence-errors --cflags $WEBKIT_PKG`
+      # If we got a WebKit package that might work...
+      # Add defintitions necessary for the correct code paths
+      if test x"$WEBKIT_LIBS" != x; then
+         if test "$WEBKIT_PKG" = "webkit-1.0"; then
+            $as_echo "#define USE_WEBKIT10 1" >>confdefs.h
+
+         fi
+         if test "$WEBKIT_PKG" = "webkit-1.1"; then
             $as_echo "#define USE_WEBKIT11 1" >>confdefs.h
 
-         else
+         fi
+         if test "$WEBKIT_PKG" = "webkit2gtk-4.0"; then
             $as_echo "#define USE_WEBKIT2 1" >>confdefs.h
 
          fi
--- a/configure.in	Mon Dec 27 14:03:33 2021 +0000
+++ b/configure.in	Tue Dec 28 11:00:26 2021 +0000
@@ -213,16 +213,13 @@
    LIBS="$LIBS $X_LIBS -lX11"
    AC_CHECK_PROG(PKG_CFG, pkg-config, pkg-config)
    if test x"$PKG_CFG" != x; then
+      # Figure out the best available GTK packages...
+      # Preference order GTK3>GTK4>GTK2, WebKit2>WebKit1.1>WebKit1.0>WebKit
       GTK_LIBS=""
-      if test $with_gtk2 = "yes"; then
-         DW_DIR=gtk
-         GTK_PACKAGES="gtk+-2.0 gthread-2.0"
-         GTK_LIBS=`$PKG_CFG --silence-errors --libs $GTK_PACKAGES`
-      fi
-      # Default WebKitGTK test is 4.0 for GTK3
-      WEBKIT_PKG="webkit2gtk-4.0"
+      GTK_PACKAGES=""
+      WEBKIT_PKG=""
+      WEBKIT_ALT_PKG=""      
       if test $with_gtk4 = "yes"; then
-         DW_DIR=gtk4
          # First try the X11 version so we can call Xlib directly 
          # to fill in the holes not available with Wayland
          GTK_PACKAGES="gtk4-x11"
@@ -231,54 +228,57 @@
             GTK_PACKAGES="gtk4"
             GTK_LIBS=`$PKG_CFG --silence-errors --libs $GTK_PACKAGES`
          fi
-         # WebKitGTK built for GTK4 becomes 5.0
-         WEBKIT_PKG="webkitgtk-5.0"
-      fi
-      if test x"$GTK_LIBS" = x; then
-         GTK_PACKAGES="gtk+-3.0"
-         GTK_LIBS=`$PKG_CFG --silence-errors --libs $GTK_PACKAGES`
+         if test x"$GTK_LIBS" != x; then 
+            DW_DIR=gtk4
+            # WebKit2GTK built for GTK4 becomes 5.0
+            WEBKIT_PKG="webkit2gtk-5.0"
+         fi
       else
-         WEBKIT_PKG="webkit-1.1"
-      fi
-      # test for webkit2gtk or webkitgtk packages
-      WEBKIT_CFLAGS=`$PKG_CFG --silence-errors --cflags $WEBKIT_PKG`
-      if test x"$WEBKIT_CFLAGS" = x; then
-         # no webkit2gtk-4.0 or webkitgtk-1.1
-         if test $DW_DIR = "gtk"; then
-            WEBKIT_PKG="webkit-1.0"
-            WEBKIT_CFLAGS=`$PKG_CFG --silence-errors --cflags $WEBKIT_PKG`
-            if test x"$WEBKIT_CFLAGS" = x; then
-               WEBKIT_PKG="WebKitGtk"
-               WEBKIT_CFLAGS=`$PKG_CFG --silence-errors --cflags $WEBKIT_PKG`
-               if test x"$WEBKIT_CFLAGS" = x; then
-                  WEBKIT_LIBS=`$PKG_CFG --silence-errors --libs $WEBKIT_PKG`
-               fi
-            else
-               AC_DEFINE(USE_WEBKIT10)
-               WEBKIT_LIBS=`$PKG_CFG --silence-errors --libs $WEBKIT_PKG`
-            fi
-         else
-            if test $DW_DIR = "gtk3"; then
-               WEBKIT_PKG="webkitgtk-3.0"
-               WEBKIT_CFLAGS=`$PKG_CFG --silence-errors --cflags $WEBKIT_PKG`
-               if test x"$WEBKIT_CFLAGS" = x; then
-                  WEBKIT_PKG="webkitgtk-1.0"
-                  WEBKIT_CFLAGS=`$PKG_CFG --silence-errors --cflags $WEBKIT_PKG`
-                  if test x"$WEBKIT_CFLAGS" = x; then
-                     AC_DEFINE(USE_WEBKIT10)
-                     WEBKIT_LIBS=`$PKG_CFG --silence-errors --libs $WEBKIT_PKG`
-                  fi
-               else
-                  AC_DEFINE(USE_WEBKIT11)
-                  WEBKIT_LIBS=`$PKG_CFG --silence-errors --libs $WEBKIT_PKG`
-               fi
+         # Put the GTK2 test here since --with-gtk2 is mutually
+         # exclusive with --with-gtk4
+         if test $with_gtk2 = "yes"; then
+            GTK_PACKAGES="gtk+-2.0 gthread-2.0"
+            GTK_LIBS=`$PKG_CFG --silence-errors --libs $GTK_PACKAGES`
+            if test x"$GTK_LIBS" != x; then 
+               DW_DIR=gtk
+               WEBKIT_PKG="webkit-1.1"
+               WEBKIT_ALT_PKG="webkit-1.0"
             fi
          fi
-      else
-         WEBKIT_LIBS=`$PKG_CFG --silence-errors --libs $WEBKIT_PKG`
-         if test $with_gtk2 = "yes"; then
+      fi
+      # We did not successfully find a GTK installation after
+      # handling --with-gtk2 and --with-gtk4 so try GTK3
+      if test x"$GTK_LIBS" = x; then
+         # GTK3 Defaults section
+         GTK_PACKAGES="gtk+-3.0"
+         GTK_LIBS=`$PKG_CFG --silence-errors --libs $GTK_PACKAGES`     
+         WEBKIT_PKG="webkit2gtk-4.0"
+         WEBKIT_ALT_PKG="webkitgtk-3.0"
+      fi
+      echo "checking for GTK version: $DW_DIR"
+      # Test for the preferred WebKit package
+      WEBKIT_LIBS=`$PKG_CFG --silence-errors --libs $WEBKIT_PKG`
+      if test x"$WEBKIT_LIBS" = x; then
+         # Preferred package is not available, try the alternate if defined
+         if test x"$WEBKIT_ALT_PKG" != x; then
+            WEBKIT_LIBS=`$PKG_CFG --silence-errors --libs $WEBKIT_ALT_PKG`
+            if test x"$WEBKIT_LIBS" != x; then
+               WEBKIT_PKG=$WEBKIT_ALT_PKG
+            fi
+         fi
+      fi
+      echo "checking for WebKit package: $WEBKIT_PKG"
+      WEBKIT_CFLAGS=`$PKG_CFG --silence-errors --cflags $WEBKIT_PKG`
+      # If we got a WebKit package that might work... 
+      # Add defintitions necessary for the correct code paths      
+      if test x"$WEBKIT_LIBS" != x; then
+         if test "$WEBKIT_PKG" = "webkit-1.0"; then
+            AC_DEFINE(USE_WEBKIT10)
+         fi
+         if test "$WEBKIT_PKG" = "webkit-1.1"; then
             AC_DEFINE(USE_WEBKIT11)
-         else            
+         fi
+         if test "$WEBKIT_PKG" = "webkit2gtk-4.0"; then
             AC_DEFINE(USE_WEBKIT2)
          fi
       fi