compile revision 5788ca14
15788ca14Smrg#! /bin/sh
25788ca14Smrg# Wrapper for compilers which do not understand '-c -o'.
35788ca14Smrg
45788ca14Smrgscriptversion=2012-01-04.17; # UTC
55788ca14Smrg
65788ca14Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009, 2010, 2012 Free
75788ca14Smrg# Software Foundation, Inc.
85788ca14Smrg# Written by Tom Tromey <tromey@cygnus.com>.
95788ca14Smrg#
105788ca14Smrg# This program is free software; you can redistribute it and/or modify
115788ca14Smrg# it under the terms of the GNU General Public License as published by
125788ca14Smrg# the Free Software Foundation; either version 2, or (at your option)
135788ca14Smrg# any later version.
145788ca14Smrg#
155788ca14Smrg# This program is distributed in the hope that it will be useful,
165788ca14Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
175788ca14Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
185788ca14Smrg# GNU General Public License for more details.
195788ca14Smrg#
205788ca14Smrg# You should have received a copy of the GNU General Public License
215788ca14Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
225788ca14Smrg
235788ca14Smrg# As a special exception to the GNU General Public License, if you
245788ca14Smrg# distribute this file as part of a program that contains a
255788ca14Smrg# configuration script generated by Autoconf, you may include it under
265788ca14Smrg# the same distribution terms that you use for the rest of that program.
275788ca14Smrg
285788ca14Smrg# This file is maintained in Automake, please report
295788ca14Smrg# bugs to <bug-automake@gnu.org> or send patches to
305788ca14Smrg# <automake-patches@gnu.org>.
315788ca14Smrg
325788ca14Smrgnl='
335788ca14Smrg'
345788ca14Smrg
355788ca14Smrg# We need space, tab and new line, in precisely that order.  Quoting is
365788ca14Smrg# there to prevent tools from complaining about whitespace usage.
375788ca14SmrgIFS=" ""	$nl"
385788ca14Smrg
395788ca14Smrgfile_conv=
405788ca14Smrg
415788ca14Smrg# func_file_conv build_file lazy
425788ca14Smrg# Convert a $build file to $host form and store it in $file
435788ca14Smrg# Currently only supports Windows hosts. If the determined conversion
445788ca14Smrg# type is listed in (the comma separated) LAZY, no conversion will
455788ca14Smrg# take place.
465788ca14Smrgfunc_file_conv ()
475788ca14Smrg{
485788ca14Smrg  file=$1
495788ca14Smrg  case $file in
505788ca14Smrg    / | /[!/]*) # absolute file, and not a UNC file
515788ca14Smrg      if test -z "$file_conv"; then
525788ca14Smrg	# lazily determine how to convert abs files
535788ca14Smrg	case `uname -s` in
545788ca14Smrg	  MINGW*)
555788ca14Smrg	    file_conv=mingw
565788ca14Smrg	    ;;
575788ca14Smrg	  CYGWIN*)
585788ca14Smrg	    file_conv=cygwin
595788ca14Smrg	    ;;
605788ca14Smrg	  *)
615788ca14Smrg	    file_conv=wine
625788ca14Smrg	    ;;
635788ca14Smrg	esac
645788ca14Smrg      fi
655788ca14Smrg      case $file_conv/,$2, in
665788ca14Smrg	*,$file_conv,*)
675788ca14Smrg	  ;;
685788ca14Smrg	mingw/*)
695788ca14Smrg	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
705788ca14Smrg	  ;;
715788ca14Smrg	cygwin/*)
725788ca14Smrg	  file=`cygpath -m "$file" || echo "$file"`
735788ca14Smrg	  ;;
745788ca14Smrg	wine/*)
755788ca14Smrg	  file=`winepath -w "$file" || echo "$file"`
765788ca14Smrg	  ;;
775788ca14Smrg      esac
785788ca14Smrg      ;;
795788ca14Smrg  esac
805788ca14Smrg}
815788ca14Smrg
825788ca14Smrg# func_cl_wrapper cl arg...
835788ca14Smrg# Adjust compile command to suit cl
845788ca14Smrgfunc_cl_wrapper ()
855788ca14Smrg{
865788ca14Smrg  # Assume a capable shell
875788ca14Smrg  lib_path=
885788ca14Smrg  shared=:
895788ca14Smrg  linker_opts=
905788ca14Smrg  for arg
915788ca14Smrg  do
925788ca14Smrg    if test -n "$eat"; then
935788ca14Smrg      eat=
945788ca14Smrg    else
955788ca14Smrg      case $1 in
965788ca14Smrg	-o)
975788ca14Smrg	  # configure might choose to run compile as 'compile cc -o foo foo.c'.
985788ca14Smrg	  eat=1
995788ca14Smrg	  case $2 in
1005788ca14Smrg	    *.o | *.[oO][bB][jJ])
1015788ca14Smrg	      func_file_conv "$2"
1025788ca14Smrg	      set x "$@" -Fo"$file"
1035788ca14Smrg	      shift
1045788ca14Smrg	      ;;
1055788ca14Smrg	    *)
1065788ca14Smrg	      func_file_conv "$2"
1075788ca14Smrg	      set x "$@" -Fe"$file"
1085788ca14Smrg	      shift
1095788ca14Smrg	      ;;
1105788ca14Smrg	  esac
1115788ca14Smrg	  ;;
1125788ca14Smrg	-I*)
1135788ca14Smrg	  func_file_conv "${1#-I}" mingw
1145788ca14Smrg	  set x "$@" -I"$file"
1155788ca14Smrg	  shift
1165788ca14Smrg	  ;;
1175788ca14Smrg	-l*)
1185788ca14Smrg	  lib=${1#-l}
1195788ca14Smrg	  found=no
1205788ca14Smrg	  save_IFS=$IFS
1215788ca14Smrg	  IFS=';'
1225788ca14Smrg	  for dir in $lib_path $LIB
1235788ca14Smrg	  do
1245788ca14Smrg	    IFS=$save_IFS
1255788ca14Smrg	    if $shared && test -f "$dir/$lib.dll.lib"; then
1265788ca14Smrg	      found=yes
1275788ca14Smrg	      set x "$@" "$dir/$lib.dll.lib"
1285788ca14Smrg	      break
1295788ca14Smrg	    fi
1305788ca14Smrg	    if test -f "$dir/$lib.lib"; then
1315788ca14Smrg	      found=yes
1325788ca14Smrg	      set x "$@" "$dir/$lib.lib"
1335788ca14Smrg	      break
1345788ca14Smrg	    fi
1355788ca14Smrg	  done
1365788ca14Smrg	  IFS=$save_IFS
1375788ca14Smrg
1385788ca14Smrg	  test "$found" != yes && set x "$@" "$lib.lib"
1395788ca14Smrg	  shift
1405788ca14Smrg	  ;;
1415788ca14Smrg	-L*)
1425788ca14Smrg	  func_file_conv "${1#-L}"
1435788ca14Smrg	  if test -z "$lib_path"; then
1445788ca14Smrg	    lib_path=$file
1455788ca14Smrg	  else
1465788ca14Smrg	    lib_path="$lib_path;$file"
1475788ca14Smrg	  fi
1485788ca14Smrg	  linker_opts="$linker_opts -LIBPATH:$file"
1495788ca14Smrg	  ;;
1505788ca14Smrg	-static)
1515788ca14Smrg	  shared=false
1525788ca14Smrg	  ;;
1535788ca14Smrg	-Wl,*)
1545788ca14Smrg	  arg=${1#-Wl,}
1555788ca14Smrg	  save_ifs="$IFS"; IFS=','
1565788ca14Smrg	  for flag in $arg; do
1575788ca14Smrg	    IFS="$save_ifs"
1585788ca14Smrg	    linker_opts="$linker_opts $flag"
1595788ca14Smrg	  done
1605788ca14Smrg	  IFS="$save_ifs"
1615788ca14Smrg	  ;;
1625788ca14Smrg	-Xlinker)
1635788ca14Smrg	  eat=1
1645788ca14Smrg	  linker_opts="$linker_opts $2"
1655788ca14Smrg	  ;;
1665788ca14Smrg	-*)
1675788ca14Smrg	  set x "$@" "$1"
1685788ca14Smrg	  shift
1695788ca14Smrg	  ;;
1705788ca14Smrg	*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
1715788ca14Smrg	  func_file_conv "$1"
1725788ca14Smrg	  set x "$@" -Tp"$file"
1735788ca14Smrg	  shift
1745788ca14Smrg	  ;;
1755788ca14Smrg	*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
1765788ca14Smrg	  func_file_conv "$1" mingw
1775788ca14Smrg	  set x "$@" "$file"
1785788ca14Smrg	  shift
1795788ca14Smrg	  ;;
1805788ca14Smrg	*)
1815788ca14Smrg	  set x "$@" "$1"
1825788ca14Smrg	  shift
1835788ca14Smrg	  ;;
1845788ca14Smrg      esac
1855788ca14Smrg    fi
1865788ca14Smrg    shift
1875788ca14Smrg  done
1885788ca14Smrg  if test -n "$linker_opts"; then
1895788ca14Smrg    linker_opts="-link$linker_opts"
1905788ca14Smrg  fi
1915788ca14Smrg  exec "$@" $linker_opts
1925788ca14Smrg  exit 1
1935788ca14Smrg}
1945788ca14Smrg
1955788ca14Smrgeat=
1965788ca14Smrg
1975788ca14Smrgcase $1 in
1985788ca14Smrg  '')
1995788ca14Smrg     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
2005788ca14Smrg     exit 1;
2015788ca14Smrg     ;;
2025788ca14Smrg  -h | --h*)
2035788ca14Smrg    cat <<\EOF
2045788ca14SmrgUsage: compile [--help] [--version] PROGRAM [ARGS]
2055788ca14Smrg
2065788ca14SmrgWrapper for compilers which do not understand '-c -o'.
2075788ca14SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining
2085788ca14Smrgarguments, and rename the output as expected.
2095788ca14Smrg
2105788ca14SmrgIf you are trying to build a whole package this is not the
2115788ca14Smrgright script to run: please start by reading the file 'INSTALL'.
2125788ca14Smrg
2135788ca14SmrgReport bugs to <bug-automake@gnu.org>.
2145788ca14SmrgEOF
2155788ca14Smrg    exit $?
2165788ca14Smrg    ;;
2175788ca14Smrg  -v | --v*)
2185788ca14Smrg    echo "compile $scriptversion"
2195788ca14Smrg    exit $?
2205788ca14Smrg    ;;
2215788ca14Smrg  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
2225788ca14Smrg    func_cl_wrapper "$@"      # Doesn't return...
2235788ca14Smrg    ;;
2245788ca14Smrgesac
2255788ca14Smrg
2265788ca14Smrgofile=
2275788ca14Smrgcfile=
2285788ca14Smrg
2295788ca14Smrgfor arg
2305788ca14Smrgdo
2315788ca14Smrg  if test -n "$eat"; then
2325788ca14Smrg    eat=
2335788ca14Smrg  else
2345788ca14Smrg    case $1 in
2355788ca14Smrg      -o)
2365788ca14Smrg	# configure might choose to run compile as 'compile cc -o foo foo.c'.
2375788ca14Smrg	# So we strip '-o arg' only if arg is an object.
2385788ca14Smrg	eat=1
2395788ca14Smrg	case $2 in
2405788ca14Smrg	  *.o | *.obj)
2415788ca14Smrg	    ofile=$2
2425788ca14Smrg	    ;;
2435788ca14Smrg	  *)
2445788ca14Smrg	    set x "$@" -o "$2"
2455788ca14Smrg	    shift
2465788ca14Smrg	    ;;
2475788ca14Smrg	esac
2485788ca14Smrg	;;
2495788ca14Smrg      *.c)
2505788ca14Smrg	cfile=$1
2515788ca14Smrg	set x "$@" "$1"
2525788ca14Smrg	shift
2535788ca14Smrg	;;
2545788ca14Smrg      *)
2555788ca14Smrg	set x "$@" "$1"
2565788ca14Smrg	shift
2575788ca14Smrg	;;
2585788ca14Smrg    esac
2595788ca14Smrg  fi
2605788ca14Smrg  shift
2615788ca14Smrgdone
2625788ca14Smrg
2635788ca14Smrgif test -z "$ofile" || test -z "$cfile"; then
2645788ca14Smrg  # If no '-o' option was seen then we might have been invoked from a
2655788ca14Smrg  # pattern rule where we don't need one.  That is ok -- this is a
2665788ca14Smrg  # normal compilation that the losing compiler can handle.  If no
2675788ca14Smrg  # '.c' file was seen then we are probably linking.  That is also
2685788ca14Smrg  # ok.
2695788ca14Smrg  exec "$@"
2705788ca14Smrgfi
2715788ca14Smrg
2725788ca14Smrg# Name of file we expect compiler to create.
2735788ca14Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
2745788ca14Smrg
2755788ca14Smrg# Create the lock directory.
2765788ca14Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name
2775788ca14Smrg# that we are using for the .o file.  Also, base the name on the expected
2785788ca14Smrg# object file name, since that is what matters with a parallel build.
2795788ca14Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
2805788ca14Smrgwhile true; do
2815788ca14Smrg  if mkdir "$lockdir" >/dev/null 2>&1; then
2825788ca14Smrg    break
2835788ca14Smrg  fi
2845788ca14Smrg  sleep 1
2855788ca14Smrgdone
2865788ca14Smrg# FIXME: race condition here if user kills between mkdir and trap.
2875788ca14Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15
2885788ca14Smrg
2895788ca14Smrg# Run the compile.
2905788ca14Smrg"$@"
2915788ca14Smrgret=$?
2925788ca14Smrg
2935788ca14Smrgif test -f "$cofile"; then
2945788ca14Smrg  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
2955788ca14Smrgelif test -f "${cofile}bj"; then
2965788ca14Smrg  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
2975788ca14Smrgfi
2985788ca14Smrg
2995788ca14Smrgrmdir "$lockdir"
3005788ca14Smrgexit $ret
3015788ca14Smrg
3025788ca14Smrg# Local Variables:
3035788ca14Smrg# mode: shell-script
3045788ca14Smrg# sh-indentation: 2
3055788ca14Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
3065788ca14Smrg# time-stamp-start: "scriptversion="
3075788ca14Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
3085788ca14Smrg# time-stamp-time-zone: "UTC"
3095788ca14Smrg# time-stamp-end: "; # UTC"
3105788ca14Smrg# End:
311