1240116Smarcel#! /bin/sh 2240116Smarcel# Wrapper for compilers which do not understand '-c -o'. 3240116Smarcel 4240116Smarcelscriptversion=2012-01-04.17; # UTC 5240116Smarcel 6240116Smarcel# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009, 2010, 2012 Free 7240116Smarcel# Software Foundation, Inc. 8240116Smarcel# Written by Tom Tromey <tromey@cygnus.com>. 9240116Smarcel# 10240116Smarcel# This program is free software; you can redistribute it and/or modify 11240116Smarcel# it under the terms of the GNU General Public License as published by 12240116Smarcel# the Free Software Foundation; either version 2, or (at your option) 13240116Smarcel# any later version. 14240116Smarcel# 15240116Smarcel# This program is distributed in the hope that it will be useful, 16240116Smarcel# but WITHOUT ANY WARRANTY; without even the implied warranty of 17240116Smarcel# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18240116Smarcel# GNU General Public License for more details. 19240116Smarcel# 20240116Smarcel# You should have received a copy of the GNU General Public License 21240116Smarcel# along with this program. If not, see <http://www.gnu.org/licenses/>. 22240116Smarcel 23240116Smarcel# As a special exception to the GNU General Public License, if you 24240116Smarcel# distribute this file as part of a program that contains a 25240116Smarcel# configuration script generated by Autoconf, you may include it under 26240116Smarcel# the same distribution terms that you use for the rest of that program. 27240116Smarcel 28240116Smarcel# This file is maintained in Automake, please report 29240116Smarcel# bugs to <bug-automake@gnu.org> or send patches to 30240116Smarcel# <automake-patches@gnu.org>. 31240116Smarcel 32240116Smarcelnl=' 33240116Smarcel' 34240116Smarcel 35240116Smarcel# We need space, tab and new line, in precisely that order. Quoting is 36240116Smarcel# there to prevent tools from complaining about whitespace usage. 37240116SmarcelIFS=" "" $nl" 38240116Smarcel 39240116Smarcelfile_conv= 40240116Smarcel 41240116Smarcel# func_file_conv build_file lazy 42240116Smarcel# Convert a $build file to $host form and store it in $file 43240116Smarcel# Currently only supports Windows hosts. If the determined conversion 44240116Smarcel# type is listed in (the comma separated) LAZY, no conversion will 45240116Smarcel# take place. 46240116Smarcelfunc_file_conv () 47240116Smarcel{ 48240116Smarcel file=$1 49240116Smarcel case $file in 50240116Smarcel / | /[!/]*) # absolute file, and not a UNC file 51240116Smarcel if test -z "$file_conv"; then 52240116Smarcel # lazily determine how to convert abs files 53240116Smarcel case `uname -s` in 54240116Smarcel MINGW*) 55240116Smarcel file_conv=mingw 56240116Smarcel ;; 57240116Smarcel CYGWIN*) 58240116Smarcel file_conv=cygwin 59240116Smarcel ;; 60240116Smarcel *) 61240116Smarcel file_conv=wine 62240116Smarcel ;; 63240116Smarcel esac 64240116Smarcel fi 65240116Smarcel case $file_conv/,$2, in 66240116Smarcel *,$file_conv,*) 67240116Smarcel ;; 68240116Smarcel mingw/*) 69240116Smarcel file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 70240116Smarcel ;; 71240116Smarcel cygwin/*) 72240116Smarcel file=`cygpath -m "$file" || echo "$file"` 73240116Smarcel ;; 74240116Smarcel wine/*) 75240116Smarcel file=`winepath -w "$file" || echo "$file"` 76240116Smarcel ;; 77240116Smarcel esac 78240116Smarcel ;; 79240116Smarcel esac 80240116Smarcel} 81240116Smarcel 82240116Smarcel# func_cl_wrapper cl arg... 83240116Smarcel# Adjust compile command to suit cl 84240116Smarcelfunc_cl_wrapper () 85240116Smarcel{ 86240116Smarcel # Assume a capable shell 87240116Smarcel lib_path= 88240116Smarcel shared=: 89240116Smarcel linker_opts= 90240116Smarcel for arg 91240116Smarcel do 92240116Smarcel if test -n "$eat"; then 93240116Smarcel eat= 94240116Smarcel else 95240116Smarcel case $1 in 96240116Smarcel -o) 97240116Smarcel # configure might choose to run compile as 'compile cc -o foo foo.c'. 98240116Smarcel eat=1 99240116Smarcel case $2 in 100240116Smarcel *.o | *.[oO][bB][jJ]) 101240116Smarcel func_file_conv "$2" 102240116Smarcel set x "$@" -Fo"$file" 103240116Smarcel shift 104240116Smarcel ;; 105240116Smarcel *) 106240116Smarcel func_file_conv "$2" 107240116Smarcel set x "$@" -Fe"$file" 108240116Smarcel shift 109240116Smarcel ;; 110240116Smarcel esac 111240116Smarcel ;; 112240116Smarcel -I*) 113240116Smarcel func_file_conv "${1#-I}" mingw 114240116Smarcel set x "$@" -I"$file" 115240116Smarcel shift 116240116Smarcel ;; 117240116Smarcel -l*) 118240116Smarcel lib=${1#-l} 119240116Smarcel found=no 120240116Smarcel save_IFS=$IFS 121240116Smarcel IFS=';' 122240116Smarcel for dir in $lib_path $LIB 123240116Smarcel do 124240116Smarcel IFS=$save_IFS 125240116Smarcel if $shared && test -f "$dir/$lib.dll.lib"; then 126240116Smarcel found=yes 127240116Smarcel set x "$@" "$dir/$lib.dll.lib" 128240116Smarcel break 129240116Smarcel fi 130240116Smarcel if test -f "$dir/$lib.lib"; then 131240116Smarcel found=yes 132240116Smarcel set x "$@" "$dir/$lib.lib" 133240116Smarcel break 134240116Smarcel fi 135240116Smarcel done 136240116Smarcel IFS=$save_IFS 137240116Smarcel 138240116Smarcel test "$found" != yes && set x "$@" "$lib.lib" 139240116Smarcel shift 140240116Smarcel ;; 141240116Smarcel -L*) 142240116Smarcel func_file_conv "${1#-L}" 143240116Smarcel if test -z "$lib_path"; then 144240116Smarcel lib_path=$file 145240116Smarcel else 146240116Smarcel lib_path="$lib_path;$file" 147240116Smarcel fi 148240116Smarcel linker_opts="$linker_opts -LIBPATH:$file" 149240116Smarcel ;; 150240116Smarcel -static) 151240116Smarcel shared=false 152240116Smarcel ;; 153240116Smarcel -Wl,*) 154240116Smarcel arg=${1#-Wl,} 155240116Smarcel save_ifs="$IFS"; IFS=',' 156240116Smarcel for flag in $arg; do 157240116Smarcel IFS="$save_ifs" 158240116Smarcel linker_opts="$linker_opts $flag" 159240116Smarcel done 160240116Smarcel IFS="$save_ifs" 161240116Smarcel ;; 162240116Smarcel -Xlinker) 163240116Smarcel eat=1 164240116Smarcel linker_opts="$linker_opts $2" 165240116Smarcel ;; 166240116Smarcel -*) 167240116Smarcel set x "$@" "$1" 168240116Smarcel shift 169240116Smarcel ;; 170240116Smarcel *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 171240116Smarcel func_file_conv "$1" 172240116Smarcel set x "$@" -Tp"$file" 173240116Smarcel shift 174240116Smarcel ;; 175240116Smarcel *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 176240116Smarcel func_file_conv "$1" mingw 177240116Smarcel set x "$@" "$file" 178240116Smarcel shift 179240116Smarcel ;; 180240116Smarcel *) 181240116Smarcel set x "$@" "$1" 182240116Smarcel shift 183240116Smarcel ;; 184240116Smarcel esac 185240116Smarcel fi 186240116Smarcel shift 187240116Smarcel done 188240116Smarcel if test -n "$linker_opts"; then 189240116Smarcel linker_opts="-link$linker_opts" 190240116Smarcel fi 191240116Smarcel exec "$@" $linker_opts 192240116Smarcel exit 1 193240116Smarcel} 194240116Smarcel 195240116Smarceleat= 196240116Smarcel 197240116Smarcelcase $1 in 198240116Smarcel '') 199240116Smarcel echo "$0: No command. Try '$0 --help' for more information." 1>&2 200240116Smarcel exit 1; 201240116Smarcel ;; 202240116Smarcel -h | --h*) 203240116Smarcel cat <<\EOF 204240116SmarcelUsage: compile [--help] [--version] PROGRAM [ARGS] 205240116Smarcel 206240116SmarcelWrapper for compilers which do not understand '-c -o'. 207240116SmarcelRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 208240116Smarcelarguments, and rename the output as expected. 209240116Smarcel 210240116SmarcelIf you are trying to build a whole package this is not the 211240116Smarcelright script to run: please start by reading the file 'INSTALL'. 212240116Smarcel 213240116SmarcelReport bugs to <bug-automake@gnu.org>. 214240116SmarcelEOF 215240116Smarcel exit $? 216240116Smarcel ;; 217240116Smarcel -v | --v*) 218240116Smarcel echo "compile $scriptversion" 219240116Smarcel exit $? 220240116Smarcel ;; 221240116Smarcel cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 222240116Smarcel func_cl_wrapper "$@" # Doesn't return... 223240116Smarcel ;; 224240116Smarcelesac 225240116Smarcel 226240116Smarcelofile= 227240116Smarcelcfile= 228240116Smarcel 229240116Smarcelfor arg 230240116Smarceldo 231240116Smarcel if test -n "$eat"; then 232240116Smarcel eat= 233240116Smarcel else 234240116Smarcel case $1 in 235240116Smarcel -o) 236240116Smarcel # configure might choose to run compile as 'compile cc -o foo foo.c'. 237240116Smarcel # So we strip '-o arg' only if arg is an object. 238240116Smarcel eat=1 239240116Smarcel case $2 in 240240116Smarcel *.o | *.obj) 241240116Smarcel ofile=$2 242240116Smarcel ;; 243240116Smarcel *) 244240116Smarcel set x "$@" -o "$2" 245240116Smarcel shift 246240116Smarcel ;; 247240116Smarcel esac 248240116Smarcel ;; 249240116Smarcel *.c) 250240116Smarcel cfile=$1 251240116Smarcel set x "$@" "$1" 252240116Smarcel shift 253240116Smarcel ;; 254240116Smarcel *) 255240116Smarcel set x "$@" "$1" 256240116Smarcel shift 257240116Smarcel ;; 258240116Smarcel esac 259240116Smarcel fi 260240116Smarcel shift 261240116Smarceldone 262240116Smarcel 263240116Smarcelif test -z "$ofile" || test -z "$cfile"; then 264240116Smarcel # If no '-o' option was seen then we might have been invoked from a 265240116Smarcel # pattern rule where we don't need one. That is ok -- this is a 266240116Smarcel # normal compilation that the losing compiler can handle. If no 267240116Smarcel # '.c' file was seen then we are probably linking. That is also 268240116Smarcel # ok. 269240116Smarcel exec "$@" 270240116Smarcelfi 271240116Smarcel 272240116Smarcel# Name of file we expect compiler to create. 273240116Smarcelcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 274240116Smarcel 275240116Smarcel# Create the lock directory. 276240116Smarcel# Note: use '[/\\:.-]' here to ensure that we don't use the same name 277240116Smarcel# that we are using for the .o file. Also, base the name on the expected 278240116Smarcel# object file name, since that is what matters with a parallel build. 279240116Smarcellockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 280240116Smarcelwhile true; do 281240116Smarcel if mkdir "$lockdir" >/dev/null 2>&1; then 282240116Smarcel break 283240116Smarcel fi 284240116Smarcel sleep 1 285240116Smarceldone 286240116Smarcel# FIXME: race condition here if user kills between mkdir and trap. 287240116Smarceltrap "rmdir '$lockdir'; exit 1" 1 2 15 288240116Smarcel 289240116Smarcel# Run the compile. 290240116Smarcel"$@" 291240116Smarcelret=$? 292240116Smarcel 293240116Smarcelif test -f "$cofile"; then 294240116Smarcel test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 295240116Smarcelelif test -f "${cofile}bj"; then 296240116Smarcel test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 297240116Smarcelfi 298240116Smarcel 299240116Smarcelrmdir "$lockdir" 300240116Smarcelexit $ret 301240116Smarcel 302240116Smarcel# Local Variables: 303240116Smarcel# mode: shell-script 304240116Smarcel# sh-indentation: 2 305240116Smarcel# eval: (add-hook 'write-file-hooks 'time-stamp) 306240116Smarcel# time-stamp-start: "scriptversion=" 307240116Smarcel# time-stamp-format: "%:y-%02m-%02d.%02H" 308240116Smarcel# time-stamp-time-zone: "UTC" 309240116Smarcel# time-stamp-end: "; # UTC" 310240116Smarcel# End: 311