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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
This commit is contained in:
Anachronaut
2026-09-02 23:24:06 -04:00
co-authored by Claude Opus 5
parent df50c2f0f8
commit 6def343e97
+28 -10
View File
@@ -87,16 +87,34 @@ LINT_TARGET = SplitLint
# pkg-config first because that is what a packaged Raylib provides, and a bare -lraylib # 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. # after it because a Raylib built from source usually does not install one.
RAYLIB_CFLAGS := $(shell pkg-config --cflags raylib 2>/dev/null) RAYLIB_CFLAGS := $(shell pkg-config --cflags raylib 2>/dev/null)
RAYLIB_LIBS := $(shell pkg-config --libs raylib 2>/dev/null) RAYLIB_PKG := $(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 # ---- The flags are FOUND rather than assumed ----
# 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. # What a static Raylib needs beside itself changes with the version. Six's GetClipboardImage
RAYLIB_LIBS := -lraylib -lm # calls X11 directly, so -lX11 became necessary on a Linux desktop where five did not want it
endif # - and because it is a static archive, one function nobody calls drags the whole object in
HAVE_RAYLIB := $(shell printf '#include <raylib.h>\nint main(void){return (int)GetTime();}\n' \ # and every X symbol with it.
| $(CC) -x c - -o /dev/null $(RAYLIB_CFLAGS) $(RAYLIB_LIBS) 2>/dev/null \ #
&& echo yes) # 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 <raylib.h>\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. # Default target: the machine, its three host-side tools, and Voyager where it can be built.
# #