1 1.1 christos #!/bin/sh 2 1.1 christos # install-reloc - install a program including a relocating wrapper 3 1.1 christos # Copyright (C) 2003, 2005-2006 Free Software Foundation, Inc. 4 1.1 christos # Written by Bruno Haible <bruno (at] clisp.org>, 2003. 5 1.1 christos # 6 1.1 christos # This program is free software; you can redistribute it and/or modify 7 1.1 christos # it under the terms of the GNU General Public License as published by 8 1.1 christos # the Free Software Foundation; either version 2, or (at your option) 9 1.1 christos # any later version. 10 1.1 christos # 11 1.1 christos # This program is distributed in the hope that it will be useful, 12 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 1.1 christos # GNU General Public License for more details. 15 1.1 christos # 16 1.1 christos # You should have received a copy of the GNU General Public License 17 1.1 christos # along with this program; if not, write to the Free Software Foundation, 18 1.1 christos # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 1.1 christos 20 1.1 christos # Usage: 21 1.1 christos # install-reloc library_path_var library_path_value prefix compile_command srcdir config_h_dir exeext install_command... destprog 22 1.1 christos # where 23 1.1 christos # - library_path_var is the platform dependent runtime library path variable 24 1.1 christos # - library_path_value is a colon separated list of directories that contain 25 1.1 christos # the libraries at installation time (use this instead of -rpath) 26 1.1 christos # - prefix is the base directory at installation time 27 1.1 christos # - compile_command is a C compiler compilation and linking command 28 1.1 christos # - srcdir is the directory where to find relocwrapper.c and its dependencies 29 1.1 christos # - builddir is the directory where to find built dependencies (namely, 30 1.1 christos # alloca.h and stdbool.h) 31 1.1 christos # - config_h_dir is the directory where to find config.h 32 1.1 christos # - exeext is platform dependent suffix of executables 33 1.1 christos # - install-command is the install command line, excluding the final destprog 34 1.1 christos # - destprog is the destination program name 35 1.1 christos # install-reloc renames destprog to destprog.bin and installs a relocating 36 1.1 christos # wrapper in the place of destprog. 37 1.1 christos 38 1.1 christos progname=$0 39 1.1 christos 40 1.1 christos if test $# -eq 2; then 41 1.1 christos # Get arguments from environment variables. 42 1.1 christos library_path_var=$RELOC_LIBRARY_PATH_VAR 43 1.1 christos library_path_value=$RELOC_LIBRARY_PATH_VALUE 44 1.1 christos prefix=$RELOC_PREFIX 45 1.1 christos compile_command=$RELOC_COMPILE_COMMAND 46 1.1 christos srcdir=$RELOC_SRCDIR 47 1.1 christos builddir=$RELOC_BUILDDIR 48 1.1 christos config_h_dir=$RELOC_CONFIG_H_DIR 49 1.1 christos exeext=$RELOC_EXEEXT 50 1.1 christos install_prog=$RELOC_INSTALL_PROG # including the "-c" option 51 1.1 christos else 52 1.1 christos if test $# -ge 9; then 53 1.1 christos # Get fixed position arguments. 54 1.1 christos library_path_var=$1 55 1.1 christos library_path_value=$2 56 1.1 christos prefix=$3 57 1.1 christos compile_command=$4 58 1.1 christos srcdir=$5 59 1.1 christos builddir=$6 60 1.1 christos config_h_dir=$7 61 1.1 christos exeext=$8 62 1.1 christos install_prog=$9 # maybe not including the "-c" option 63 1.1 christos shift 64 1.1 christos shift 65 1.1 christos shift 66 1.1 christos shift 67 1.1 christos shift 68 1.1 christos shift 69 1.1 christos shift 70 1.1 christos shift 71 1.1 christos shift 72 1.1 christos else 73 1.1 christos echo "Usage: $0 library_path_var library_path_value prefix compile_command srcdir builddir config_h_dir exeext install_command... destprog" 1>&2 74 1.1 christos exit 1 75 1.1 christos fi 76 1.1 christos fi 77 1.1 christos 78 1.1 christos # Get destprog, last argument. 79 1.1 christos destprog= 80 1.1 christos for arg 81 1.1 christos do 82 1.1 christos destprog=$arg 83 1.1 christos done 84 1.1 christos # Remove trailing $exeext, if present. 85 1.1 christos if test -n "$exeext"; then 86 1.1 christos sedexpr='s|'`echo "$exeext" | sed -e 's,\.,\\\.,g'`'$||' 87 1.1 christos destprog=`echo "$destprog" | sed -e "$sedexpr"` 88 1.1 christos fi 89 1.1 christos 90 1.1 christos # Outputs a command and runs it. 91 1.1 christos func_verbose () 92 1.1 christos { 93 1.1 christos echo "$@" 94 1.1 christos "$@" 95 1.1 christos } 96 1.1 christos 97 1.1 christos # Run install_command. 98 1.1 christos func_verbose $install_prog "$@" || exit $? 99 1.1 christos 100 1.1 christos # If the platform doesn't support LD_LIBRARY_PATH or similar, we cannot build 101 1.1 christos # a wrapper. 102 1.1 christos test -n "$library_path_var" || exit 0 103 1.1 christos 104 1.1 christos libdirs= 105 1.1 christos save_IFS="$IFS"; IFS=":" 106 1.1 christos for dir in $library_path_value; do 107 1.1 christos IFS="$save_IFS" 108 1.1 christos if test -n "$dir"; then 109 1.1 christos case "$libdirs" in 110 1.1 christos *"\"$dir\""*) ;; # remove duplicate 111 1.1 christos *) libdirs="$libdirs\"$dir\"," ;; 112 1.1 christos esac 113 1.1 christos fi 114 1.1 christos done 115 1.1 christos IFS="$save_IFS" 116 1.1 christos # If there are no library directories to add at runtime, we don't need a 117 1.1 christos # wrapper. 118 1.1 christos test -n "$libdirs" || exit 0 119 1.1 christos 120 1.1 christos # Compile wrapper. 121 1.1 christos installdir=`echo "$destprog" | sed -e 's,/[^/]*$,,'` 122 1.1 christos func_verbose $compile_command -I"$builddir" -I"$srcdir" -I"$config_h_dir" -DHAVE_CONFIG_H -DIN_RELOCWRAPPER -DNO_XMALLOC -D"INSTALLPREFIX=\"$prefix\"" -D"INSTALLDIR=\"$installdir\"" -D"LIBPATHVAR=\"$library_path_var\"" -D"LIBDIRS=$libdirs" -D"EXEEXT=\"$exeext\"" "$srcdir"/relocwrapper.c "$srcdir"/progname.c "$srcdir"/progreloc.c "$srcdir"/xreadlink.c "$srcdir"/readlink.c "$srcdir"/canonicalize.c "$srcdir"/allocsa.c "$srcdir"/relocatable.c "$srcdir"/setenv.c "$srcdir"/strerror.c -o "$destprog.wrapper$exeext" || exit $? 123 1.1 christos 124 1.1 christos # Rename $destprog.wrapper -> $destprog -> $destprog.bin. 125 1.1 christos ln -f "$destprog$exeext" "$destprog.bin$exeext" \ 126 1.1 christos || { rm -f "$destprog.bin$exeext" && cp -p "$destprog$exeext" "$destprog.bin$exeext"; } \ 127 1.1 christos || exit 1 128 1.1 christos mv "$destprog.wrapper$exeext" "$destprog$exeext" || exit 1 129 1.1 christos 130 1.1 christos exit 0 131