Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | #! /bin/sh |
michael@0 | 2 | # Wrapper for compilers which do not understand '-c -o'. |
michael@0 | 3 | |
michael@0 | 4 | scriptversion=2012-03-05.13; # UTC |
michael@0 | 5 | |
michael@0 | 6 | # Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009, 2010, 2012 Free |
michael@0 | 7 | # Software Foundation, Inc. |
michael@0 | 8 | # Written by Tom Tromey <tromey@cygnus.com>. |
michael@0 | 9 | # |
michael@0 | 10 | # This program is free software; you can redistribute it and/or modify |
michael@0 | 11 | # it under the terms of the GNU General Public License as published by |
michael@0 | 12 | # the Free Software Foundation; either version 2, or (at your option) |
michael@0 | 13 | # any later version. |
michael@0 | 14 | # |
michael@0 | 15 | # This program is distributed in the hope that it will be useful, |
michael@0 | 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
michael@0 | 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
michael@0 | 18 | # GNU General Public License for more details. |
michael@0 | 19 | # |
michael@0 | 20 | # You should have received a copy of the GNU General Public License |
michael@0 | 21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
michael@0 | 22 | |
michael@0 | 23 | # As a special exception to the GNU General Public License, if you |
michael@0 | 24 | # distribute this file as part of a program that contains a |
michael@0 | 25 | # configuration script generated by Autoconf, you may include it under |
michael@0 | 26 | # the same distribution terms that you use for the rest of that program. |
michael@0 | 27 | |
michael@0 | 28 | # This file is maintained in Automake, please report |
michael@0 | 29 | # bugs to <bug-automake@gnu.org> or send patches to |
michael@0 | 30 | # <automake-patches@gnu.org>. |
michael@0 | 31 | |
michael@0 | 32 | nl=' |
michael@0 | 33 | ' |
michael@0 | 34 | |
michael@0 | 35 | # We need space, tab and new line, in precisely that order. Quoting is |
michael@0 | 36 | # there to prevent tools from complaining about whitespace usage. |
michael@0 | 37 | IFS=" "" $nl" |
michael@0 | 38 | |
michael@0 | 39 | file_conv= |
michael@0 | 40 | |
michael@0 | 41 | # func_file_conv build_file lazy |
michael@0 | 42 | # Convert a $build file to $host form and store it in $file |
michael@0 | 43 | # Currently only supports Windows hosts. If the determined conversion |
michael@0 | 44 | # type is listed in (the comma separated) LAZY, no conversion will |
michael@0 | 45 | # take place. |
michael@0 | 46 | func_file_conv () |
michael@0 | 47 | { |
michael@0 | 48 | file=$1 |
michael@0 | 49 | case $file in |
michael@0 | 50 | / | /[!/]*) # absolute file, and not a UNC file |
michael@0 | 51 | if test -z "$file_conv"; then |
michael@0 | 52 | # lazily determine how to convert abs files |
michael@0 | 53 | case `uname -s` in |
michael@0 | 54 | MINGW*) |
michael@0 | 55 | file_conv=mingw |
michael@0 | 56 | ;; |
michael@0 | 57 | CYGWIN*) |
michael@0 | 58 | file_conv=cygwin |
michael@0 | 59 | ;; |
michael@0 | 60 | *) |
michael@0 | 61 | file_conv=wine |
michael@0 | 62 | ;; |
michael@0 | 63 | esac |
michael@0 | 64 | fi |
michael@0 | 65 | case $file_conv/,$2, in |
michael@0 | 66 | *,$file_conv,*) |
michael@0 | 67 | ;; |
michael@0 | 68 | mingw/*) |
michael@0 | 69 | file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` |
michael@0 | 70 | ;; |
michael@0 | 71 | cygwin/*) |
michael@0 | 72 | file=`cygpath -m "$file" || echo "$file"` |
michael@0 | 73 | ;; |
michael@0 | 74 | wine/*) |
michael@0 | 75 | file=`winepath -w "$file" || echo "$file"` |
michael@0 | 76 | ;; |
michael@0 | 77 | esac |
michael@0 | 78 | ;; |
michael@0 | 79 | esac |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | # func_cl_dashL linkdir |
michael@0 | 83 | # Make cl look for libraries in LINKDIR |
michael@0 | 84 | func_cl_dashL () |
michael@0 | 85 | { |
michael@0 | 86 | func_file_conv "$1" |
michael@0 | 87 | if test -z "$lib_path"; then |
michael@0 | 88 | lib_path=$file |
michael@0 | 89 | else |
michael@0 | 90 | lib_path="$lib_path;$file" |
michael@0 | 91 | fi |
michael@0 | 92 | linker_opts="$linker_opts -LIBPATH:$file" |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | # func_cl_dashl library |
michael@0 | 96 | # Do a library search-path lookup for cl |
michael@0 | 97 | func_cl_dashl () |
michael@0 | 98 | { |
michael@0 | 99 | lib=$1 |
michael@0 | 100 | found=no |
michael@0 | 101 | save_IFS=$IFS |
michael@0 | 102 | IFS=';' |
michael@0 | 103 | for dir in $lib_path $LIB |
michael@0 | 104 | do |
michael@0 | 105 | IFS=$save_IFS |
michael@0 | 106 | if $shared && test -f "$dir/$lib.dll.lib"; then |
michael@0 | 107 | found=yes |
michael@0 | 108 | lib=$dir/$lib.dll.lib |
michael@0 | 109 | break |
michael@0 | 110 | fi |
michael@0 | 111 | if test -f "$dir/$lib.lib"; then |
michael@0 | 112 | found=yes |
michael@0 | 113 | lib=$dir/$lib.lib |
michael@0 | 114 | break |
michael@0 | 115 | fi |
michael@0 | 116 | done |
michael@0 | 117 | IFS=$save_IFS |
michael@0 | 118 | |
michael@0 | 119 | if test "$found" != yes; then |
michael@0 | 120 | lib=$lib.lib |
michael@0 | 121 | fi |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | # func_cl_wrapper cl arg... |
michael@0 | 125 | # Adjust compile command to suit cl |
michael@0 | 126 | func_cl_wrapper () |
michael@0 | 127 | { |
michael@0 | 128 | # Assume a capable shell |
michael@0 | 129 | lib_path= |
michael@0 | 130 | shared=: |
michael@0 | 131 | linker_opts= |
michael@0 | 132 | for arg |
michael@0 | 133 | do |
michael@0 | 134 | if test -n "$eat"; then |
michael@0 | 135 | eat= |
michael@0 | 136 | else |
michael@0 | 137 | case $1 in |
michael@0 | 138 | -o) |
michael@0 | 139 | # configure might choose to run compile as 'compile cc -o foo foo.c'. |
michael@0 | 140 | eat=1 |
michael@0 | 141 | case $2 in |
michael@0 | 142 | *.o | *.[oO][bB][jJ]) |
michael@0 | 143 | func_file_conv "$2" |
michael@0 | 144 | set x "$@" -Fo"$file" |
michael@0 | 145 | shift |
michael@0 | 146 | ;; |
michael@0 | 147 | *) |
michael@0 | 148 | func_file_conv "$2" |
michael@0 | 149 | set x "$@" -Fe"$file" |
michael@0 | 150 | shift |
michael@0 | 151 | ;; |
michael@0 | 152 | esac |
michael@0 | 153 | ;; |
michael@0 | 154 | -I) |
michael@0 | 155 | eat=1 |
michael@0 | 156 | func_file_conv "$2" mingw |
michael@0 | 157 | set x "$@" -I"$file" |
michael@0 | 158 | shift |
michael@0 | 159 | ;; |
michael@0 | 160 | -I*) |
michael@0 | 161 | func_file_conv "${1#-I}" mingw |
michael@0 | 162 | set x "$@" -I"$file" |
michael@0 | 163 | shift |
michael@0 | 164 | ;; |
michael@0 | 165 | -l) |
michael@0 | 166 | eat=1 |
michael@0 | 167 | func_cl_dashl "$2" |
michael@0 | 168 | set x "$@" "$lib" |
michael@0 | 169 | shift |
michael@0 | 170 | ;; |
michael@0 | 171 | -l*) |
michael@0 | 172 | func_cl_dashl "${1#-l}" |
michael@0 | 173 | set x "$@" "$lib" |
michael@0 | 174 | shift |
michael@0 | 175 | ;; |
michael@0 | 176 | -L) |
michael@0 | 177 | eat=1 |
michael@0 | 178 | func_cl_dashL "$2" |
michael@0 | 179 | ;; |
michael@0 | 180 | -L*) |
michael@0 | 181 | func_cl_dashL "${1#-L}" |
michael@0 | 182 | ;; |
michael@0 | 183 | -static) |
michael@0 | 184 | shared=false |
michael@0 | 185 | ;; |
michael@0 | 186 | -Wl,*) |
michael@0 | 187 | arg=${1#-Wl,} |
michael@0 | 188 | save_ifs="$IFS"; IFS=',' |
michael@0 | 189 | for flag in $arg; do |
michael@0 | 190 | IFS="$save_ifs" |
michael@0 | 191 | linker_opts="$linker_opts $flag" |
michael@0 | 192 | done |
michael@0 | 193 | IFS="$save_ifs" |
michael@0 | 194 | ;; |
michael@0 | 195 | -Xlinker) |
michael@0 | 196 | eat=1 |
michael@0 | 197 | linker_opts="$linker_opts $2" |
michael@0 | 198 | ;; |
michael@0 | 199 | -*) |
michael@0 | 200 | set x "$@" "$1" |
michael@0 | 201 | shift |
michael@0 | 202 | ;; |
michael@0 | 203 | *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) |
michael@0 | 204 | func_file_conv "$1" |
michael@0 | 205 | set x "$@" -Tp"$file" |
michael@0 | 206 | shift |
michael@0 | 207 | ;; |
michael@0 | 208 | *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) |
michael@0 | 209 | func_file_conv "$1" mingw |
michael@0 | 210 | set x "$@" "$file" |
michael@0 | 211 | shift |
michael@0 | 212 | ;; |
michael@0 | 213 | *) |
michael@0 | 214 | set x "$@" "$1" |
michael@0 | 215 | shift |
michael@0 | 216 | ;; |
michael@0 | 217 | esac |
michael@0 | 218 | fi |
michael@0 | 219 | shift |
michael@0 | 220 | done |
michael@0 | 221 | if test -n "$linker_opts"; then |
michael@0 | 222 | linker_opts="-link$linker_opts" |
michael@0 | 223 | fi |
michael@0 | 224 | exec "$@" $linker_opts |
michael@0 | 225 | exit 1 |
michael@0 | 226 | } |
michael@0 | 227 | |
michael@0 | 228 | eat= |
michael@0 | 229 | |
michael@0 | 230 | case $1 in |
michael@0 | 231 | '') |
michael@0 | 232 | echo "$0: No command. Try '$0 --help' for more information." 1>&2 |
michael@0 | 233 | exit 1; |
michael@0 | 234 | ;; |
michael@0 | 235 | -h | --h*) |
michael@0 | 236 | cat <<\EOF |
michael@0 | 237 | Usage: compile [--help] [--version] PROGRAM [ARGS] |
michael@0 | 238 | |
michael@0 | 239 | Wrapper for compilers which do not understand '-c -o'. |
michael@0 | 240 | Remove '-o dest.o' from ARGS, run PROGRAM with the remaining |
michael@0 | 241 | arguments, and rename the output as expected. |
michael@0 | 242 | |
michael@0 | 243 | If you are trying to build a whole package this is not the |
michael@0 | 244 | right script to run: please start by reading the file 'INSTALL'. |
michael@0 | 245 | |
michael@0 | 246 | Report bugs to <bug-automake@gnu.org>. |
michael@0 | 247 | EOF |
michael@0 | 248 | exit $? |
michael@0 | 249 | ;; |
michael@0 | 250 | -v | --v*) |
michael@0 | 251 | echo "compile $scriptversion" |
michael@0 | 252 | exit $? |
michael@0 | 253 | ;; |
michael@0 | 254 | cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) |
michael@0 | 255 | func_cl_wrapper "$@" # Doesn't return... |
michael@0 | 256 | ;; |
michael@0 | 257 | esac |
michael@0 | 258 | |
michael@0 | 259 | ofile= |
michael@0 | 260 | cfile= |
michael@0 | 261 | |
michael@0 | 262 | for arg |
michael@0 | 263 | do |
michael@0 | 264 | if test -n "$eat"; then |
michael@0 | 265 | eat= |
michael@0 | 266 | else |
michael@0 | 267 | case $1 in |
michael@0 | 268 | -o) |
michael@0 | 269 | # configure might choose to run compile as 'compile cc -o foo foo.c'. |
michael@0 | 270 | # So we strip '-o arg' only if arg is an object. |
michael@0 | 271 | eat=1 |
michael@0 | 272 | case $2 in |
michael@0 | 273 | *.o | *.obj) |
michael@0 | 274 | ofile=$2 |
michael@0 | 275 | ;; |
michael@0 | 276 | *) |
michael@0 | 277 | set x "$@" -o "$2" |
michael@0 | 278 | shift |
michael@0 | 279 | ;; |
michael@0 | 280 | esac |
michael@0 | 281 | ;; |
michael@0 | 282 | *.c) |
michael@0 | 283 | cfile=$1 |
michael@0 | 284 | set x "$@" "$1" |
michael@0 | 285 | shift |
michael@0 | 286 | ;; |
michael@0 | 287 | *) |
michael@0 | 288 | set x "$@" "$1" |
michael@0 | 289 | shift |
michael@0 | 290 | ;; |
michael@0 | 291 | esac |
michael@0 | 292 | fi |
michael@0 | 293 | shift |
michael@0 | 294 | done |
michael@0 | 295 | |
michael@0 | 296 | if test -z "$ofile" || test -z "$cfile"; then |
michael@0 | 297 | # If no '-o' option was seen then we might have been invoked from a |
michael@0 | 298 | # pattern rule where we don't need one. That is ok -- this is a |
michael@0 | 299 | # normal compilation that the losing compiler can handle. If no |
michael@0 | 300 | # '.c' file was seen then we are probably linking. That is also |
michael@0 | 301 | # ok. |
michael@0 | 302 | exec "$@" |
michael@0 | 303 | fi |
michael@0 | 304 | |
michael@0 | 305 | # Name of file we expect compiler to create. |
michael@0 | 306 | cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` |
michael@0 | 307 | |
michael@0 | 308 | # Create the lock directory. |
michael@0 | 309 | # Note: use '[/\\:.-]' here to ensure that we don't use the same name |
michael@0 | 310 | # that we are using for the .o file. Also, base the name on the expected |
michael@0 | 311 | # object file name, since that is what matters with a parallel build. |
michael@0 | 312 | lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d |
michael@0 | 313 | while true; do |
michael@0 | 314 | if mkdir "$lockdir" >/dev/null 2>&1; then |
michael@0 | 315 | break |
michael@0 | 316 | fi |
michael@0 | 317 | sleep 1 |
michael@0 | 318 | done |
michael@0 | 319 | # FIXME: race condition here if user kills between mkdir and trap. |
michael@0 | 320 | trap "rmdir '$lockdir'; exit 1" 1 2 15 |
michael@0 | 321 | |
michael@0 | 322 | # Run the compile. |
michael@0 | 323 | "$@" |
michael@0 | 324 | ret=$? |
michael@0 | 325 | |
michael@0 | 326 | if test -f "$cofile"; then |
michael@0 | 327 | test "$cofile" = "$ofile" || mv "$cofile" "$ofile" |
michael@0 | 328 | elif test -f "${cofile}bj"; then |
michael@0 | 329 | test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" |
michael@0 | 330 | fi |
michael@0 | 331 | |
michael@0 | 332 | rmdir "$lockdir" |
michael@0 | 333 | exit $ret |
michael@0 | 334 | |
michael@0 | 335 | # Local Variables: |
michael@0 | 336 | # mode: shell-script |
michael@0 | 337 | # sh-indentation: 2 |
michael@0 | 338 | # eval: (add-hook 'write-file-hooks 'time-stamp) |
michael@0 | 339 | # time-stamp-start: "scriptversion=" |
michael@0 | 340 | # time-stamp-format: "%:y-%02m-%02d.%02H" |
michael@0 | 341 | # time-stamp-time-zone: "UTC" |
michael@0 | 342 | # time-stamp-end: "; # UTC" |
michael@0 | 343 | # End: |