Index: gcc/fortran/gfortranspec.c =================================================================== --- gcc/fortran/gfortranspec.c (revision 136591) +++ gcc/fortran/gfortranspec.c (working copy) @@ -62,21 +62,36 @@ #define FORTRAN_INIT "-lgfortranbegin" #endif -#ifndef FORTRAN_LIBRARY -#define FORTRAN_LIBRARY "-lgfortran" +#ifndef FORTRAN_SHARED_LIBRARY +#define FORTRAN_SHARED_LIBRARY "-lgfortran" #endif +#ifndef FORTRAN_STATIC_LIBRARY +#define FORTRAN_STATIC_LIBRARY "-lgfortran_static" +#endif + #ifdef HAVE_LD_STATIC_DYNAMIC -#define ADD_ARG_LIBGFORTRAN(arg) \ +#define ADD_ARG_LIBGFORTRAN \ { \ - if (static_lib && !static_linking) \ - append_arg ("-Wl,-Bstatic"); \ - append_arg (arg); \ - if (static_lib && !static_linking) \ - append_arg ("-Wl,-Bdynamic"); \ + if (static_lib) \ + { \ + if (!static_linking) append_arg ("-Wl,-Bstatic"); \ + append_arg(FORTRAN_STATIC_LIBRARY) ; \ + if (!static_linking) append_arg ("-Wl,-Bdynamic"); \ + } \ + else \ + { \ + append_arg(FORTRAN_SHARED_LIBRARY) ; \ + } \ } #else -#define ADD_ARG_LIBGFORTRAN(arg) append_arg (arg); +#define ADD_ARG_LIBGFORTRAN \ + { \ + if (static_lib) \ + append_arg(FORTRAN_STATIC_LIBRARY) ; \ + else \ + append_arg(FORTRAN_SHARED_LIBRARY) ; \ + } #endif @@ -265,9 +280,9 @@ int skip; const char *arg; - /* This will be NULL if we encounter a situation where we should not - link in libf2c. */ - const char *library = FORTRAN_LIBRARY; + /* 0 => don't link libgfortran etc. + 1 => link libgfortran version as determined by static_lib */ + int should_link_libs = 1; /* 0 => -xnone in effect. 1 => -xfoo in effect. */ @@ -346,7 +361,7 @@ case OPTION_E: /* These options disable linking entirely or linking of the standard libraries. */ - library = 0; + should_link_libs = 0; break; case OPTION_static_libgfortran: @@ -411,7 +426,7 @@ /* If there are no input files, no need for the library. */ if (n_infiles == 0) - library = 0; + should_link_libs = 0; /* Second pass through arglist, transforming arguments as appropriate. */ @@ -511,15 +526,23 @@ use_init = 1; } - ADD_ARG_LIBGFORTRAN (FORTRAN_LIBRARY); + ADD_ARG_LIBGFORTRAN ; } } - else if (strcmp (argv[i], FORTRAN_LIBRARY) == 0) + else if (strcmp (argv[i], FORTRAN_SHARED_LIBRARY) == 0) { saw_library = 1; /* -l. */ - ADD_ARG_LIBGFORTRAN (argv[i]); + static_lib = 0 ; + ADD_ARG_LIBGFORTRAN ; continue; } + else if (strcmp (argv[i], FORTRAN_STATIC_LIBRARY) == 0) + { + saw_library = 1; /* -l. */ + static_lib = 1 ; + ADD_ARG_LIBGFORTRAN; + continue; + } else { /* Other library, or filename. */ if (saw_library == 1 && need_math) @@ -532,7 +555,7 @@ /* Append `-lg2c -lm' as necessary. */ - if (library) + if (should_link_libs) { /* Doing a link and no -nostdlib. */ if (saw_speclang) append_arg ("-xnone"); @@ -545,7 +568,7 @@ append_arg (FORTRAN_INIT); use_init = 1; } - ADD_ARG_LIBGFORTRAN (library); + ADD_ARG_LIBGFORTRAN ; /* Fall through. */ case 1: @@ -557,7 +580,7 @@ } #ifdef ENABLE_SHARED_LIBGCC - if (library) + if (should_link_libs) { int i;