compile revision 9511053f
1a850946eSmrg#! /bin/sh
29511053fSmrg# Wrapper for compilers which do not understand '-c -o'.
3a850946eSmrg
49511053fSmrgscriptversion=2012-10-14.11; # UTC
5a850946eSmrg
69511053fSmrg# Copyright (C) 1999-2013 Free Software Foundation, Inc.
7a850946eSmrg# Written by Tom Tromey <tromey@cygnus.com>.
8a850946eSmrg#
9a850946eSmrg# This program is free software; you can redistribute it and/or modify
10a850946eSmrg# it under the terms of the GNU General Public License as published by
11a850946eSmrg# the Free Software Foundation; either version 2, or (at your option)
12a850946eSmrg# any later version.
13a850946eSmrg#
14a850946eSmrg# This program is distributed in the hope that it will be useful,
15a850946eSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16a850946eSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17a850946eSmrg# GNU General Public License for more details.
18a850946eSmrg#
19a850946eSmrg# You should have received a copy of the GNU General Public License
209511053fSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21a850946eSmrg
22a850946eSmrg# As a special exception to the GNU General Public License, if you
23a850946eSmrg# distribute this file as part of a program that contains a
24a850946eSmrg# configuration script generated by Autoconf, you may include it under
25a850946eSmrg# the same distribution terms that you use for the rest of that program.
26a850946eSmrg
279511053fSmrg# This file is maintained in Automake, please report
289511053fSmrg# bugs to <bug-automake@gnu.org> or send patches to
299511053fSmrg# <automake-patches@gnu.org>.
30a850946eSmrg
319511053fSmrgnl='
329511053fSmrg'
339511053fSmrg
349511053fSmrg# We need space, tab and new line, in precisely that order.  Quoting is
359511053fSmrg# there to prevent tools from complaining about whitespace usage.
369511053fSmrgIFS=" ""	$nl"
379511053fSmrg
389511053fSmrgfile_conv=
399511053fSmrg
409511053fSmrg# func_file_conv build_file lazy
419511053fSmrg# Convert a $build file to $host form and store it in $file
429511053fSmrg# Currently only supports Windows hosts. If the determined conversion
439511053fSmrg# type is listed in (the comma separated) LAZY, no conversion will
449511053fSmrg# take place.
459511053fSmrgfunc_file_conv ()
469511053fSmrg{
479511053fSmrg  file=$1
489511053fSmrg  case $file in
499511053fSmrg    / | /[!/]*) # absolute file, and not a UNC file
509511053fSmrg      if test -z "$file_conv"; then
519511053fSmrg	# lazily determine how to convert abs files
529511053fSmrg	case `uname -s` in
539511053fSmrg	  MINGW*)
549511053fSmrg	    file_conv=mingw
559511053fSmrg	    ;;
569511053fSmrg	  CYGWIN*)
579511053fSmrg	    file_conv=cygwin
589511053fSmrg	    ;;
599511053fSmrg	  *)
609511053fSmrg	    file_conv=wine
619511053fSmrg	    ;;
629511053fSmrg	esac
639511053fSmrg      fi
649511053fSmrg      case $file_conv/,$2, in
659511053fSmrg	*,$file_conv,*)
669511053fSmrg	  ;;
679511053fSmrg	mingw/*)
689511053fSmrg	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
699511053fSmrg	  ;;
709511053fSmrg	cygwin/*)
719511053fSmrg	  file=`cygpath -m "$file" || echo "$file"`
729511053fSmrg	  ;;
739511053fSmrg	wine/*)
749511053fSmrg	  file=`winepath -w "$file" || echo "$file"`
759511053fSmrg	  ;;
769511053fSmrg      esac
779511053fSmrg      ;;
789511053fSmrg  esac
799511053fSmrg}
809511053fSmrg
819511053fSmrg# func_cl_dashL linkdir
829511053fSmrg# Make cl look for libraries in LINKDIR
839511053fSmrgfunc_cl_dashL ()
849511053fSmrg{
859511053fSmrg  func_file_conv "$1"
869511053fSmrg  if test -z "$lib_path"; then
879511053fSmrg    lib_path=$file
889511053fSmrg  else
899511053fSmrg    lib_path="$lib_path;$file"
909511053fSmrg  fi
919511053fSmrg  linker_opts="$linker_opts -LIBPATH:$file"
929511053fSmrg}
939511053fSmrg
949511053fSmrg# func_cl_dashl library
959511053fSmrg# Do a library search-path lookup for cl
969511053fSmrgfunc_cl_dashl ()
979511053fSmrg{
989511053fSmrg  lib=$1
999511053fSmrg  found=no
1009511053fSmrg  save_IFS=$IFS
1019511053fSmrg  IFS=';'
1029511053fSmrg  for dir in $lib_path $LIB
1039511053fSmrg  do
1049511053fSmrg    IFS=$save_IFS
1059511053fSmrg    if $shared && test -f "$dir/$lib.dll.lib"; then
1069511053fSmrg      found=yes
1079511053fSmrg      lib=$dir/$lib.dll.lib
1089511053fSmrg      break
1099511053fSmrg    fi
1109511053fSmrg    if test -f "$dir/$lib.lib"; then
1119511053fSmrg      found=yes
1129511053fSmrg      lib=$dir/$lib.lib
1139511053fSmrg      break
1149511053fSmrg    fi
1159511053fSmrg    if test -f "$dir/lib$lib.a"; then
1169511053fSmrg      found=yes
1179511053fSmrg      lib=$dir/lib$lib.a
1189511053fSmrg      break
1199511053fSmrg    fi
1209511053fSmrg  done
1219511053fSmrg  IFS=$save_IFS
1229511053fSmrg
1239511053fSmrg  if test "$found" != yes; then
1249511053fSmrg    lib=$lib.lib
1259511053fSmrg  fi
1269511053fSmrg}
1279511053fSmrg
1289511053fSmrg# func_cl_wrapper cl arg...
1299511053fSmrg# Adjust compile command to suit cl
1309511053fSmrgfunc_cl_wrapper ()
1319511053fSmrg{
1329511053fSmrg  # Assume a capable shell
1339511053fSmrg  lib_path=
1349511053fSmrg  shared=:
1359511053fSmrg  linker_opts=
1369511053fSmrg  for arg
1379511053fSmrg  do
1389511053fSmrg    if test -n "$eat"; then
1399511053fSmrg      eat=
1409511053fSmrg    else
1419511053fSmrg      case $1 in
1429511053fSmrg	-o)
1439511053fSmrg	  # configure might choose to run compile as 'compile cc -o foo foo.c'.
1449511053fSmrg	  eat=1
1459511053fSmrg	  case $2 in
1469511053fSmrg	    *.o | *.[oO][bB][jJ])
1479511053fSmrg	      func_file_conv "$2"
1489511053fSmrg	      set x "$@" -Fo"$file"
1499511053fSmrg	      shift
1509511053fSmrg	      ;;
1519511053fSmrg	    *)
1529511053fSmrg	      func_file_conv "$2"
1539511053fSmrg	      set x "$@" -Fe"$file"
1549511053fSmrg	      shift
1559511053fSmrg	      ;;
1569511053fSmrg	  esac
1579511053fSmrg	  ;;
1589511053fSmrg	-I)
1599511053fSmrg	  eat=1
1609511053fSmrg	  func_file_conv "$2" mingw
1619511053fSmrg	  set x "$@" -I"$file"
1629511053fSmrg	  shift
1639511053fSmrg	  ;;
1649511053fSmrg	-I*)
1659511053fSmrg	  func_file_conv "${1#-I}" mingw
1669511053fSmrg	  set x "$@" -I"$file"
1679511053fSmrg	  shift
1689511053fSmrg	  ;;
1699511053fSmrg	-l)
1709511053fSmrg	  eat=1
1719511053fSmrg	  func_cl_dashl "$2"
1729511053fSmrg	  set x "$@" "$lib"
1739511053fSmrg	  shift
1749511053fSmrg	  ;;
1759511053fSmrg	-l*)
1769511053fSmrg	  func_cl_dashl "${1#-l}"
1779511053fSmrg	  set x "$@" "$lib"
1789511053fSmrg	  shift
1799511053fSmrg	  ;;
1809511053fSmrg	-L)
1819511053fSmrg	  eat=1
1829511053fSmrg	  func_cl_dashL "$2"
1839511053fSmrg	  ;;
1849511053fSmrg	-L*)
1859511053fSmrg	  func_cl_dashL "${1#-L}"
1869511053fSmrg	  ;;
1879511053fSmrg	-static)
1889511053fSmrg	  shared=false
1899511053fSmrg	  ;;
1909511053fSmrg	-Wl,*)
1919511053fSmrg	  arg=${1#-Wl,}
1929511053fSmrg	  save_ifs="$IFS"; IFS=','
1939511053fSmrg	  for flag in $arg; do
1949511053fSmrg	    IFS="$save_ifs"
1959511053fSmrg	    linker_opts="$linker_opts $flag"
1969511053fSmrg	  done
1979511053fSmrg	  IFS="$save_ifs"
1989511053fSmrg	  ;;
1999511053fSmrg	-Xlinker)
2009511053fSmrg	  eat=1
2019511053fSmrg	  linker_opts="$linker_opts $2"
2029511053fSmrg	  ;;
2039511053fSmrg	-*)
2049511053fSmrg	  set x "$@" "$1"
2059511053fSmrg	  shift
2069511053fSmrg	  ;;
2079511053fSmrg	*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
2089511053fSmrg	  func_file_conv "$1"
2099511053fSmrg	  set x "$@" -Tp"$file"
2109511053fSmrg	  shift
2119511053fSmrg	  ;;
2129511053fSmrg	*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
2139511053fSmrg	  func_file_conv "$1" mingw
2149511053fSmrg	  set x "$@" "$file"
2159511053fSmrg	  shift
2169511053fSmrg	  ;;
2179511053fSmrg	*)
2189511053fSmrg	  set x "$@" "$1"
2199511053fSmrg	  shift
2209511053fSmrg	  ;;
2219511053fSmrg      esac
2229511053fSmrg    fi
2239511053fSmrg    shift
2249511053fSmrg  done
2259511053fSmrg  if test -n "$linker_opts"; then
2269511053fSmrg    linker_opts="-link$linker_opts"
2279511053fSmrg  fi
2289511053fSmrg  exec "$@" $linker_opts
2299511053fSmrg  exit 1
2309511053fSmrg}
2319511053fSmrg
2329511053fSmrgeat=
2339511053fSmrg
2349511053fSmrgcase $1 in
2359511053fSmrg  '')
2369511053fSmrg     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
2379511053fSmrg     exit 1;
2389511053fSmrg     ;;
2399511053fSmrg  -h | --h*)
2409511053fSmrg    cat <<\EOF
2419511053fSmrgUsage: compile [--help] [--version] PROGRAM [ARGS]
2429511053fSmrg
2439511053fSmrgWrapper for compilers which do not understand '-c -o'.
2449511053fSmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining
2459511053fSmrgarguments, and rename the output as expected.
2469511053fSmrg
2479511053fSmrgIf you are trying to build a whole package this is not the
2489511053fSmrgright script to run: please start by reading the file 'INSTALL'.
2499511053fSmrg
2509511053fSmrgReport bugs to <bug-automake@gnu.org>.
2519511053fSmrgEOF
2529511053fSmrg    exit $?
2539511053fSmrg    ;;
2549511053fSmrg  -v | --v*)
2559511053fSmrg    echo "compile $scriptversion"
2569511053fSmrg    exit $?
2579511053fSmrg    ;;
2589511053fSmrg  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
2599511053fSmrg    func_cl_wrapper "$@"      # Doesn't return...
2609511053fSmrg    ;;
2619511053fSmrgesac
262a850946eSmrg
263a850946eSmrgofile=
264a850946eSmrgcfile=
2659511053fSmrg
2669511053fSmrgfor arg
2679511053fSmrgdo
2689511053fSmrg  if test -n "$eat"; then
2699511053fSmrg    eat=
2709511053fSmrg  else
2719511053fSmrg    case $1 in
2729511053fSmrg      -o)
2739511053fSmrg	# configure might choose to run compile as 'compile cc -o foo foo.c'.
2749511053fSmrg	# So we strip '-o arg' only if arg is an object.
2759511053fSmrg	eat=1
2769511053fSmrg	case $2 in
2779511053fSmrg	  *.o | *.obj)
2789511053fSmrg	    ofile=$2
2799511053fSmrg	    ;;
2809511053fSmrg	  *)
2819511053fSmrg	    set x "$@" -o "$2"
2829511053fSmrg	    shift
2839511053fSmrg	    ;;
2849511053fSmrg	esac
2859511053fSmrg	;;
2869511053fSmrg      *.c)
2879511053fSmrg	cfile=$1
2889511053fSmrg	set x "$@" "$1"
2899511053fSmrg	shift
2909511053fSmrg	;;
2919511053fSmrg      *)
2929511053fSmrg	set x "$@" "$1"
2939511053fSmrg	shift
2949511053fSmrg	;;
2959511053fSmrg    esac
2969511053fSmrg  fi
2979511053fSmrg  shift
298a850946eSmrgdone
299a850946eSmrg
300a850946eSmrgif test -z "$ofile" || test -z "$cfile"; then
3019511053fSmrg  # If no '-o' option was seen then we might have been invoked from a
3029511053fSmrg  # pattern rule where we don't need one.  That is ok -- this is a
3039511053fSmrg  # normal compilation that the losing compiler can handle.  If no
3049511053fSmrg  # '.c' file was seen then we are probably linking.  That is also
3059511053fSmrg  # ok.
3069511053fSmrg  exec "$@"
307a850946eSmrgfi
308a850946eSmrg
309a850946eSmrg# Name of file we expect compiler to create.
3109511053fSmrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
311a850946eSmrg
312a850946eSmrg# Create the lock directory.
3139511053fSmrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name
314a850946eSmrg# that we are using for the .o file.  Also, base the name on the expected
315a850946eSmrg# object file name, since that is what matters with a parallel build.
3169511053fSmrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
317a850946eSmrgwhile true; do
3189511053fSmrg  if mkdir "$lockdir" >/dev/null 2>&1; then
3199511053fSmrg    break
3209511053fSmrg  fi
3219511053fSmrg  sleep 1
322a850946eSmrgdone
323a850946eSmrg# FIXME: race condition here if user kills between mkdir and trap.
3249511053fSmrgtrap "rmdir '$lockdir'; exit 1" 1 2 15
325a850946eSmrg
326a850946eSmrg# Run the compile.
3279511053fSmrg"$@"
3289511053fSmrgret=$?
329a850946eSmrg
330a850946eSmrgif test -f "$cofile"; then
3319511053fSmrg  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
3329511053fSmrgelif test -f "${cofile}bj"; then
3339511053fSmrg  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
334a850946eSmrgfi
335a850946eSmrg
3369511053fSmrgrmdir "$lockdir"
3379511053fSmrgexit $ret
3389511053fSmrg
3399511053fSmrg# Local Variables:
3409511053fSmrg# mode: shell-script
3419511053fSmrg# sh-indentation: 2
3429511053fSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
3439511053fSmrg# time-stamp-start: "scriptversion="
3449511053fSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
3459511053fSmrg# time-stamp-time-zone: "UTC"
3469511053fSmrg# time-stamp-end: "; # UTC"
3479511053fSmrg# End:
348