Skip to content

Commit bccd734

Browse files
committed
configury: fix support for flang on OSX
Refs. #13137 - replace -framework foo with -Wl,-framework,foo - replace -dynamiclib with --shared when flang is used - use -Wl when needed Signed-off-by: Gilles Gouaillardet <[email protected]>
1 parent 9fbd849 commit bccd734

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

autogen.pl

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,10 @@ sub patch_autotools_output {
867867
verbose "$indent_str"."Patching \"-pthread\" option for NAG compiler in ltmain.sh\n";
868868
system("$patch_prog -N -p0 < $topdir/config/ltmain_nag_pthread.diff >/dev/null 2>&1");
869869
unlink("config/ltmain.sh.rej");
870+
871+
verbose "$indent_str"."Patching \"-framework\" option for flang compiler in ltmain.sh\n";
872+
system("$patch_prog -N -p0 < $topdir/config/ltmain_flang_darwin.diff >/dev/null 2>&1");
873+
unlink("config/ltmain.sh.rej");
870874
}
871875

872876
# If there's no configure script, there's nothing else to do.
@@ -1071,8 +1075,14 @@ sub patch_autotools_output {
10711075
lt_prog_compiler_static_FC=\'-Bstatic\'
10721076
;;';
10731077
$replace_string = "case \$cc_basename in
1078+
flang*)
1079+
# flang compiler
1080+
lt_prog_compiler_wl_FC='-Wl,'
1081+
lt_prog_compiler_pic_FC='-fPIC'
1082+
lt_prog_compiler_static_FC='-static'
1083+
;;
10741084
icc* | ifort*)
1075-
#Intel Fortran compiler
1085+
# Intel Fortran compiler
10761086
lt_prog_compiler_wl_FC='-Wl,'
10771087
lt_prog_compiler_pic_FC='-fno-common -PIC'
10781088
lt_prog_compiler_static_FC=''
@@ -1109,6 +1119,23 @@ sub patch_autotools_output {
11091119
$c =~ s/$search_string/$replace_string/g;
11101120
}
11111121

1122+
$search_string = 'case \$cc_basename in
1123+
ifort\*\|nagfor\*\) _lt_dar_can_shared=yes ;;
1124+
\*\) _lt_dar_can_shared=\$GCC ;;
1125+
esac';
1126+
$replace_string = "case \$cc_basename in
1127+
flang*|ifort*|nagfor*) _lt_dar_can_shared=yes ;;
1128+
*) _lt_dar_can_shared=\$GCC ;;
1129+
esac";
1130+
push(@verbose_out, $indent_str . "Patching configure for flang compiler on Darwin (FC)\n");
1131+
$c =~ s/$search_string/$replace_string/g;
1132+
1133+
$search_string = 'archive_cmds_FC="\\\\\\$CC -dynamiclib';
1134+
$replace_string = 'archive_cmds_FC="\$CC --shared';
1135+
push(@verbose_out, $indent_str . "Patching configure for flang compiler on Darwin (FC)\n");
1136+
$c =~ s/$search_string/$replace_string/g;
1137+
$c =~ s/(archive_cmds_FC.*)-install_name \\\$rpath/$1-Wl,-install_name,\\\`echo \\\$rpath | sed \'s%^[ ]*%%\'\\\`/g;
1138+
11121139
# Only write out verbose statements and a new configure if the
11131140
# configure content actually changed
11141141
return

config/ltmain_flang_darwin.diff

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
--- config/ltmain.sh
2+
+++ config/ltmain.sh
3+
@@ -8338,7 +8338,7 @@
4+
esac
5+
done
6+
fi
7+
- dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8+
+ dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -Wl,-framework,\1%g'`
9+
if test lib,link = "$linkmode,$pass" ||
10+
test prog,scan = "$linkmode,$pass" ||
11+
{ test prog != "$linkmode" && test lib != "$linkmode"; }; then
12+
@@ -9023,7 +9023,7 @@
13+
compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
14+
finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
15+
else
16+
- compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
17+
+ compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -Wl,-framework,\1%g'`
18+
fi
19+
fi
20+
dependency_libs=$newdependency_libs
21+
@@ -9367,7 +9367,7 @@
22+
# On Darwin other compilers
23+
func_cc_basename $CC
24+
case $func_cc_basename_result in
25+
- nagfor*)
26+
+ flang*|nagfor*)
27+
verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
28+
;;
29+
*)
30+
@@ -9864,12 +9864,12 @@
31+
# Done checking deplibs!
32+
deplibs=$newdeplibs
33+
fi
34+
- # Time to change all our "foo.ltframework" stuff back to "-framework foo"
35+
+ # Time to change all our "foo.ltframework" stuff back to "-Wl,-framework,foo"
36+
case $host in
37+
*-*-darwin*)
38+
- newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
39+
- new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
40+
- deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
41+
+ newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -Wl,-framework,\1%g'`
42+
+ new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -Wl,-framework,\1%g'`
43+
+ deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -Wl,-framework,\1%g'`
44+
;;
45+
esac
46+
47+
@@ -10598,9 +10598,9 @@
48+
;;
49+
esac
50+
fi
51+
- # Time to change all our "foo.ltframework" stuff back to "-framework foo"
52+
- compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
53+
- finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
54+
+ # Time to change all our "foo.ltframework" stuff back to "-Wl,-framework,foo"
55+
+ compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -Wl,-framework,\1%g'`
56+
+ finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -Wl,-framework,\1%g'`
57+
;;
58+
esac
59+

0 commit comments

Comments
 (0)