From 38ed6d1569354ad5b6b027bb357798dcde90f7ec Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 23 Mar 2020 11:27:07 +0100 Subject: [PATCH] app/internal: use pkg-config for finding system headers and libraries I've resisted relying on pkg-config in the hope that hard-coded include and library paths would suffice. However, apart from having to work around some distro-specific differences, building with hardcoded include paths fails when building on a buildroot: x86_64-buildroot-linux-gnu-gcc: ERROR: unsafe header/library path used in cross-compilation: '-I/usr/include/wayland' (see #91) Andri mentions a workaround (prefixing paths with "="), but that doesn't seem to work on the BSDs. Let's see how pkg-config fares. It's an extra dependency, but it promises to keep us isolated from the varying paths on Linux distrobutions. Updates #91 Signed-off-by: Elias Naur --- app/internal/egl/egl_unix.go | 5 ++--- app/internal/glimpl/gl.go | 3 ++- app/internal/window/egl_wayland.go | 5 +++-- app/internal/window/os_wayland.go | 3 ++- app/internal/window/os_x11.go | 4 +++- app/internal/xkb/xkb_unix.go | 4 ++-- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/internal/egl/egl_unix.go b/app/internal/egl/egl_unix.go index e23660ff..4a0cac22 100644 --- a/app/internal/egl/egl_unix.go +++ b/app/internal/egl/egl_unix.go @@ -5,7 +5,8 @@ package egl /* -#cgo LDFLAGS: -lEGL +#cgo linux pkg-config: egl +#cgo freebsd openbsd LDFLAGS: -lEGL #cgo freebsd CFLAGS: -I/usr/local/include #cgo freebsd LDFLAGS: -L/usr/local/lib #cgo openbsd CFLAGS: -I/usr/X11R6/include @@ -14,8 +15,6 @@ package egl #include #include -#include -#include */ import "C" diff --git a/app/internal/glimpl/gl.go b/app/internal/glimpl/gl.go index 17bac1f7..0f8272c1 100644 --- a/app/internal/glimpl/gl.go +++ b/app/internal/glimpl/gl.go @@ -14,8 +14,9 @@ import ( /* #cgo CFLAGS: -Werror -#cgo linux freebsd openbsd LDFLAGS: -lGLESv2 +#cgo linux pkg-config: glesv2 #cgo linux freebsd LDFLAGS: -ldl +#cgo freebsd openbsd LDFLAGS: -lGLESv2 #cgo freebsd CFLAGS: -I/usr/local/include #cgo freebsd LDFLAGS: -L/usr/local/lib #cgo openbsd CFLAGS: -I/usr/X11R6/include diff --git a/app/internal/window/egl_wayland.go b/app/internal/window/egl_wayland.go index c4115fb5..b4878b4c 100644 --- a/app/internal/window/egl_wayland.go +++ b/app/internal/window/egl_wayland.go @@ -12,8 +12,9 @@ import ( ) /* -#cgo LDFLAGS: -lwayland-egl -#cgo CFLAGS: -I/usr/include/wayland -DMESA_EGL_NO_X11_HEADERS +#cgo linux pkg-config: egl wayland-egl +#cgo freebsd openbsd LDFLAGS: -lwayland-egl +#cgo CFLAGS: -DMESA_EGL_NO_X11_HEADERS #include #include diff --git a/app/internal/window/os_wayland.go b/app/internal/window/os_wayland.go index 700c307f..95a75bbf 100644 --- a/app/internal/window/os_wayland.go +++ b/app/internal/window/os_wayland.go @@ -40,7 +40,8 @@ import ( //go:generate sed -i "1s;^;// +build linux,!android,!nowayland freebsd\\n\\n;" wayland_text_input.c /* -#cgo LDFLAGS: -lwayland-client -lwayland-cursor +#cgo linux pkg-config: wayland-client wayland-cursor +#cgo freebsd openbsd LDFLAGS: -lwayland-client -lwayland-cursor #cgo freebsd CFLAGS: -I/usr/local/include #cgo freebsd LDFLAGS: -L/usr/local/lib diff --git a/app/internal/window/os_x11.go b/app/internal/window/os_x11.go index fa6f7a31..7189d042 100644 --- a/app/internal/window/os_x11.go +++ b/app/internal/window/os_x11.go @@ -7,7 +7,9 @@ package window /* #cgo openbsd CFLAGS: -I/usr/X11R6/include -I/usr/local/include #cgo openbsd LDFLAGS: -L/usr/X11R6/lib -L/usr/local/lib -#cgo LDFLAGS: -lX11 -lxkbcommon -lxkbcommon-x11 -lX11-xcb +#cgo freebsd openbsd LDFLAGS: -lX11 -lxkbcommon -lxkbcommon-x11 -lX11-xcb +#cgo linux pkg-config: x11 xkbcommon xkbcommon-x11 x11-xcb + #include #include #include diff --git a/app/internal/xkb/xkb_unix.go b/app/internal/xkb/xkb_unix.go index 026b2e69..89cd6495 100644 --- a/app/internal/xkb/xkb_unix.go +++ b/app/internal/xkb/xkb_unix.go @@ -19,9 +19,9 @@ import ( ) /* -#cgo LDFLAGS: -lxkbcommon +#cgo linux pkg-config: xkbcommon #cgo freebsd openbsd CFLAGS: -I/usr/local/include -#cgo freebsd openbsd LDFLAGS: -L/usr/local/lib +#cgo freebsd openbsd LDFLAGS: -L/usr/local/lib -lxkbcommon #include #include