From 1f7cd29615b06f4462b7aa73cb2c2c50a3d961c1 Mon Sep 17 00:00:00 2001
From: Sergey Kosukhin <sergey.kosukhin@mpimet.mpg.de>
Date: Wed, 14 Apr 2021 11:59:15 +0200
Subject: [PATCH] Better handling of librt (fixup 20884586).

---
 configure                | 14 ++++++++++----
 configure.ac             | 12 ++++++------
 examples/pio/Makefile.am |  4 ++--
 examples/pio/Makefile.in | 12 ++++++------
 src/Makefile.am          |  2 +-
 src/Makefile.in          |  5 +++--
 tests/Makefile.am        |  4 ++--
 tests/Makefile.in        | 10 ++++------
 8 files changed, 34 insertions(+), 29 deletions(-)

diff --git a/configure b/configure
index 0993d703e..ef4c93415 100755
--- a/configure
+++ b/configure
@@ -29965,11 +29965,15 @@ fi
 
 ENABLE_MPI=`test x"$enable_mpi" = xyes && echo true || echo false`
 
+LIBRT=''
 
 if test -z "$USE_MPI_TRUE"; then :
-  LIBRT=
-   LIBS_save=$LIBS
-   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing aio_suspend" >&5
+  ac_fn_c_check_decl "$LINENO" "_SX" "ac_cv_have_decl__SX" "$ac_includes_default"
+if test "x$ac_cv_have_decl__SX" = xyes; then :
+
+else
+  LIBS_save=$LIBS
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing aio_suspend" >&5
 $as_echo_n "checking for library containing aio_suspend... " >&6; }
 if ${ac_cv_search_aio_suspend+:} false; then :
   $as_echo_n "(cached) " >&6
@@ -30025,7 +30029,9 @@ if test "$ac_res" != no; then :
   test "$ac_res" = "none required" || LIBRT=$ac_res
 fi
 
-   LIBS=$LIBS_save
+      LIBS=$LIBS_save
+fi
+
 fi
 #  ----------------------------------------------------------------------
 #  Create the Fortran Interface via iso_c_binding module (Fortran 2003 Standard)
diff --git a/configure.ac b/configure.ac
index 96c64c31e..07085eb9b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -284,13 +284,13 @@ AM_CONDITIONAL([USE_PPM_CORE],[test $enable_ppm = yes])
 AM_CONDITIONAL([HAVE_PARALLEL_NC4],[test $HAVE_PARALLEL_NC4 -gt 0])
 AC_SUBST([USE_MPI])
 AC_SUBST([ENABLE_MPI],[`test x"$enable_mpi" = xyes && echo true || echo false`])
-AC_SUBST([LIBRT])
+AC_SUBST([LIBRT], [''])
 AM_COND_IF([USE_MPI],
-  [LIBRT=
-   LIBS_save=$LIBS
-   AC_SEARCH_LIBS([aio_suspend], [rt],
-     [test "$ac_res" = "none required" || LIBRT=$ac_res])
-   LIBS=$LIBS_save])
+  [AC_CHECK_DECL([_SX], [],
+     [LIBS_save=$LIBS
+      AC_SEARCH_LIBS([aio_suspend], [rt],
+        [test "$ac_res" = "none required" || LIBRT=$ac_res])
+      LIBS=$LIBS_save])])
 #  ----------------------------------------------------------------------
 #  Create the Fortran Interface via iso_c_binding module (Fortran 2003 Standard)
 #
diff --git a/examples/pio/Makefile.am b/examples/pio/Makefile.am
index 82f232df7..ed3a4db66 100644
--- a/examples/pio/Makefile.am
+++ b/examples/pio/Makefile.am
@@ -16,8 +16,8 @@ endif
 collectData_SOURCES=collectData.c
 
 if USE_MPI
-LDADD=$(top_builddir)/src/libcdipio.la $(LIBRT) $(MPI_C_LIB)
-collectData2003_LDADD=$(top_builddir)/src/libcdipio.la $(LIBRT) $(MPI_FC_LIB)
+LDADD=$(top_builddir)/src/libcdipio.la $(MPI_C_LIB)
+collectData2003_LDADD=$(top_builddir)/src/libcdipio.la $(MPI_FC_LIB)
 else
 LDADD=$(top_builddir)/src/libcdi.la
 collectData2003_LDADD=$(top_builddir)/src/libcdi.la
diff --git a/examples/pio/Makefile.in b/examples/pio/Makefile.in
index 852624f90..fb621ce9f 100644
--- a/examples/pio/Makefile.in
+++ b/examples/pio/Makefile.in
@@ -139,7 +139,7 @@ am__DEPENDENCIES_1 =
 @USE_MPI_FALSE@	$(top_builddir)/src/libcdi.la
 @USE_MPI_TRUE@collectData_DEPENDENCIES =  \
 @USE_MPI_TRUE@	$(top_builddir)/src/libcdipio.la \
