bochs-emu / Bochs

Bochs - Cross Platform x86 Emulator Project
https://bochs.sourceforge.io/
GNU Lesser General Public License v2.1
865 stars 100 forks source link

Building the debugger GUI with GTK3 #266

Closed maronz closed 6 months ago

maronz commented 8 months ago

On a current Linux Mint system (which is based on Ubuntu 22.04) one can build Bochs simply by having the g++ and the libx11-dev packages installed. I'm generally happy enough to use the simple 'X11' GUI, so that works so far.

For some other project I might have added also the libgtk-3-dev package. Lets assume I want to now use the Bochs debugger GUI. I'd therefore perform a rebuild with: configure --enable-debugger

At this stage one would be forced to install additionally: libgtk2.0-dev (even though the GTK3 dev files are already available).

I've done a small "tweak", which should amend 'configure' insofar as to also perform a check for GTK3, if the GTK2 dev files can't be found:

--- Bochs-5c715aa/bochs/configure.ac    2024-02-10 03:03:32.000000000 +1300
+++ Bochs-5c715aa+/bochs/configure.ac   2024-02-10 14:45:58.904346461 +1300
@@ -2715,6 +2715,13 @@ if test "$needs_gtk2" = 1; then
         TOOLKIT_CXXFLAGS="`pkg-config --cflags gtk+-2.0`"
         LIBS="$LIBS `pkg-config --libs gtk+-2.0`"
         bx_have_gtk_version=2
+      else
+        pkg-config --exists gtk+-3.0
+        if test x$? = x0; then
+          TOOLKIT_CXXFLAGS="`pkg-config --cflags gtk+-3.0`"
+          LIBS="$LIBS `pkg-config --libs gtk+-3.0`"
+          bx_have_gtk_version=3
+        fi
       fi
     fi
   else

This seems to work for me, but I'm not really happy to repeat this block of code. Probably some refactoring could be done to achieve a better result. But since I'm not a user of any of the other interfaces, I did not want to break things.

stlintel commented 7 months ago

This is what I see in the configure script:

# some display libraries and the enhanced debugger may depend on the GTK+ software package
bx_have_gtk_version=0
if test "$needs_gtk2" = 1; then
  # pkg-config is required to set TOOLKIT_CXXFLAGS and LIBS
  if test "$PKGCONFIG" != not_found; then
    # if wxGTK is based on GTK 3.0, use it for gui debugger to avoid conflicts
    if test "$with_wx" = yes -a "$wx_needs_gdk_version" = 3; then
      pkg-config --exists gtk+-3.0
      if test x$? = x0; then
        TOOLKIT_CXXFLAGS="`pkg-config --cflags gtk+-3.0`"
        LIBS="$LIBS `pkg-config --libs gtk+-3.0`"
        bx_have_gtk_version=3
      fi
    else
      pkg-config --exists gtk+-2.0
      if test x$? = x0; then
        TOOLKIT_CXXFLAGS="`pkg-config --cflags gtk+-2.0`"
        LIBS="$LIBS `pkg-config --libs gtk+-2.0`"
        bx_have_gtk_version=2
      fi
    fi
  else
    echo "ERROR: pkg-config was not found, unable to access the gtk+-2.0 package."
    echo "The gui debugger support is disabled now."
  fi
fi

The code for GTK 3 is already there:

  # if wxGTK is based on GTK 3.0, use it for gui debugger to avoid conflicts
    if test "$with_wx" = yes -a "$wx_needs_gdk_version" = 3; then
      pkg-config --exists gtk+-3.0
      if test x$? = x0; then
        TOOLKIT_CXXFLAGS="`pkg-config --cflags gtk+-3.0`"
        LIBS="$LIBS `pkg-config --libs gtk+-3.0`"
        bx_have_gtk_version=3
      fi

What did you done specifically ?

maronz commented 7 months ago

I have to admit that I could have expressed myself more clearly. My issue came up when I wanted to build the debugger GUI with GTK3, but without having the required libraries for GTK2 or WX.

It might help if I put a few remarks into the following expanded diff:

  # some display libraries and the enhanced debugger may depend on the GTK+ software package
  bx_have_gtk_version=0
  if test "$needs_gtk2" = 1; then
    # pkg-config is required to set TOOLKIT_CXXFLAGS and LIBS
    if test "$PKGCONFIG" != not_found; then
      # if wxGTK is based on GTK 3.0, use it for gui debugger to avoid conflicts
      if test "$with_wx" = yes -a "$wx_needs_gdk_version" = 3; then
        pkg-config --exists gtk+-3.0                          ### with    WX, check for GTK3
        if test x$? = x0; then
          TOOLKIT_CXXFLAGS="`pkg-config --cflags gtk+-3.0`"
          LIBS="$LIBS `pkg-config --libs gtk+-3.0`"
          bx_have_gtk_version=3
        fi
      else
        pkg-config --exists gtk+-2.0                          ### without WX, check for GTK2
        if test x$? = x0; then
          TOOLKIT_CXXFLAGS="`pkg-config --cflags gtk+-2.0`"
          LIBS="$LIBS `pkg-config --libs gtk+-2.0`"
          bx_have_gtk_version=2
+       else
+         pkg-config --exists gtk+-3.0                        ### without WX, check for GTK3
+         if test x$? = x0; then
+           TOOLKIT_CXXFLAGS="`pkg-config --cflags gtk+-3.0`"
+           LIBS="$LIBS `pkg-config --libs gtk+-3.0`"
+           bx_have_gtk_version=3
+         fi
        fi
      fi
    else
      echo "ERROR: pkg-config was not found, unable to access the gtk+-2.0 package."
      echo "The gui debugger support is disabled now."
    fi
  fi
vruppert commented 6 months ago

It looks okay to me, so I have applied the changes. I cannot test it here, since wxWidgets still uses GTK2.