From 6def343e979a99eb39374638f60abf668034b848 Mon Sep 17 00:00:00 2001 From: Anachronaut Date: Wed, 2 Sep 2026 23:24:06 -0400 Subject: [PATCH] Find Raylib's link flags instead of guessing one set Raylib 6 calls X11 directly from GetClipboardImage, so a static libraylib needs -lX11 on a Linux desktop where 5.6 did not - and because it is an archive, one function nobody calls drags in the whole object and every X symbol with it. THE OLD SHAPE FAILED IN THE WORST AVAILABLE WAY. One hardcoded guess was test-linked, and when the guess went short the probe reported that Raylib was not installed - so make quietly stopped building Voyager and said so in the words it keeps for a machine with no graphics library at all. The answer looked like an absence and was a missing flag. So the candidates are tried in order and the first that links is the answer. The probe and the flags are the same thing now rather than two facts that can disagree, which is the property that was actually missing: a probe that tests something other than what gets built can only ever be a coincidence. Verified against 6.1-dev: Voyager builds and all 210 tests pass under it. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW --- makefile | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/makefile b/makefile index a193183..aa1b907 100644 --- a/makefile +++ b/makefile @@ -87,16 +87,34 @@ LINT_TARGET = SplitLint # pkg-config first because that is what a packaged Raylib provides, and a bare -lraylib # after it because a Raylib built from source usually does not install one. RAYLIB_CFLAGS := $(shell pkg-config --cflags raylib 2>/dev/null) -RAYLIB_LIBS := $(shell pkg-config --libs raylib 2>/dev/null) -ifeq ($(strip $(RAYLIB_LIBS)),) -# The -lm is not spare, even though MATHLIB names it again on the link line below. This -# variable is what the probe underneath test-links with, and Raylib does not link without it, -# so taking it out here does not tidy a duplicate - it makes the probe say Raylib is missing. -RAYLIB_LIBS := -lraylib -lm -endif -HAVE_RAYLIB := $(shell printf '#include \nint main(void){return (int)GetTime();}\n' \ - | $(CC) -x c - -o /dev/null $(RAYLIB_CFLAGS) $(RAYLIB_LIBS) 2>/dev/null \ - && echo yes) +RAYLIB_PKG := $(shell pkg-config --libs raylib 2>/dev/null) + +# ---- The flags are FOUND rather than assumed ---- +# +# What a static Raylib needs beside itself changes with the version. Six's GetClipboardImage +# calls X11 directly, so -lX11 became necessary on a Linux desktop where five did not want it +# - and because it is a static archive, one function nobody calls drags the whole object in +# and every X symbol with it. +# +# THE OLD SHAPE FAILED IN THE WORST WAY. One hardcoded guess was test-linked, and when the +# guess went short the probe said Raylib was not installed - so make quietly stopped building +# Voyager and said so in the words it uses for a machine with no graphics library at all. The +# answer looked like an absence and was a missing flag. +# +# So the candidates are tried in order and the first that links is the answer. The probe and +# the flags are now the same thing rather than two facts that can disagree. +# +# GetTime is enough to catch it because a static link pulls objects, not functions: it lives +# in the same object as the clipboard code, so a program that calls it needs everything that +# code needs. -lm is not spare either - Raylib does not link without it, so dropping it here +# does not tidy a duplicate, it makes the probe say Raylib is missing. +RAYLIB_LIBS := $(shell for libs in "$(RAYLIB_PKG)" "-lraylib -lm" "-lraylib -lm -lX11"; do \ + [ -z "$$libs" ] && continue; \ + printf '#include \nint main(void){return (int)GetTime();}\n' \ + | $(CC) -x c - -o /dev/null $(RAYLIB_CFLAGS) $$libs 2>/dev/null \ + && { printf '%s' "$$libs"; break; }; \ + done) +HAVE_RAYLIB := $(if $(strip $(RAYLIB_LIBS)),yes,) # Default target: the machine, its three host-side tools, and Voyager where it can be built. #