132001f49Smrg#! /bin/sh
232001f49Smrg# Wrapper for compilers which do not understand '-c -o'.
332001f49Smrg
432001f49Smrgscriptversion=2012-10-14.11; # UTC
532001f49Smrg
67ec3b29aSmrg# Copyright (C) 1999-2014 Free Software Foundation, Inc.
732001f49Smrg# Written by Tom Tromey <tromey@cygnus.com>.
832001f49Smrg#
932001f49Smrg# This program is free software; you can redistribute it and/or modify
1032001f49Smrg# it under the terms of the GNU General Public License as published by
1132001f49Smrg# the Free Software Foundation; either version 2, or (at your option)
1232001f49Smrg# any later version.
1332001f49Smrg#
1432001f49Smrg# This program is distributed in the hope that it will be useful,
1532001f49Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1632001f49Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1732001f49Smrg# GNU General Public License for more details.
1832001f49Smrg#
1932001f49Smrg# You should have received a copy of the GNU General Public License
2032001f49Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2132001f49Smrg
2232001f49Smrg# As a special exception to the GNU General Public License, if you
2332001f49Smrg# distribute this file as part of a program that contains a
2432001f49Smrg# configuration script generated by Autoconf, you may include it under
2532001f49Smrg# the same distribution terms that you use for the rest of that program.
2632001f49Smrg
2732001f49Smrg# This file is maintained in Automake, please report
2832001f49Smrg# bugs to <bug-automake@gnu.org> or send patches to
2932001f49Smrg# <automake-patches@gnu.org>.
3032001f49Smrg
3132001f49Smrgnl='
3232001f49Smrg'
3332001f49Smrg
3432001f49Smrg# We need space, tab and new line, in precisely that order.  Quoting is
3532001f49Smrg# there to prevent tools from complaining about whitespace usage.
3632001f49SmrgIFS=" ""	$nl"
3732001f49Smrg
3832001f49Smrgfile_conv=
3932001f49Smrg
4032001f49Smrg# func_file_conv build_file lazy
4132001f49Smrg# Convert a $build file to $host form and store it in $file
4232001f49Smrg# Currently only supports Windows hosts. If the determined conversion
4332001f49Smrg# type is listed in (the comma separated) LAZY, no conversion will
4432001f49Smrg# take place.
4532001f49Smrgfunc_file_conv ()
4632001f49Smrg{
4732001f49Smrg  file=$1
4832001f49Smrg  case $file in
4932001f49Smrg    / | /[!/]*) # absolute file, and not a UNC file
5032001f49Smrg      if test -z "$file_conv"; then
5132001f49Smrg	# lazily determine how to convert abs files
5232001f49Smrg	case `uname -s` in
5332001f49Smrg	  MINGW*)
5432001f49Smrg	    file_conv=mingw
5532001f49Smrg	    ;;
5632001f49Smrg	  CYGWIN*)
5732001f49Smrg	    file_conv=cygwin
5832001f49Smrg	    ;;
5932001f49Smrg	  *)
6032001f49Smrg	    file_conv=wine
6132001f49Smrg	    ;;
6232001f49Smrg	esac
6332001f49Smrg      fi
6432001f49Smrg      case $file_conv/,$2, in
6532001f49Smrg	*,$file_conv,*)
6632001f49Smrg	  ;;
6732001f49Smrg	mingw/*)
6832001f49Smrg	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
6932001f49Smrg	  ;;
7032001f49Smrg	cygwin/*)
7132001f49Smrg	  file=`cygpath -m "$file" || echo "$file"`
7232001f49Smrg	  ;;
7332001f49Smrg	wine/*)
7432001f49Smrg	  file=`winepath -w "$file" || echo "$file"`
7532001f49Smrg	  ;;
7632001f49Smrg      esac
7732001f49Smrg      ;;
7832001f49Smrg  esac
7932001f49Smrg}
8032001f49Smrg
8132001f49Smrg# func_cl_dashL linkdir
8232001f49Smrg# Make cl look for libraries in LINKDIR
8332001f49Smrgfunc_cl_dashL ()
8432001f49Smrg{
8532001f49Smrg  func_file_conv "$1"
8632001f49Smrg  if test -z "$lib_path"; then
8732001f49Smrg    lib_path=$file
8832001f49Smrg  else
8932001f49Smrg    lib_path="$lib_path;$file"
9032001f49Smrg  fi
9132001f49Smrg  linker_opts="$linker_opts -LIBPATH:$file"
9232001f49Smrg}
9332001f49Smrg
9432001f49Smrg# func_cl_dashl library
9532001f49Smrg# Do a library search-path lookup for cl
9632001f49Smrgfunc_cl_dashl ()
9732001f49Smrg{
9832001f49Smrg  lib=$1
9932001f49Smrg  found=no
10032001f49Smrg  save_IFS=$IFS
10132001f49Smrg  IFS=';'
10232001f49Smrg  for dir in $lib_path $LIB
10332001f49Smrg  do
10432001f49Smrg    IFS=$save_IFS
10532001f49Smrg    if $shared && test -f "$dir/$lib.dll.lib"; then
10632001f49Smrg      found=yes
10732001f49Smrg      lib=$dir/$lib.dll.lib
10832001f49Smrg      break
10932001f49Smrg    fi
11032001f49Smrg    if test -f "$dir/$lib.lib"; then
11132001f49Smrg      found=yes
11232001f49Smrg      lib=$dir/$lib.lib
11332001f49Smrg      break
11432001f49Smrg    fi
11532001f49Smrg    if test -f "$dir/lib$lib.a"; then
11632001f49Smrg      found=yes
11732001f49Smrg      lib=$dir/lib$lib.a
11832001f49Smrg      break
11932001f49Smrg    fi
12032001f49Smrg  done
12132001f49Smrg  IFS=$save_IFS
12232001f49Smrg
12332001f49Smrg  if test "$found" != yes; then
12432001f49Smrg    lib=$lib.lib
12532001f49Smrg  fi
12632001f49Smrg}
12732001f49Smrg
12832001f49Smrg# func_cl_wrapper cl arg...
12932001f49Smrg# Adjust compile command to suit cl
13032001f49Smrgfunc_cl_wrapper ()
13132001f49Smrg{
13232001f49Smrg  # Assume a capable shell
13332001f49Smrg  lib_path=
13432001f49Smrg  shared=:
13532001f49Smrg  linker_opts=
13632001f49Smrg  for arg
13732001f49Smrg  do
13832001f49Smrg    if test -n "$eat"; then
13932001f49Smrg      eat=
14032001f49Smrg    else
14132001f49Smrg      case $1 in
14232001f49Smrg	-o)
14332001f49Smrg	  # configure might choose to run compile as 'compile cc -o foo foo.c'.
14432001f49Smrg	  eat=1
14532001f49Smrg	  case $2 in
14632001f49Smrg	    *.o | *.[oO][bB][jJ])
14732001f49Smrg	      func_file_conv "$2"
14832001f49Smrg	      set x "$@" -Fo"$file"
14932001f49Smrg	      shift
15032001f49Smrg	      ;;
15132001f49Smrg	    *)
15232001f49Smrg	      func_file_conv "$2"
15332001f49Smrg	      set x "$@" -Fe"$file"
15432001f49Smrg	      shift
15532001f49Smrg	      ;;
15632001f49Smrg	  esac
15732001f49Smrg	  ;;
15832001f49Smrg	-I)
15932001f49Smrg	  eat=1
16032001f49Smrg	  func_file_conv "$2" mingw
16132001f49Smrg	  set x "$@" -I"$file"
16232001f49Smrg	  shift
16332001f49Smrg	  ;;
16432001f49Smrg	-I*)
16532001f49Smrg	  func_file_conv "${1#-I}" mingw
16632001f49Smrg	  set x "$@" -I"$file"
16732001f49Smrg	  shift
16832001f49Smrg	  ;;
16932001f49Smrg	-l)
17032001f49Smrg	  eat=1
17132001f49Smrg	  func_cl_dashl "$2"
17232001f49Smrg	  set x "$@" "$lib"
17332001f49Smrg	  shift
17432001f49Smrg	  ;;
17532001f49Smrg	-l*)
17632001f49Smrg	  func_cl_dashl "${1#-l}"
17732001f49Smrg	  set x "$@" "$lib"
17832001f49Smrg	  shift
17932001f49Smrg	  ;;
18032001f49Smrg	-L)
18132001f49Smrg	  eat=1
18232001f49Smrg	  func_cl_dashL "$2"
18332001f49Smrg	  ;;
18432001f49Smrg	-L*)
18532001f49Smrg	  func_cl_dashL "${1#-L}"
18632001f49Smrg	  ;;
18732001f49Smrg	-static)
18832001f49Smrg	  shared=false
18932001f49Smrg	  ;;
19032001f49Smrg	-Wl,*)
19132001f49Smrg	  arg=${1#-Wl,}
19232001f49Smrg	  save_ifs="$IFS"; IFS=','
19332001f49Smrg	  for flag in $arg; do
19432001f49Smrg	    IFS="$save_ifs"
19532001f49Smrg	    linker_opts="$linker_opts $flag"
19632001f49Smrg	  done
19732001f49Smrg	  IFS="$save_ifs"
19832001f49Smrg	  ;;
19932001f49Smrg	-Xlinker)
20032001f49Smrg	  eat=1
20132001f49Smrg	  linker_opts="$linker_opts $2"
20232001f49Smrg	  ;;
20332001f49Smrg	-*)
20432001f49Smrg	  set x "$@" "$1"
20532001f49Smrg	  shift
20632001f49Smrg	  ;;
20732001f49Smrg	*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
20832001f49Smrg	  func_file_conv "$1"
20932001f49Smrg	  set x "$@" -Tp"$file"
21032001f49Smrg	  shift
21132001f49Smrg	  ;;
21232001f49Smrg	*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
21332001f49Smrg	  func_file_conv "$1" mingw
21432001f49Smrg	  set x "$@" "$file"
21532001f49Smrg	  shift
21632001f49Smrg	  ;;
21732001f49Smrg	*)
21832001f49Smrg	  set x "$@" "$1"
21932001f49Smrg	  shift
22032001f49Smrg	  ;;
22132001f49Smrg      esac
22232001f49Smrg    fi
22332001f49Smrg    shift
22432001f49Smrg  done
22532001f49Smrg  if test -n "$linker_opts"; then
22632001f49Smrg    linker_opts="-link$linker_opts"
22732001f49Smrg  fi
22832001f49Smrg  exec "$@" $linker_opts
22932001f49Smrg  exit 1
23032001f49Smrg}
23132001f49Smrg
23232001f49Smrgeat=
23332001f49Smrg
23432001f49Smrgcase $1 in
23532001f49Smrg  '')
23632001f49Smrg     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
23732001f49Smrg     exit 1;
23832001f49Smrg     ;;
23932001f49Smrg  -h | --h*)
24032001f49Smrg    cat <<\EOF
24132001f49SmrgUsage: compile [--help] [--version] PROGRAM [ARGS]
24232001f49Smrg
24332001f49SmrgWrapper for compilers which do not understand '-c -o'.
24432001f49SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining
24532001f49Smrgarguments, and rename the output as expected.
24632001f49Smrg
24732001f49SmrgIf you are trying to build a whole package this is not the
24832001f49Smrgright script to run: please start by reading the file 'INSTALL'.
24932001f49Smrg
25032001f49SmrgReport bugs to <bug-automake@gnu.org>.
25132001f49SmrgEOF
25232001f49Smrg    exit $?
25332001f49Smrg    ;;
25432001f49Smrg  -v | --v*)
25532001f49Smrg    echo "compile $scriptversion"
25632001f49Smrg    exit $?
25732001f49Smrg    ;;
25832001f49Smrg  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
25932001f49Smrg    func_cl_wrapper "$@"      # Doesn't return...
26032001f49Smrg    ;;
26132001f49Smrgesac
26232001f49Smrg
26332001f49Smrgofile=
26432001f49Smrgcfile=
26532001f49Smrg
26632001f49Smrgfor arg
26732001f49Smrgdo
26832001f49Smrg  if test -n "$eat"; then
26932001f49Smrg    eat=
27032001f49Smrg  else
27132001f49Smrg    case $1 in
27232001f49Smrg      -o)
27332001f49Smrg	# configure might choose to run compile as 'compile cc -o foo foo.c'.
27432001f49Smrg	# So we strip '-o arg' only if arg is an object.
27532001f49Smrg	eat=1
27632001f49Smrg	case $2 in
27732001f49Smrg	  *.o | *.obj)
27832001f49Smrg	    ofile=$2
27932001f49Smrg	    ;;
28032001f49Smrg	  *)
28132001f49Smrg	    set x "$@" -o "$2"
28232001f49Smrg	    shift
28332001f49Smrg	    ;;
28432001f49Smrg	esac
28532001f49Smrg	;;
28632001f49Smrg      *.c)
28732001f49Smrg	cfile=$1
28832001f49Smrg	set x "$@" "$1"
28932001f49Smrg	shift
29032001f49Smrg	;;
29132001f49Smrg      *)
29232001f49Smrg	set x "$@" "$1"
29332001f49Smrg	shift
29432001f49Smrg	;;
29532001f49Smrg    esac
29632001f49Smrg  fi
29732001f49Smrg  shift
29832001f49Smrgdone
29932001f49Smrg
30032001f49Smrgif test -z "$ofile" || test -z "$cfile"; then
30132001f49Smrg  # If no '-o' option was seen then we might have been invoked from a
30232001f49Smrg  # pattern rule where we don't need one.  That is ok -- this is a
30332001f49Smrg  # normal compilation that the losing compiler can handle.  If no
30432001f49Smrg  # '.c' file was seen then we are probably linking.  That is also
30532001f49Smrg  # ok.
30632001f49Smrg  exec "$@"
30732001f49Smrgfi
30832001f49Smrg
30932001f49Smrg# Name of file we expect compiler to create.
31032001f49Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
31132001f49Smrg
31232001f49Smrg# Create the lock directory.
31332001f49Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name
31432001f49Smrg# that we are using for the .o file.  Also, base the name on the expected
31532001f49Smrg# object file name, since that is what matters with a parallel build.
31632001f49Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
31732001f49Smrgwhile true; do
31832001f49Smrg  if mkdir "$lockdir" >/dev/null 2>&1; then
31932001f49Smrg    break
32032001f49Smrg  fi
32132001f49Smrg  sleep 1
32232001f49Smrgdone
32332001f49Smrg# FIXME: race condition here if user kills between mkdir and trap.
32432001f49Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15
32532001f49Smrg
32632001f49Smrg# Run the compile.
32732001f49Smrg"$@"
32832001f49Smrgret=$?
32932001f49Smrg
33032001f49Smrgif test -f "$cofile"; then
33132001f49Smrg  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
33232001f49Smrgelif test -f "${cofile}bj"; then
33332001f49Smrg  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
33432001f49Smrgfi
33532001f49Smrg
33632001f49Smrgrmdir "$lockdir"
33732001f49Smrgexit $ret
33832001f49Smrg
33932001f49Smrg# Local Variables:
34032001f49Smrg# mode: shell-script
34132001f49Smrg# sh-indentation: 2
34232001f49Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
34332001f49Smrg# time-stamp-start: "scriptversion="
34432001f49Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
34532001f49Smrg# time-stamp-time-zone: "UTC"
34632001f49Smrg# time-stamp-end: "; # UTC"
34732001f49Smrg# End:
348