maintainer-makefile: Prohibit BSD4.3/SysV u_char etc types.
[gnulib.git] / build-aux / reloc-ldflags
blobf6b636624f638bd2fe5fac7756ba5b4706f72f02
1 #! /bin/sh
2 # Output a system dependent linker command for putting a relocatable library
3 # search path into an executable.
5 # Copyright 2003-2024 Free Software Foundation, Inc.
6 # Written by Bruno Haible <bruno@clisp.org>, 2003.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <https://www.gnu.org/licenses/>.
21 # As a special exception to the GNU General Public License, if you
22 # distribute this file as part of a program that contains a
23 # configuration script generated by Autoconf, you may include it under
24 # the same distribution terms that you use for the rest of that program.
26 # The first argument passed to this file is the canonical host specification,
27 # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
28 # or
29 # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
30 # The environment variable LD should be set by the caller.
32 # The second argument is a colon separated list of directories that contain
33 # the libraries at installation time.
35 # The third argument is the directory into which the executable is going to be
36 # installed.
38 host="$1"
39 host_cpu=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
40 host_vendor=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
41 host_os=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
43 library_path_value=$2
45 installdir=$3
47 # Verify that installdir is absolute.
48 case "$installdir" in
49 /*) ;;
51 echo "installdir is not absolute: $installdir" 1>&2
52 exit 1
54 esac
56 origin_token=
57 case "$host_os" in
58 linux* | gnu* | kfreebsd* | \
59 freebsd* | dragonfly* | midnightbsd* | \
60 netbsd* | \
61 openbsd* | \
62 solaris* | \
63 haiku*)
64 origin_token='$ORIGIN'
66 darwin*)
67 origin_token='@loader_path'
69 esac
70 if test -n "$origin_token"; then
71 # We are not on AIX, HP-UX, or IRIX. Therefore the -rpath options are
72 # cumulative.
73 rpath_options=
74 saved_IFS="$IFS"; IFS=":"
75 for dir in $library_path_value; do
76 IFS="$saved_IFS"
77 case "$dir" in
78 /*)
79 # Make dir relative to installdir. (Works only if dir is absolute.)
80 idir="$installdir"
81 while true; do
82 dfirst=`echo "$dir" | sed -n -e 's,^//*\([^/]*\).*$,/\1,p'`
83 ifirst=`echo "$idir" | sed -n -e 's,^//*\([^/]*\).*$,/\1,p'`
84 if test -z "$dfirst" || test -z "$ifirst"; then
85 break
87 if test "$dfirst" != "$ifirst"; then
88 break
90 dir=`echo "$dir" | sed -e 's,^//*[^/]*,,'`
91 idir=`echo "$idir" | sed -e 's,^//*[^/]*,,'`
92 done
93 dir="$origin_token"`echo "$idir" | sed -e 's,//*[^/]*,/..,g'`"$dir"
94 # Augment rpath_options with dir.
95 rpath_options="${rpath_options}${rpath_options:+ }-Wl,-rpath,$dir"
98 if test -n "$dir"; then
99 echo "libdir is not absolute: $dir" 1>&2
102 esac
103 done
104 IFS="$saved_IFS"
105 # Output it.
106 if test -n "$rpath_options"; then
107 case "$host_os" in
108 # At least some versions of FreeBSD, DragonFly, and OpenBSD need the
109 # linker option "-z origin". See <https://lekensteyn.nl/rpath.html>.
110 freebsd* | dragonfly* | openbsd*)
111 rpath_options="-Wl,-z,origin $rpath_options" ;;
112 esac
113 echo "$rpath_options"
115 else
116 echo "relocation via rpath not supported on this system: $host" 1>&2
117 exit 1
120 exit 0