From 9a3bf1ed84b24387900dfe09cfc09634012db680 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Wed, 5 Oct 2022 12:48:02 -0700
Subject: [PATCH v2 2/5] autoconf: Rely on ar supporting index creation

This way we don't need RANLIB anymore, making it a bit simpler to for the
meson build to generate Makefile.global for PGXS compatibility.

FreeBSD, NetBSD, OpenBSD, the only platforms were we didn't use AROPT=crs, all
have supported the 's' option for a long time.

This removes the 'touch' added after the ranlib, added in 826eff57c4c. Both ar
and ranlib do set the finegrained timestamps today. We could instead just keep
the touch, with an adjusted comment.

On macOS we ran ranlib after installing a static library. This was added a
long time ago, in 58ad65ec2def. I cannot reproduce an issue in more recent
macOS versions.
---
 src/makefiles/Makefile.aix     |  3 --
 src/makefiles/Makefile.cygwin  |  2 -
 src/makefiles/Makefile.darwin  |  2 -
 src/makefiles/Makefile.freebsd |  2 -
 src/makefiles/Makefile.linux   |  2 -
 src/makefiles/Makefile.netbsd  |  2 -
 src/makefiles/Makefile.openbsd |  2 -
 src/makefiles/Makefile.solaris |  2 -
 src/makefiles/Makefile.win32   |  2 -
 configure                      | 93 ----------------------------------
 configure.ac                   |  1 -
 src/Makefile.global.in         |  2 +-
 src/Makefile.shlib             | 11 ----
 13 files changed, 1 insertion(+), 125 deletions(-)

diff --git a/src/makefiles/Makefile.aix b/src/makefiles/Makefile.aix
index 56d7f22aff6..dd16a7a0378 100644
--- a/src/makefiles/Makefile.aix
+++ b/src/makefiles/Makefile.aix
@@ -2,9 +2,6 @@
 # symbol names to tell them what to export/import.
 MAKE_EXPORTS= true
 
-RANLIB= touch
-AROPT = crs
-
 # -blibpath must contain ALL directories where we should look for libraries
 libpath := $(shell echo $(subst -L,:,$(filter -L/%,$(LDFLAGS))) | sed -e's/ //g'):/usr/lib:/lib
 
diff --git a/src/makefiles/Makefile.cygwin b/src/makefiles/Makefile.cygwin
index 6afa9a06a1b..77593972638 100644
--- a/src/makefiles/Makefile.cygwin
+++ b/src/makefiles/Makefile.cygwin
@@ -10,8 +10,6 @@ endif
 # (see http://sources.redhat.com/cygwin/faq/faq.html#SEC110)
 LIBS:=$(filter-out -lm -lc, $(LIBS))
 
-AROPT = crs
-
 override CPPFLAGS += -DWIN32_STACK_RLIMIT=$(WIN32_STACK_RLIMIT)
 
 ifneq (,$(findstring backend,$(subdir)))
diff --git a/src/makefiles/Makefile.darwin b/src/makefiles/Makefile.darwin
index 45f253a5b43..7095f66e25c 100644
--- a/src/makefiles/Makefile.darwin
+++ b/src/makefiles/Makefile.darwin
@@ -1,5 +1,3 @@
-AROPT = crs
-
 # env var name to use in place of LD_LIBRARY_PATH
 ld_library_path_var = DYLD_LIBRARY_PATH
 
diff --git a/src/makefiles/Makefile.freebsd b/src/makefiles/Makefile.freebsd
index 0e77616b0f9..db74a21568c 100644
--- a/src/makefiles/Makefile.freebsd
+++ b/src/makefiles/Makefile.freebsd
@@ -1,5 +1,3 @@
-AROPT = cr
-
 export_dynamic = -Wl,-export-dynamic
 rpath = -Wl,-R'$(rpathdir)'
 
diff --git a/src/makefiles/Makefile.linux b/src/makefiles/Makefile.linux
index 1ffec9d1698..5a9451371ab 100644
--- a/src/makefiles/Makefile.linux
+++ b/src/makefiles/Makefile.linux
@@ -1,5 +1,3 @@
-AROPT = crs
-
 export_dynamic = -Wl,-E
 # Use --enable-new-dtags to generate DT_RUNPATH instead of DT_RPATH.
 # This allows LD_LIBRARY_PATH to still work when needed.
diff --git a/src/makefiles/Makefile.netbsd b/src/makefiles/Makefile.netbsd
index 421b735e407..4f8e9ec2521 100644
--- a/src/makefiles/Makefile.netbsd
+++ b/src/makefiles/Makefile.netbsd
@@ -1,5 +1,3 @@
-AROPT = cr
-
 export_dynamic = -Wl,-E
 rpath = -Wl,-R'$(rpathdir)'
 
diff --git a/src/makefiles/Makefile.openbsd b/src/makefiles/Makefile.openbsd
index 421b735e407..4f8e9ec2521 100644
--- a/src/makefiles/Makefile.openbsd
+++ b/src/makefiles/Makefile.openbsd
@@ -1,5 +1,3 @@
-AROPT = cr
-
 export_dynamic = -Wl,-E
 rpath = -Wl,-R'$(rpathdir)'
 
