--- a/config/ltmain.sh
+++ b/config/ltmain.sh
@@ -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
+	  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,22 @@ EOF
 	  ;;
       esac
 
+      # Time to revert the changes made for nagfor. This might be required if
+      # we need to make the output '*.la' file to be correctly interpreted for
+      # gcc (e.g. the output library that we are linking now with nagfor needs
+      # to be linked by gcc later). In this case, the libtool script of a
+      # package that will try to link our library will have to make similar
+      # non-standard nagfor-specific modifications of the '-pthread' flag.
+      # Thus, if we are creating a Fortran library for nagfor only, it is
+      # better not to revert the changes, otherwise, uncomment the following
+      # lines.
+
+      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
       new_libs=
