1ef01931fSBen Gras#! /bin/sh 284d9c625SLionel Sambuc# Wrapper for compilers which do not understand '-c -o'. 3ef01931fSBen Gras 4*0a6a1f1dSLionel Sambucscriptversion=2012-10-14.11; # UTC 5ef01931fSBen Gras 6*0a6a1f1dSLionel Sambuc# Copyright (C) 1999-2013 Free Software Foundation, Inc. 7ef01931fSBen Gras# Written by Tom Tromey <tromey@cygnus.com>. 8ef01931fSBen Gras# 9ef01931fSBen Gras# This program is free software; you can redistribute it and/or modify 10ef01931fSBen Gras# it under the terms of the GNU General Public License as published by 11ef01931fSBen Gras# the Free Software Foundation; either version 2, or (at your option) 12ef01931fSBen Gras# any later version. 13ef01931fSBen Gras# 14ef01931fSBen Gras# This program is distributed in the hope that it will be useful, 15ef01931fSBen Gras# but WITHOUT ANY WARRANTY; without even the implied warranty of 16ef01931fSBen Gras# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17ef01931fSBen Gras# GNU General Public License for more details. 18ef01931fSBen Gras# 19ef01931fSBen Gras# You should have received a copy of the GNU General Public License 20835f6802SDirk Vogt# along with this program. If not, see <http://www.gnu.org/licenses/>. 21ef01931fSBen Gras 22ef01931fSBen Gras# As a special exception to the GNU General Public License, if you 23ef01931fSBen Gras# distribute this file as part of a program that contains a 24ef01931fSBen Gras# configuration script generated by Autoconf, you may include it under 25ef01931fSBen Gras# the same distribution terms that you use for the rest of that program. 26ef01931fSBen Gras 27ef01931fSBen Gras# This file is maintained in Automake, please report 28ef01931fSBen Gras# bugs to <bug-automake@gnu.org> or send patches to 29ef01931fSBen Gras# <automake-patches@gnu.org>. 30ef01931fSBen Gras 3184d9c625SLionel Sambucnl=' 3284d9c625SLionel Sambuc' 3384d9c625SLionel Sambuc 3484d9c625SLionel Sambuc# We need space, tab and new line, in precisely that order. Quoting is 3584d9c625SLionel Sambuc# there to prevent tools from complaining about whitespace usage. 3684d9c625SLionel SambucIFS=" "" $nl" 3784d9c625SLionel Sambuc 3884d9c625SLionel Sambucfile_conv= 3984d9c625SLionel Sambuc 4084d9c625SLionel Sambuc# func_file_conv build_file lazy 4184d9c625SLionel Sambuc# Convert a $build file to $host form and store it in $file 4284d9c625SLionel Sambuc# Currently only supports Windows hosts. If the determined conversion 4384d9c625SLionel Sambuc# type is listed in (the comma separated) LAZY, no conversion will 4484d9c625SLionel Sambuc# take place. 4584d9c625SLionel Sambucfunc_file_conv () 4684d9c625SLionel Sambuc{ 4784d9c625SLionel Sambuc file=$1 4884d9c625SLionel Sambuc case $file in 4984d9c625SLionel Sambuc / | /[!/]*) # absolute file, and not a UNC file 5084d9c625SLionel Sambuc if test -z "$file_conv"; then 5184d9c625SLionel Sambuc # lazily determine how to convert abs files 5284d9c625SLionel Sambuc case `uname -s` in 5384d9c625SLionel Sambuc MINGW*) 5484d9c625SLionel Sambuc file_conv=mingw 5584d9c625SLionel Sambuc ;; 5684d9c625SLionel Sambuc CYGWIN*) 5784d9c625SLionel Sambuc file_conv=cygwin 5884d9c625SLionel Sambuc ;; 5984d9c625SLionel Sambuc *) 6084d9c625SLionel Sambuc file_conv=wine 6184d9c625SLionel Sambuc ;; 6284d9c625SLionel Sambuc esac 6384d9c625SLionel Sambuc fi 6484d9c625SLionel Sambuc case $file_conv/,$2, in 6584d9c625SLionel Sambuc *,$file_conv,*) 6684d9c625SLionel Sambuc ;; 6784d9c625SLionel Sambuc mingw/*) 6884d9c625SLionel Sambuc file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 6984d9c625SLionel Sambuc ;; 7084d9c625SLionel Sambuc cygwin/*) 7184d9c625SLionel Sambuc file=`cygpath -m "$file" || echo "$file"` 7284d9c625SLionel Sambuc ;; 7384d9c625SLionel Sambuc wine/*) 7484d9c625SLionel Sambuc file=`winepath -w "$file" || echo "$file"` 7584d9c625SLionel Sambuc ;; 7684d9c625SLionel Sambuc esac 7784d9c625SLionel Sambuc ;; 7884d9c625SLionel Sambuc esac 7984d9c625SLionel Sambuc} 8084d9c625SLionel Sambuc 8184d9c625SLionel Sambuc# func_cl_dashL linkdir 8284d9c625SLionel Sambuc# Make cl look for libraries in LINKDIR 8384d9c625SLionel Sambucfunc_cl_dashL () 8484d9c625SLionel Sambuc{ 8584d9c625SLionel Sambuc func_file_conv "$1" 8684d9c625SLionel Sambuc if test -z "$lib_path"; then 8784d9c625SLionel Sambuc lib_path=$file 8884d9c625SLionel Sambuc else 8984d9c625SLionel Sambuc lib_path="$lib_path;$file" 9084d9c625SLionel Sambuc fi 9184d9c625SLionel Sambuc linker_opts="$linker_opts -LIBPATH:$file" 9284d9c625SLionel Sambuc} 9384d9c625SLionel Sambuc 9484d9c625SLionel Sambuc# func_cl_dashl library 9584d9c625SLionel Sambuc# Do a library search-path lookup for cl 9684d9c625SLionel Sambucfunc_cl_dashl () 9784d9c625SLionel Sambuc{ 9884d9c625SLionel Sambuc lib=$1 9984d9c625SLionel Sambuc found=no 10084d9c625SLionel Sambuc save_IFS=$IFS 10184d9c625SLionel Sambuc IFS=';' 10284d9c625SLionel Sambuc for dir in $lib_path $LIB 10384d9c625SLionel Sambuc do 10484d9c625SLionel Sambuc IFS=$save_IFS 10584d9c625SLionel Sambuc if $shared && test -f "$dir/$lib.dll.lib"; then 10684d9c625SLionel Sambuc found=yes 10784d9c625SLionel Sambuc lib=$dir/$lib.dll.lib 10884d9c625SLionel Sambuc break 10984d9c625SLionel Sambuc fi 11084d9c625SLionel Sambuc if test -f "$dir/$lib.lib"; then 11184d9c625SLionel Sambuc found=yes 11284d9c625SLionel Sambuc lib=$dir/$lib.lib 11384d9c625SLionel Sambuc break 11484d9c625SLionel Sambuc fi 115*0a6a1f1dSLionel Sambuc if test -f "$dir/lib$lib.a"; then 116*0a6a1f1dSLionel Sambuc found=yes 117*0a6a1f1dSLionel Sambuc lib=$dir/lib$lib.a 118*0a6a1f1dSLionel Sambuc break 119*0a6a1f1dSLionel Sambuc fi 12084d9c625SLionel Sambuc done 12184d9c625SLionel Sambuc IFS=$save_IFS 12284d9c625SLionel Sambuc 12384d9c625SLionel Sambuc if test "$found" != yes; then 12484d9c625SLionel Sambuc lib=$lib.lib 12584d9c625SLionel Sambuc fi 12684d9c625SLionel Sambuc} 12784d9c625SLionel Sambuc 12884d9c625SLionel Sambuc# func_cl_wrapper cl arg... 12984d9c625SLionel Sambuc# Adjust compile command to suit cl 13084d9c625SLionel Sambucfunc_cl_wrapper () 13184d9c625SLionel Sambuc{ 13284d9c625SLionel Sambuc # Assume a capable shell 13384d9c625SLionel Sambuc lib_path= 13484d9c625SLionel Sambuc shared=: 13584d9c625SLionel Sambuc linker_opts= 13684d9c625SLionel Sambuc for arg 13784d9c625SLionel Sambuc do 13884d9c625SLionel Sambuc if test -n "$eat"; then 13984d9c625SLionel Sambuc eat= 14084d9c625SLionel Sambuc else 14184d9c625SLionel Sambuc case $1 in 14284d9c625SLionel Sambuc -o) 14384d9c625SLionel Sambuc # configure might choose to run compile as 'compile cc -o foo foo.c'. 14484d9c625SLionel Sambuc eat=1 14584d9c625SLionel Sambuc case $2 in 14684d9c625SLionel Sambuc *.o | *.[oO][bB][jJ]) 14784d9c625SLionel Sambuc func_file_conv "$2" 14884d9c625SLionel Sambuc set x "$@" -Fo"$file" 14984d9c625SLionel Sambuc shift 15084d9c625SLionel Sambuc ;; 15184d9c625SLionel Sambuc *) 15284d9c625SLionel Sambuc func_file_conv "$2" 15384d9c625SLionel Sambuc set x "$@" -Fe"$file" 15484d9c625SLionel Sambuc shift 15584d9c625SLionel Sambuc ;; 15684d9c625SLionel Sambuc esac 15784d9c625SLionel Sambuc ;; 15884d9c625SLionel Sambuc -I) 15984d9c625SLionel Sambuc eat=1 16084d9c625SLionel Sambuc func_file_conv "$2" mingw 16184d9c625SLionel Sambuc set x "$@" -I"$file" 16284d9c625SLionel Sambuc shift 16384d9c625SLionel Sambuc ;; 16484d9c625SLionel Sambuc -I*) 16584d9c625SLionel Sambuc func_file_conv "${1#-I}" mingw 16684d9c625SLionel Sambuc set x "$@" -I"$file" 16784d9c625SLionel Sambuc shift 16884d9c625SLionel Sambuc ;; 16984d9c625SLionel Sambuc -l) 17084d9c625SLionel Sambuc eat=1 17184d9c625SLionel Sambuc func_cl_dashl "$2" 17284d9c625SLionel Sambuc set x "$@" "$lib" 17384d9c625SLionel Sambuc shift 17484d9c625SLionel Sambuc ;; 17584d9c625SLionel Sambuc -l*) 17684d9c625SLionel Sambuc func_cl_dashl "${1#-l}" 17784d9c625SLionel Sambuc set x "$@" "$lib" 17884d9c625SLionel Sambuc shift 17984d9c625SLionel Sambuc ;; 18084d9c625SLionel Sambuc -L) 18184d9c625SLionel Sambuc eat=1 18284d9c625SLionel Sambuc func_cl_dashL "$2" 18384d9c625SLionel Sambuc ;; 18484d9c625SLionel Sambuc -L*) 18584d9c625SLionel Sambuc func_cl_dashL "${1#-L}" 18684d9c625SLionel Sambuc ;; 18784d9c625SLionel Sambuc -static) 18884d9c625SLionel Sambuc shared=false 18984d9c625SLionel Sambuc ;; 19084d9c625SLionel Sambuc -Wl,*) 19184d9c625SLionel Sambuc arg=${1#-Wl,} 19284d9c625SLionel Sambuc save_ifs="$IFS"; IFS=',' 19384d9c625SLionel Sambuc for flag in $arg; do 19484d9c625SLionel Sambuc IFS="$save_ifs" 19584d9c625SLionel Sambuc linker_opts="$linker_opts $flag" 19684d9c625SLionel Sambuc done 19784d9c625SLionel Sambuc IFS="$save_ifs" 19884d9c625SLionel Sambuc ;; 19984d9c625SLionel Sambuc -Xlinker) 20084d9c625SLionel Sambuc eat=1 20184d9c625SLionel Sambuc linker_opts="$linker_opts $2" 20284d9c625SLionel Sambuc ;; 20384d9c625SLionel Sambuc -*) 20484d9c625SLionel Sambuc set x "$@" "$1" 20584d9c625SLionel Sambuc shift 20684d9c625SLionel Sambuc ;; 20784d9c625SLionel Sambuc *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 20884d9c625SLionel Sambuc func_file_conv "$1" 20984d9c625SLionel Sambuc set x "$@" -Tp"$file" 21084d9c625SLionel Sambuc shift 21184d9c625SLionel Sambuc ;; 21284d9c625SLionel Sambuc *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 21384d9c625SLionel Sambuc func_file_conv "$1" mingw 21484d9c625SLionel Sambuc set x "$@" "$file" 21584d9c625SLionel Sambuc shift 21684d9c625SLionel Sambuc ;; 21784d9c625SLionel Sambuc *) 21884d9c625SLionel Sambuc set x "$@" "$1" 21984d9c625SLionel Sambuc shift 22084d9c625SLionel Sambuc ;; 22184d9c625SLionel Sambuc esac 22284d9c625SLionel Sambuc fi 22384d9c625SLionel Sambuc shift 22484d9c625SLionel Sambuc done 22584d9c625SLionel Sambuc if test -n "$linker_opts"; then 22684d9c625SLionel Sambuc linker_opts="-link$linker_opts" 22784d9c625SLionel Sambuc fi 22884d9c625SLionel Sambuc exec "$@" $linker_opts 22984d9c625SLionel Sambuc exit 1 23084d9c625SLionel Sambuc} 23184d9c625SLionel Sambuc 23284d9c625SLionel Sambuceat= 23384d9c625SLionel Sambuc 234ef01931fSBen Grascase $1 in 235ef01931fSBen Gras '') 23684d9c625SLionel Sambuc echo "$0: No command. Try '$0 --help' for more information." 1>&2 237ef01931fSBen Gras exit 1; 238ef01931fSBen Gras ;; 239ef01931fSBen Gras -h | --h*) 240ef01931fSBen Gras cat <<\EOF 241ef01931fSBen GrasUsage: compile [--help] [--version] PROGRAM [ARGS] 242ef01931fSBen Gras 24384d9c625SLionel SambucWrapper for compilers which do not understand '-c -o'. 24484d9c625SLionel SambucRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 245ef01931fSBen Grasarguments, and rename the output as expected. 246ef01931fSBen Gras 247ef01931fSBen GrasIf you are trying to build a whole package this is not the 24884d9c625SLionel Sambucright script to run: please start by reading the file 'INSTALL'. 249ef01931fSBen Gras 250ef01931fSBen GrasReport bugs to <bug-automake@gnu.org>. 251ef01931fSBen GrasEOF 252ef01931fSBen Gras exit $? 253ef01931fSBen Gras ;; 254ef01931fSBen Gras -v | --v*) 255ef01931fSBen Gras echo "compile $scriptversion" 256ef01931fSBen Gras exit $? 257ef01931fSBen Gras ;; 25884d9c625SLionel Sambuc cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 25984d9c625SLionel Sambuc func_cl_wrapper "$@" # Doesn't return... 26084d9c625SLionel Sambuc ;; 261ef01931fSBen Grasesac 262ef01931fSBen Gras 263ef01931fSBen Grasofile= 264ef01931fSBen Grascfile= 265ef01931fSBen Gras 266ef01931fSBen Grasfor arg 267ef01931fSBen Grasdo 268ef01931fSBen Gras if test -n "$eat"; then 269ef01931fSBen Gras eat= 270ef01931fSBen Gras else 271ef01931fSBen Gras case $1 in 272ef01931fSBen Gras -o) 27384d9c625SLionel Sambuc # configure might choose to run compile as 'compile cc -o foo foo.c'. 27484d9c625SLionel Sambuc # So we strip '-o arg' only if arg is an object. 275ef01931fSBen Gras eat=1 276ef01931fSBen Gras case $2 in 277ef01931fSBen Gras *.o | *.obj) 278ef01931fSBen Gras ofile=$2 279ef01931fSBen Gras ;; 280ef01931fSBen Gras *) 281ef01931fSBen Gras set x "$@" -o "$2" 282ef01931fSBen Gras shift 283ef01931fSBen Gras ;; 284ef01931fSBen Gras esac 285ef01931fSBen Gras ;; 286ef01931fSBen Gras *.c) 287ef01931fSBen Gras cfile=$1 288ef01931fSBen Gras set x "$@" "$1" 289ef01931fSBen Gras shift 290ef01931fSBen Gras ;; 291ef01931fSBen Gras *) 292ef01931fSBen Gras set x "$@" "$1" 293ef01931fSBen Gras shift 294ef01931fSBen Gras ;; 295ef01931fSBen Gras esac 296ef01931fSBen Gras fi 297ef01931fSBen Gras shift 298ef01931fSBen Grasdone 299ef01931fSBen Gras 300ef01931fSBen Grasif test -z "$ofile" || test -z "$cfile"; then 30184d9c625SLionel Sambuc # If no '-o' option was seen then we might have been invoked from a 302ef01931fSBen Gras # pattern rule where we don't need one. That is ok -- this is a 303ef01931fSBen Gras # normal compilation that the losing compiler can handle. If no 30484d9c625SLionel Sambuc # '.c' file was seen then we are probably linking. That is also 305ef01931fSBen Gras # ok. 306ef01931fSBen Gras exec "$@" 307ef01931fSBen Grasfi 308ef01931fSBen Gras 309ef01931fSBen Gras# Name of file we expect compiler to create. 310835f6802SDirk Vogtcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 311ef01931fSBen Gras 312ef01931fSBen Gras# Create the lock directory. 31384d9c625SLionel Sambuc# Note: use '[/\\:.-]' here to ensure that we don't use the same name 314ef01931fSBen Gras# that we are using for the .o file. Also, base the name on the expected 315ef01931fSBen Gras# object file name, since that is what matters with a parallel build. 316835f6802SDirk Vogtlockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 317ef01931fSBen Graswhile true; do 318ef01931fSBen Gras if mkdir "$lockdir" >/dev/null 2>&1; then 319ef01931fSBen Gras break 320ef01931fSBen Gras fi 321ef01931fSBen Gras sleep 1 322ef01931fSBen Grasdone 323ef01931fSBen Gras# FIXME: race condition here if user kills between mkdir and trap. 324ef01931fSBen Grastrap "rmdir '$lockdir'; exit 1" 1 2 15 325ef01931fSBen Gras 326ef01931fSBen Gras# Run the compile. 327ef01931fSBen Gras"$@" 328ef01931fSBen Grasret=$? 329ef01931fSBen Gras 330ef01931fSBen Grasif test -f "$cofile"; then 33184d9c625SLionel Sambuc test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 332ef01931fSBen Graselif test -f "${cofile}bj"; then 33384d9c625SLionel Sambuc test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 334ef01931fSBen Grasfi 335ef01931fSBen Gras 336ef01931fSBen Grasrmdir "$lockdir" 337ef01931fSBen Grasexit $ret 338ef01931fSBen Gras 339ef01931fSBen Gras# Local Variables: 340ef01931fSBen Gras# mode: shell-script 341ef01931fSBen Gras# sh-indentation: 2 342ef01931fSBen Gras# eval: (add-hook 'write-file-hooks 'time-stamp) 343ef01931fSBen Gras# time-stamp-start: "scriptversion=" 344ef01931fSBen Gras# time-stamp-format: "%:y-%02m-%02d.%02H" 345835f6802SDirk Vogt# time-stamp-time-zone: "UTC" 346835f6802SDirk Vogt# time-stamp-end: "; # UTC" 347ef01931fSBen Gras# End: 348