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. #