compile revision 5dd5f640
15dd5f640Smrg#! /bin/sh
25dd5f640Smrg# Wrapper for compilers which do not understand '-c -o'.
35dd5f640Smrg
45dd5f640Smrgscriptversion=2012-10-14.11; # UTC
55dd5f640Smrg
65dd5f640Smrg# Copyright (C) 1999-2013 Free Software Foundation, Inc.
75dd5f640Smrg# Written by Tom Tromey <tromey@cygnus.com>.
85dd5f640Smrg#
95dd5f640Smrg# This program is free software; you can redistribute it and/or modify
105dd5f640Smrg# it under the terms of the GNU General Public License as published by
115dd5f640Smrg# the Free Software Foundation; either version 2, or (at your option)
125dd5f640Smrg# any later version.
135dd5f640Smrg#
145dd5f640Smrg# This program is distributed in the hope that it will be useful,
155dd5f640Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
165dd5f640Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
175dd5f640Smrg# GNU General Public License for more details.
185dd5f640Smrg#
195dd5f640Smrg# You should have received a copy of the GNU General Public License
205dd5f640Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
215dd5f640Smrg
225dd5f640Smrg# As a special exception to the GNU General Public License, if you
235dd5f640Smrg# distribute this file as part of a program that contains a
245dd5f640Smrg# configuration script generated by Autoconf, you may include it under
255dd5f640Smrg# the same distribution terms that you use for the rest of that program.
265dd5f640Smrg
275dd5f640Smrg# This file is maintained in Automake, please report
285dd5f640Smrg# bugs to <bug-automake@gnu.org> or send patches to
295dd5f640Smrg# <automake-patches@gnu.org>.
305dd5f640Smrg
315dd5f640Smrgnl='
325dd5f640Smrg'
335dd5f640Smrg
345dd5f640Smrg# We need space, tab and new line, in precisely that order.  Quoting is
355dd5f640Smrg# there to prevent tools from complaining about whitespace usage.
365dd5f640SmrgIFS=" ""	$nl"
375dd5f640Smrg
385dd5f640Smrgfile_conv=
395dd5f640Smrg
405dd5f640Smrg# func_file_conv build_file lazy
415dd5f640Smrg# Convert a $build file to $host form and store it in $file
425dd5f640Smrg# Currently only supports Windows hosts. If the determined conversion
435dd5f640Smrg# type is listed in (the comma separated) LAZY, no conversion will
445dd5f640Smrg# take place.
455dd5f640Smrgfunc_file_conv ()
465dd5f640Smrg{
475dd5f640Smrg  file=$1
485dd5f640Smrg  case $file in
495dd5f640Smrg    / | /[!/]*) # absolute file, and not a UNC file
505dd5f640Smrg      if test -z "$file_conv"; then
515dd5f640Smrg	# lazily determine how to convert abs files
525dd5f640Smrg	case `uname -s` in
535dd5f640Smrg	  MINGW*)
545dd5f640Smrg	    file_conv=mingw
555dd5f640Smrg	    ;;
565dd5f640Smrg	  CYGWIN*)
575dd5f640Smrg	    file_conv=cygwin
585dd5f640Smrg	    ;;
595dd5f640Smrg	  *)
605dd5f640Smrg	    file_conv=wine
615dd5f640Smrg	    ;;
625dd5f640Smrg	esac
635dd5f640Smrg      fi
645dd5f640Smrg      case $file_conv/,$2, in
655dd5f640Smrg	*,$file_conv,*)
665dd5f640Smrg	  ;;
675dd5f640Smrg	mingw/*)
685dd5f640Smrg	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
695dd5f640Smrg	  ;;
705dd5f640Smrg	cygwin/*)
715dd5f640Smrg	  file=`cygpath -m "$file" || echo "$file"`
725dd5f640Smrg	  ;;
735dd5f640Smrg	wine/*)
745dd5f640Smrg	  file=`winepath -w "$file" || echo "$file"`
755dd5f640Smrg	  ;;
765dd5f640Smrg      esac
775dd5f640Smrg      ;;
785dd5f640Smrg  esac
795dd5f640Smrg}
805dd5f640Smrg
815dd5f640Smrg# func_cl_dashL linkdir
825dd5f640Smrg# Make cl look for libraries in LINKDIR
835dd5f640Smrgfunc_cl_dashL ()
845dd5f640Smrg{
855dd5f640Smrg  func_file_conv "$1"
865dd5f640Smrg  if test -z "$lib_path"; then
875dd5f640Smrg    lib_path=$file
885dd5f640Smrg  else
895dd5f640Smrg    lib_path="$lib_path;$file"
905dd5f640Smrg  fi
915dd5f640Smrg  linker_opts="$linker_opts -LIBPATH:$file"
925dd5f640Smrg}
935dd5f640Smrg
945dd5f640Smrg# func_cl_dashl library
955dd5f640Smrg# Do a library search-path lookup for cl
965dd5f640Smrgfunc_cl_dashl ()
975dd5f640Smrg{
985dd5f640Smrg  lib=$1
995dd5f640Smrg  found=no
1005dd5f640Smrg  save_IFS=$IFS
1015dd5f640Smrg  IFS=';'
1025dd5f640Smrg  for dir in $lib_path $LIB
1035dd5f640Smrg  do
1045dd5f640Smrg    IFS=$save_IFS
1055dd5f640Smrg    if $shared && test -f "$dir/$lib.dll.lib"; then
1065dd5f640Smrg      found=yes
1075dd5f640Smrg      lib=$dir/$lib.dll.lib
1085dd5f640Smrg      break
1095dd5f640Smrg    fi
1105dd5f640Smrg    if test -f "$dir/$lib.lib"; then
1115dd5f640Smrg      found=yes
1125dd5f640Smrg      lib=$dir/$lib.lib
1135dd5f640Smrg      break
1145dd5f640Smrg    fi
1155dd5f640Smrg    if test -f "$dir/lib$lib.a"; then
1165dd5f640Smrg      found=yes
1175dd5f640Smrg      lib=$dir/lib$lib.a
1185dd5f640Smrg      break
1195dd5f640Smrg    fi
1205dd5f640Smrg  done
1215dd5f640Smrg  IFS=$save_IFS
1225dd5f640Smrg
1235dd5f640Smrg  if test "$found" != yes; then
1245dd5f640Smrg    lib=$lib.lib
1255dd5f640Smrg  fi
1265dd5f640Smrg}
1275dd5f640Smrg
1285dd5f640Smrg# func_cl_wrapper cl arg...
1295dd5f640Smrg# Adjust compile command to suit cl
1305dd5f640Smrgfunc_cl_wrapper ()
1315dd5f640Smrg{
1325dd5f640Smrg  # Assume a capable shell
1335dd5f640Smrg  lib_path=
1345dd5f640Smrg  shared=:
1355dd5f640Smrg  linker_opts=
1365dd5f640Smrg  for arg
1375dd5f640Smrg  do
1385dd5f640Smrg    if test -n "$eat"; then
1395dd5f640Smrg      eat=
1405dd5f640Smrg    else
1415dd5f640Smrg      case $1 in
1425dd5f640Smrg	-o)
1435dd5f640Smrg	  # configure might choose to run compile as 'compile cc -o foo foo.c'.
1445dd5f640Smrg	  eat=1
1455dd5f640Smrg	  case $2 in
1465dd5f640Smrg	    *.o | *.[oO][bB][jJ])
1475dd5f640Smrg	      func_file_conv "$2"
1485dd5f640Smrg	      set x "$@" -Fo"$file"
1495dd5f640Smrg	      shift
1505dd5f640Smrg	      ;;
1515dd5f640Smrg	    *)
1525dd5f640Smrg	      func_file_conv "$2"
1535dd5f640Smrg	      set x "$@" -Fe"$file"
1545dd5f640Smrg	      shift
1555dd5f640Smrg	      ;;
1565dd5f640Smrg	  esac
1575dd5f640Smrg	  ;;
1585dd5f640Smrg	-I)
1595dd5f640Smrg	  eat=1
1605dd5f640Smrg	  func_file_conv "$2" mingw
1615dd5f640Smrg	  set x "$@" -I"$file"
1625dd5f640Smrg	  shift
1635dd5f640Smrg	  ;;
1645dd5f640Smrg	-I*)
1655dd5f640Smrg	  func_file_conv "${1#-I}" mingw
1665dd5f640Smrg	  set x "$@" -I"$file"
1675dd5f640Smrg	  shift
1685dd5f640Smrg	  ;;
1695dd5f640Smrg	-l)
1705dd5f640Smrg	  eat=1
1715dd5f640Smrg	  func_cl_dashl "$2"
1725dd5f640Smrg	  set x "$@" "$lib"
1735dd5f640Smrg	  shift
1745dd5f640Smrg	  ;;
1755dd5f640Smrg	-l*)
1765dd5f640Smrg	  func_cl_dashl "${1#-l}"
1775dd5f640Smrg	  set x "$@" "$lib"
1785dd5f640Smrg	  shift
1795dd5f640Smrg	  ;;
1805dd5f640Smrg	-L)
1815dd5f640Smrg	  eat=1
1825dd5f640Smrg	  func_cl_dashL "$2"
1835dd5f640Smrg	  ;;
1845dd5f640Smrg	-L*)
1855dd5f640Smrg	  func_cl_dashL "${1#-L}"
1865dd5f640Smrg	  ;;
1875dd5f640Smrg	-static)
1885dd5f640Smrg	  shared=false
1895dd5f640Smrg	  ;;
1905dd5f640Smrg	-Wl,*)
1915dd5f640Smrg	  arg=${1#-Wl,}
1925dd5f640Smrg	  save_ifs="$IFS"; IFS=','
1935dd5f640Smrg	  for flag in $arg; do
1945dd5f640Smrg	    IFS="$save_ifs"
1955dd5f640Smrg	    linker_opts="$linker_opts $flag"
1965dd5f640Smrg	  done
1975dd5f640Smrg	  IFS="$save_ifs"
1985dd5f640Smrg	  ;;
1995dd5f640Smrg	-Xlinker)
2005dd5f640Smrg	  eat=1
2015dd5f640Smrg	  linker_opts="$linker_opts $2"
2025dd5f640Smrg	  ;;
2035dd5f640Smrg	-*)
2045dd5f640Smrg	  set x "$@" "$1"
2055dd5f640Smrg	  shift
2065dd5f640Smrg	  ;;
2075dd5f640Smrg	*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
2085dd5f640Smrg	  func_file_conv "$1"
2095dd5f640Smrg	  set x "$@" -Tp"$file"
2105dd5f640Smrg	  shift
2115dd5f640Smrg	  ;;
2125dd5f640Smrg	*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
2135dd5f640Smrg	  func_file_conv "$1" mingw
2145dd5f640Smrg	  set x "$@" "$file"
2155dd5f640Smrg	  shift
2165dd5f640Smrg	  ;;
2175dd5f640Smrg	*)
2185dd5f640Smrg	  set x "$@" "$1"
2195dd5f640Smrg	  shift
2205dd5f640Smrg	  ;;
2215dd5f640Smrg      esac
2225dd5f640Smrg    fi
2235dd5f640Smrg    shift
2245dd5f640Smrg  done
2255dd5f640Smrg  if test -n "$linker_opts"; then
2265dd5f640Smrg    linker_opts="-link$linker_opts"
2275dd5f640Smrg  fi
2285dd5f640Smrg  exec "$@" $linker_opts
2295dd5f640Smrg  exit 1
2305dd5f640Smrg}
2315dd5f640Smrg
2325dd5f640Smrgeat=
2335dd5f640Smrg
2345dd5f640Smrgcase $1 in
2355dd5f640Smrg  '')
2365dd5f640Smrg     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
2375dd5f640Smrg     exit 1;
2385dd5f640Smrg     ;;
2395dd5f640Smrg  -h | --h*)
2405dd5f640Smrg    cat <<\EOF
2415dd5f640SmrgUsage: compile [--help] [--version] PROGRAM [ARGS]
2425dd5f640Smrg
2435dd5f640SmrgWrapper for compilers which do not understand '-c -o'.
2445dd5f640SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining
2455dd5f640Smrgarguments, and rename the output as expected.
2465dd5f640Smrg
2475dd5f640SmrgIf you are trying to build a whole package this is not the
2485dd5f640Smrgright script to run: please start by reading the file 'INSTALL'.
2495dd5f640Smrg
2505dd5f640SmrgReport bugs to <bug-automake@gnu.org>.
2515dd5f640SmrgEOF
2525dd5f640Smrg    exit $?
2535dd5f640Smrg    ;;
2545dd5f640Smrg  -v | --v*)
2555dd5f640Smrg    echo "compile $scriptversion"
2565dd5f640Smrg    exit $?
2575dd5f640Smrg    ;;
2585dd5f640Smrg  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
2595dd5f640Smrg    func_cl_wrapper "$@"      # Doesn't return...
2605dd5f640Smrg    ;;
2615dd5f640Smrgesac
2625dd5f640Smrg
2635dd5f640Smrgofile=
2645dd5f640Smrgcfile=
2655dd5f640Smrg
2665dd5f640Smrgfor arg
2675dd5f640Smrgdo
2685dd5f640Smrg  if test -n "$eat"; then
2695dd5f640Smrg    eat=
2705dd5f640Smrg  else
2715dd5f640Smrg    case $1 in
2725dd5f640Smrg      -o)
2735dd5f640Smrg	# configure might choose to run compile as 'compile cc -o foo foo.c'.
2745dd5f640Smrg	# So we strip '-o arg' only if arg is an object.
2755dd5f640Smrg	eat=1
2765dd5f640Smrg	case $2 in
2775dd5f640Smrg	  *.o | *.obj)
2785dd5f640Smrg	    ofile=$2
2795dd5f640Smrg	    ;;
2805dd5f640Smrg	  *)
2815dd5f640Smrg	    set x "$@" -o "$2"
2825dd5f640Smrg	    shift
2835dd5f640Smrg	    ;;
2845dd5f640Smrg	esac
2855dd5f640Smrg	;;
2865dd5f640Smrg      *.c)
2875dd5f640Smrg	cfile=$1
2885dd5f640Smrg	set x "$@" "$1"
2895dd5f640Smrg	shift
2905dd5f640Smrg	;;
2915dd5f640Smrg      *)
2925dd5f640Smrg	set x "$@" "$1"
2935dd5f640Smrg	shift
2945dd5f640Smrg	;;
2955dd5f640Smrg    esac
2965dd5f640Smrg  fi
2975dd5f640Smrg  shift
2985dd5f640Smrgdone
2995dd5f640Smrg
3005dd5f640Smrgif test -z "$ofile" || test -z "$cfile"; then
3015dd5f640Smrg  # If no '-o' option was seen then we might have been invoked from a
3025dd5f640Smrg  # pattern rule where we don't need one.  That is ok -- this is a
3035dd5f640Smrg  # normal compilation that the losing compiler can handle.  If no
3045dd5f640Smrg  # '.c' file was seen then we are probably linking.  That is also
3055dd5f640Smrg  # ok.
3065dd5f640Smrg  exec "$@"
3075dd5f640Smrgfi
3085dd5f640Smrg
3095dd5f640Smrg# Name of file we expect compiler to create.
3105dd5f640Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
3115dd5f640Smrg
3125dd5f640Smrg# Create the lock directory.
3135dd5f640Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name
3145dd5f640Smrg# that we are using for the .o file.  Also, base the name on the expected
3155dd5f640Smrg# object file name, since that is what matters with a parallel build.
3165dd5f640Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
3175dd5f640Smrgwhile true; do
3185dd5f640Smrg  if mkdir "$lockdir" >/dev/null 2>&1; then
3195dd5f640Smrg    break
3205dd5f640Smrg  fi
3215dd5f640Smrg  sleep 1
3225dd5f640Smrgdone
3235dd5f640Smrg# FIXME: race condition here if user kills between mkdir and trap.
3245dd5f640Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15
3255dd5f640Smrg
3265dd5f640Smrg# Run the compile.
3275dd5f640Smrg"$@"
3285dd5f640Smrgret=$?
3295dd5f640Smrg
3305dd5f640Smrgif test -f "$cofile"; then
3315dd5f640Smrg  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
3325dd5f640Smrgelif test -f "${cofile}bj"; then
3335dd5f640Smrg  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
3345dd5f640Smrgfi
3355dd5f640Smrg
3365dd5f640Smrgrmdir "$lockdir"
3375dd5f640Smrgexit $ret
3385dd5f640Smrg
3395dd5f640Smrg# Local Variables:
3405dd5f640Smrg# mode: shell-script
3415dd5f640Smrg# sh-indentation: 2
3425dd5f640Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
3435dd5f640Smrg# time-stamp-start: "scriptversion="
3445dd5f640Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
3455dd5f640Smrg# time-stamp-time-zone: "UTC"
3465dd5f640Smrg# time-stamp-end: "; # UTC"
3475dd5f640Smrg# End:
348