diff --git a/src/makefiles/Makefile.solaris b/src/makefiles/Makefile.solaris
index acdf44cc0f2..3de73ebc010 100644
--- a/src/makefiles/Makefile.solaris
+++ b/src/makefiles/Makefile.solaris
@@ -1,6 +1,4 @@
 # src/makefiles/Makefile.solaris
-
-AROPT = crs
 rpath = -Wl,-rpath,'$(rpathdir)'
 
 ifeq ($(with_gnu_ld), yes)
diff --git a/src/makefiles/Makefile.win32 b/src/makefiles/Makefile.win32
index d268b3ebafd..dc1aafa115a 100644
--- a/src/makefiles/Makefile.win32
+++ b/src/makefiles/Makefile.win32
@@ -10,8 +10,6 @@ endif
 
 override CPPFLAGS += -DWIN32_STACK_RLIMIT=$(WIN32_STACK_RLIMIT)
 
-AROPT = crs
-
 ifneq (,$(findstring backend,$(subdir)))
 ifeq (,$(findstring conversion_procs,$(subdir)))
 ifeq (,$(findstring libpqwalreceiver,$(subdir)))
diff --git a/configure b/configure
index 80b28cb9310..d338ae2cc8b 100755
--- a/configure
+++ b/configure
@@ -691,7 +691,6 @@ AR
 STRIP_SHARED_LIB
 STRIP_STATIC_LIB
 STRIP
-RANLIB
 with_gnu_ld
 LD
 LDFLAGS_SL
@@ -9465,98 +9464,6 @@ with_gnu_ld=$ac_cv_prog_gnu_ld
 
 
 
-if test -n "$ac_tool_prefix"; then
-  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
-set dummy ${ac_tool_prefix}ranlib; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_RANLIB+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  if test -n "$RANLIB"; then
-  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-fi
-fi
-RANLIB=$ac_cv_prog_RANLIB
-if test -n "$RANLIB"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
-$as_echo "$RANLIB" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
-fi
-if test -z "$ac_cv_prog_RANLIB"; then
-  ac_ct_RANLIB=$RANLIB
-  # Extract the first word of "ranlib", so it can be a program name with args.
-set dummy ranlib; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_ac_ct_RANLIB+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  if test -n "$ac_ct_RANLIB"; then
-  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_prog_ac_ct_RANLIB="ranlib"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-fi
-fi
-ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
-if test -n "$ac_ct_RANLIB"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5
-$as_echo "$ac_ct_RANLIB" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-  if test "x$ac_ct_RANLIB" = x; then
-    RANLIB=":"
-  else
-    case $cross_compiling:$ac_tool_warned in
-yes:)
-{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
-$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
-ac_tool_warned=yes ;;
-esac
-    RANLIB=$ac_ct_RANLIB
-  fi
-else
-  RANLIB="$ac_cv_prog_RANLIB"
-fi
-
 
   if test -n "$ac_tool_prefix"; then
   # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args.
diff --git a/configure.ac b/configure.ac
index f837a602d01..66c60974ef9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1129,7 +1129,6 @@ AC_ARG_VAR(LDFLAGS_SL, [extra linker flags for linking shared libraries only])
 PGAC_PROG_LD
 AC_SUBST(LD)
 AC_SUBST(with_gnu_ld)
-AC_PROG_RANLIB
 PGAC_CHECK_STRIP
 AC_CHECK_TOOL(AR, ar, ar)
 if test "$PORTNAME" = "win32"; then
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index c87b6d97ca9..a5e2f36d217 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -283,6 +283,7 @@ ZIC = @ZIC@
 # Linking
 
 AR = @AR@
+AROPT = crs
 LIBS = @LIBS@
 LDAP_LIBS_FE = @LDAP_LIBS_FE@
 LDAP_LIBS_BE = @LDAP_LIBS_BE@
@@ -317,7 +318,6 @@ LDFLAGS_EX = @LDFLAGS_EX@
 LDFLAGS_SL += @LDFLAGS_SL@
 LDREL = -r
 LDOUT = -o
-RANLIB = @RANLIB@
 WINDRES = @WINDRES@
 X = @EXEEXT@
 
diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index db466b3b845..fd0909b95df 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -251,17 +251,10 @@ all-static-lib: $(stlib)
 
 all-shared-lib: $(shlib)
 
-# In this rule, "touch $@" works around a problem on some platforms wherein
-# ranlib updates the library file's mod time with a value calculated to
-# seconds precision.  If the filesystem has sub-second timestamps, this can
-# cause the library file to appear older than its input files, triggering
-# parallel-make problems.
 ifndef haslibarule
 $(stlib): $(OBJS) | $(SHLIB_PREREQS)
 	rm -f $@
 	$(LINK.static) $@ $^
-	$(RANLIB) $@
-	touch $@
 endif #haslibarule
 
 # AIX wraps shared libraries inside a static library, can be used both
@@ -394,10 +387,6 @@ install-lib-pc: lib$(NAME).pc installdirs-lib
 
 install-lib-static: $(stlib) installdirs-lib
 	$(INSTALL_STLIB) $< '$(DESTDIR)$(libdir)/$(stlib)'
-ifeq ($(PORTNAME), darwin)
-	cd '$(DESTDIR)$(libdir)' && \
-	$(RANLIB) $(stlib)
-endif
 
 install-lib-shared: $(shlib) installdirs-lib
 ifdef soname
-- 
2.37.3.542.gdd3f6c4cae

