From f1becf1234ee8065e8c8c8be8d9d0d87435eeeee Mon Sep 17 00:00:00 2001
From: Fred Wright <fw@fwright.net>
Date: Sat, 2 Nov 2024 18:49:19 -0700
Subject: [PATCH] Makefile: Fix superfluous library rebuilds.

The fix for parallel builds made directories separate targets, but
directory dependencies need to be order-only, since their mtimes are
updated whenever files are added, removed, or renamed.  Failure to do
this resulted in intermittent unnecessary rebuilds of libraries when
building tests.  When building directly in the repo, this is a
harmless waste of time, but when building in the MacPorts context,
such rebuilds fail due to ownership and permission issues.  This
change makes directories order-only dependencies, thereby ignoring
their mtimes.

This also removes unnecessary directory dependencies from the tests
that don't use the library.

TESTED:
Ran tests on all platforms.  Intermittent test failures are now gone.
---
 Makefile | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index 44a7369..37be43b 100644
--- a/Makefile
+++ b/Makefile
@@ -328,14 +328,14 @@ $(SOBJLIST): $(ALLSLIBOBJS)
 $(BUILDLIBDIR) $(DESTDIR)$(LIBDIR):
 	$(MKINSTALLDIRS) $@
 
-$(BUILDDLIBPATH): $(ALLDLIBOBJS) $(BUILDLIBDIR)
+$(BUILDDLIBPATH): $(ALLDLIBOBJS) | $(BUILDLIBDIR)
 	$(CC) $(BUILDDLIBFLAGS) $(ALLLDFLAGS) $(ALLDLIBOBJS) -o $@
 
-$(BUILDSYSLIBPATH): $(ALLSYSLIBOBJS) $(BUILDLIBDIR)
+$(BUILDSYSLIBPATH): $(ALLSYSLIBOBJS) | $(BUILDLIBDIR)
 	$(CC) $(BUILDSYSLIBFLAGS) $(ALLLDFLAGS) $(SYSREEXPORTFLAG) \
 	      $(ALLSYSLIBOBJS) -o $@
 
-$(BUILDSLIBPATH): $(SOBJLIST) $(BUILDLIBDIR)
+$(BUILDSLIBPATH): $(SOBJLIST) | $(BUILDLIBDIR)
 	$(RM) $@
 	$(AR) $(BUILDSLIBFLAGS) $@ $$(cat $<)
 
@@ -367,7 +367,7 @@ $(XTESTOBJS_C): %.o: %.c $(ALLHEADERS)
 	$(CC) -c -std=c99 -fno-builtin -I$(SRCINCDIR) $(CFLAGS) $< -o $@
 
 # The xtests don't require the library
-$(XTESTPRGS_C): %: %.o $(BUILDLIBDIR)
+$(XTESTPRGS_C): %: %.o
 	$(CC) $(XTESTLDFLAGS) $< -o $@
 
 # The "darwin_c" tests need the -fno-builtin option with some compilers.
@@ -376,7 +376,7 @@ $(MANTESTOBJS_C): %.o: %.c $(ALLHEADERS)
 	$(CC) -c -std=c99 -fno-builtin -I$(SRCINCDIR) $(CFLAGS) $< -o $@
 
 # Currently, the manual C tests don't require the library
-$(MANTESTPRGS_C): %: %.o $(BUILDLIBDIR)
+$(MANTESTPRGS_C): %: %.o
 	$(CC) $(MANTESTLDFLAGS) $< -o $@
 
 # But the manual C++ tests *do* require the library
@@ -471,15 +471,15 @@ install-headers:
 
 install-lib: install-dlib install-slib install-syslib
 
-install-dlib: $(BUILDDLIBPATH) $(DESTDIR)$(LIBDIR)
+install-dlib: $(BUILDDLIBPATH) | $(DESTDIR)$(LIBDIR)
 	$(INSTALL_PROGRAM) $(BUILDDLIBPATH) $(DESTDIR)$(LIBDIR)
 	$(POSTINSTALL) -id $(DLIBPATH) $(DESTDIR)$(DLIBPATH)
 
-install-syslib: $(BUILDSYSLIBPATH) $(DESTDIR)$(LIBDIR)
+install-syslib: $(BUILDSYSLIBPATH) | $(DESTDIR)$(LIBDIR)
 	$(INSTALL_PROGRAM) $(BUILDSYSLIBPATH) $(DESTDIR)$(LIBDIR)
 	$(POSTINSTALL) -id $(SYSLIBPATH) $(DESTDIR)$(SYSLIBPATH)
 
-install-slib: $(BUILDSLIBPATH) $(DESTDIR)$(LIBDIR)
+install-slib: $(BUILDSLIBPATH) | $(DESTDIR)$(LIBDIR)
 	$(INSTALL_DATA) $(BUILDSLIBPATH) $(DESTDIR)$(LIBDIR)
 
 install-tiger: $(TIGERBINS)
-- 
GitLab