Thanks for all the helpful suggestions made in response to :
http://gcc.gnu.org/ml/gcc/2008-06/msg00244.html
------
Here is version 2 of the patch.
This is now conditional on darwin* as the host.
(I guess, in principle, it should really depend on LD_FOR_TARGET, but
I couldn't see how to achieve that tidily).
to implement it requires:
a change to the gfortran driver.
a change to the build of libgfortran.
---
a. I've made the change to the driver such that any other host
requiring this only need to define a flag in its x-host.
b. this "USE_DISTINCT_STATIC_LIB_NAME" flag is also available for any
other front ends that want to cater for this darwin 'feature'.
---
change summary:
gcc/config/x-darwin : add a flag identifying this as a system
wanting separate static lib names
gcc/fortran/gfortranspec.c : provide for a distinct static library
name on -static-libgfortran
libgfortran/Makefile.am : generate differently named static/dynamic
libraries on darwin
libgfortran/configure.ac: likewise
----
*I have NOT attached the following generated file diffs (it made a
huge mail, and conveys no extra info):
Index: libgfortran/configure
Index: libgfortran/Makefile.in
Index: libgfortran/config.h.in
Index: libgfortran/aclocal.m4
if anyone wants them - I can email them g/b/zip.
otherwise, to replicate what I did run autoreconf in libgfortran with :
autoconf (GNU Autoconf) 2.61,
automake (GNU automake) 1.9.6,
ltmain.sh (GNU libtool) 1.5.26 (1.1220.2.492 2008/01/30 06:40:56)
*************************************
TESTS carried out;
This has been bootstrapped on:
powerpc-apple-darwin9
powerpc-apple-darwin8
i686-apple-darwin8
cross tools have also been built on those platforms.
it has been checked by comparing RUNTESTFLAGS="--target_board=unix/-
static-libgfortran" with the default on
powerpc-apple-darwin9 [m32, m64]
powerpc-apple-darwin8 [m32, m64 ***]
i686-apple-darwin8
*** note you need to do this : http://gcc.gnu.org/ml/gcc/2008-06/
msg00361.html for m64 tests
no regressions noted.
=====
Missing tests:
1/ a non-darwin system (sorry, don't have one up at the moment).
2/ x86_64 darwin8
3/ i686/x86_64 darwin9
*************************************
Index: gcc/config/x-darwin
===================================================================
--- gcc/config/x-darwin (revision 136861)
+++ gcc/config/x-darwin (working copy)
@@ -1,3 +1,5 @@
+# for static lib on gfortran
+T_CFLAGS += "-DUSE_DISTINCT_STATIC_LIB_NAME"
host-darwin.o : $(srcdir)/config/host-darwin.c $(CONFIG_H) $
(SYSTEM_H) \
coretypes.h toplev.h config/host-darwin.h
$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<
Index: gcc/fortran/gfortranspec.c
===================================================================
--- gcc/fortran/gfortranspec.c (revision 136861)
+++ gcc/fortran/gfortranspec.c (working copy)
@@ -62,21 +62,40 @@
#define FORTRAN_INIT "-lgfortranbegin"
#endif
-#ifndef FORTRAN_LIBRARY
-#define FORTRAN_LIBRARY "-lgfortran"
+#ifndef FORTRAN_SHARED_LIBRARY
+#define FORTRAN_SHARED_LIBRARY "-lgfortran"
#endif
+#ifdef USE_DISTINCT_STATIC_LIB_NAME
+# ifndef FORTRAN_STATIC_LIBRARY
+# define FORTRAN_STATIC_LIBRARY "-lgfortran-static"
+# endif
+#else
+# define FORTRAN_STATIC_LIBRARY FORTRAN_SHARED_LIBRARY
+#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 +284,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 +365,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 +430,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 +530,27 @@
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<library>. */
- ADD_ARG_LIBGFORTRAN (argv[i]);
+#ifdef USE_DISTINCT_STATIC_LIB_NAME
+ static_lib = 0 ;
+#endif
+ ADD_ARG_LIBGFORTRAN ;
continue;
}
+#ifdef USE_DISTINCT_STATIC_LIB_NAME
+ else if (strcmp (argv[i], FORTRAN_STATIC_LIBRARY) == 0)
+ {
+ saw_library = 1; /* -l<library>. */
+ static_lib = 1 ;
+ ADD_ARG_LIBGFORTRAN;
+ continue;
+ }
+#endif
else
{ /* Other library, or filename. */
if (saw_library == 1 && need_math)
@@ -532,7 +563,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 +576,7 @@
append_arg (FORTRAN_INIT);
use_init = 1;
}
- ADD_ARG_LIBGFORTRAN (library);
+ ADD_ARG_LIBGFORTRAN ;
/* Fall through. */
case 1:
@@ -557,7 +588,7 @@
}
#ifdef ENABLE_SHARED_LIBGCC
- if (library)
+ if (should_link_libs)
{
int i;
Index: libgfortran/configure.ac
===================================================================
--- libgfortran/configure.ac (revision 136861)
+++ libgfortran/configure.ac (working copy)
@@ -178,6 +178,16 @@
esac
AC_SUBST(extra_ldflags_libgfortran)
+# any hosts that need different lib names for the static/shared
+darwinstatic=false
+case "${host}" in
+ *-darwin*)
+ # Darwin needs a distinct library name to accommodate -static-
libgfortran
+ darwinstatic=true
+ ;;
+esac
+AM_CONDITIONAL([NEED_DISTINCT_STATIC_LIB_NAME], [test x$darwinstatic
= xtrue])
+
# We need a working compiler at that point, otherwise give a clear
# error message and bail out.
LIBGFOR_WORKING_GFORTRAN
Index: libgfortran/Makefile.am
===================================================================
--- libgfortran/Makefile.am (revision 136861)
+++ libgfortran/Makefile.am (working copy)
@@ -17,13 +17,24 @@
toolexeclib_LTLIBRARIES = libgfortran.la
libgfortran_la_LINK = $(LINK)
-libgfortran_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/
libtool-version` $(LTLDFLAGS) -lm $(extra_ldflags_libgfortran) $
(version_arg)
myexeclib_LTLIBRARIES = libgfortranbegin.la
myexeclibdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$
(MULTISUBDIR)
+
+if NEED_DISTINCT_STATIC_LIB_NAME
+## generate a distinctly named static lib
+myexeclib_LTLIBRARIES += libgfortran-static.la
+## supress the extraneous static lib.
+libgfortran_la_LDFLAGS = -shared -version-info `grep -v '^\#' $
(srcdir)/libtool-version` $(LTLDFLAGS) -lm $
(extra_ldflags_libgfortran) $(version_arg)
+else
+libgfortran_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/
libtool-version` $(LTLDFLAGS) -lm $(extra_ldflags_libgfortran) $
(version_arg)
+endif
+
libgfortranbegin_la_SOURCES = fmain.c
libgfortranbegin_la_LDFLAGS = -static
+libgfortran_static_la_LDFLAGS = -static
+
## io.h conflicts with a system header on some platforms, so
## use -iquote
AM_CPPFLAGS = -iquote$(srcdir)/io -I$(srcdir)/$(MULTISRCTOP)../gcc \
@@ -742,9 +753,12 @@
# $(LTPPFCCOMPILE) -c -o $@ $^ -combine
libgfortran_la_SOURCES = libgfortran_c.c $(filter-out %.c,$
(prereq_SRC))
+libgfortran_static_la_SOURCES = libgfortran_c.c $(filter-out %.c,$
(prereq_SRC))
else
+
libgfortran_la_SOURCES = $(prereq_SRC)
+libgfortran_static_la_SOURCES = $(prereq_SRC)
endif
====
ttfn,
Iain