-@USE_MPI_TRUE@	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
+@USE_MPI_TRUE@	$(am__DEPENDENCIES_1)
 AM_V_lt = $(am__v_lt_@AM_V@)
 am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
 am__v_lt_0 = --silent
@@ -150,7 +150,7 @@ collectData2003_OBJECTS = $(am_collectData2003_OBJECTS)
 @USE_MPI_FALSE@	$(top_builddir)/src/libcdi.la
 @USE_MPI_TRUE@collectData2003_DEPENDENCIES =  \
 @USE_MPI_TRUE@	$(top_builddir)/src/libcdipio.la \
-@USE_MPI_TRUE@	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
+@USE_MPI_TRUE@	$(am__DEPENDENCIES_1)
 am_collectDataNStreams_OBJECTS = collectDataNStreams.$(OBJEXT)
 collectDataNStreams_OBJECTS = $(am_collectDataNStreams_OBJECTS)
 collectDataNStreams_LDADD = $(LDADD)
@@ -158,7 +158,7 @@ collectDataNStreams_LDADD = $(LDADD)
 @USE_MPI_FALSE@	$(top_builddir)/src/libcdi.la
 @USE_MPI_TRUE@collectDataNStreams_DEPENDENCIES =  \
 @USE_MPI_TRUE@	$(top_builddir)/src/libcdipio.la \
-@USE_MPI_TRUE@	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
+@USE_MPI_TRUE@	$(am__DEPENDENCIES_1)
 am_compareResourcesArray_OBJECTS = compareResourcesArray.$(OBJEXT)
 compareResourcesArray_OBJECTS = $(am_compareResourcesArray_OBJECTS)
 compareResourcesArray_LDADD = $(LDADD)
@@ -166,7 +166,7 @@ compareResourcesArray_LDADD = $(LDADD)
 @USE_MPI_FALSE@	$(top_builddir)/src/libcdi.la
 @USE_MPI_TRUE@compareResourcesArray_DEPENDENCIES =  \
 @USE_MPI_TRUE@	$(top_builddir)/src/libcdipio.la \
-@USE_MPI_TRUE@	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
+@USE_MPI_TRUE@	$(am__DEPENDENCIES_1)
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
 am__v_P_0 = false
@@ -447,9 +447,9 @@ AM_FCFLAGS = $(FPP_INCOPT)$(top_srcdir)/src $(MPI_FC_INCLUDE) \
 AM_CFLAGS = $(MPI_C_INCLUDE)
 collectData_SOURCES = collectData.c
 @USE_MPI_FALSE@LDADD = $(top_builddir)/src/libcdi.la
-@USE_MPI_TRUE@LDADD = $(top_builddir)/src/libcdipio.la $(LIBRT) $(MPI_C_LIB)
+@USE_MPI_TRUE@LDADD = $(top_builddir)/src/libcdipio.la $(MPI_C_LIB)
 @USE_MPI_FALSE@collectData2003_LDADD = $(top_builddir)/src/libcdi.la
-@USE_MPI_TRUE@collectData2003_LDADD = $(top_builddir)/src/libcdipio.la $(LIBRT) $(MPI_FC_LIB)
+@USE_MPI_TRUE@collectData2003_LDADD = $(top_builddir)/src/libcdipio.la $(MPI_FC_LIB)
 collectData2003_SOURCES = collectData2003.F90
 collectDataNStreams_SOURCES = collectDataNStreams.c
 compareResourcesArray_SOURCES = compareResourcesArray.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 9c240f82c..25ea43c26 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -245,7 +245,7 @@ libcdipio_la_SOURCES += $(libcdipio_la_HAVE_PARALLEL_NC4_extra_sources)
 endif
 endif
 
-libcdipio_la_LIBADD    = libcdi.la $(PPM_CORE_LIBS) $(YAXT_LIBS) $(MPI_C_LIB)
+libcdipio_la_LIBADD    = libcdi.la $(LIBRT) $(PPM_CORE_LIBS) $(YAXT_LIBS) $(MPI_C_LIB)
 
 libcdi_la_LIBADD    = $(UUID_C_LIB)
 #
diff --git a/src/Makefile.in b/src/Makefile.in
index 876f56330..1a801f31c 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -248,7 +248,8 @@ libcdi_f2003_la_OBJECTS = $(am_libcdi_f2003_la_OBJECTS)
 @CREATE_ISOC_TRUE@@ENABLE_CDI_LIB_TRUE@am_libcdi_f2003_la_rpath =  \
 @CREATE_ISOC_TRUE@@ENABLE_CDI_LIB_TRUE@	-rpath $(libdir)
 libcdipio_la_DEPENDENCIES = libcdi.la $(am__DEPENDENCIES_1) \
-	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1)
 am__libcdipio_la_SOURCES_DIST = cdipio.h cdipioFortran.c cfortran.h \
 	pio.c pio.h pio_comm.c pio_comm.h pio_conf.c pio_conf.h \
 	pio_dbuffer.c pio_id_set.h pio_impl.h pio_interface.c \
