Mercurial > gnulib
annotate build-aux/reloc-ldflags @ 8265:20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
See http://lists.gnu.org/archive/html/bug-gnulib/2003-03/msg00020.html
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Thu, 01 Mar 2007 01:15:40 +0000 |
parents | |
children | bbbbbf4cd1c5 |
rev | line source |
---|---|
8265
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 #! /bin/sh |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
2 # Output a system dependent linker command for putting a relocatable library |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 # search path into an executable. |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 # |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 # Copyright 2003 Free Software Foundation, Inc. |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 # Written by Bruno Haible <bruno@clisp.org>, 2003. |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 # |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 # This program is free software; you can redistribute it and/or modify |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 # it under the terms of the GNU General Public License as published by |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 # the Free Software Foundation; either version 2 of the License, or |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 # (at your option) any later version. |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 # |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 # This program is distributed in the hope that it will be useful, but |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 # WITHOUT ANY WARRANTY; without even the implied warranty of |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 # General Public License for more details. |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 # |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 # You should have received a copy of the GNU General Public License |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 # along with this program; if not, write to the Free Software Foundation, |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 # |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 # As a special exception to the GNU General Public License, if you |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 # distribute this file as part of a program that contains a |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 # configuration script generated by Autoconf, you may include it under |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 # the same distribution terms that you use for the rest of that program. |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 # |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 # The first argument passed to this file is the canonical host specification, |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 # or |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 # The environment variable LD should be set by the caller. |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 # |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 # The second argument is a colon separated list of directories that contain |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 # the libraries at installation time. |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 # |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 # The third argument is the directory into which the executable is going to be |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 # installed. |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 host="$1" |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 host_cpu=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'` |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 host_vendor=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'` |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 host_os=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 library_path_value=$2 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 installdir=$3 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 # Verify that installdir is absolute. |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 case "$installdir" in |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 /*) ;; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 *) |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 echo "installdir is not absolute: $installdir" 1>&2 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 exit 1 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 ;; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 esac |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 case "$host_os" in |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 linux*) # Supported since Linux 2.1 and glibc 2.1. |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 rpath= |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 save_IFS="$IFS"; IFS=":" |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
61 for dir in $library_path_value; do |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 IFS="$save_IFS" |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 case "$dir" in |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
64 /*) |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 # Make dir relative to installdir. (Works only if dir is absolute.) |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 idir="$installdir" |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 while true; do |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
68 dfirst=`echo "$dir" | sed -n -e 's,^//*\([^/]*\).*$,/\1,p'` |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
69 ifirst=`echo "$idir" | sed -n -e 's,^//*\([^/]*\).*$,/\1,p'` |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
70 if test -z "$dfirst" || test -z "$ifirst"; then |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
71 break |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
72 fi |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
73 if test "$dfirst" != "$ifirst"; then |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
74 break |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
75 fi |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
76 dir=`echo "$dir" | sed -e 's,^//*[^/]*,,'` |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
77 idir=`echo "$idir" | sed -e 's,^//*[^/]*,,'` |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
78 done |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
79 dir="\$ORIGIN"`echo "$idir" | sed -e 's,//*[^/]*,/..,g'`"$dir" |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
80 # Add dir to rpath. |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
81 rpath="${rpath}${rpath:+ }$dir" |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
82 ;; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
83 *) |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
84 if test -n "$dir"; then |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
85 echo "libdir is not absolute: $dir" 1>&2 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
86 fi |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
87 ;; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
88 esac |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
89 done |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
90 IFS="$save_IFS" |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
91 # Output it. |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
92 if test -n "$rpath"; then |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
93 echo "-Wl,-rpath,$rpath" |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
94 fi |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
95 ;; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
96 *) |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
97 echo "relocation via rpath not supported on this system: $host" 1>&2 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
98 exit 1 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
99 ;; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
100 esac |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
101 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
102 exit 0 |