diff --git a/Makefile.am b/Makefile.am
index af4fe5a019a369ed497db7b8436a748afadbc1ba..a083881901e98189677f04c0a2113d27182596a5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -94,13 +94,13 @@ EXTRA_DIST = util/sunf95preproc-wrapper \
 	contrib/02nagfor53-shared-patch/README.txt \
 	contrib/02nagfor53-shared-patch/nagfor53-shared.patch \
 	contrib/03ltmain-ld-groups-patch/README \
-	contrib/03ltmain-ld-groups-patch/ltmain-ld-groups-libtool-2.4.6.patch \
 	contrib/03ltmain-ld-groups-patch/ltmain-ld-groups-libtool-2.4.2.patch \
+	contrib/03ltmain-ld-groups-patch/ltmain-ld-groups-libtool-2.4.6.patch \
 	contrib/04ltmain-xlinker-patch/README \
 	contrib/04ltmain-xlinker-patch/ltmain-xlinker-patch.patch \
 	contrib/05macos-nagfor-patch/macos-nagfor-libtool-2.4.2.patch \
-	contrib/05macos-nagfor-patch/macos-nagfor.patch \
-	contrib/06ltmain_nag_pthread-patch/ltmain_nag_pthread.patch \
+	contrib/05macos-nagfor-patch/macos-nagfor-libtool-2.4.6.patch \
+	contrib/06ltmain_nag_pthread-patch/ltmain_nag_pthread-libtool-2.4.6.patch \
 	contrib/06ltmain_nag_pthread-patch/ltmain_nag_pthread-libtool-2.4.2.patch \
 	contrib/07ltmain-early-xcompile-patch/README \
 	contrib/07ltmain-early-xcompile-patch/ltmain-early-xcompile-libtool-2.4.6.patch \
diff --git a/contrib/05macos-nagfor-patch/macos-nagfor-libtool-2.4.2.patch b/contrib/05macos-nagfor-patch/macos-nagfor-libtool-2.4.2.patch
index 56a9132ce12002b19e45d5f76fc3656b5ae5d873..a2bf34687dcc4f8fccc00ef474c55cf056637971 100644
--- a/contrib/05macos-nagfor-patch/macos-nagfor-libtool-2.4.2.patch
+++ b/contrib/05macos-nagfor-patch/macos-nagfor-libtool-2.4.2.patch
@@ -5,8 +5,8 @@
  	  xlcverstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision"
  	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
 +          # On Darwin other compilers
-+          case $with_nagfor in
-+              yes)
++          case $compiler_lineage in
++              NAG)
 +                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
 +                  ;;
 +              *)
diff --git a/contrib/05macos-nagfor-patch/macos-nagfor.patch b/contrib/05macos-nagfor-patch/macos-nagfor-libtool-2.4.6.patch
similarity index 91%
rename from contrib/05macos-nagfor-patch/macos-nagfor.patch
rename to contrib/05macos-nagfor-patch/macos-nagfor-libtool-2.4.6.patch
index befdb41228fa2551824267b237573afcb10579f6..b26151a6f8978f01566b6e1a5a667ac8b8d71105 100644
--- a/contrib/05macos-nagfor-patch/macos-nagfor.patch
+++ b/contrib/05macos-nagfor-patch/macos-nagfor-libtool-2.4.6.patch
@@ -6,8 +6,8 @@
            # On Darwin other compilers
 -          case $CC in
 -              nagfor*)
-+          case $with_nagfor in
-+              yes)
++          case $compiler_lineage in
++              NAG)
                    verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
                    ;;
                *)
diff --git a/contrib/06ltmain_nag_pthread-patch/ltmain_nag_pthread-libtool-2.4.2.patch b/contrib/06ltmain_nag_pthread-patch/ltmain_nag_pthread-libtool-2.4.2.patch
index 96f03b375fb240cb326cba7feec9c54d41d313c8..046b98dff73d6a5127454e909c7afd7c7680171d 100644
--- a/contrib/06ltmain_nag_pthread-patch/ltmain_nag_pthread-libtool-2.4.2.patch
+++ b/contrib/06ltmain_nag_pthread-patch/ltmain_nag_pthread-libtool-2.4.2.patch
@@ -1,19 +1,24 @@
 --- a/config/ltmain.sh
 +++ b/config/ltmain.sh
-@@ -6490,6 +6490,12 @@ func_mode_link ()
+@@ -6490,6 +6490,17 @@ func_mode_link ()
  	# Convert "-framework foo" to "foo.ltframework"
  	if test -n "$inherited_linker_flags"; then
  	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
 +
 +	  # Additionally convert " -pthread" to " -Wl,-pthread" for nagfor
