compile revision 4a8d91dc
14a8d91dcSmrg#! /bin/sh
24a8d91dcSmrg# Wrapper for compilers which do not understand '-c -o'.
34a8d91dcSmrg
44a8d91dcSmrgscriptversion=2012-10-14.11; # UTC
54a8d91dcSmrg
64a8d91dcSmrg# Copyright (C) 1999-2014 Free Software Foundation, Inc.
74a8d91dcSmrg# Written by Tom Tromey <tromey@cygnus.com>.
84a8d91dcSmrg#
94a8d91dcSmrg# This program is free software; you can redistribute it and/or modify
104a8d91dcSmrg# it under the terms of the GNU General Public License as published by
114a8d91dcSmrg# the Free Software Foundation; either version 2, or (at your option)
124a8d91dcSmrg# any later version.
134a8d91dcSmrg#
144a8d91dcSmrg# This program is distributed in the hope that it will be useful,
154a8d91dcSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
164a8d91dcSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
174a8d91dcSmrg# GNU General Public License for more details.
184a8d91dcSmrg#
194a8d91dcSmrg# You should have received a copy of the GNU General Public License
204a8d91dcSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
214a8d91dcSmrg
224a8d91dcSmrg# As a special exception to the GNU General Public License, if you
234a8d91dcSmrg# distribute this file as part of a program that contains a
244a8d91dcSmrg# configuration script generated by Autoconf, you may include it under
254a8d91dcSmrg# the same distribution terms that you use for the rest of that program.
264a8d91dcSmrg
274a8d91dcSmrg# This file is maintained in Automake, please report
284a8d91dcSmrg# bugs to <bug-automake@gnu.org> or send patches to
294a8d91dcSmrg# <automake-patches@gnu.org>.
304a8d91dcSmrg
314a8d91dcSmrgnl='
324a8d91dcSmrg'
334a8d91dcSmrg
344a8d91dcSmrg# We need space, tab and new line, in precisely that order.  Quoting is
354a8d91dcSmrg# there to prevent tools from complaining about whitespace usage.
364a8d91dcSmrgIFS=" ""	$nl"
374a8d91dcSmrg
384a8d91dcSmrgfile_conv=
394a8d91dcSmrg
404a8d91dcSmrg# func_file_conv build_file lazy
414a8d91dcSmrg# Convert a $build file to $host form and store it in $file
424a8d91dcSmrg# Currently only supports Windows hosts. If the determined conversion
434a8d91dcSmrg# type is listed in (the comma separated) LAZY, no conversion will
444a8d91dcSmrg# take place.
454a8d91dcSmrgfunc_file_conv ()
464a8d91dcSmrg{
474a8d91dcSmrg  file=$1
484a8d91dcSmrg  case $file in
494a8d91dcSmrg    / | /[!/]*) # absolute file, and not a UNC file
504a8d91dcSmrg      if test -z "$file_conv"; then
514a8d91dcSmrg	# lazily determine how to convert abs files
524a8d91dcSmrg	case `uname -s` in
534a8d91dcSmrg	  MINGW*)
544a8d91dcSmrg	    file_conv=mingw
554a8d91dcSmrg	    ;;
564a8d91dcSmrg	  CYGWIN*)
574a8d91dcSmrg	    file_conv=cygwin
584a8d91dcSmrg	    ;;
594a8d91dcSmrg	  *)
604a8d91dcSmrg	    file_conv=wine
614a8d91dcSmrg	    ;;
624a8d91dcSmrg	esac
634a8d91dcSmrg      fi
644a8d91dcSmrg      case $file_conv/,$2, in
654a8d91dcSmrg	*,$file_conv,*)
664a8d91dcSmrg	  ;;
674a8d91dcSmrg	mingw/*)
684a8d91dcSmrg	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
694a8d91dcSmrg	  ;;
704a8d91dcSmrg	cygwin/*)
714a8d91dcSmrg	  file=`cygpath -m "$file" || echo "$file"`
724a8d91dcSmrg	  ;;
734a8d91dcSmrg	wine/*)
744a8d91dcSmrg	  file=`winepath -w "$file" || echo "$file"`
754a8d91dcSmrg	  ;;
764a8d91dcSmrg      esac
774a8d91dcSmrg      ;;
784a8d91dcSmrg  esac
794a8d91dcSmrg}
804a8d91dcSmrg
814a8d91dcSmrg# func_cl_dashL linkdir
824a8d91dcSmrg# Make cl look for libraries in LINKDIR
834a8d91dcSmrgfunc_cl_dashL ()
844a8d91dcSmrg{
854a8d91dcSmrg  func_file_conv "$1"
864a8d91dcSmrg  if test -z "$lib_path"; then
874a8d91dcSmrg    lib_path=$file
884a8d91dcSmrg  else
894a8d91dcSmrg    lib_path="$lib_path;$file"
904a8d91dcSmrg  fi
914a8d91dcSmrg  linker_opts="$linker_opts -LIBPATH:$file"
924a8d91dcSmrg}
934a8d91dcSmrg
944a8d91dcSmrg# func_cl_dashl library
954a8d91dcSmrg# Do a library search-path lookup for cl
964a8d91dcSmrgfunc_cl_dashl ()
974a8d91dcSmrg{
984a8d91dcSmrg  lib=$1
994a8d91dcSmrg  found=no
1004a8d91dcSmrg  save_IFS=$IFS
1014a8d91dcSmrg  IFS=';'
1024a8d91dcSmrg  for dir in $lib_path $LIB
1034a8d91dcSmrg  do
1044a8d91dcSmrg    IFS=$save_IFS
1054a8d91dcSmrg    if $shared && test -f "$dir/$lib.dll.lib"; then
1064a8d91dcSmrg      found=yes
1074a8d91dcSmrg      lib=$dir/$lib.dll.lib
1084a8d91dcSmrg      break
1094a8d91dcSmrg    fi
1104a8d91dcSmrg    if test -f "$dir/$lib.lib"; then
1114a8d91dcSmrg      found=yes
1124a8d91dcSmrg      lib=$dir/$lib.lib
1134a8d91dcSmrg      break
1144a8d91dcSmrg    fi
1154a8d91dcSmrg    if test -f "$dir/lib$lib.a"; then
1164a8d91dcSmrg      found=yes
1174a8d91dcSmrg      lib=$dir/lib$lib.a
1184a8d91dcSmrg      break
1194a8d91dcSmrg    fi
1204a8d91dcSmrg  done
1214a8d91dcSmrg  IFS=$save_IFS
1224a8d91dcSmrg
1234a8d91dcSmrg  if test "$found" != yes; then
1244a8d91dcSmrg    lib=$lib.lib
1254a8d91dcSmrg  fi
1264a8d91dcSmrg}
1274a8d91dcSmrg
1284a8d91dcSmrg# func_cl_wrapper cl arg...
1294a8d91dcSmrg# Adjust compile command to suit cl
1304a8d91dcSmrgfunc_cl_wrapper ()
1314a8d91dcSmrg{
1324a8d91dcSmrg  # Assume a capable shell
1334a8d91dcSmrg  lib_path=
1344a8d91dcSmrg  shared=:
1354a8d91dcSmrg  linker_opts=
1364a8d91dcSmrg  for arg
1374a8d91dcSmrg  do
1384a8d91dcSmrg    if test -n "$eat"; then
1394a8d91dcSmrg      eat=
1404a8d91dcSmrg    else
1414a8d91dcSmrg      case $1 in
1424a8d91dcSmrg	-o)
1434a8d91dcSmrg	  # configure might choose to run compile as 'compile cc -o foo foo.c'.
1444a8d91dcSmrg	  eat=1
1454a8d91dcSmrg	  case $2 in
1464a8d91dcSmrg	    *.o | *.[oO][bB][jJ])
1474a8d91dcSmrg	      func_file_conv "$2"
1484a8d91dcSmrg	      set x "$@" -Fo"$file"
1494a8d91dcSmrg	      shift
1504a8d91dcSmrg	      ;;
1514a8d91dcSmrg	    *)
1524a8d91dcSmrg	      func_file_conv "$2"
1534a8d91dcSmrg	      set x "$@" -Fe"$file"
1544a8d91dcSmrg	      shift
1554a8d91dcSmrg	      ;;
1564a8d91dcSmrg	  esac
1574a8d91dcSmrg	  ;;
1584a8d91dcSmrg	-I)
1594a8d91dcSmrg	  eat=1
1604a8d91dcSmrg	  func_file_conv "$2" mingw
1614a8d91dcSmrg	  set x "$@" -I"$file"
1624a8d91dcSmrg	  shift
1634a8d91dcSmrg	  ;;
1644a8d91dcSmrg	-I*)
1654a8d91dcSmrg	  func_file_conv "${1#-I}" mingw
1664a8d91dcSmrg	  set x "$@" -I"$file"
1674a8d91dcSmrg	  shift
1684a8d91dcSmrg	  ;;
1694a8d91dcSmrg	-l)
1704a8d91dcSmrg	  eat=1
1714a8d91dcSmrg	  func_cl_dashl "$2"
1724a8d91dcSmrg	  set x "$@" "$lib"
1734a8d91dcSmrg	  shift
1744a8d91dcSmrg	  ;;
1754a8d91dcSmrg	-l*)
1764a8d91dcSmrg	  func_cl_dashl "${1#-l}"
1774a8d91dcSmrg	  set x "$@" "$lib"
1784a8d91dcSmrg	  shift
1794a8d91dcSmrg	  ;;
1804a8d91dcSmrg	-L)
1814a8d91dcSmrg	  eat=1
1824a8d91dcSmrg	  func_cl_dashL "$2"
1834a8d91dcSmrg	  ;;
1844a8d91dcSmrg	-L*)
1854a8d91dcSmrg	  func_cl_dashL "${1#-L}"
1864a8d91dcSmrg	  ;;
1874a8d91dcSmrg	-static)
1884a8d91dcSmrg	  shared=false
1894a8d91dcSmrg	  ;;
1904a8d91dcSmrg	-Wl,*)
1914a8d91dcSmrg	  arg=${1#-Wl,}
1924a8d91dcSmrg	  save_ifs="$IFS"; IFS=','
1934a8d91dcSmrg	  for flag in $arg; do
1944a8d91dcSmrg	    IFS="$save_ifs"
1954a8d91dcSmrg	    linker_opts="$linker_opts $flag"
1964a8d91dcSmrg	  done
1974a8d91dcSmrg	  IFS="$save_ifs"
1984a8d91dcSmrg	  ;;
1994a8d91dcSmrg	-Xlinker)
2004a8d91dcSmrg	  eat=1
2014a8d91dcSmrg	  linker_opts="$linker_opts $2"
2024a8d91dcSmrg	  ;;
2034a8d91dcSmrg	-*)
2044a8d91dcSmrg	  set x "$@" "$1"
2054a8d91dcSmrg	  shift
2064a8d91dcSmrg	  ;;
2074a8d91dcSmrg	*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
2084a8d91dcSmrg	  func_file_conv "$1"
2094a8d91dcSmrg	  set x "$@" -Tp"$file"
2104a8d91dcSmrg	  shift
2114a8d91dcSmrg	  ;;
2124a8d91dcSmrg	*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
2134a8d91dcSmrg	  func_file_conv "$1" mingw
2144a8d91dcSmrg	  set x "$@" "$file"
2154a8d91dcSmrg	  shift
2164a8d91dcSmrg	  ;;
2174a8d91dcSmrg	*)
2184a8d91dcSmrg	  set x "$@" "$1"
2194a8d91dcSmrg	  shift
2204a8d91dcSmrg	  ;;
2214a8d91dcSmrg      esac
2224a8d91dcSmrg    fi
2234a8d91dcSmrg    shift
2244a8d91dcSmrg  done
2254a8d91dcSmrg  if test -n "$linker_opts"; then
2264a8d91dcSmrg    linker_opts="-link$linker_opts"
2274a8d91dcSmrg  fi
2284a8d91dcSmrg  exec "$@" $linker_opts
2294a8d91dcSmrg  exit 1
2304a8d91dcSmrg}
2314a8d91dcSmrg
2324a8d91dcSmrgeat=
2334a8d91dcSmrg
2344a8d91dcSmrgcase $1 in
2354a8d91dcSmrg  '')
2364a8d91dcSmrg     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
2374a8d91dcSmrg     exit 1;
2384a8d91dcSmrg     ;;
2394a8d91dcSmrg  -h | --h*)
2404a8d91dcSmrg    cat <<\EOF
2414a8d91dcSmrgUsage: compile [--help] [--version] PROGRAM [ARGS]
2424a8d91dcSmrg
2434a8d91dcSmrgWrapper for compilers which do not understand '-c -o'.
2444a8d91dcSmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining
2454a8d91dcSmrgarguments, and rename the output as expected.
2464a8d91dcSmrg
2474a8d91dcSmrgIf you are trying to build a whole package this is not the
2484a8d91dcSmrgright script to run: please start by reading the file 'INSTALL'.
2494a8d91dcSmrg
2504a8d91dcSmrgReport bugs to <bug-automake@gnu.org>.
2514a8d91dcSmrgEOF
2524a8d91dcSmrg    exit $?
2534a8d91dcSmrg    ;;
2544a8d91dcSmrg  -v | --v*)
2554a8d91dcSmrg    echo "compile $scriptversion"
2564a8d91dcSmrg    exit $?
2574a8d91dcSmrg    ;;
2584a8d91dcSmrg  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
2594a8d91dcSmrg    func_cl_wrapper "$@"      # Doesn't return...
2604a8d91dcSmrg    ;;
2614a8d91dcSmrgesac
2624a8d91dcSmrg
2634a8d91dcSmrgofile=
2644a8d91dcSmrgcfile=
2654a8d91dcSmrg
2664a8d91dcSmrgfor arg
2674a8d91dcSmrgdo
2684a8d91dcSmrg  if test -n "$eat"; then
2694a8d91dcSmrg    eat=
2704a8d91dcSmrg  else
2714a8d91dcSmrg    case $1 in
2724a8d91dcSmrg      -o)
2734a8d91dcSmrg	# configure might choose to run compile as 'compile cc -o foo foo.c'.
2744a8d91dcSmrg	# So we strip '-o arg' only if arg is an object.
2754a8d91dcSmrg	eat=1
2764a8d91dcSmrg	case $2 in
2774a8d91dcSmrg	  *.o | *.obj)
2784a8d91dcSmrg	    ofile=$2
2794a8d91dcSmrg	    ;;
2804a8d91dcSmrg	  *)
2814a8d91dcSmrg	    set x "$@" -o "$2"
2824a8d91dcSmrg	    shift
2834a8d91dcSmrg	    ;;
2844a8d91dcSmrg	esac
2854a8d91dcSmrg	;;
2864a8d91dcSmrg      *.c)
2874a8d91dcSmrg	cfile=$1
2884a8d91dcSmrg	set x "$@" "$1"
2894a8d91dcSmrg	shift
2904a8d91dcSmrg	;;
2914a8d91dcSmrg      *)
2924a8d91dcSmrg	set x "$@" "$1"
2934a8d91dcSmrg	shift
2944a8d91dcSmrg	;;
2954a8d91dcSmrg    esac
2964a8d91dcSmrg  fi
2974a8d91dcSmrg  shift
2984a8d91dcSmrgdone
2994a8d91dcSmrg
3004a8d91dcSmrgif test -z "$ofile" || test -z "$cfile"; then
3014a8d91dcSmrg  # If no '-o' option was seen then we might have been invoked from a
3024a8d91dcSmrg  # pattern rule where we don't need one.  That is ok -- this is a
3034a8d91dcSmrg  # normal compilation that the losing compiler can handle.  If no
3044a8d91dcSmrg  # '.c' file was seen then we are probably linking.  That is also
3054a8d91dcSmrg  # ok.
3064a8d91dcSmrg  exec "$@"
3074a8d91dcSmrgfi
3084a8d91dcSmrg
3094a8d91dcSmrg# Name of file we expect compiler to create.
3104a8d91dcSmrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
3114a8d91dcSmrg
3124a8d91dcSmrg# Create the lock directory.
3134a8d91dcSmrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name
3144a8d91dcSmrg# that we are using for the .o file.  Also, base the name on the expected
3154a8d91dcSmrg# object file name, since that is what matters with a parallel build.
3164a8d91dcSmrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
3174a8d91dcSmrgwhile true; do
3184a8d91dcSmrg  if mkdir "$lockdir" >/dev/null 2>&1; then
3194a8d91dcSmrg    break
3204a8d91dcSmrg  fi
3214a8d91dcSmrg  sleep 1
3224a8d91dcSmrgdone
3234a8d91dcSmrg# FIXME: race condition here if user kills between mkdir and trap.
3244a8d91dcSmrgtrap "rmdir '$lockdir'; exit 1" 1 2 15
3254a8d91dcSmrg
3264a8d91dcSmrg# Run the compile.
3274a8d91dcSmrg"$@"
3284a8d91dcSmrgret=$?
3294a8d91dcSmrg
3304a8d91dcSmrgif test -f "$cofile"; then
3314a8d91dcSmrg  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
3324a8d91dcSmrgelif test -f "${cofile}bj"; then
3334a8d91dcSmrg  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
3344a8d91dcSmrgfi
3354a8d91dcSmrg
3364a8d91dcSmrgrmdir "$lockdir"
3374a8d91dcSmrgexit $ret
3384a8d91dcSmrg
3394a8d91dcSmrg# Local Variables:
3404a8d91dcSmrg# mode: shell-script
3414a8d91dcSmrg# sh-indentation: 2
3424a8d91dcSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
3434a8d91dcSmrg# time-stamp-start: "scriptversion="
3444a8d91dcSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
3454a8d91dcSmrg# time-stamp-time-zone: "UTC"
3464a8d91dcSmrg# time-stamp-end: "; # UTC"
3474a8d91dcSmrg# End:
348