Subject: turning linker options into an environment variable with buildlink3
To: None <tech-pkg@NetBSD.org>
From: Klaus Heinz <k.heinz.apr.vier@onlinehome.de>
List: tech-pkg
Date: 04/20/2004 02:15:03
Hi,

the native linker on Unixware does not provide an option to specify
the library search paths to be recorded in the executable. It knows "-L"
but not "-R". The only way to do it is through the environment variable
LD_RUN_PATH.

So I need to turn the library options given to gcc or ld (I will set
_USE_RPATH=yes and _OPSYS_RPATH_NAME=-R in defs.UnixWare.mk) into this
variable.

To test that this is feasible I changed buildcmd and wrapper.sh in
mk/buildlink3/ like this

  --- buildcmd.orig       Sat Jan 31 19:14:48 2004
  +++ buildcmd    Tue Apr 20 01:25:35 2004
  @@ -24,6 +24,12 @@
                  # they're given.  All other instances are redundant.
                  #
                  case $arg in
  +               -R*)
  +                       _BLNK_LD_RUN_PATH="${_BLNK_LD_RUN_PATH}:${arg#-R}"
  +                       ;;
  +               -Wl,-R*)
  +                       _BLNK_LD_RUN_PATH="${_BLNK_LD_RUN_PATH}:${arg#-Wl,-R}"
  +                       ;;
                  -L*)
                          case "$ldflags" in
                          *" "$arg|*" "$arg" "*)     ;;




  --- wrapper.sh.orig     Sat Feb 14 01:03:08 2004
  +++ wrapper.sh  Tue Apr 20 01:24:52 2004
  @@ -88,8 +88,12 @@

   cmd="$cmd $ldflags $libs"

  +if [ -n "${_BLNK_LD_RUN_PATH}" ]; then
  +       LD_RUN_PATH=${_BLNK_LD_RUN_PATH#:}
  +       export LD_RUN_PATH
  +fi
   @_BLNK_WRAP_ENV@
   @_BLNK_WRAP_SANITIZE_PATH@

  -$echo "<.>" $cmd >> $wrapperlog
  +$echo "<.>" LD_RUN_PATH=\"${LD_RUN_PATH}\" $cmd >> $wrapperlog
   eval exec $cmd


I could successfully build devel/patch and /opt/pkg/lib was recorded in the
ELF header.


The final patch will look a bit different but I need help to do it right.

- Obviously I need buildlink3 for this, but there are some (many?)
  packages still using buildlink2 (or not using any buildlink framwwork
  at all). Incidentally devel/patch is one of them. Is it intended to
  convert _every_ package to buildlink3?

- Is buildcmd/wrapper.sh the right place or is there some better way to
  achieve the desired result?

- Is it ok to alter the files wrapper.sh/buildcmd so all wrappers will
  end up with the changes or should I try to restrict this to the cc/gcc
  and ld wrappers?

- Since this is a special case only needed for Unixware I think about
  creating wrapper.sh.UnixWare and checking for wrapper.sh.${OPSYS} in
  bsd.buildlink3.mk.
  Should I avoid duplicating the files and create appropriate @_BLNK_...@
  variables instead, to be filled in with the code (on Unixware) or
  nothing (all other systems) in the original files wrapper.sh/buildcmd?


ciao
     Klaus