From b673c5889e5c9c10b32846cf0e470f5a987d472b Mon Sep 17 00:00:00 2001 From: Michele Guerini Rocco Date: Fri, 21 Mar 2025 21:03:13 +0100 Subject: [PATCH] Makefile: fix parallel building MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This changes the default rules for ar archives to work correctly under parallel buildings in GNU make ≥4.4.1. Incidentally, this also fixes the entire build being sequential for GNU make <4.4 due to .NOTPARALLEL not supporting prerequisites. For older versions, timestamps of archive members are not handled correctly, but that's a relatively minor issue. --- Makefile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 52959ea..ef5ad40 100644 --- a/Makefile +++ b/Makefile @@ -203,11 +203,7 @@ $(LIBDIR)/libgray.so: $(MODULES) | $(LIBDIR) $(LD) -shared $(LDFLAGS) -o '$@' $^ # GRAY static library -$(LIBDIR)/libgray.a($(MODULES)): | $(LIBDIR) -$(LIBDIR)/libgray.a: $(LIBDIR)/libgray.a($(MODULES)) - -# Don't update archives in parallel, it's unsupported -.NOTPARALLEL: $(LIBDIR)/libgray.a +$(LIBDIR)/libgray.a: $(LIBDIR)/libgray.a($(MODULES)) | $(LIBDIR) # GRAY static library when compiling from JETTO -include ../include.mk @@ -270,6 +266,12 @@ $(OBJDIR)/%.d: %.f90 | $(OBJDIR) sort -u >> '$@' @sed -nE 's@^#include "(.+)"@$(INCDIR)/\1 \\@p' '$<' >> '$@' +# Accumulate members and update archives all at once +# Note: this replaces the default POSIX rules that +# break under parallel building (make -j) +(%) : % ; +%.a : ; $(AR) $(ARFLAGS) $@ $? + # Load the generated rules include $(DEPS)