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