From 4defe2871f0c9849b0acb33b41b00a4c55e569e3 Mon Sep 17 00:00:00 2001
From: Fred Wright <fw@fwright.net>
Date: Fri, 15 Nov 2024 22:02:40 -0800
Subject: [PATCH] Makefile: Use C-based 'which' on Tiger.

Unlike the 10.5+ 'which' command, which is a C program, the
OS-supplied 10.4 version is a csh script, with some deficiencies.
Since 2019, legacy-support has been supplying a patched version
of the csh script correcting some, but not all, deficiencies.  In
particular, the replacement version doesn't implement the '-a'
option, without providing an informative error message.

This change replaces the patched csh script with a build of the
10.5 version.  For consistency, it has the same universality as
the Apple-supplied programs, regardless of whether legacy-support
is being built universal in general.  Specifically, it uses the
new binarchs tool to copy the architectures from /usr/bin/true,
since full universal builds don't work on 10.4 ppc.

TESTED:
Built and tested with all option combinations.
Tested the updated install target.
---
 Makefile | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 65a9ea2..62a3836 100644
--- a/Makefile
+++ b/Makefile
@@ -177,8 +177,12 @@ MANTESTPRGS      = $(MANTESTPRGS_C) $(MANTESTPRGS_CPP)
 MANTESTRUNS     := $(patsubst \
                      $(MANTESTPREFIX)%,$(MANRUNPREFIX)%,$(MANTESTPRGS))
 
-TIGERBINDIR      = tiger_only/bin
-TIGERBINS       := $(wildcard $(TIGERBINDIR)/*)
+TIGERSRCDIR      = tiger_only/src
+TIGERSRCS       := $(wildcard $(TIGERSRCDIR)/*.c)
+TIGERPRGS       := $(patsubst %.c,%,$(TIGERSRCS))
+
+TOOLDIR          = tools
+ARCHTOOL         = $(TOOLDIR)/binarchs.sh
 
 define splitandfilterandmergemultiarch
 	output='$(1)' && \
@@ -387,9 +391,10 @@ $(MANTESTOBJS_CPP): %.o: %.cpp $(ALLHEADERS)
 $(MANTESTPRGS_CPP): %: %.o $(BUILDDLIBPATH)
 	$(CXX) $(TESTLDFLAGS) $< $(TESTLIBS) -o $@
 
-# Dummy target for building Tiger-only binaries, so Portfile can
-# reference it in case we need it in the future.
-tiger-bins:
+$(TIGERPRGS): %: %.c
+	$(CC) $$($(ARCHTOOL)) $< -o $@
+
+tiger-bins: $(TIGERPRGS)
 
 # Special clause for testing the cmath fix: Just need to verify that
 # building succeeds or fails, not that the executable runs or what it
@@ -491,8 +496,8 @@ install-syslib: $(BUILDSYSLIBPATH) | $(DESTDIR)$(LIBDIR)
 install-slib: $(BUILDSLIBPATH) | $(DESTDIR)$(LIBDIR)
 	$(INSTALL_DATA) $(BUILDSLIBPATH) $(DESTDIR)$(LIBDIR)
 
-install-tiger: $(TIGERBINS)
-	$(INSTALL_PROGRAM) $(TIGERBINS) $(DESTDIR)$(BINDIR)
+install-tiger: $(TIGERPRGS)
+	$(INSTALL_PROGRAM) $(TIGERPRGS) $(DESTDIR)$(BINDIR)
 
 test check: $(TESTRUNS) $(XTESTRUNS) test_cmath test_faccessat_setuid_msg
 
-- 
GitLab