Skip to content

Commit 5827840

Browse files
committed
Add FreeBSD support
Partially based on an earlier porting attempt by Johannes Lundberg from https://github.com/FreeBSDDesktop/freebsd-ports-graphics (specifically, the vt switching code)
1 parent 903e445 commit 5827840

24 files changed

+383
-76
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ weston-nested-client
6767
weston-presentation-shm
6868
weston-resizor
6969
weston-scaler
70+
weston-simple-dmabuf-drm
7071
weston-simple-dmabuf-intel
7172
weston-simple-dmabuf-v4l
7273
weston-simple-egl

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ $(if $(findstring unstable,$1),unstable,stable)
16091609
endef
16101610

16111611
define protoname
1612-
$(shell echo $1 | sed 's/\([a-z\-]\+\)-[a-z]\+-v[0-9]\+/\1/')
1612+
$(shell echo $1 | $(SED) 's/\([a-z\-]\+\)-[a-z]\+-v[0-9]\+/\1/')
16131613
endef
16141614

16151615
protocol/%-protocol.c : $(WAYLAND_PROTOCOLS_DATADIR)/$$(call protostability,$$*)/$$(call protoname,$$*)/$$*.xml

clients/desktop-shell.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
#include <ctype.h>
4242
#include <time.h>
4343
#include <assert.h>
44+
#ifdef __FreeBSD__
45+
#include <signal.h>
46+
#endif
4447

4548
#include <wayland-client.h>
4649
#include "window.h"

clients/terminal.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@
3232
#include <unistd.h>
3333
#include <math.h>
3434
#include <time.h>
35+
#ifdef __linux__
3536
#include <pty.h>
37+
#elif __FreeBSD__
38+
#include <libutil.h>
39+
#endif
3640
#include <ctype.h>
3741
#include <cairo.h>
3842
#include <sys/epoll.h>

