Skip to content

Commit db2d0d1

Browse files
committed
Bug 540801: [GTK4] Build SWT on GTK4
Modify build scripts so bindings can be compiled against GTK4. Change-Id: I7319d7a242f81a589a28070d37038363947a3f8a Signed-off-by: Eric Williams <[email protected]>
1 parent 322aa5c commit db2d0d1

File tree

6 files changed

+99
-11
lines changed

6 files changed

+99
-11
lines changed

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,33 @@
1616
#*******************************************************************************
1717

1818
HELP="
19+
Build GTK4 or GTK3 bindings and (optionally) copy them to binary repository.
1920
Paramaters (specified in this order):
2021
clean - delete *.o and *.so files from current folder. If this is the only paramater, do nothing else.
2122
But if other paramaters are given and this is the first one, then continue with other actions.
2223
24+
One of the following 3:
25+
-gtk3 : Build bindings with GTK3.
26+
-gtk4 : Build bindings with GTK4.
27+
-gtk-all : Build bindings with GTK3 as well as GTK4. Note, this flag triggers cleanups before each build
28+
because a cleanup is required when building different GTK versions for linking to be done correctly.
29+
During active development, if you only want to compile updated files, use -gtk3/-gtk4 flags instead,
30+
however do not forget to do a cleanup in between gtk3/gtk4.
31+
2332
install - copy *.so libraries to binary repository.
2433
2534
--print-outputdir-and-exit - This simply echos the OUTPUT folder where .so libs are copied to,
2635
then exits the script. Used by external
2736
2837
-- Examples:
2938
Most commonly used:
30-
./build.sh install
31-
This will clean everything in your repository, build and then copy .so files to binary repository.
39+
./build.sh -gtk-all install
40+
This will clean everything in your repository, build GTK3 and GTK4, then copy .so files to binary repository.
3241
3342
Also:
3443
./build.sh - only build .so files, do not copy them across. Build according to what GTK_VERSION is set to.
3544
./build.sh clean - clean working directory of *.o and *.so files.
36-
./build.sh install - build.so files and copy to binary repository
45+
./build.sh -gtk4 install - build.so files and copy to binary repository
3746
3847
Also note:
3948
Sometimes you might have to cleanup the binary repository manually as old *.so files are not automatically removed
@@ -283,7 +292,7 @@ if [ "x${1}" = "xclean" ]; then
283292
shift
284293

285294
# if there are no more other parameters, exit.
286-
# don't exit if there are more paramaters. Useful for one-liners like: ./build.sh clean install
295+
# don't exit if there are more paramaters. Useful for one-liners like: ./build.sh clean -gtk-all install
287296
if [ "$1" = "" ]; then
288297
exit $?
289298
fi
@@ -293,6 +302,28 @@ fi
293302
# Announce our target
294303
func_echo_plus "Building SWT/GTK+ for Architectures: $SWT_OS $SWT_ARCH"
295304

