176404edcSAsim Jamshed#! /bin/sh 276404edcSAsim Jamshed# Wrapper for compilers which do not understand '-c -o'. 376404edcSAsim Jamshed 4d270d183SAsim Jamshedscriptversion=2012-10-14.11; # UTC 576404edcSAsim Jamshed 6d270d183SAsim Jamshed# Copyright (C) 1999-2014 Free Software Foundation, Inc. 776404edcSAsim Jamshed# Written by Tom Tromey <[email protected]>. 876404edcSAsim Jamshed# 976404edcSAsim Jamshed# This program is free software; you can redistribute it and/or modify 1076404edcSAsim Jamshed# it under the terms of the GNU General Public License as published by 1176404edcSAsim Jamshed# the Free Software Foundation; either version 2, or (at your option) 1276404edcSAsim Jamshed# any later version. 1376404edcSAsim Jamshed# 1476404edcSAsim Jamshed# This program is distributed in the hope that it will be useful, 1576404edcSAsim Jamshed# but WITHOUT ANY WARRANTY; without even the implied warranty of 1676404edcSAsim Jamshed# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1776404edcSAsim Jamshed# GNU General Public License for more details. 1876404edcSAsim Jamshed# 1976404edcSAsim Jamshed# You should have received a copy of the GNU General Public License 2076404edcSAsim Jamshed# along with this program. If not, see <http://www.gnu.org/licenses/>. 2176404edcSAsim Jamshed 2276404edcSAsim Jamshed# As a special exception to the GNU General Public License, if you 2376404edcSAsim Jamshed# distribute this file as part of a program that contains a 2476404edcSAsim Jamshed# configuration script generated by Autoconf, you may include it under 2576404edcSAsim Jamshed# the same distribution terms that you use for the rest of that program. 2676404edcSAsim Jamshed 2776404edcSAsim Jamshed# This file is maintained in Automake, please report 2876404edcSAsim Jamshed# bugs to <[email protected]> or send patches to 2976404edcSAsim Jamshed# <[email protected]>. 3076404edcSAsim Jamshed 3176404edcSAsim Jamshednl=' 3276404edcSAsim Jamshed' 3376404edcSAsim Jamshed 3476404edcSAsim Jamshed# We need space, tab and new line, in precisely that order. Quoting is 3576404edcSAsim Jamshed# there to prevent tools from complaining about whitespace usage. 3676404edcSAsim JamshedIFS=" "" $nl" 3776404edcSAsim Jamshed 3876404edcSAsim Jamshedfile_conv= 3976404edcSAsim Jamshed 4076404edcSAsim Jamshed# func_file_conv build_file lazy 4176404edcSAsim Jamshed# Convert a $build file to $host form and store it in $file 4276404edcSAsim Jamshed# Currently only supports Windows hosts. If the determined conversion 4376404edcSAsim Jamshed# type is listed in (the comma separated) LAZY, no conversion will 4476404edcSAsim Jamshed# take place. 4576404edcSAsim Jamshedfunc_file_conv () 4676404edcSAsim Jamshed{ 4776404edcSAsim Jamshed file=$1 4876404edcSAsim Jamshed case $file in 4976404edcSAsim Jamshed / | /[!/]*) # absolute file, and not a UNC file 5076404edcSAsim Jamshed if test -z "$file_conv"; then 5176404edcSAsim Jamshed # lazily determine how to convert abs files 5276404edcSAsim Jamshed case `uname -s` in 5376404edcSAsim Jamshed MINGW*) 5476404edcSAsim Jamshed file_conv=mingw 5576404edcSAsim Jamshed ;; 5676404edcSAsim Jamshed CYGWIN*) 5776404edcSAsim Jamshed file_conv=cygwin 5876404edcSAsim Jamshed ;; 5976404edcSAsim Jamshed *) 6076404edcSAsim Jamshed file_conv=wine 6176404edcSAsim Jamshed ;; 6276404edcSAsim Jamshed esac 6376404edcSAsim Jamshed fi 6476404edcSAsim Jamshed case $file_conv/,$2, in 6576404edcSAsim Jamshed *,$file_conv,*) 6676404edcSAsim Jamshed ;; 6776404edcSAsim Jamshed mingw/*) 6876404edcSAsim Jamshed file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 6976404edcSAsim Jamshed ;; 7076404edcSAsim Jamshed cygwin/*) 7176404edcSAsim Jamshed file=`cygpath -m "$file" || echo "$file"` 7276404edcSAsim Jamshed ;; 7376404edcSAsim Jamshed wine/*) 7476404edcSAsim Jamshed file=`winepath -w "$file" || echo "$file"` 7576404edcSAsim Jamshed ;; 7676404edcSAsim Jamshed esac 7776404edcSAsim Jamshed ;; 7876404edcSAsim Jamshed esac 7976404edcSAsim Jamshed} 8076404edcSAsim Jamshed 8176404edcSAsim Jamshed# func_cl_dashL linkdir 8276404edcSAsim Jamshed# Make cl look for libraries in LINKDIR 8376404edcSAsim Jamshedfunc_cl_dashL () 8476404edcSAsim Jamshed{ 8576404edcSAsim Jamshed func_file_conv "$1" 8676404edcSAsim Jamshed if test -z "$lib_path"; then 8776404edcSAsim Jamshed lib_path=$file 8876404edcSAsim Jamshed else 8976404edcSAsim Jamshed lib_path="$lib_path;$file" 9076404edcSAsim Jamshed fi 9176404edcSAsim Jamshed linker_opts="$linker_opts -LIBPATH:$file" 9276404edcSAsim Jamshed} 9376404edcSAsim Jamshed 9476404edcSAsim Jamshed# func_cl_dashl library 9576404edcSAsim Jamshed# Do a library search-path lookup for cl 9676404edcSAsim Jamshedfunc_cl_dashl () 9776404edcSAsim Jamshed{ 9876404edcSAsim Jamshed lib=$1 9976404edcSAsim Jamshed found=no 10076404edcSAsim Jamshed save_IFS=$IFS 10176404edcSAsim Jamshed IFS=';' 10276404edcSAsim Jamshed for dir in $lib_path $LIB 10376404edcSAsim Jamshed do 10476404edcSAsim Jamshed IFS=$save_IFS 10576404edcSAsim Jamshed if $shared && test -f "$dir/$lib.dll.lib"; then 10676404edcSAsim Jamshed found=yes 10776404edcSAsim Jamshed lib=$dir/$lib.dll.lib 10876404edcSAsim Jamshed break 10976404edcSAsim Jamshed fi 11076404edcSAsim Jamshed if test -f "$dir/$lib.lib"; then 11176404edcSAsim Jamshed found=yes 11276404edcSAsim Jamshed lib=$dir/$lib.lib 11376404edcSAsim Jamshed break 11476404edcSAsim Jamshed fi 115d270d183SAsim Jamshed if test -f "$dir/lib$lib.a"; then 116d270d183SAsim Jamshed found=yes 117d270d183SAsim Jamshed lib=$dir/lib$lib.a 118d270d183SAsim Jamshed break 119d270d183SAsim Jamshed fi 12076404edcSAsim Jamshed done 12176404edcSAsim Jamshed IFS=$save_IFS 12276404edcSAsim Jamshed 12376404edcSAsim Jamshed if test "$found" != yes; then 12476404edcSAsim Jamshed lib=$lib.lib 12576404edcSAsim Jamshed fi 12676404edcSAsim Jamshed} 12776404edcSAsim Jamshed 12876404edcSAsim Jamshed# func_cl_wrapper cl arg... 12976404edcSAsim Jamshed# Adjust compile command to suit cl 13076404edcSAsim Jamshedfunc_cl_wrapper () 13176404edcSAsim Jamshed{ 13276404edcSAsim Jamshed # Assume a capable shell 13376404edcSAsim Jamshed lib_path= 13476404edcSAsim Jamshed shared=: 13576404edcSAsim Jamshed linker_opts= 13676404edcSAsim Jamshed for arg 13776404edcSAsim Jamshed do 13876404edcSAsim Jamshed if test -n "$eat"; then 13976404edcSAsim Jamshed eat= 14076404edcSAsim Jamshed else 14176404edcSAsim Jamshed case $1 in 14276404edcSAsim Jamshed -o) 14376404edcSAsim Jamshed # configure might choose to run compile as 'compile cc -o foo foo.c'. 14476404edcSAsim Jamshed eat=1 14576404edcSAsim Jamshed case $2 in 14676404edcSAsim Jamshed *.o | *.[oO][bB][jJ]) 14776404edcSAsim Jamshed func_file_conv "$2" 14876404edcSAsim Jamshed set x "$@" -Fo"$file" 14976404edcSAsim Jamshed shift 15076404edcSAsim Jamshed ;; 15176404edcSAsim Jamshed *) 15276404edcSAsim Jamshed func_file_conv "$2" 15376404edcSAsim Jamshed set x "$@" -Fe"$file" 15476404edcSAsim Jamshed shift 15576404edcSAsim Jamshed ;; 15676404edcSAsim Jamshed esac 15776404edcSAsim Jamshed ;; 15876404edcSAsim Jamshed -I) 15976404edcSAsim Jamshed eat=1 16076404edcSAsim Jamshed func_file_conv "$2" mingw 16176404edcSAsim Jamshed set x "$@" -I"$file" 16276404edcSAsim Jamshed shift 16376404edcSAsim Jamshed ;; 16476404edcSAsim Jamshed -I*) 16576404edcSAsim Jamshed func_file_conv "${1#-I}" mingw 16676404edcSAsim Jamshed set x "$@" -I"$file" 16776404edcSAsim Jamshed shift 16876404edcSAsim Jamshed ;; 16976404edcSAsim Jamshed -l) 17076404edcSAsim Jamshed eat=1 17176404edcSAsim Jamshed func_cl_dashl "$2" 17276404edcSAsim Jamshed set x "$@" "$lib" 17376404edcSAsim Jamshed shift 17476404edcSAsim Jamshed ;; 17576404edcSAsim Jamshed -l*) 17676404edcSAsim Jamshed func_cl_dashl "${1#-l}" 17776404edcSAsim Jamshed set x "$@" "$lib" 17876404edcSAsim Jamshed shift 17976404edcSAsim Jamshed ;; 18076404edcSAsim Jamshed -L) 18176404edcSAsim Jamshed eat=1 18276404edcSAsim Jamshed func_cl_dashL "$2" 18376404edcSAsim Jamshed ;; 18476404edcSAsim Jamshed -L*) 18576404edcSAsim Jamshed func_cl_dashL "${1#-L}" 18676404edcSAsim Jamshed ;; 18776404edcSAsim Jamshed -static) 18876404edcSAsim Jamshed shared=false 18976404edcSAsim Jamshed ;; 19076404edcSAsim Jamshed -Wl,*) 19176404edcSAsim Jamshed arg=${1#-Wl,} 19276404edcSAsim Jamshed save_ifs="$IFS"; IFS=',' 19376404edcSAsim Jamshed for flag in $arg; do 19476404edcSAsim Jamshed IFS="$save_ifs" 19576404edcSAsim Jamshed linker_opts="$linker_opts $flag" 19676404edcSAsim Jamshed done 19776404edcSAsim Jamshed IFS="$save_ifs" 19876404edcSAsim Jamshed ;; 19976404edcSAsim Jamshed -Xlinker) 20076404edcSAsim Jamshed eat=1 20176404edcSAsim Jamshed linker_opts="$linker_opts $2" 20276404edcSAsim Jamshed ;; 20376404edcSAsim Jamshed -*) 20476404edcSAsim Jamshed set x "$@" "$1" 20576404edcSAsim Jamshed shift 20676404edcSAsim Jamshed ;; 20776404edcSAsim Jamshed *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 20876404edcSAsim Jamshed func_file_conv "$1" 20976404edcSAsim Jamshed set x "$@" -Tp"$file" 21076404edcSAsim Jamshed shift 21176404edcSAsim Jamshed ;; 21276404edcSAsim Jamshed *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 21376404edcSAsim Jamshed func_file_conv "$1" mingw 21476404edcSAsim Jamshed set x "$@" "$file" 21576404edcSAsim Jamshed shift 21676404edcSAsim Jamshed ;; 21776404edcSAsim Jamshed *) 21876404edcSAsim Jamshed set x "$@" "$1" 21976404edcSAsim Jamshed shift 22076404edcSAsim Jamshed ;; 22176404edcSAsim Jamshed esac 22276404edcSAsim Jamshed fi 22376404edcSAsim Jamshed shift 22476404edcSAsim Jamshed done 22576404edcSAsim Jamshed if test -n "$linker_opts"; then 22676404edcSAsim Jamshed linker_opts="-link$linker_opts" 22776404edcSAsim Jamshed fi 22876404edcSAsim Jamshed exec "$@" $linker_opts 22976404edcSAsim Jamshed exit 1 23076404edcSAsim Jamshed} 23176404edcSAsim Jamshed 23276404edcSAsim Jamshedeat= 23376404edcSAsim Jamshed 23476404edcSAsim Jamshedcase $1 in 23576404edcSAsim Jamshed '') 23676404edcSAsim Jamshed echo "$0: No command. Try '$0 --help' for more information." 1>&2 23776404edcSAsim Jamshed exit 1; 23876404edcSAsim Jamshed ;; 23976404edcSAsim Jamshed -h | --h*) 24076404edcSAsim Jamshed cat <<\EOF 24176404edcSAsim JamshedUsage: compile [--help] [--version] PROGRAM [ARGS] 24276404edcSAsim Jamshed 24376404edcSAsim JamshedWrapper for compilers which do not understand '-c -o'. 24476404edcSAsim JamshedRemove '-o dest.o' from ARGS, run PROGRAM with the remaining 24576404edcSAsim Jamshedarguments, and rename the output as expected. 24676404edcSAsim Jamshed 24776404edcSAsim JamshedIf you are trying to build a whole package this is not the 24876404edcSAsim Jamshedright script to run: please start by reading the file 'INSTALL'. 24976404edcSAsim Jamshed 25076404edcSAsim JamshedReport bugs to <bug-automake@gnu.org>. 25176404edcSAsim JamshedEOF 25276404edcSAsim Jamshed exit $? 25376404edcSAsim Jamshed ;; 25476404edcSAsim Jamshed -v | --v*) 25576404edcSAsim Jamshed echo "compile $scriptversion" 25676404edcSAsim Jamshed exit $? 25776404edcSAsim Jamshed ;; 25876404edcSAsim Jamshed cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 25976404edcSAsim Jamshed func_cl_wrapper "$@" # Doesn't return... 26076404edcSAsim Jamshed ;; 26176404edcSAsim Jamshedesac 26276404edcSAsim Jamshed 26376404edcSAsim Jamshedofile= 26476404edcSAsim Jamshedcfile= 26576404edcSAsim Jamshed 26676404edcSAsim Jamshedfor arg 26776404edcSAsim Jamsheddo 26876404edcSAsim Jamshed if test -n "$eat"; then 26976404edcSAsim Jamshed eat= 27076404edcSAsim Jamshed else 27176404edcSAsim Jamshed case $1 in 27276404edcSAsim Jamshed -o) 27376404edcSAsim Jamshed # configure might choose to run compile as 'compile cc -o foo foo.c'. 27476404edcSAsim Jamshed # So we strip '-o arg' only if arg is an object. 27576404edcSAsim Jamshed eat=1 27676404edcSAsim Jamshed case $2 in 27776404edcSAsim Jamshed *.o | *.obj) 27876404edcSAsim Jamshed ofile=$2 27976404edcSAsim Jamshed ;; 28076404edcSAsim Jamshed *) 28176404edcSAsim Jamshed set x "$@" -o "$2" 28276404edcSAsim Jamshed shift 28376404edcSAsim Jamshed ;; 28476404edcSAsim Jamshed esac 28576404edcSAsim Jamshed ;; 28676404edcSAsim Jamshed *.c) 28776404edcSAsim Jamshed cfile=$1 28876404edcSAsim Jamshed set x "$@" "$1" 28976404edcSAsim Jamshed shift 29076404edcSAsim Jamshed ;; 29176404edcSAsim Jamshed *) 29276404edcSAsim Jamshed set x "$@" "$1" 29376404edcSAsim Jamshed shift 29476404edcSAsim Jamshed ;; 29576404edcSAsim Jamshed esac 29676404edcSAsim Jamshed fi 29776404edcSAsim Jamshed shift 29876404edcSAsim Jamsheddone 29976404edcSAsim Jamshed 30076404edcSAsim Jamshedif test -z "$ofile" || test -z "$cfile"; then 30176404edcSAsim Jamshed # If no '-o' option was seen then we might have been invoked from a 30276404edcSAsim Jamshed # pattern rule where we don't need one. That is ok -- this is a 30376404edcSAsim Jamshed # normal compilation that the losing compiler can handle. If no 30476404edcSAsim Jamshed # '.c' file was seen then we are probably linking. That is also 30576404edcSAsim Jamshed # ok. 30676404edcSAsim Jamshed exec "$@" 30776404edcSAsim Jamshedfi 30876404edcSAsim Jamshed 30976404edcSAsim Jamshed# Name of file we expect compiler to create. 31076404edcSAsim Jamshedcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 31176404edcSAsim Jamshed 31276404edcSAsim Jamshed# Create the lock directory. 31376404edcSAsim Jamshed# Note: use '[/\\:.-]' here to ensure that we don't use the same name 31476404edcSAsim Jamshed# that we are using for the .o file. Also, base the name on the expected 31576404edcSAsim Jamshed# object file name, since that is what matters with a parallel build. 31676404edcSAsim Jamshedlockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 31776404edcSAsim Jamshedwhile true; do 31876404edcSAsim Jamshed if mkdir "$lockdir" >/dev/null 2>&1; then 31976404edcSAsim Jamshed break 32076404edcSAsim Jamshed fi 32176404edcSAsim Jamshed sleep 1 32276404edcSAsim Jamsheddone 32376404edcSAsim Jamshed# FIXME: race condition here if user kills between mkdir and trap. 32476404edcSAsim Jamshedtrap "rmdir '$lockdir'; exit 1" 1 2 15 32576404edcSAsim Jamshed 32676404edcSAsim Jamshed# Run the compile. 32776404edcSAsim Jamshed"$@" 32876404edcSAsim Jamshedret=$? 32976404edcSAsim Jamshed 33076404edcSAsim Jamshedif test -f "$cofile"; then 33176404edcSAsim Jamshed test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 33276404edcSAsim Jamshedelif test -f "${cofile}bj"; then 33376404edcSAsim Jamshed test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 33476404edcSAsim Jamshedfi 33576404edcSAsim Jamshed 33676404edcSAsim Jamshedrmdir "$lockdir" 33776404edcSAsim Jamshedexit $ret 33876404edcSAsim Jamshed 33976404edcSAsim Jamshed# Local Variables: 34076404edcSAsim Jamshed# mode: shell-script 34176404edcSAsim Jamshed# sh-indentation: 2 34276404edcSAsim Jamshed# eval: (add-hook 'write-file-hooks 'time-stamp) 34376404edcSAsim Jamshed# time-stamp-start: "scriptversion=" 34476404edcSAsim Jamshed# time-stamp-format: "%:y-%02m-%02d.%02H" 34576404edcSAsim Jamshed# time-stamp-time-zone: "UTC" 34676404edcSAsim Jamshed# time-stamp-end: "; # UTC" 34776404edcSAsim Jamshed# End: 348