@@ -660,7 +661,7 @@ libcdipio_la_SOURCES = cdipio.h cdipioFortran.c cfortran.h pio.c pio.h \
 libcdipio_la_HAVE_PARALLEL_NC4_extra_sources = \
 	pio_cdf_int.c
 
-libcdipio_la_LIBADD = libcdi.la $(PPM_CORE_LIBS) $(YAXT_LIBS) $(MPI_C_LIB)
+libcdipio_la_LIBADD = libcdi.la $(LIBRT) $(PPM_CORE_LIBS) $(YAXT_LIBS) $(MPI_C_LIB)
 libcdi_la_LIBADD = $(UUID_C_LIB)
 #
 #cdilib.c:
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 77b66d22f..5e9053f30 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -45,8 +45,8 @@ test_byteswap_SOURCES = test_byteswap.c
 #
 AM_CFLAGS = $(PPM_CORE_CFLAGS) $(YAXT_CFLAGS) $(MPI_C_INCLUDE)
 if USE_MPI
-pio_write_LDADD = ../src/libcdipio.la $(LIBRT) $(UUID_C_LIB) $(MPI_C_LIB)
-pio_write_deco2d_LDADD = ../src/libcdipio.la $(LIBRT) $(UUID_C_LIB) $(MPI_C_LIB)
+pio_write_LDADD = ../src/libcdipio.la $(UUID_C_LIB) $(MPI_C_LIB)
+pio_write_deco2d_LDADD = ../src/libcdipio.la $(UUID_C_LIB) $(MPI_C_LIB)
 TESTS +=  test_resource_copy_mpi_run
 check_PROGRAMS += test_resource_copy_mpi
 test_resource_copy_mpi_LDADD = ../src/libcdipio.la $(UUID_C_LIB)
diff --git a/tests/Makefile.in b/tests/Makefile.in
index 59ef4050f..8cde7664f 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -180,16 +180,14 @@ pio_write_OBJECTS = $(am_pio_write_OBJECTS)
 am__DEPENDENCIES_1 =
 @USE_MPI_FALSE@pio_write_DEPENDENCIES = $(LDADD) $(am__DEPENDENCIES_1)
 @USE_MPI_TRUE@pio_write_DEPENDENCIES = ../src/libcdipio.la \
-@USE_MPI_TRUE@	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
-@USE_MPI_TRUE@	$(am__DEPENDENCIES_1)
+@USE_MPI_TRUE@	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
 am_pio_write_deco2d_OBJECTS = pio_write.$(OBJEXT) \
 	deco2d_model.$(OBJEXT) simple_model_helper.$(OBJEXT)
 pio_write_deco2d_OBJECTS = $(am_pio_write_deco2d_OBJECTS)
 @USE_MPI_FALSE@pio_write_deco2d_DEPENDENCIES = $(LDADD) \
 @USE_MPI_FALSE@	$(am__DEPENDENCIES_1)
 @USE_MPI_TRUE@pio_write_deco2d_DEPENDENCIES = ../src/libcdipio.la \
-@USE_MPI_TRUE@	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
-@USE_MPI_TRUE@	$(am__DEPENDENCIES_1)
+@USE_MPI_TRUE@	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
 am_test_byteswap_OBJECTS = test_byteswap.$(OBJEXT)
 test_byteswap_OBJECTS = $(am_test_byteswap_OBJECTS)
 test_byteswap_LDADD = $(LDADD)
@@ -560,9 +558,9 @@ test_byteswap_SOURCES = test_byteswap.c
 #
 AM_CFLAGS = $(PPM_CORE_CFLAGS) $(YAXT_CFLAGS) $(MPI_C_INCLUDE)
 @USE_MPI_FALSE@pio_write_LDADD = $(LDADD) $(UUID_C_LIB)
-@USE_MPI_TRUE@pio_write_LDADD = ../src/libcdipio.la $(LIBRT) $(UUID_C_LIB) $(MPI_C_LIB)
+@USE_MPI_TRUE@pio_write_LDADD = ../src/libcdipio.la $(UUID_C_LIB) $(MPI_C_LIB)
 @USE_MPI_FALSE@pio_write_deco2d_LDADD = $(LDADD) $(UUID_C_LIB)
-@USE_MPI_TRUE@pio_write_deco2d_LDADD = ../src/libcdipio.la $(LIBRT) $(UUID_C_LIB) $(MPI_C_LIB)
+@USE_MPI_TRUE@pio_write_deco2d_LDADD = ../src/libcdipio.la $(UUID_C_LIB) $(MPI_C_LIB)
 @USE_MPI_FALSE@test_resource_copy_mpi_LDADD = $(LDADD) $(UUID_C_LIB)
 @USE_MPI_TRUE@test_resource_copy_mpi_LDADD = ../src/libcdipio.la $(UUID_C_LIB)
 @USE_MPI_TRUE@test_resource_copy_mpi_CFLAGS = $(AM_CFLAGS) $(CFLAGS) \
-- 
GitLab