Skip to content

configury: fix support for flang on OSX #13142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion autogen.pl
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,10 @@ sub patch_autotools_output {
verbose "$indent_str"."Patching \"-pthread\" option for NAG compiler in ltmain.sh\n";
system("$patch_prog -N -p0 < $topdir/config/ltmain_nag_pthread.diff >/dev/null 2>&1");
unlink("config/ltmain.sh.rej");

verbose "$indent_str"."Patching \"-framework\" option for flang compiler in ltmain.sh\n";
system("$patch_prog -N -p0 < $topdir/config/ltmain_flang_darwin.diff >/dev/null 2>&1");
unlink("config/ltmain.sh.rej");
}

# If there's no configure script, there's nothing else to do.
Expand Down Expand Up @@ -1071,8 +1075,14 @@ sub patch_autotools_output {
lt_prog_compiler_static_FC=\'-Bstatic\'
;;';
$replace_string = "case \$cc_basename in
flang*)
# flang compiler
lt_prog_compiler_wl_FC='-Wl,'
lt_prog_compiler_pic_FC='-fPIC'
lt_prog_compiler_static_FC='-static'
;;
icc* | ifort*)
#Intel Fortran compiler
# Intel Fortran compiler
lt_prog_compiler_wl_FC='-Wl,'
lt_prog_compiler_pic_FC='-fno-common -PIC'
lt_prog_compiler_static_FC=''
Expand Down Expand Up @@ -1109,6 +1119,23 @@ sub patch_autotools_output {
$c =~ s/$search_string/$replace_string/g;
}

$search_string = 'case \$cc_basename in
ifort\*\|nagfor\*\) _lt_dar_can_shared=yes ;;
\*\) _lt_dar_can_shared=\$GCC ;;
esac';
$replace_string = "case \$cc_basename in
flang*|ifort*|nagfor*) _lt_dar_can_shared=yes ;;
*) _lt_dar_can_shared=\$GCC ;;
esac";
push(@verbose_out, $indent_str . "Patching configure for flang compiler on Darwin (FC)\n");
$c =~ s/$search_string/$replace_string/g;

$search_string = 'archive_cmds_FC="\\\\\\$CC -dynamiclib';
$replace_string = 'archive_cmds_FC="\$CC --shared';
push(@verbose_out, $indent_str . "Patching configure for flang compiler on Darwin (FC)\n");
$c =~ s/$search_string/$replace_string/g;
$c =~ s/(archive_cmds_FC.*)-install_name \\\$rpath/$1-Wl,-install_name,\\\`echo \\\$rpath | sed \'s%^[ ]*%%\'\\\`/g;

# Only write out verbose statements and a new configure if the
# configure content actually changed
return
Expand Down
39 changes: 39 additions & 0 deletions config/ltmain_flang_darwin.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--- config/ltmain.sh
+++ config/ltmain.sh
@@ -9024,7 +9024,14 @@
compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
else
- compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
+ case $host in
+ *-*-darwin*)
+ case $CC in
+ flang*) compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -Wl,-framework,\1%g'`;;
+ *) compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`;;
+ esac;;
+ *) compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`;;
+ esac
fi
fi
dependency_libs=$newdependency_libs
@@ -9369,7 +9376,7 @@
# On Darwin other compilers
func_cc_basename $CC
case $func_cc_basename_result in
- nagfor*)
+ flang*|nagfor*)
verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
;;
*)
@@ -9869,7 +9876,10 @@
# Time to change all our "foo.ltframework" stuff back to "-framework foo"
case $host in
*-*-darwin*)
- newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
+ case $CC in
+ flang*) newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -Wl,-framework,\1%g'`;;
+ *) newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`;;
+ esac
new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
;;