-+	  if test yes = "$with_nagfor" ; then
-+	    tmp_inherited_linker_flags=`$ECHO " $tmp_inherited_linker_flags " | $SED 's/ -pthread[[:blank:]]/ -Wl,-pthread /g'`
-+	  fi
++	  case $compiler_lineage in #(
++           NAG)
++	      tmp_inherited_linker_flags=`$ECHO " $tmp_inherited_linker_flags " | $SED 's/ -pthread[[:blank:]]/ -Wl,-pthread /g'`
++	      ;; #(
++	    PGI)
++	      tmp_inherited_linker_flags=`$ECHO " $tmp_inherited_linker_flags " | $SED 's/ -pthread[[:blank:]]//g'`
++	      ;;
++	  esac
 +
  	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
  	    case " $new_inherited_linker_flags " in
  	      *" $tmp_inherited_linker_flag "*) ;;
-@@ -8084,6 +8090,20 @@ EOF
+@@ -8084,6 +8090,22 @@ EOF
  	  ;;
        esac
  
@@ -27,9 +32,11 @@
 +      # better not to revert the changes, otherwise, uncomment the following
 +      # lines.
 +
-+      if test yes = "$with_nagfor" ; then
-+        new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags " | $SED 's/ -Wl,-pthread / -pthread /g;s/^ *//;s/ *$//'`
-+      fi
++      case $compiler_lineage in #(
++	NAG)
++	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags " | $SED 's/ -Wl,-pthread / -pthread /g;s/^ *//;s/ *$//'`
++	  ;;
++      esac
 +
        # move library search paths that coincide with paths to not yet
        # installed libraries to the beginning of the library search list
diff --git a/contrib/06ltmain_nag_pthread-patch/ltmain_nag_pthread.patch b/contrib/06ltmain_nag_pthread-patch/ltmain_nag_pthread-libtool-2.4.6.patch
similarity index 72%
rename from contrib/06ltmain_nag_pthread-patch/ltmain_nag_pthread.patch
rename to contrib/06ltmain_nag_pthread-patch/ltmain_nag_pthread-libtool-2.4.6.patch
index 6e6355b98f104ed7bf4a144bfe8e38d2e4cd7e24..87cd70529da26cc6f54d5adb9b4a795728f102ec 100644
--- a/contrib/06ltmain_nag_pthread-patch/ltmain_nag_pthread.patch
+++ b/contrib/06ltmain_nag_pthread-patch/ltmain_nag_pthread-libtool-2.4.6.patch
@@ -1,19 +1,24 @@
 --- a/config/ltmain.sh
 +++ b/config/ltmain.sh
-@@ -7936,6 +7936,12 @@ func_mode_link ()
+@@ -7936,6 +7936,17 @@ func_mode_link ()
  	# Convert "-framework foo" to "foo.ltframework"
  	if test -n "$inherited_linker_flags"; then
  	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
 +
 +	  # Additionally convert " -pthread" to " -Wl,-pthread" for nagfor
-+	  if test yes = $with_nagfor ; then
-+	    tmp_inherited_linker_flags=`$ECHO " $tmp_inherited_linker_flags " | $SED 's/ -pthread[[:blank:]]/ -Wl,-pthread /g'`
-+	  fi
++	  case $compiler_lineage in #(
++           NAG)
++	      tmp_inherited_linker_flags=`$ECHO " $tmp_inherited_linker_flags " | $SED 's/ -pthread[[:blank:]]/ -Wl,-pthread /g'`
++	      ;; #(
++	    PGI)
++	      tmp_inherited_linker_flags=`$ECHO " $tmp_inherited_linker_flags " | $SED 's/ -pthread[[:blank:]]//g'`
++	      ;;
++	  esac
 +
  	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
  	    case " $new_inherited_linker_flags " in
  	      *" $tmp_inherited_linker_flag "*) ;;
-@@ -9570,6 +9577,20 @@ EOF
+@@ -9570,6 +9577,22 @@ EOF
  	  ;;
        esac
  
@@ -27,9 +32,11 @@
 +      # better not to revert the changes, otherwise, uncomment the following
 +      # lines.
 +
-+      if test yes = $with_nagfor ; then
-+        new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags " | $SED 's/ -Wl,-pthread / -pthread /g;s/^ *//;s/ *$//'`
-+      fi
++      case $compiler_lineage in #(
++	NAG)
++	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags " | $SED 's/ -Wl,-pthread / -pthread /g;s/^ *//;s/ *$//'`
++	  ;;
++      esac
 +
        # move library search paths that coincide with paths to not yet
        # installed libraries to the beginning of the library search list
