From 69f3ceb90300b531b7ad1754356aeb6b21994c5b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 28 Mar 2018 09:47:16 +0530 Subject: [PATCH] Merge glfw upstream changes to build on Wayland on FreeBSD --- glfw/glfw.py | 33 +++++++++++++++++++++++++++++---- glfw/source-info.json | 8 ++++---- glfw/wl_init.c | 4 ++++ glfw/wl_platform.h | 4 ++++ 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/glfw/glfw.py b/glfw/glfw.py index 567d7895a..e6460fa5b 100755 --- a/glfw/glfw.py +++ b/glfw/glfw.py @@ -10,6 +10,10 @@ import sys _plat = sys.platform.lower() is_macos = 'darwin' in _plat +is_freebsd = 'freebsd' in _plat +is_netbsd = 'netbsd' in _plat +is_dragonflybsd = 'dragonfly' in _plat +is_bsd = is_freebsd or is_netbsd or is_dragonflybsd base = os.path.dirname(os.path.abspath(__file__)) @@ -18,6 +22,20 @@ def wayland_protocol_file_name(base, ext='c'): return 'wayland-{}-client-protocol.{}'.format(base, ext) +def find_epoll_shim(): + cflags, ldflags, libs = [], [], [] + for candidate in '/usr/local/include/libepoll-shim /usr/include/libepoll-shim /usr/local/include /usr/include'.split(): + if os.path.exists(os.path.join(candidate, 'sys/timerfd.h')): + cflags.append('-I' + candidate) + break + for candidate in '/usr/local/lib /usr/lib'.split(): + if os.path.exists(os.path.join(candidate, 'libepoll-shim.so')): + ldflags.append('-L' + candidate) + libs.append('-lepoll-shim') + break + return cflags, ldflags, libs + + def init_env(env, pkg_config, at_least_version, module='x11'): ans = env.copy() ans.cflags = [ @@ -59,6 +77,12 @@ def init_env(env, pkg_config, at_least_version, module='x11'): for p in ans.wayland_protocols: ans.sources.append(wayland_protocol_file_name(p)) ans.all_headers.append(wayland_protocol_file_name(p, 'h')) + if is_bsd: + epoll_cflags, epoll_libdirs, epoll_libs = find_epoll_shim() + if not epoll_cflags + epoll_libdirs: + raise Exception('Failed to find the epoll-shim package, needed to build the GLFW Wayland backend') + ans.cflags.extend(epoll_cflags) + ans.ldpaths.extend(epoll_libdirs + epoll_libs) for dep in 'wayland-egl wayland-client wayland-cursor xkbcommon'.split(): ans.cflags.extend(pkg_config(dep, '--cflags-only-I')) ans.ldpaths.extend(pkg_config(dep, '--libs')) @@ -100,13 +124,14 @@ def collect_source_information(): 'common': dict(extract_sources('common')), 'wayland_protocols': wayland_protocols, } + joystick = 'null' if is_bsd else 'linux' for group in 'cocoa win32 x11 wayland osmesa'.split(): m = re.search('_GLFW_' + group.upper(), raw) ans[group] = dict(extract_sources('glfw', m.start())) - if group == 'x11': - ans[group]['headers'].append('linux_joystick.h') - ans[group]['sources'].append('linux_joystick.c') - elif group == 'wayland': + if group in ('x11', 'wayland'): + ans[group]['headers'].append('{}_joystick.h'.format(joystick)) + ans[group]['sources'].append('{}_joystick.c'.format(joystick)) + if group == 'wayland': ans[group]['protocols'] = p = [] for m in re.finditer(r'WAYLAND_PROTOCOLS_PKGDATADIR\}/(.+?)"?$', raw, flags=re.M): p.append(m.group(1)) diff --git a/glfw/source-info.json b/glfw/source-info.json index 16e34e9df..8b205fdbd 100644 --- a/glfw/source-info.json +++ b/glfw/source-info.json @@ -55,12 +55,12 @@ "wayland": { "headers": [ "wl_platform.h", - "linux_joystick.h", "posix_time.h", "posix_thread.h", "xkb_unicode.h", "egl_context.h", - "osmesa_context.h" + "osmesa_context.h", + "linux_joystick.h" ], "protocols": [ "stable/xdg-shell/xdg-shell.xml", @@ -73,12 +73,12 @@ "wl_init.c", "wl_monitor.c", "wl_window.c", - "linux_joystick.c", "posix_time.c", "posix_thread.c", "xkb_unicode.c", "egl_context.c", - "osmesa_context.c" + "osmesa_context.c", + "linux_joystick.c" ] }, "wayland_protocols": [ diff --git a/glfw/wl_init.c b/glfw/wl_init.c index 6cd3df720..c19184d0d 100644 --- a/glfw/wl_init.c +++ b/glfw/wl_init.c @@ -1046,8 +1046,10 @@ int _glfwPlatformInit(void) // Sync so we got all initial output events wl_display_roundtrip(_glfw.wl.display); +#ifdef __linux__ if (!_glfwInitJoysticksLinux()) return GLFW_FALSE; +#endif _glfwInitTimerPOSIX(); @@ -1073,7 +1075,9 @@ int _glfwPlatformInit(void) void _glfwPlatformTerminate(void) { +#ifdef __linux__ _glfwTerminateJoysticksLinux(); +#endif _glfwTerminateEGL(); if (_glfw.wl.egl.handle) { diff --git a/glfw/wl_platform.h b/glfw/wl_platform.h index e84d1b57c..ef8419e7b 100644 --- a/glfw/wl_platform.h +++ b/glfw/wl_platform.h @@ -47,7 +47,11 @@ typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR #include "posix_thread.h" #include "posix_time.h" +#ifdef __linux__ #include "linux_joystick.h" +#else +#include "null_joystick.h" +#endif #include "xkb_unicode.h" #include "egl_context.h" #include "osmesa_context.h"