Skip to content

Commit 7f5ff2a

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 7f5ff2a

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--- config/ltmain.sh.orig 2025-03-17 00:35:39
2+
+++ config/ltmain.sh 2025-03-17 00:36:13
3+
@@ -9024,7 +9024,14 @@
4+
compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
5+
finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
6+
else
7+
+ case $host in
8+
+ *-*-darwin*)
9+
+ case $CC in
10+
+ flang*) compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -Wl,-framework,\1%g'`;;
11+
+ *) compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`;;
12+
+ esac;;
13+
+ *) compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`;;
14+
+ esac
15+
- compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
16+
fi
17+
fi
18+
dependency_libs=$newdependency_libs
19+
@@ -9369,7 +9375,7 @@
20+
# On Darwin other compilers
21+
func_cc_basename $CC
22+
case $func_cc_basename_result in
23+
- nagfor*)
24+
+ flang*|nagfor*)
25+
verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
26+
;;
27+
*)
28+
@@ -9870,7 +9876,10 @@
29+
# Time to change all our "foo.ltframework" stuff back to "-framework foo"
30+
case $host in
31+
*-*-darwin*)
32+
- newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
33+
+ case $CC in
34+
+ flang*) newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -Wl,-framework,\1%g'`;;
35+
+ *) newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`;;
36+
+ esac
37+
new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
38+
deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
39+
;;

0 commit comments

Comments
 (0)