Hi all, Attached is a first draft of a patch to add a -fstatic-libgfortran option. This new option is recognized by the driver and instead of adding "-lgfortran" to the various subprocesses, it adds "-Wl,-Bstatic -lgfortran -Wl,-Bdynamic". I have two questions about this: + linkers other than the GNU linker might have problems with that. is there a more general way of doing this? or should it be conditional on some macro, like HAVE_LD_STATIC_DYNAMIC? + when -static is used later in the command line, this trick doesn't work; would "%{!static:-Wl,-Bstatic} -lgfortran %{!static:-Wl,-Bdynamic}" be a good replacement?
Thanks for the help, I'm a bit a loss with non-GNU linkers... :( FX
Index: lang.opt =================================================================== --- lang.opt (revision 123942) +++ lang.opt (working copy) @@ -249,6 +249,10 @@ Fortran Use the narrowest integer type possible for enumeration types +fstatic-libgfortran +Fortran +Statically link the GNU Fortran helper library (libgfortran) + funderscoring Fortran Append underscores to externally visible names Index: options.c =================================================================== --- options.c (revision 123942) +++ options.c (working copy) @@ -549,6 +549,9 @@ gfc_option.flag_second_underscore = value; break; + case OPT_fstatic_libgfortran: + break; + case OPT_fimplicit_none: gfc_option.flag_implicit_none = value; break; Index: gfortranspec.c =================================================================== --- gfortranspec.c (revision 123942) +++ gfortranspec.c (working copy) @@ -82,6 +82,7 @@ -nodefaultlibs. */ OPTION_o, /* Aka --output. */ OPTION_S, /* Aka --assemble. */ + OPTION_static_libgfortran, /* -fstatic-libgfortran. */ OPTION_syntax_only, /* -fsyntax-only. */ OPTION_v, /* Aka --verbose. */ OPTION_version, /* --version. */ @@ -170,6 +171,8 @@ opt = OPTION_nostdlib; else if (!strcmp (text, "-fsyntax-only")) opt = OPTION_syntax_only; + else if (!strcmp (text, "-fstatic-libgfortran")) + opt = OPTION_static_libgfortran; else if (!strcmp (text, "-dumpversion")) opt = OPTION_version; else if (!strcmp (text, "-fversion")) /* Really --version!! */ @@ -265,6 +268,9 @@ /* By default, we throw on the math library if we have one. */ int need_math = (MATH_LIBRARY[0] != '\0'); + /* Whether we should link a static libgfortran. */ + int static_lib = 0; + /* The number of input and output files in the incoming arg list. */ int n_infiles = 0; int n_outfiles = 0; @@ -323,6 +329,10 @@ library = 0; break; + case OPTION_static_libgfortran: + static_lib = 1; + break; + case OPTION_l: ++n_infiles; break; @@ -468,11 +478,28 @@ append_arg (FORTRAN_INIT); use_init = 1; } + + if (static_lib) + append_arg ("-Wl,-Bstatic"); append_arg (FORTRAN_LIBRARY); + if (static_lib) + append_arg ("-Wl,-Bdynamic"); } } else if (strcmp (argv[i], FORTRAN_LIBRARY) == 0) - saw_library = 1; /* -l<library>. */ + { + saw_library = 1; /* -l<library>. */ + + if (static_lib) + append_arg ("-Wl,-Bstatic"); + + append_arg (argv[i]); + + if (static_lib) + append_arg ("-Wl,-Bdynamic"); + + continue; + } else { /* Other library, or filename. */ if (saw_library == 1 && need_math) @@ -498,7 +525,12 @@ append_arg (FORTRAN_INIT); use_init = 1; } + + if (static_lib) + append_arg ("-Wl,-Bstatic"); append_arg (library); + if (static_lib) + append_arg ("-Wl,-Bdynamic"); case 1: if (need_math) append_arg (MATH_LIBRARY);