2 # libtool-reloc - libtool wrapper with support for relocatable programs
3 # Copyright (C) 2019 Free Software Foundation, Inc.
4 # Written by Bruno Haible <bruno@clisp.org>, 2019.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 # Usage: libtool-reloc libtool LIBTOOL_ARGUMENTS
21 # Outputs a command and runs it.
24 # Make it easy to copy&paste the printed command into a shell in most cases,
25 # by escaping '\\', '"', and '$'. This is not perfect, just good enough.
26 echo "$@" |
sed -e 's/\([\\"$]\)/\\\1/g'
30 # Determine the mode from the arguments.
35 --mode=link
) mode
=link
;;
39 if test "$mode" = link
; then
40 # Determine the target from the arguments.
45 if $next_is_target; then
50 -o) next_is_target
=true
;;
51 *) next_is_target
=false
;;
57 # When creating a library:
58 # 1. Add a '-Wl,-rpath,@loader_path' option.
59 # (A '-R @loader_path' option does not work: libtool produces
60 # an error "error: only absolute run-paths are allowed".)
61 # (Also note that 'install_name_tool -add_rpath @loader_path ...'
62 # does not work on Mac OS X 10.5.)
63 # This is done through the RELOCATABLE_LDFLAGS macro.
64 # 2. After creating the library, run
65 # install_name_tool -id @rpath/$dlname $target_dir/.libs/$dlname
66 # (This is easier than to modify the libtool script to emit a different
67 # install_name. Also, an option '-Wl,-install_name,@rpath/$dlname' does
68 # not work since libtool emits another option '-Wl,-install_name,...'
71 dlname_assignment
=`grep '^dlname=' "$target"`
73 eval "$dlname_assignment"
74 # Nothing to do when --disable-shared was specified.
75 if test -n "$dlname"; then
76 target_dir
=`dirname "$target"`
77 if test -f "$target_dir/.libs/$dlname"; then
78 func_verbose install_name_tool
-id "@rpath/$dlname" "$target_dir/.libs/$dlname"