Apple f77 vs GNU autoconf
Today, I have been led a merry little chase. I got some email last week asking me to roll a pre-bootstrapped libtool for regression testing on various architectures, and today was the day I found the time to oblige. Except that I couldn’t get `make dist' to succeed as the Dec 2002 Apple Developer’s Tools don’t contain a fortran compiler, so the f77demo directory couldn’t build.
No biggie with fink installed: `sudo apt-get install f77‘ and a few minutes wait. Tried to roll a libtool distribution again, and things were going well until this point:
... checking for g77... g77 checking whether we are using the GNU Fortran 77 compiler... yes checking whether g77 accepts -g... yes checking how to get verbose linking output from g77... -v checking for Fortran libraries of g77... -L/sw/lib/gcc/darwin/3.1 -L/sw/lib/gcc/darwin -L/sw/libexec/gcc/darwin/ppc/3.1 -lcrt1.o -lcrtbegin.o -lfrtbegin -lg2c -lSystem checking for dummy main to link with Fortran libraries...configure: error: linking to Fortran libraries from C fails ...
I thought it a little odd that the fink g77 was in the /sw tree, and the rest of the compiler tool chain was in the /usr tree, so maybe I needed to build a full gcc distribution and install it to the same directory root? Luckily, Apple honour the GPL and make the patched sources they use for the Developer Tools gcc build available through ADC. So I snarfed the gcc3-1175.tar.gz tarball, and followed the instructions in the README.Apple after adding f77 to the ENABLELANGUAGES variable in `buildgcc’. A couple of hours later the build had successfully completed, but rather than overwrite my Developer Tools compilers, I manually copied the fortran files into the /usr tree:
$ tar zxf gcc3-1175.tar.gz $ cd gcc3-1175 $ mkdir -p build/obj/ppc/libf2c build/dst build/sym $ gnumake install RC_OS=macos RC_ARCHES=ppc TARGETS=ppc SRCROOT=`pwd` OBJROOT=`pwd`/build/obj DSTROOT=`pwd`/build/dst SYMROOT=`pwd`/build/sym $ cd build/obj/ppc/libf2c $ CFLAGS='-traditional-cpp' ../../../../configure --srcdir=/libf2c --host=ppc --target=ppc $ make $ sudo cp .libs/libg2c.a libfrtbegin.a /usr/lib/gcc/darwin/3.1/ $ sudo cp g2c.h /usr/include/gcc/darwin/3.1 $ sudo chown root:wheel /usr/lib/gcc/darwin/3.1/*.a /usr/include/gcc/darwin/3.1/g2c.h $ sudo chmod 444 /usr/lib/gcc/darwin/3.1/*.a /usr/include/gcc/darwin/3.1/g2c.h $ cd ../../cc-ppc-on-ppc $ sudo cp g77 /usr/bin/g773 $ sudo cp f771 /usr/libexec/gcc/darwin/ppc/3.1 $ cd /usr/bin $ sudo ln -s g773 g77 $ sudo ln -s g77 f77 $ cd ../include $ sudo ln -s gcc/darwin/default/g++-v3 . $ sudo sh -c 'for file in gcc/darwin/default/*.h; do ln -s .; done' $ cd ../lib $ sudo sh -c 'for file in gcc/darwin/default/*.a; do ln -s .; done'
After all that, still the same failure in libtool’s f77demo directory
So, it would seem that Autoconf’s support for Fortran on darwin is broken. Looking through config.log (which I really should have done much sooner), I discovered that the compiler was complaining about duplicate symbols in crt1.o and crtbegin.o… maybe the `-lcrt1.o -lcrtbegin.o' part in the Fortran libraries of g77 test was to blame. Sure enough a manual compile of the failing test file with those flags removed worked!
All that remained was to find the guilty macro in Autoconf and generate a patch. That bit, at least, was easy. I’ve submitted the patch for inclusion in the next release of Autoconf, and reproduced it here incase you want to manually patch your installed Autoconf library and have g77 (I expect this will fix the fink g77 too) play nicely with Autoconf on your Mac:
--- lib/autoconf/fortran.m4 30 Sep 2003 13:03:01 -0000 1.173 +++ lib/autoconf/fortran.m4 6 Oct 2003 20:55:09 -0000 @@ -633,7 +633,7 @@ while test $[@%:@] != 1; do [_AC_LINKER_OPTION([], ac_cv_[]_AC_LANG_ABBREV[]_libs)]) ;; # Ignore these flags. - -lang* | -lcrt[01].o | -lc | -lgcc | -libmil | -LANG:=*) + -lang* |-lcrt[[01]].o |-lcrtbegin.o |-lc |-lgcc |-libmil |-LANG:=*) ;; -lkernel32) test x"" != xyes && ac_cv_[]_AC_LANG_ABBREV[]_libs="[]_AC_LANG_ABBREV[]_libs "
Oh, and for the record, I managed to roll a bootstrapped CVS libtool in the end too.
Leave a comment
This blog uses Gravatar for comment avatar pictures: If you'd like a different picture next to your comments, sign up at gravatar.com, upload a picture, and within 5 or 10 minutes you'll be able to see it here (and at lots of other websites with Gravatar support).