clients/weston-info.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,15 @@ clock_name(clockid_t clk_id)
695695
static const char *names[] = {
696696
[CLOCK_REALTIME] = "CLOCK_REALTIME",
697697
[CLOCK_MONOTONIC] = "CLOCK_MONOTONIC",
698+
#ifdef __linux__
698699
[CLOCK_MONOTONIC_RAW] = "CLOCK_MONOTONIC_RAW",
699700
[CLOCK_REALTIME_COARSE] = "CLOCK_REALTIME_COARSE",
700701
[CLOCK_MONOTONIC_COARSE] = "CLOCK_MONOTONIC_COARSE",
702+
#elif __FreeBSD__
703+
[CLOCK_REALTIME_FAST] = "CLOCK_REALTIME_FAST",
704+
[CLOCK_MONOTONIC_FAST] = "CLOCK_MONOTONIC_FAST",
705+
#endif
706+
701707
#ifdef CLOCK_BOOTTIME
702708
[CLOCK_BOOTTIME] = "CLOCK_BOOTTIME",
703709
#endif

compositor/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@
4141
#include <sys/socket.h>
4242
#include <libinput.h>
4343
#include <sys/time.h>
44+
#ifdef __linux__
4445
#include <linux/limits.h>
46+
#else
47+
#include <sys/param.h>
48+
#endif
4549

4650
#ifdef HAVE_LIBUNWIND
4751
#define UNW_LOCAL_ONLY
@@ -681,9 +685,14 @@ clock_name(clockid_t clk_id)
681685
static const char *names[] = {
682686
[CLOCK_REALTIME] = "CLOCK_REALTIME",
683687
[CLOCK_MONOTONIC] = "CLOCK_MONOTONIC",
688+
#ifdef __linux__
684689
[CLOCK_MONOTONIC_RAW] = "CLOCK_MONOTONIC_RAW",
685690
[CLOCK_REALTIME_COARSE] = "CLOCK_REALTIME_COARSE",
686691
[CLOCK_MONOTONIC_COARSE] = "CLOCK_MONOTONIC_COARSE",
692+
#elif __FreeBSD__
693+
[CLOCK_REALTIME_FAST] = "CLOCK_REALTIME_FAST",
694+
[CLOCK_MONOTONIC_FAST] = "CLOCK_MONOTONIC_FAST",
695+
#endif
687696
#ifdef CLOCK_BOOTTIME
688697
[CLOCK_BOOTTIME] = "CLOCK_BOOTTIME",
689698
#endif

configure.ac

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,27 @@ AC_CHECK_HEADERS([execinfo.h])
107107

108108
AC_CHECK_FUNCS([mkostemp strchrnul initgroups posix_fallocate])
109109

110+
AC_MSG_CHECKING([for program_invocation_short_name])
111+
AC_TRY_COMPILE([#include <errno.h>],
112+
[const char *pn = program_invocation_short_name;],
113+
AC_DEFINE(HAVE_PROGRAM_INVOCATION_SHORT_NAME, 1, [Define to 1 if program_invocation_short_name exists])
114+
AC_MSG_RESULT(yes),
115+
AC_MSG_RESULT(no))
116+
117+
AC_MSG_CHECKING([for getprogname])
118+
AC_TRY_COMPILE([#include <stdlib.h>],
119+
[getprogname();],
120+
AC_DEFINE(HAVE_GETPROGNAME, 1, [Define to 1 if getprogname exists])
121+
AC_MSG_RESULT(yes),
122+
AC_MSG_RESULT(no))
123+
124+
AH_BOTTOM([#ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME
125+
#ifdef HAVE_GETPROGNAME
126+
#include <stdlib.h>
127+
#define program_invocation_short_name getprogname()
128+
#endif
129+
#endif])
130+
110131
# check for libdrm as a build-time dependency only
111132
# libdrm 2.4.30 introduced drm_fourcc.h.
112133
PKG_CHECK_MODULES(LIBDRM, [libdrm >= 2.4.30], [], [AC_MSG_ERROR([

libweston/compositor-drm.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
#include <fcntl.h>
3535
#include <unistd.h>
3636
#include <linux/input.h>
37+
#ifdef __linux__
3738
#include <linux/vt.h>
39+
#endif
3840
#include <assert.h>
3941
#include <sys/mman.h>
4042
#include <dlfcn.h>
@@ -3739,11 +3741,26 @@ drm_device_is_kms(struct drm_backend *b, struct udev_device *device)
37393741
static struct udev_device*
37403742
find_primary_gpu(struct drm_backend *b, const char *seat)
37413743
{
3744+
struct udev_device *device;
3745+
#ifndef __FreeBSD__
3746+
struct udev_device *drm_device, *pci;
37423747
struct udev_enumerate *e;
37433748
struct udev_list_entry *entry;
37443749
const char *path, *device_seat, *id;
3745-
struct udev_device *device, *drm_device, *pci;
3750+
#endif
37463751

3752+
#ifdef __FreeBSD__
3753+
// libudev-devd doesn't support matching
3754+
device = udev_device_new_from_syspath(b->udev, "/dev/dri/card0");
3755+
/* Make sure this device is actually capable of modesetting;
3756+
* if this call succeeds, b->drm.{fd,filename} will be set,
3757+
* and any old values freed. */
3758+
if (!drm_device_is_kms(b, device)) {
3759+
udev_device_unref(device);
3760+
device = NULL;
3761+
}
3762+
return device;
3763+
#else
37473764
e = udev_enumerate_new(b->udev);
37483765
udev_enumerate_add_match_subsystem(e, "drm");
37493766
udev_enumerate_add_match_sysname(e, "card[0-9]*");
@@ -3811,6 +3828,7 @@ find_primary_gpu(struct drm_backend *b, const char *seat)
38113828

38123829
udev_enumerate_unref(e);
38133830
return drm_device;
3831+
#endif
38143832
}
38153833

38163834
static void

libweston/compositor-x11.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
#include <errno.h>
3838
#include <sys/time.h>
3939
#include <sys/shm.h>
40+
#ifdef __FreeBSD__
41+
#include <sys/stat.h>
42+
#endif
4043
#include <linux/input.h>
4144

4245
#include <xcb/xcb.h>

libweston/compositor.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5435,10 +5435,18 @@ weston_compositor_set_presentation_clock_software(
54355435
{
54365436
/* In order of preference */
54375437
static const clockid_t clocks[] = {
5438+
#ifdef __linux__
54385439
CLOCK_MONOTONIC_RAW, /* no jumps, no crawling */
54395440
CLOCK_MONOTONIC_COARSE, /* no jumps, may crawl, fast & coarse */
5441+
#elif __FreeBSD__
5442+
CLOCK_MONOTONIC_FAST, /* no jumps, may crawl, fast & coarse */
5443+
#endif
54405444
CLOCK_MONOTONIC, /* no jumps, may crawl */
5445+
#ifdef __linux__
54415446
CLOCK_REALTIME_COARSE, /* may jump and crawl, fast & coarse */
5447+
#elif __FreeBSD__
5448+
CLOCK_REALTIME_FAST, /* may jump and crawl, fast & coarse */
5449+
#endif
54425450
CLOCK_REALTIME /* may jump and crawl */
54435451
};
54445452
unsigned i;

0 commit comments

Comments
 (0)