2 # install-reloc - install a program including a relocating wrapper
3 # Copyright (C) 2003, 2005-2007 Free Software Foundation, Inc.
4 # Written by Bruno Haible <bruno@clisp.org>, 2003.
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 2, or (at your option)
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, write to the Free Software Foundation,
18 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 # install-reloc library_path_var library_path_value prefix \
22 # compile_command srcdir config_h_dir exeext \
23 # install_command... destprog
25 # - library_path_var is the platform dependent runtime library path variable
26 # - library_path_value is a colon separated list of directories that contain
27 # the libraries at installation time (use this instead of -rpath)
28 # - prefix is the base directory at installation time
29 # - compile_command is a C compiler compilation and linking command
30 # - srcdir is the directory where to find relocwrapper.c and its dependencies
31 # - builddir is the directory where to find built dependencies (namely,
32 # alloca.h and stdbool.h)
33 # - config_h_dir is the directory where to find config.h
34 # - exeext is platform dependent suffix of executables
35 # - install-command is the install command line, excluding the final destprog
36 # - destprog is the destination program name
37 # install-reloc renames destprog to destprog.bin and installs a relocating
38 # wrapper in the place of destprog.
42 if test $# -eq 2; then
43 # Get arguments from environment variables.
44 library_path_var=$RELOC_LIBRARY_PATH_VAR
45 library_path_value=$RELOC_LIBRARY_PATH_VALUE
47 compile_command=$RELOC_COMPILE_COMMAND
49 builddir=$RELOC_BUILDDIR
50 config_h_dir=$RELOC_CONFIG_H_DIR
52 install_prog=$RELOC_INSTALL_PROG # including the "-c" option
54 if test $# -ge 9; then
55 # Get fixed position arguments.
64 install_prog=$9 # maybe not including the "-c" option
75 echo "Usage: $0 library_path_var library_path_value prefix" \
76 "compile_command srcdir builddir config_h_dir exeext" \
77 "install_command... destprog" 1>&2
82 # Get destprog, last argument.
88 # Remove trailing $exeext, if present.
89 if test -n "$exeext"; then
90 sedexpr='s|'`echo "$exeext" | sed -e 's,\.,\\\.,g'`'$||'
91 destprog=`echo "$destprog" | sed -e "$sedexpr"`
94 # Outputs a command and runs it.
101 # Run install_command.
102 func_verbose $install_prog "$@" || exit $?
104 # If the platform doesn't support LD_LIBRARY_PATH or similar, we cannot build
106 test -n "$library_path_var" || exit 0
109 save_IFS="$IFS"; IFS=":"
110 for dir in $library_path_value; do
112 if test -n "$dir"; then
114 *"\"$dir\""*) ;; # remove duplicate
115 *) libdirs="$libdirs\"$dir\"," ;;
120 # If there are no library directories to add at runtime, we don't need a
122 test -n "$libdirs" || exit 0
125 installdir=`echo "$destprog" | sed -e 's,/[^/]*$,,'`
126 func_verbose $compile_command \
127 -I"$builddir" -I"$srcdir" -I"$config_h_dir" \
128 -DHAVE_CONFIG_H -DIN_RELOCWRAPPER -DNO_XMALLOC \
129 -D"INSTALLPREFIX=\"$prefix\"" -D"INSTALLDIR=\"$installdir\"" \
130 -D"LIBPATHVAR=\"$library_path_var\"" -D"LIBDIRS=$libdirs" \
131 -D"EXEEXT=\"$exeext\"" \
132 "$srcdir"/relocwrapper.c \
133 "$srcdir"/progname.c \
134 "$srcdir"/progreloc.c \
135 "$srcdir"/xreadlink.c \
136 "$srcdir"/readlink.c \
137 "$srcdir"/canonicalize-lgpl.c \
138 "$srcdir"/malloca.c \
139 "$srcdir"/relocatable.c \
141 "$srcdir"/strerror.c \
142 "$srcdir"/c-ctype.c \
143 -o "$destprog.wrapper$exeext"
145 # Clean up object files left over in the current directory by the native C
146 # compilers on Solaris, HP-UX, OSF/1, IRIX.
147 rm -f relocwrapper.o \
151 canonicalize-lgpl.o \
157 test $rc = 0 || exit $?
159 # Rename $destprog.wrapper -> $destprog -> $destprog.bin.
160 ln -f "$destprog$exeext" "$destprog.bin$exeext" \
161 || { rm -f "$destprog.bin$exeext" \
162 && cp -p "$destprog$exeext" "$destprog.bin$exeext"; } \
164 mv "$destprog.wrapper$exeext" "$destprog$exeext" || exit 1