diff --git a/m4/acx_use_libtool_configuration.m4 b/m4/acx_use_libtool_configuration.m4
index 3f21726393fc2855655dddc9cb5966d4c6c313a0..87025eac9782f23e9b0a700524e92c12ebb6b895 100644
--- a/m4/acx_use_libtool_configuration.m4
+++ b/m4/acx_use_libtool_configuration.m4
@@ -125,14 +125,22 @@ dnl newer PGI or NAG configurations particularly well
      [m4_pushdef(acx_ltconfig,m4_bpatsubst(m4_dquote(
         m4_bpatsubst(m4_dquote(m4_defn(acx_ltconfig)),[_LT_TAG_COMPILER
 ],
-       [\&  _LT_TAGDECL([with_nagfor], [acx_is_nagfor], [0], [Is the compiler the NAG Fortran compiler?])])),
+       [\&  _LT_TAGDECL([compiler_lineage], [acx_compiler_lineage], [0], [For inherited options, we need to know how to deal with those when using a library built with compiler X in compiler Y.])])),
        [_LT_CONFIG],
-       [AC_MSG_CHECKING([whether this is the NAG Fortran compiler])
-    $CC -V 2>&1 | grep '^NAG Fortran Compiler Release' >/dev/null 2>&1
-    _lt_result=$?
-    AS_IF([test $_lt_result -eq 0],[_lt_result=yes],[_lt_result=no])
+       [AC_MSG_CHECKING([for the compiler family])
+    case `$CC -V 2>&1 | sed -n '1,20p'` in #(
+    *NAG\\ Fortran\\ Compiler\\ Release*\)
+      _lt_result=NAG
+      ;; #(
+    *PGI\\ Compilers\\ and\\ Tools*|*Portland\\ *\)
+      _lt_result=PGI
+      ;;
+    *\)
+      _lt_result=other
+      ;;
+    esac
     AC_MSG_RESULT([$_lt_result])
-    _LT_TAGVAR([acx_is_nagfor], $][1)=$_lt_result
+    _LT_TAGVAR([acx_compiler_lineage], $][1)=$_lt_result
     \&]))])dnl
    LT_INIT([$1])
    m4_popdef([_LT_LANG_F77_CONFIG])dnl
@@ -164,7 +172,8 @@ dnl only causes overhead and potential problems.
      [AC_LANG_CASE([Fortran],[m4_pushdef([acx_flags_var],[FCFLAGS])m4_pushdef([acx_lt_tag],[FC])],
         [Fortran 77],[m4_pushdef([acx_flags_var],[FFLAGS])m4_pushdef([acx_lt_tag],[F77])],
         [C],[m4_pushdef([acx_flags_var],[CFLAGS])m4_pushdef([acx_lt_tag],[])])dnl
-      AS_IF([test x"$_LT_TAGVAR([acx_is_nagfor],m4_defn([acx_lt_tag]))" = xyes],
+      AS_CASE([$_LT_TAGVAR([acx_compiler_lineage],m4_defn([acx_lt_tag]))],
+	[NAG],
         [AS_CASE([" $acx_flags_var $LDFLAGS "],
            [*\ -B*\ *],
            [extrasub="${extrasub+$extrasub$as_nl}/^\# skip internal symbols for stubs created by xlf/i \\\\${as_nl}\# ignore symbols nagfor injects into our shared objects\\\\${as_nl}/"'^${exp_sym_prefix}'"${acx_symprfx}"'(__NAGf90_|f90_)/b'
diff --git a/scripts/reconfigure b/scripts/reconfigure
index f6c1147d74bd7311b6aed7a99de00a3a019da6c1..f2de38fae7c075e7125c9772da949252b317d8cb 100755
--- a/scripts/reconfigure
+++ b/scripts/reconfigure
@@ -83,8 +83,8 @@ case "$libtoolversion" in
       contrib/01aix-deplib-rpath-patch/aix-deplib-libtool.patch \
       contrib/03ltmain-ld-groups-patch/ltmain-ld-groups-libtool-2.4.6.patch \
       contrib/04ltmain-xlinker-patch/ltmain-xlinker-patch.patch \
-      contrib/05macos-nagfor-patch/macos-nagfor.patch \
-      contrib/06ltmain_nag_pthread-patch/ltmain_nag_pthread.patch \
+      contrib/05macos-nagfor-patch/macos-nagfor-libtool-2.4.6.patch \
+      contrib/06ltmain_nag_pthread-patch/ltmain_nag_pthread-libtool-2.4.6.patch \
       contrib/07ltmain-early-xcompile-patch/ltmain-early-xcompile-libtool-2.4.6.patch \
       contrib/08ltmain-parallel-printf-patch/ltmain-parallel-printf-libtool-2.4.6.patch \
       contrib/09debian-no-overlink-patch/deplib_binary.patch \