305+
func_build_gtk4 () {
306+
export GTK_VERSION=4.0
307+
308+
# Dictate Webkit2 Extension only if pkg-config flags exist
309+
pkg-config --exists webkit2gtk-web-extension-4.0
310+
if [ $? == 0 ]; then
311+
export BUILD_WEBKIT2EXTENSION="yes";
312+
else
313+
func_echo_error "Warning: Cannot compile Webkit2 Extension because 'pkg-config --exists webkit2gtk-web-extension-4-0' check failed. Please install webkitgtk4-devel.ARCH on your system."
314+
fi
315+
316+
func_echo_plus "Building GTK4 bindings:"
317+
${MAKE_TYPE} -f $MAKEFILE all $MAKE_CAIRO $MAKE_AWT "${@}"
318+
RETURN_VALUE=$? #make can return 1 or 2 if it fails. Thus need to cache it in case it's used programmatically somewhere.
319+
if [ "$RETURN_VALUE" -eq 0 ]; then
320+
func_echo_plus "GTK4 Build succeeded"
321+
else
322+
func_echo_error "GTK4 Build failed, aborting further actions.."
323+
exit $RETURN_VALUE
324+
fi
325+
}
326+
296327
func_build_gtk3 () {
297328
export GTK_VERSION=3.0
298329

@@ -315,5 +346,22 @@ func_build_gtk3 () {
315346
fi
316347
}
317348

318-
func_build_gtk3 "$@"
319-
349+
if [ "$1" = "-gtk-all" ]; then
350+
shift
351+
func_echo_plus "Note: When building multiple GTK versions, a cleanup is required (and automatically performed) between them."
352+
func_clean_up
353+
func_build_gtk4 "$@"
354+
func_clean_up
355+
func_build_gtk3 "$@"
356+
elif [ "$1" = "-gtk4" ]; then
357+
shift
358+
func_build_gtk4 "$@"
359+
elif [ "$1" = "-gtk3" ]; then
360+
shift
361+
func_build_gtk3 "$@"
362+
elif [ "${GTK_VERSION}" = "4.0" ]; then
363+
func_build_gtk4 "$@"
364+
elif [ "${GTK_VERSION}" = "3.0" -o "${GTK_VERSION}" = "" ]; then
365+
export GTK_VERSION="3.0"
366+
func_build_gtk3 "$@"
367+
fi

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/make_linux.mak

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ endif
2727
include make_common.mak
2828

2929
SWT_VERSION=$(maj_ver)$(min_ver)r$(rev)
30-
GTK_VERSION=3.0
30+
GTK_VERSION?=3.0
3131

3232
# Define the various shared libraries to be build.
3333
WS_PREFIX = gtk
3434
SWT_PREFIX = swt
3535
AWT_PREFIX = swt-awt
36+
ifeq ($(GTK_VERSION), 4.0)
37+
SWTPI_PREFIX = swt-pi4
38+
else
3639
SWTPI_PREFIX = swt-pi3
40+
endif
3741
CAIRO_PREFIX = swt-cairo
3842
ATK_PREFIX = swt-atk
3943
WEBKIT_PREFIX = swt-webkit
@@ -59,7 +63,11 @@ CAIROLIBS = `pkg-config --libs-only-L cairo` -lcairo
5963

6064
# Do not use pkg-config to get libs because it includes unnecessary dependencies (i.e. pangoxft-1.0)
6165
GTKCFLAGS = `pkg-config --cflags gtk+-$(GTK_VERSION) gtk+-unix-print-$(GTK_VERSION)`
66+
ifeq ($(GTK_VERSION), 4.0)
67+
GTKLIBS = `pkg-config --libs-only-L gtk+-$(GTK_VERSION) gthread-2.0` $(XLIB64) -L/usr/X11R6/lib -lgtk-4 -lcairo -lgthread-2.0
68+
else
6269
GTKLIBS = `pkg-config --libs-only-L gtk+-$(GTK_VERSION) gthread-2.0` $(XLIB64) -L/usr/X11R6/lib -lgtk-3 -lgdk-3 -lcairo -lgthread-2.0
70+
endif
6371

6472
AWT_LFLAGS = -shared ${SWT_LFLAGS}
6573
AWT_LIBS = -L$(AWT_LIB_PATH) -ljawt

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44
# Build servers call build.sh directly.
55

66
all:
7-
./build.sh install
7+
./build.sh -gtk-all install
8+
9+
gtk4:
10+
./build.sh -gtk4 install
11+
12+
gtk4-build-only:
13+
./build.sh -gtk4
14+
15+
gtk3:
16+
./build.sh -gtk3 install
817

918
clean:
1019
./build.sh clean

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575

7676
// Hard-link code generated from GTK.java to LIB_GTK
7777
#define GTK_LOAD_FUNCTION(var, name) LOAD_FUNCTION_LIB(var, LIB_GTK, name)
78-
// Hard-link code generated from GTK.java to LIB_GDK
78+
// Hard-link code generated from GDK.java to LIB_GDK
7979
#define GDK_LOAD_FUNCTION(var, name) LOAD_FUNCTION_LIB(var, LIB_GDK, name)
8080

8181
#ifdef _WIN32
@@ -101,9 +101,12 @@
101101

102102

103103
#ifdef GDK_WINDOWING_X11
104-
104+
#if GTK_CHECK_VERSION(3,94,0)
105+
// GTK4 does not need gtkx.h
106+
#else
105107
#include <gdk/gdkx.h>
106108
#include <gtk/gtkx.h>
109+
#endif
107110
#else
108111

109112
#define NO_GDK_1IS_1X11_1DISPLAY

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,14 @@
3636
#define LIB_ATK "libatk-1.0-0.dll"
3737
#define LIB_FONTCONFIG "libfontconfig-1.dll"
3838
#else
39+
#if GTK_CHECK_VERSION(3,94,0)
40+
#define LIB_GTK "libgtk-4.so.0"
41+
// Point GDK to GTK for GTK4
42+
#define LIB_GDK "libgtk-4.so.0"
43+
#else
3944
#define LIB_GTK "libgtk-3.so.0"
4045
#define LIB_GDK "libgdk-3.so.0"
46+
#endif
4147
#define LIB_GTHREAD "libgthread-2.0.so.0"
4248
#define LIB_GLIB "libglib-2.0.so.0"
4349
#define LIB_ATK "libatk-1.0.so.0"

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,21 @@ public class OS extends C {
7373

7474
/** Initialization; load native libraries */
7575
static {
76-
Library.loadLibrary("swt-pi3");
76+
String propertyName = "SWT_GTK4";
77+
String gtk4 = getEnvironmentalVariable (propertyName);
78+
if (gtk4 != null && gtk4.equals("0")) {
79+
try {
80+
Library.loadLibrary("swt-pi3");
81+
} catch (Throwable e) {
82+
Library.loadLibrary("swt-pi4");
83+
}
84+
} else {
85+
try {
86+
Library.loadLibrary("swt-pi4");
87+
} catch (Throwable e) {
88+
Library.loadLibrary("swt-pi3");
89+
}
90+
}
7791
cachejvmptr();
7892
}
7993

0 commit comments

Comments
 (0)