1304732Scy#! /bin/sh 2304732Scy# Wrapper for compilers which do not understand '-c -o'. 3304732Scy 4304732Scyscriptversion=2012-10-14.11; # UTC 5304732Scy 6304732Scy# Copyright (C) 1999-2014 Free Software Foundation, Inc. 7304732Scy# Written by Tom Tromey <tromey@cygnus.com>. 8304732Scy# 9304732Scy# This program is free software; you can redistribute it and/or modify 10304732Scy# it under the terms of the GNU General Public License as published by 11304732Scy# the Free Software Foundation; either version 2, or (at your option) 12304732Scy# any later version. 13304732Scy# 14304732Scy# This program is distributed in the hope that it will be useful, 15304732Scy# but WITHOUT ANY WARRANTY; without even the implied warranty of 16304732Scy# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17304732Scy# GNU General Public License for more details. 18304732Scy# 19304732Scy# You should have received a copy of the GNU General Public License 20304732Scy# along with this program. If not, see <http://www.gnu.org/licenses/>. 21304732Scy 22304732Scy# As a special exception to the GNU General Public License, if you 23304732Scy# distribute this file as part of a program that contains a 24304732Scy# configuration script generated by Autoconf, you may include it under 25304732Scy# the same distribution terms that you use for the rest of that program. 26304732Scy 27304732Scy# This file is maintained in Automake, please report 28304732Scy# bugs to <bug-automake@gnu.org> or send patches to 29304732Scy# <automake-patches@gnu.org>. 30304732Scy 31304732Scynl=' 32304732Scy' 33304732Scy 34304732Scy# We need space, tab and new line, in precisely that order. Quoting is 35304732Scy# there to prevent tools from complaining about whitespace usage. 36304732ScyIFS=" "" $nl" 37304732Scy 38304732Scyfile_conv= 39304732Scy 40304732Scy# func_file_conv build_file lazy 41304732Scy# Convert a $build file to $host form and store it in $file 42304732Scy# Currently only supports Windows hosts. If the determined conversion 43304732Scy# type is listed in (the comma separated) LAZY, no conversion will 44304732Scy# take place. 45304732Scyfunc_file_conv () 46304732Scy{ 47304732Scy file=$1 48304732Scy case $file in 49304732Scy / | /[!/]*) # absolute file, and not a UNC file 50304732Scy if test -z "$file_conv"; then 51304732Scy # lazily determine how to convert abs files 52304732Scy case `uname -s` in 53304732Scy MINGW*) 54304732Scy file_conv=mingw 55304732Scy ;; 56304732Scy CYGWIN*) 57304732Scy file_conv=cygwin 58304732Scy ;; 59304732Scy *) 60304732Scy file_conv=wine 61304732Scy ;; 62304732Scy esac 63304732Scy fi 64304732Scy case $file_conv/,$2, in 65304732Scy *,$file_conv,*) 66304732Scy ;; 67304732Scy mingw/*) 68304732Scy file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 69304732Scy ;; 70304732Scy cygwin/*) 71304732Scy file=`cygpath -m "$file" || echo "$file"` 72304732Scy ;; 73304732Scy wine/*) 74304732Scy file=`winepath -w "$file" || echo "$file"` 75304732Scy ;; 76304732Scy esac 77304732Scy ;; 78304732Scy esac 79304732Scy} 80304732Scy 81304732Scy# func_cl_dashL linkdir 82304732Scy# Make cl look for libraries in LINKDIR 83304732Scyfunc_cl_dashL () 84304732Scy{ 85304732Scy func_file_conv "$1" 86304732Scy if test -z "$lib_path"; then 87304732Scy lib_path=$file 88304732Scy else 89304732Scy lib_path="$lib_path;$file" 90304732Scy fi 91304732Scy linker_opts="$linker_opts -LIBPATH:$file" 92304732Scy} 93304732Scy 94304732Scy# func_cl_dashl library 95304732Scy# Do a library search-path lookup for cl 96304732Scyfunc_cl_dashl () 97304732Scy{ 98304732Scy lib=$1 99304732Scy found=no 100304732Scy save_IFS=$IFS 101304732Scy IFS=';' 102304732Scy for dir in $lib_path $LIB 103304732Scy do 104304732Scy IFS=$save_IFS 105304732Scy if $shared && test -f "$dir/$lib.dll.lib"; then 106304732Scy found=yes 107304732Scy lib=$dir/$lib.dll.lib 108304732Scy break 109304732Scy fi 110304732Scy if test -f "$dir/$lib.lib"; then 111304732Scy found=yes 112304732Scy lib=$dir/$lib.lib 113304732Scy break 114304732Scy fi 115304732Scy if test -f "$dir/lib$lib.a"; then 116304732Scy found=yes 117304732Scy lib=$dir/lib$lib.a 118304732Scy break 119304732Scy fi 120304732Scy done 121304732Scy IFS=$save_IFS 122304732Scy 123304732Scy if test "$found" != yes; then 124304732Scy lib=$lib.lib 125304732Scy fi 126304732Scy} 127304732Scy 128304732Scy# func_cl_wrapper cl arg... 129304732Scy# Adjust compile command to suit cl 130304732Scyfunc_cl_wrapper () 131304732Scy{ 132304732Scy # Assume a capable shell 133304732Scy lib_path= 134304732Scy shared=: 135304732Scy linker_opts= 136304732Scy for arg 137304732Scy do 138304732Scy if test -n "$eat"; then 139304732Scy eat= 140304732Scy else 141304732Scy case $1 in 142304732Scy -o) 143304732Scy # configure might choose to run compile as 'compile cc -o foo foo.c'. 144304732Scy eat=1 145304732Scy case $2 in 146304732Scy *.o | *.[oO][bB][jJ]) 147304732Scy func_file_conv "$2" 148304732Scy set x "$@" -Fo"$file" 149304732Scy shift 150304732Scy ;; 151304732Scy *) 152304732Scy func_file_conv "$2" 153304732Scy set x "$@" -Fe"$file" 154304732Scy shift 155304732Scy ;; 156304732Scy esac 157304732Scy ;; 158304732Scy -I) 159304732Scy eat=1 160304732Scy func_file_conv "$2" mingw 161304732Scy set x "$@" -I"$file" 162304732Scy shift 163304732Scy ;; 164304732Scy -I*) 165304732Scy func_file_conv "${1#-I}" mingw 166304732Scy set x "$@" -I"$file" 167304732Scy shift 168304732Scy ;; 169304732Scy -l) 170304732Scy eat=1 171304732Scy func_cl_dashl "$2" 172304732Scy set x "$@" "$lib" 173304732Scy shift 174304732Scy ;; 175304732Scy -l*) 176304732Scy func_cl_dashl "${1#-l}" 177304732Scy set x "$@" "$lib" 178304732Scy shift 179304732Scy ;; 180304732Scy -L) 181304732Scy eat=1 182304732Scy func_cl_dashL "$2" 183304732Scy ;; 184304732Scy -L*) 185304732Scy func_cl_dashL "${1#-L}" 186304732Scy ;; 187304732Scy -static) 188304732Scy shared=false 189304732Scy ;; 190304732Scy -Wl,*) 191304732Scy arg=${1#-Wl,} 192304732Scy save_ifs="$IFS"; IFS=',' 193304732Scy for flag in $arg; do 194304732Scy IFS="$save_ifs" 195304732Scy linker_opts="$linker_opts $flag" 196304732Scy done 197304732Scy IFS="$save_ifs" 198304732Scy ;; 199304732Scy -Xlinker) 200304732Scy eat=1 201304732Scy linker_opts="$linker_opts $2" 202304732Scy ;; 203304732Scy -*) 204304732Scy set x "$@" "$1" 205304732Scy shift 206304732Scy ;; 207304732Scy *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 208304732Scy func_file_conv "$1" 209304732Scy set x "$@" -Tp"$file" 210304732Scy shift 211304732Scy ;; 212304732Scy *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 213304732Scy func_file_conv "$1" mingw 214304732Scy set x "$@" "$file" 215304732Scy shift 216304732Scy ;; 217304732Scy *) 218304732Scy set x "$@" "$1" 219304732Scy shift 220304732Scy ;; 221304732Scy esac 222304732Scy fi 223304732Scy shift 224304732Scy done 225304732Scy if test -n "$linker_opts"; then 226304732Scy linker_opts="-link$linker_opts" 227304732Scy fi 228304732Scy exec "$@" $linker_opts 229304732Scy exit 1 230304732Scy} 231304732Scy 232304732Scyeat= 233304732Scy 234304732Scycase $1 in 235304732Scy '') 236304732Scy echo "$0: No command. Try '$0 --help' for more information." 1>&2 237304732Scy exit 1; 238304732Scy ;; 239304732Scy -h | --h*) 240304732Scy cat <<\EOF 241304732ScyUsage: compile [--help] [--version] PROGRAM [ARGS] 242304732Scy 243304732ScyWrapper for compilers which do not understand '-c -o'. 244304732ScyRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 245304732Scyarguments, and rename the output as expected. 246304732Scy 247304732ScyIf you are trying to build a whole package this is not the 248304732Scyright script to run: please start by reading the file 'INSTALL'. 249304732Scy 250304732ScyReport bugs to <bug-automake@gnu.org>. 251304732ScyEOF 252304732Scy exit $? 253304732Scy ;; 254304732Scy -v | --v*) 255304732Scy echo "compile $scriptversion" 256304732Scy exit $? 257304732Scy ;; 258304732Scy cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 259304732Scy func_cl_wrapper "$@" # Doesn't return... 260304732Scy ;; 261304732Scyesac 262304732Scy 263304732Scyofile= 264304732Scycfile= 265304732Scy 266304732Scyfor arg 267304732Scydo 268304732Scy if test -n "$eat"; then 269304732Scy eat= 270304732Scy else 271304732Scy case $1 in 272304732Scy -o) 273304732Scy # configure might choose to run compile as 'compile cc -o foo foo.c'. 274304732Scy # So we strip '-o arg' only if arg is an object. 275304732Scy eat=1 276304732Scy case $2 in 277304732Scy *.o | *.obj) 278304732Scy ofile=$2 279304732Scy ;; 280304732Scy *) 281304732Scy set x "$@" -o "$2" 282304732Scy shift 283304732Scy ;; 284304732Scy esac 285304732Scy ;; 286304732Scy *.c) 287304732Scy cfile=$1 288304732Scy set x "$@" "$1" 289304732Scy shift 290304732Scy ;; 291304732Scy *) 292304732Scy set x "$@" "$1" 293304732Scy shift 294304732Scy ;; 295304732Scy esac 296304732Scy fi 297304732Scy shift 298304732Scydone 299304732Scy 300304732Scyif test -z "$ofile" || test -z "$cfile"; then 301304732Scy # If no '-o' option was seen then we might have been invoked from a 302304732Scy # pattern rule where we don't need one. That is ok -- this is a 303304732Scy # normal compilation that the losing compiler can handle. If no 304304732Scy # '.c' file was seen then we are probably linking. That is also 305304732Scy # ok. 306304732Scy exec "$@" 307304732Scyfi 308304732Scy 309304732Scy# Name of file we expect compiler to create. 310304732Scycofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 311304732Scy 312304732Scy# Create the lock directory. 313304732Scy# Note: use '[/\\:.-]' here to ensure that we don't use the same name 314304732Scy# that we are using for the .o file. Also, base the name on the expected 315304732Scy# object file name, since that is what matters with a parallel build. 316304732Scylockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 317304732Scywhile true; do 318304732Scy if mkdir "$lockdir" >/dev/null 2>&1; then 319304732Scy break 320304732Scy fi 321304732Scy sleep 1 322304732Scydone 323304732Scy# FIXME: race condition here if user kills between mkdir and trap. 324304732Scytrap "rmdir '$lockdir'; exit 1" 1 2 15 325304732Scy 326304732Scy# Run the compile. 327304732Scy"$@" 328304732Scyret=$? 329304732Scy 330304732Scyif test -f "$cofile"; then 331304732Scy test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 332304732Scyelif test -f "${cofile}bj"; then 333304732Scy test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 334304732Scyfi 335304732Scy 336304732Scyrmdir "$lockdir" 337304732Scyexit $ret 338304732Scy 339304732Scy# Local Variables: 340304732Scy# mode: shell-script 341304732Scy# sh-indentation: 2 342304732Scy# eval: (add-hook 'write-file-hooks 'time-stamp) 343304732Scy# time-stamp-start: "scriptversion=" 344304732Scy# time-stamp-format: "%:y-%02m-%02d.%02H" 345304732Scy# time-stamp-time-zone: "UTC" 346304732Scy# time-stamp-end: "; # UTC" 347304732Scy# End: 348