1#! /bin/sh
2# Output a system dependent set of variables, describing how to set the
3# run time search path of shared libraries in an executable.
4#
5#   Copyright 1996-2012 Free Software Foundation, Inc.
6#   Taken from GNU libtool, 2001
7#   Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
8#
9#   This file is free software; the Free Software Foundation gives
10#   unlimited permission to copy and/or distribute it, with or without
11#   modifications, as long as this notice is preserved.
12
13# http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob_plain;f=build-aux/config.rpath;hb=HEAD
14#
15# The first argument passed to this file is the canonical host specification,
16#    CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
17# or
18#    CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
19# The environment variables CC, GCC, LDFLAGS, LD, with_gnu_ld
20# should be set by the caller.
21#
22# The set of defined variables is at the end of this script.
23
24# Known limitations:
25# - On IRIX 6.5 with CC="cc", the run time search patch must not be longer
26#   than 256 bytes, otherwise the compiler driver will dump core. The only
27#   known workaround is to choose shorter directory names for the build
28#   directory and/or the installation directory.
29
30# All known linkers require a '.a' archive for static linking (except MSVC,
31# which needs '.lib').
32libext=a
33shrext=.so
34
35host="$1"
36host_cpu=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
37host_vendor=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
38host_os=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
39
40# Code taken from libtool.m4's _LT_CC_BASENAME.
41
42for cc_temp in $CC""; do
43  case $cc_temp in
44    compile | *[\\/]compile | ccache | *[\\/]ccache ) ;;
45    distcc | *[\\/]distcc | purify | *[\\/]purify ) ;;
46    \-*) ;;
47    *) break;;
48  esac
49done
50cc_basename=`echo "$cc_temp" | sed -e 's%^.*/%%'`
51
52# Code taken from libtool.m4's _LT_COMPILER_PIC.
53
54wl=
55if test "$GCC" = yes; then
56  wl='-Wl,'
57else
58  case "$host_os" in
59    aix*)
60      wl='-Wl,'
61      ;;
62    mingw* | cygwin* | pw32* | os2* | cegcc*)
63      ;;
64    hpux9* | hpux10* | hpux11*)
65      wl='-Wl,'
66      ;;
67    irix5* | irix6* | nonstopux*)
68      wl='-Wl,'
69      ;;
70    linux* | k*bsd*-gnu | kopensolaris*-gnu)
71      case $cc_basename in
72        ecc*)
73          wl='-Wl,'
74          ;;
75        icc* | ifort*)
76          wl='-Wl,'
77          ;;
78        lf95*)
79          wl='-Wl,'
80          ;;
81        nagfor*)
82          wl='-Wl,-Wl,,'
83          ;;
84        pgcc* | pgf77* | pgf90* | pgf95* | pgfortran*)
85          wl='-Wl,'
86          ;;
87        ccc*)
88          wl='-Wl,'
89          ;;
90        xl* | bgxl* | bgf* | mpixl*)
91          wl='-Wl,'
92          ;;
93        como)
94          wl='-lopt='
95          ;;
96        *)
97          case `$CC -V 2>&1 | sed 5q` in
98            *Sun\ F* | *Sun*Fortran*)
99              wl=
100              ;;
101            *Sun\ C*)
102              wl='-Wl,'
103              ;;
104          esac
105          ;;
106      esac
107      ;;
108    newsos6)
109      ;;
110    *nto* | *qnx*)
111      ;;
112    osf3* | osf4* | osf5*)
113      wl='-Wl,'
114      ;;
115    rdos*)
116      ;;
117    solaris*)
118      case $cc_basename in
119        f77* | f90* | f95* | sunf77* | sunf90* | sunf95*)
120          wl='-Qoption ld '
121          ;;
122        *)
123          wl='-Wl,'
124          ;;
125      esac
126      ;;
127    sunos4*)
128      wl='-Qoption ld '
129      ;;
130    sysv4 | sysv4.2uw2* | sysv4.3*)
131      wl='-Wl,'
132      ;;
133    sysv4*MP*)
134      ;;
135    sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
136      wl='-Wl,'
137      ;;
138    unicos*)
139      wl='-Wl,'
140      ;;
141    uts4*)
142      ;;
143  esac
144fi
145
146# Code taken from libtool.m4's _LT_LINKER_SHLIBS.
147
148hardcode_libdir_flag_spec=
149hardcode_libdir_separator=
150hardcode_direct=no
151hardcode_minus_L=no
152
153case "$host_os" in
154  cygwin* | mingw* | pw32* | cegcc*)
155    # FIXME: the MSVC++ port hasn't been tested in a loooong time
156    # When not using gcc, we currently assume that we are using
157    # Microsoft Visual C++.
158    if test "$GCC" != yes; then
159      with_gnu_ld=no
160    fi
161    ;;
162  interix*)
163    # we just hope/assume this is gcc and not c89 (= MSVC++)
164    with_gnu_ld=yes
165    ;;
166  openbsd*)
167    with_gnu_ld=no
168    ;;
169esac
170
171ld_shlibs=yes
172if test "$with_gnu_ld" = yes; then
173  # Set some defaults for GNU ld with shared library support. These
174  # are reset later if shared libraries are not supported. Putting them
175  # here allows them to be overridden if necessary.
176  # Unlike libtool, we use -rpath here, not --rpath, since the documented
177  # option of GNU ld is called -rpath, not --rpath.
178  hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
179  case "$host_os" in
180    aix[3-9]*)
181      # On AIX/PPC, the GNU linker is very broken
182      if test "$host_cpu" != ia64; then
183        ld_shlibs=no
184      fi
185      ;;
186    amigaos*)
187      case "$host_cpu" in
188        powerpc)
189          ;;
190        m68k)
191          hardcode_libdir_flag_spec='-L$libdir'
192          hardcode_minus_L=yes
193          ;;
194      esac
195      ;;
196    beos*)
197      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
198        :
199      else
200        ld_shlibs=no
201      fi
202      ;;
203    cygwin* | mingw* | pw32* | cegcc*)
204      # hardcode_libdir_flag_spec is actually meaningless, as there is
205      # no search path for DLLs.
206      hardcode_libdir_flag_spec='-L$libdir'
207      if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then
208        :
209      else
210        ld_shlibs=no
211      fi
212      ;;
213    haiku*)
214      ;;
215    interix[3-9]*)
216      hardcode_direct=no
217      hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
218      ;;
219    gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu)
220      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
221        :
222      else
223        ld_shlibs=no
224      fi
225      ;;
226    netbsd*)
227      ;;
228    solaris*)
229      if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then
230        ld_shlibs=no
231      elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
232        :
233      else
234        ld_shlibs=no
235      fi
236      ;;
237    sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
238      case `$LD -v 2>&1` in
239        *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*)
240          ld_shlibs=no
241          ;;
242        *)
243          if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
244            hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-rpath,$libdir`'
245          else
246            ld_shlibs=no
247          fi
248          ;;
249      esac
250      ;;
251    sunos4*)
252      hardcode_direct=yes
253      ;;
254    *)
255      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
256        :
257      else
258        ld_shlibs=no
259      fi
260      ;;
261  esac
262  if test "$ld_shlibs" = no; then
263    hardcode_libdir_flag_spec=
264  fi
265else
266  case "$host_os" in
267    aix3*)
268      # Note: this linker hardcodes the directories in LIBPATH if there
269      # are no directories specified by -L.
270      hardcode_minus_L=yes
271      if test "$GCC" = yes; then
272        # Neither direct hardcoding nor static linking is supported with a
273        # broken collect2.
274        hardcode_direct=unsupported
275      fi
276      ;;
277    aix[4-9]*)
278      if test "$host_cpu" = ia64; then
279        # On IA64, the linker does run time linking by default, so we don't
280        # have to do anything special.
281        aix_use_runtimelinking=no
282      else
283        aix_use_runtimelinking=no
284        # Test if we are trying to use run time linking or normal
285        # AIX style linking. If -brtl is somewhere in LDFLAGS, we
286        # need to do runtime linking.
287        case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*)
288          for ld_flag in $LDFLAGS; do
289            if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
290              aix_use_runtimelinking=yes
291              break
292            fi
293          done
294          ;;
295        esac
296      fi
297      hardcode_direct=yes
298      hardcode_libdir_separator=':'
299      if test "$GCC" = yes; then
300        case $host_os in aix4.[012]|aix4.[012].*)
301          collect2name=`${CC} -print-prog-name=collect2`
302          if test -f "$collect2name" && \
303            strings "$collect2name" | grep resolve_lib_name >/dev/null
304          then
305            # We have reworked collect2
306            :
307          else
308            # We have old collect2
309            hardcode_direct=unsupported
310            hardcode_minus_L=yes
311            hardcode_libdir_flag_spec='-L$libdir'
312            hardcode_libdir_separator=
313          fi
314          ;;
315        esac
316      fi
317      # Begin _LT_AC_SYS_LIBPATH_AIX.
318      echo 'int main () { return 0; }' > conftest.c
319      ${CC} ${LDFLAGS} conftest.c -o conftest
320      aix_libpath=`dump -H conftest 2>/dev/null | sed -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0  *\(.*\)$/\1/; p; }
321}'`
322      if test -z "$aix_libpath"; then
323        aix_libpath=`dump -HX64 conftest 2>/dev/null | sed -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0  *\(.*\)$/\1/; p; }
324}'`
325      fi
326      if test -z "$aix_libpath"; then
327        aix_libpath="/usr/lib:/lib"
328      fi
329      rm -f conftest.c conftest
330      # End _LT_AC_SYS_LIBPATH_AIX.
331      if test "$aix_use_runtimelinking" = yes; then
332        hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath"
333      else
334        if test "$host_cpu" = ia64; then
335          hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib'
336        else
337          hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath"
338        fi
339      fi
340      ;;
341    amigaos*)
342      case "$host_cpu" in
343        powerpc)
344          ;;
345        m68k)
346          hardcode_libdir_flag_spec='-L$libdir'
347          hardcode_minus_L=yes
348          ;;
349      esac
350      ;;
351    bsdi[45]*)
352      ;;
353    cygwin* | mingw* | pw32* | cegcc*)
354      # When not using gcc, we currently assume that we are using
355      # Microsoft Visual C++.
356      # hardcode_libdir_flag_spec is actually meaningless, as there is
357      # no search path for DLLs.
358      hardcode_libdir_flag_spec=' '
359      libext=lib
360      ;;
361    darwin* | rhapsody*)
362      hardcode_direct=no
363      if { case $cc_basename in ifort*) true;; *) test "$GCC" = yes;; esac; }; then
364        :
365      else
366        ld_shlibs=no
367      fi
368      ;;
369    dgux*)
370      hardcode_libdir_flag_spec='-L$libdir'
371      ;;
372    freebsd2.2*)
373      hardcode_libdir_flag_spec='-R$libdir'
374      hardcode_direct=yes
375      ;;
376    freebsd2*)
377      hardcode_direct=yes
378      hardcode_minus_L=yes
379      ;;
380    freebsd* | dragonfly*)
381      hardcode_libdir_flag_spec='-R$libdir'
382      hardcode_direct=yes
383      ;;
384    hpux9*)
385      hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
386      hardcode_libdir_separator=:
387      hardcode_direct=yes
388      # hardcode_minus_L: Not really in the search PATH,
389      # but as the default location of the library.
390      hardcode_minus_L=yes
391      ;;
392    hpux10*)
393      if test "$with_gnu_ld" = no; then
394        hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
395        hardcode_libdir_separator=:
396        hardcode_direct=yes
397        # hardcode_minus_L: Not really in the search PATH,
398        # but as the default location of the library.
399        hardcode_minus_L=yes
400      fi
401      ;;
402    hpux11*)
403      if test "$with_gnu_ld" = no; then
404        hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
405        hardcode_libdir_separator=:
406        case $host_cpu in
407          hppa*64*|ia64*)
408            hardcode_direct=no
409            ;;
410          *)
411            hardcode_direct=yes
412            # hardcode_minus_L: Not really in the search PATH,
413            # but as the default location of the library.
414            hardcode_minus_L=yes
415            ;;
416        esac
417      fi
418      ;;
419    irix5* | irix6* | nonstopux*)
420      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
421      hardcode_libdir_separator=:
422      ;;
423    netbsd*)
424      hardcode_libdir_flag_spec='-R$libdir'
425      hardcode_direct=yes
426      ;;
427    newsos6)
428      hardcode_direct=yes
429      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
430      hardcode_libdir_separator=:
431      ;;
432    *nto* | *qnx*)
433      ;;
434    openbsd*)
435      if test -f /usr/libexec/ld.so; then
436        hardcode_direct=yes
437        if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
438          hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
439        else
440          case "$host_os" in
441            openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*)
442              hardcode_libdir_flag_spec='-R$libdir'
443              ;;
444            *)
445              hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
446              ;;
447          esac
448        fi
449      else
450        ld_shlibs=no
451      fi
452      ;;
453    os2*)
454      hardcode_libdir_flag_spec='-L$libdir'
455      hardcode_minus_L=yes
456      ;;
457    osf3*)
458      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
459      hardcode_libdir_separator=:
460      ;;
461    osf4* | osf5*)
462      if test "$GCC" = yes; then
463        hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
464      else
465        # Both cc and cxx compiler support -rpath directly
466        hardcode_libdir_flag_spec='-rpath $libdir'
467      fi
468      hardcode_libdir_separator=:
469      ;;
470    solaris*)
471      hardcode_libdir_flag_spec='-R$libdir'
472      ;;
473    sunos4*)
474      hardcode_libdir_flag_spec='-L$libdir'
475      hardcode_direct=yes
476      hardcode_minus_L=yes
477      ;;
478    sysv4)
479      case $host_vendor in
480        sni)
481          hardcode_direct=yes # is this really true???
482          ;;
483        siemens)
484          hardcode_direct=no
485          ;;
486        motorola)
487          hardcode_direct=no #Motorola manual says yes, but my tests say they lie
488          ;;
489      esac
490      ;;
491    sysv4.3*)
492      ;;
493    sysv4*MP*)
494      if test -d /usr/nec; then
495        ld_shlibs=yes
496      fi
497      ;;
498    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*)
499      ;;
500    sysv5* | sco3.2v5* | sco5v6*)
501      hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`'
502      hardcode_libdir_separator=':'
503      ;;
504    uts4*)
505      hardcode_libdir_flag_spec='-L$libdir'
506      ;;
507    *)
508      ld_shlibs=no
509      ;;
510  esac
511fi
512
513# Check dynamic linker characteristics
514# Code taken from libtool.m4's _LT_SYS_DYNAMIC_LINKER.
515# Unlike libtool.m4, here we don't care about _all_ names of the library, but
516# only about the one the linker finds when passed -lNAME. This is the last
517# element of library_names_spec in libtool.m4, or possibly two of them if the
518# linker has special search rules.
519library_names_spec=      # the last element of library_names_spec in libtool.m4
520libname_spec='lib$name'
521case "$host_os" in
522  aix3*)
523    library_names_spec='$libname.a'
524    ;;
525  aix[4-9]*)
526    library_names_spec='$libname$shrext'
527    ;;
528  amigaos*)
529    case "$host_cpu" in
530      powerpc*)
531        library_names_spec='$libname$shrext' ;;
532      m68k)
533        library_names_spec='$libname.a' ;;
534    esac
535    ;;
536  beos*)
537    library_names_spec='$libname$shrext'
538    ;;
539  bsdi[45]*)
540    library_names_spec='$libname$shrext'
541    ;;
542  cygwin* | mingw* | pw32* | cegcc*)
543    shrext=.dll
544    library_names_spec='$libname.dll.a $libname.lib'
545    ;;
546  darwin* | rhapsody*)
547    shrext=.dylib
548    library_names_spec='$libname$shrext'
549    ;;
550  dgux*)
551    library_names_spec='$libname$shrext'
552    ;;
553  freebsd* | dragonfly*)
554    case "$host_os" in
555      freebsd[123]*)
556        library_names_spec='$libname$shrext$versuffix' ;;
557      *)
558        library_names_spec='$libname$shrext' ;;
559    esac
560    ;;
561  gnu*)
562    library_names_spec='$libname$shrext'
563    ;;
564  haiku*)
565    library_names_spec='$libname$shrext'
566    ;;
567  hpux9* | hpux10* | hpux11*)
568    case $host_cpu in
569      ia64*)
570        shrext=.so
571        ;;
572      hppa*64*)
573        shrext=.sl
574        ;;
575      *)
576        shrext=.sl
577        ;;
578    esac
579    library_names_spec='$libname$shrext'
580    ;;
581  interix[3-9]*)
582    library_names_spec='$libname$shrext'
583    ;;
584  irix5* | irix6* | nonstopux*)
585    library_names_spec='$libname$shrext'
586    case "$host_os" in
587      irix5* | nonstopux*)
588        libsuff= shlibsuff=
589        ;;
590      *)
591        case $LD in
592          *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") libsuff= shlibsuff= ;;
593          *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") libsuff=32 shlibsuff=N32 ;;
594          *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") libsuff=64 shlibsuff=64 ;;
595          *) libsuff= shlibsuff= ;;
596        esac
597        ;;
598    esac
599    ;;
600  linux*oldld* | linux*aout* | linux*coff*)
601    ;;
602  linux* | k*bsd*-gnu | kopensolaris*-gnu)
603    library_names_spec='$libname$shrext'
604    ;;
605  knetbsd*-gnu)
606    library_names_spec='$libname$shrext'
607    ;;
608  netbsd*)
609    library_names_spec='$libname$shrext'
610    ;;
611  newsos6)
612    library_names_spec='$libname$shrext'
613    ;;
614  *nto* | *qnx*)
615    library_names_spec='$libname$shrext'
616    ;;
617  openbsd*)
618    library_names_spec='$libname$shrext$versuffix'
619    ;;
620  os2*)
621    libname_spec='$name'
622    shrext=.dll
623    library_names_spec='$libname.a'
624    ;;
625  osf3* | osf4* | osf5*)
626    library_names_spec='$libname$shrext'
627    ;;
628  rdos*)
629    ;;
630  solaris*)
631    library_names_spec='$libname$shrext'
632    ;;
633  sunos4*)
634    library_names_spec='$libname$shrext$versuffix'
635    ;;
636  sysv4 | sysv4.3*)
637    library_names_spec='$libname$shrext'
638    ;;
639  sysv4*MP*)
640    library_names_spec='$libname$shrext'
641    ;;
642  sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
643    library_names_spec='$libname$shrext'
644    ;;
645  tpf*)
646    library_names_spec='$libname$shrext'
647    ;;
648  uts4*)
649    library_names_spec='$libname$shrext'
650    ;;
651esac
652
653sed_quote_subst='s/\(["`$\\]\)/\\\1/g'
654escaped_wl=`echo "X$wl" | sed -e 's/^X//' -e "$sed_quote_subst"`
655shlibext=`echo "$shrext" | sed -e 's,^\.,,'`
656escaped_libname_spec=`echo "X$libname_spec" | sed -e 's/^X//' -e "$sed_quote_subst"`
657escaped_library_names_spec=`echo "X$library_names_spec" | sed -e 's/^X//' -e "$sed_quote_subst"`
658escaped_hardcode_libdir_flag_spec=`echo "X$hardcode_libdir_flag_spec" | sed -e 's/^X//' -e "$sed_quote_subst"`
659
660LC_ALL=C sed -e 's/^\([a-zA-Z0-9_]*\)=/acl_cv_\1=/' <<EOF
661
662# How to pass a linker flag through the compiler.
663wl="$escaped_wl"
664
665# Static library suffix (normally "a").
666libext="$libext"
667
668# Shared library suffix (normally "so").
669shlibext="$shlibext"
670
671# Format of library name prefix.
672libname_spec="$escaped_libname_spec"
673
674# Library names that the linker finds when passed -lNAME.
675library_names_spec="$escaped_library_names_spec"
676
677# Flag to hardcode \$libdir into a binary during linking.
678# This must work even if \$libdir does not exist.
679hardcode_libdir_flag_spec="$escaped_hardcode_libdir_flag_spec"
680
681# Whether we need a single -rpath flag with a separated argument.
682hardcode_libdir_separator="$hardcode_libdir_separator"
683
684# Set to yes if using DIR/libNAME.so during linking hardcodes DIR into the
685# resulting binary.
686hardcode_direct="$hardcode_direct"
687
688# Set to yes if using the -LDIR flag during linking hardcodes DIR into the
689# resulting binary.
690hardcode_minus_L="$hardcode_minus_L"
691
692EOF
693