From Kurt.Hornik@ci.tuwien.ac.at  Wed Aug  1 10:00:16 2001
From: Kurt.Hornik@ci.tuwien.ac.at (Kurt Hornik)
Date: Wed, 1 Aug 2001 11:00:16 +0200
Subject: [Rd] Compiling R (1.3.0) on AIX (4.3) fails (PR#1034)
In-Reply-To: <pxbsm1jg8b.fsf@infiniti.ece.cmu.edu>
References: <200107291917.VAA24794@pubhealth.ku.dk>
 <pxsnffpkc8.fsf@infiniti.ece.cmu.edu>
 <pxlml6cxfo.fsf@infiniti.ece.cmu.edu>
 <15205.38703.553276.335905@mithrandir.hornik.net>
 <pxbsm1jg8b.fsf@infiniti.ece.cmu.edu>
Message-ID: <15207.50464.266507.281379@mithrandir.hornik.net>

>>>>> Thomas Vogels writes:

> Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at> writes:

>> >>>>> Thomas Vogels writes:
>> 
>> > Excerpt from Kurt's email this morning:
>> 
>> >>>> > 2) after configure (with CC=gcc but using AIX's linker
>> >> /usr/bin/ld), the
>> >>>> > Makefile in src/library/tcltk/src doesn't protect the linker
>> >> flags
>> >> -bI
>> >>>> > with -Xlinker! (-Xlinker is required when using gcc so that the
>> >> linker flags
>> >>>> > are passed on to ld correctly.  Which I know that you know...)
>> >>>> >   The fix is to add -Xlinker before every -bI. Sorry, haven't
>> >> looked into
>> >>>> > patching configure yet...
>> >> 
>> >> Very strange.  Configure has
>> >> 
>> >> *aix4.[2-9]*)
>> >> EXPORTFILE="\$(top_builddir)/etc/R.exp"
>> >> cpicflags=
>> >> cxxpicflags=
>> >> fpicflags=
>> >> wl="-Wl,"
>> >> main_ldflags="${wl}-bdynamic ${wl}-bE:${EXPORTFILE} ${wl}-bM:SRE"
>> >> shlib_ldflags="${wl}-bM:SRE ${wl}-H512 ${wl}-T512 ${wl}-bnoentry \
>> >> ${wl}-bexpall ${wl}-bI:\$(R_HOME)/etc/R.exp"
>> >> SHLIB_LIBADD="\$(LIBM)"
>> >> ;;
>> >> 
>> >> so unless I am missing something obvious all linker flages are
>> >> protected
>> >> via `-Wl,' (which should also work if the C compiler is not gcc).
>> >> 
>> 
>> > Sorry, should have been more explicit, I guess: the problem is with
>> > PKG_LIBS (which is the only variable in that Makefile using linker
>> > flags...)  Some digging shows that '-Wl,' (or '-Xlinker') is missing
>> > in tkConfig.sh.  So if you have Tcl/Tk (8.3 in my case) installed and
>> > used AIX's 'cc' compiler, you get in trouble with later using gcc
>> > (e.g. for R).  Oddly, this didn't show when compiling, say, Tktable.
>> 
>> > There is the question, why configure didn't "see" this coming.  What
>> > would be nice is a warning to the effect that tkConfig.sh is broken
>> > when R can't compile tcltk.c.  (Currently I get messages about libc.a
>> > not found...)
>> 
>> This is asking for a bit much, I think.  How would configure know for
>> sure that tkConfig.sh is broken?

> I promise to get more sleep soon... 'What would be nice is a warning
> to the effect that the Tcl/Tk configuration failed, like:
> checking how to compile and link tcl/tk.... failed
> '  Asking about tkConfig.sh (or tclConfig.sh) is probably too muc as
> threre are other factors that can cause the fail (config.site...).

> What this would boil down to is trying to compile e.g. tkAppInit.c and
> see whether compilation and linking works.  But even this may
> be asking  fortoo much, this is just one architecture.  Things like these
> will continue to happen with AIX as long as there are those '.exp'
> files around...


>> On second thought: the comment in tkConfig.sh says
>> 
>> # String to pass to linker to pick up the Tk library from its
>> # installed directory.
>> TK_LIB_SPEC='@TK_LIB_SPEC@'
>> 
>> so maybe this assumes to be called by ld directly ...
>> 
>> What happens if we omit TK_LIB_SPEC from TCLTK_LIBS?

> hell breaks loose.  TK_LIB_SPEC contains '-bI/some/path/libtk8.3.exp'
> which is needed badly when linking on AIX.

Argh.  After sinking some more time into this ... here's what happens.

Assuming that both tclConfig.sh and tkConfig.sh are found, we do

	TCLTL_LIBS="${TCL_LIB_SPEC} ${TK_LIB_SPEC} ${TK_LIBS}"

Using tcl8.4a1 and tk8.4a1 one gets for a shared build on AIX from the
TclTk configure code:

    if test "$using_gcc" = "yes" ; then
        TCL_BUILD_LIB_SPEC="-Wl,-bI:`pwd`/${TCL_BUILD_EXP_FILE} -L`pwd`"
        TCL_LIB_SPEC="-Wl,-bI:${exec_prefix}/lib/${TCL_EXP_FILE} -L`pwd`"    
    else
        TCL_BUILD_LIB_SPEC="-bI:`pwd`/${TCL_BUILD_EXP_FILE}"
        TCL_LIB_SPEC="-bI:${exec_prefix}/lib/${TCL_EXP_FILE}"    
    fi

    TK_LIB_SPEC="-bI:${exec_prefix}/lib/${TK_EXP_FILE}"

So the TclTk maintainers in their infinite wisdom have caught the gcc
case for tcl but not for tk.

I therefore suggest the following.

* Can you try replacing

      TCLTK_LIBS="${TCLTK_LIBS} ${TK_LIB_SPEC} ${TK_LIBS}"

  in m4/R.m4 by

      TCLTK_LIBS="${TCLTK_LIBS} ${wl}${TK_LIB_SPEC} ${TK_LIBS}"

  and see if that works?  (You will have to configure using
  --enable-maintainer-mode to get configure rebuilt.  Or, you could
  simply edit configure.)  By `works' I mean under both gcc and cc.

* If so, this is the short-term fix we could go for.  If not, we may
  need to infer wl for non-gcc from libtool, which is doable.

* It may be useful to report the discrepancy to the TclTk maintainers.

* Provided they fix the problem, we need to think about better
  strategies.  (Something like if wl is not the empty string and
  TK_LIB_SPEC does not start with it then add it as prefix.)  But let us
  not worry about this now.

-k
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] Compiling R (1.3.0) on AIX (4.3) fails (PR#1034)
Kurt Hornik