compile revision a33c354d
188cd5fc2Smrg#! /bin/sh
288cd5fc2Smrg# Wrapper for compilers which do not understand '-c -o'.
388cd5fc2Smrg
4a33c354dSmrgscriptversion=2018-03-07.03; # UTC
588cd5fc2Smrg
6a33c354dSmrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
788cd5fc2Smrg# Written by Tom Tromey <tromey@cygnus.com>.
888cd5fc2Smrg#
988cd5fc2Smrg# This program is free software; you can redistribute it and/or modify
1088cd5fc2Smrg# it under the terms of the GNU General Public License as published by
1188cd5fc2Smrg# the Free Software Foundation; either version 2, or (at your option)
1288cd5fc2Smrg# any later version.
1388cd5fc2Smrg#
1488cd5fc2Smrg# This program is distributed in the hope that it will be useful,
1588cd5fc2Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1688cd5fc2Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1788cd5fc2Smrg# GNU General Public License for more details.
1888cd5fc2Smrg#
1988cd5fc2Smrg# You should have received a copy of the GNU General Public License
20a33c354dSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2188cd5fc2Smrg
2288cd5fc2Smrg# As a special exception to the GNU General Public License, if you
2388cd5fc2Smrg# distribute this file as part of a program that contains a
2488cd5fc2Smrg# configuration script generated by Autoconf, you may include it under
2588cd5fc2Smrg# the same distribution terms that you use for the rest of that program.
2688cd5fc2Smrg
2788cd5fc2Smrg# This file is maintained in Automake, please report
2888cd5fc2Smrg# bugs to <bug-automake@gnu.org> or send patches to
2988cd5fc2Smrg# <automake-patches@gnu.org>.
3088cd5fc2Smrg
3188cd5fc2Smrgnl='
3288cd5fc2Smrg'
3388cd5fc2Smrg
3488cd5fc2Smrg# We need space, tab and new line, in precisely that order.  Quoting is
3588cd5fc2Smrg# there to prevent tools from complaining about whitespace usage.
3688cd5fc2SmrgIFS=" ""	$nl"
3788cd5fc2Smrg
3888cd5fc2Smrgfile_conv=
3988cd5fc2Smrg
4088cd5fc2Smrg# func_file_conv build_file lazy
4188cd5fc2Smrg# Convert a $build file to $host form and store it in $file
4288cd5fc2Smrg# Currently only supports Windows hosts. If the determined conversion
4388cd5fc2Smrg# type is listed in (the comma separated) LAZY, no conversion will
4488cd5fc2Smrg# take place.
4588cd5fc2Smrgfunc_file_conv ()
4688cd5fc2Smrg{
4788cd5fc2Smrg  file=$1
4888cd5fc2Smrg  case $file in
4988cd5fc2Smrg    / | /[!/]*) # absolute file, and not a UNC file
5088cd5fc2Smrg      if test -z "$file_conv"; then
5188cd5fc2Smrg	# lazily determine how to convert abs files
5288cd5fc2Smrg	case `uname -s` in
5388cd5fc2Smrg	  MINGW*)
5488cd5fc2Smrg	    file_conv=mingw
5588cd5fc2Smrg	    ;;
56a33c354dSmrg	  CYGWIN* | MSYS*)
5788cd5fc2Smrg	    file_conv=cygwin
5888cd5fc2Smrg	    ;;
5988cd5fc2Smrg	  *)
6088cd5fc2Smrg	    file_conv=wine
6188cd5fc2Smrg	    ;;
6288cd5fc2Smrg	esac
6388cd5fc2Smrg      fi
6488cd5fc2Smrg      case $file_conv/,$2, in
6588cd5fc2Smrg	*,$file_conv,*)
6688cd5fc2Smrg	  ;;
6788cd5fc2Smrg	mingw/*)
6888cd5fc2Smrg	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
6988cd5fc2Smrg	  ;;
70a33c354dSmrg	cygwin/* | msys/*)
7188cd5fc2Smrg	  file=`cygpath -m "$file" || echo "$file"`
7288cd5fc2Smrg	  ;;
7388cd5fc2Smrg	wine/*)
7488cd5fc2Smrg	  file=`winepath -w "$file" || echo "$file"`
7588cd5fc2Smrg	  ;;
7688cd5fc2Smrg      esac
7788cd5fc2Smrg      ;;
7888cd5fc2Smrg  esac
7988cd5fc2Smrg}
8088cd5fc2Smrg
8188cd5fc2Smrg# func_cl_dashL linkdir
8288cd5fc2Smrg# Make cl look for libraries in LINKDIR
8388cd5fc2Smrgfunc_cl_dashL ()
8488cd5fc2Smrg{
8588cd5fc2Smrg  func_file_conv "$1"
8688cd5fc2Smrg  if test -z "$lib_path"; then
8788cd5fc2Smrg    lib_path=$file
8888cd5fc2Smrg  else
8988cd5fc2Smrg    lib_path="$lib_path;$file"
9088cd5fc2Smrg  fi
9188cd5fc2Smrg  linker_opts="$linker_opts -LIBPATH:$file"
9288cd5fc2Smrg}
9388cd5fc2Smrg
9488cd5fc2Smrg# func_cl_dashl library
9588cd5fc2Smrg# Do a library search-path lookup for cl
9688cd5fc2Smrgfunc_cl_dashl ()
9788cd5fc2Smrg{
9888cd5fc2Smrg  lib=$1
9988cd5fc2Smrg  found=no
10088cd5fc2Smrg  save_IFS=$IFS
10188cd5fc2Smrg  IFS=';'
10288cd5fc2Smrg  for dir in $lib_path $LIB
10388cd5fc2Smrg  do
10488cd5fc2Smrg    IFS=$save_IFS
10588cd5fc2Smrg    if $shared && test -f "$dir/$lib.dll.lib"; then
10688cd5fc2Smrg      found=yes
10788cd5fc2Smrg      lib=$dir/$lib.dll.lib
10888cd5fc2Smrg      break
10988cd5fc2Smrg    fi
11088cd5fc2Smrg    if test -f "$dir/$lib.lib"; then
11188cd5fc2Smrg      found=yes
11288cd5fc2Smrg      lib=$dir/$lib.lib
11388cd5fc2Smrg      break
11488cd5fc2Smrg    fi
11588cd5fc2Smrg    if test -f "$dir/lib$lib.a"; then
11688cd5fc2Smrg      found=yes
11788cd5fc2Smrg      lib=$dir/lib$lib.a
11888cd5fc2Smrg      break
11988cd5fc2Smrg    fi
12088cd5fc2Smrg  done
12188cd5fc2Smrg  IFS=$save_IFS
12288cd5fc2Smrg
12388cd5fc2Smrg  if test "$found" != yes; then
12488cd5fc2Smrg    lib=$lib.lib
12588cd5fc2Smrg  fi
12688cd5fc2Smrg}
12788cd5fc2Smrg
12888cd5fc2Smrg# func_cl_wrapper cl arg...
12988cd5fc2Smrg# Adjust compile command to suit cl
13088cd5fc2Smrgfunc_cl_wrapper ()
13188cd5fc2Smrg{
13288cd5fc2Smrg  # Assume a capable shell
13388cd5fc2Smrg  lib_path=
13488cd5fc2Smrg  shared=:
13588cd5fc2Smrg  linker_opts=
13688cd5fc2Smrg  for arg
13788cd5fc2Smrg  do
13888cd5fc2Smrg    if test -n "$eat"; then
13988cd5fc2Smrg      eat=
14088cd5fc2Smrg    else
14188cd5fc2Smrg      case $1 in
14288cd5fc2Smrg	-o)
14388cd5fc2Smrg	  # configure might choose to run compile as 'compile cc -o foo foo.c'.
14488cd5fc2Smrg	  eat=1
14588cd5fc2Smrg	  case $2 in
14688cd5fc2Smrg	    *.o | *.[oO][bB][jJ])
14788cd5fc2Smrg	      func_file_conv "$2"
14888cd5fc2Smrg	      set x "$@" -Fo"$file"
14988cd5fc2Smrg	      shift
15088cd5fc2Smrg	      ;;
15188cd5fc2Smrg	    *)
15288cd5fc2Smrg	      func_file_conv "$2"
15388cd5fc2Smrg	      set x "$@" -Fe"$file"
15488cd5fc2Smrg	      shift
15588cd5fc2Smrg	      ;;
15688cd5fc2Smrg	  esac
15788cd5fc2Smrg	  ;;
15888cd5fc2Smrg	-I)
15988cd5fc2Smrg	  eat=1
16088cd5fc2Smrg	  func_file_conv "$2" mingw
16188cd5fc2Smrg	  set x "$@" -I"$file"
16288cd5fc2Smrg	  shift
16388cd5fc2Smrg	  ;;
16488cd5fc2Smrg	-I*)
16588cd5fc2Smrg	  func_file_conv "${1#-I}" mingw
16688cd5fc2Smrg	  set x "$@" -I"$file"
16788cd5fc2Smrg	  shift
16888cd5fc2Smrg	  ;;
16988cd5fc2Smrg	-l)
17088cd5fc2Smrg	  eat=1
17188cd5fc2Smrg	  func_cl_dashl "$2"
17288cd5fc2Smrg	  set x "$@" "$lib"
17388cd5fc2Smrg	  shift
17488cd5fc2Smrg	  ;;
17588cd5fc2Smrg	-l*)
17688cd5fc2Smrg	  func_cl_dashl "${1#-l}"
17788cd5fc2Smrg	  set x "$@" "$lib"
17888cd5fc2Smrg	  shift
17988cd5fc2Smrg	  ;;
18088cd5fc2Smrg	-L)
18188cd5fc2Smrg	  eat=1
18288cd5fc2Smrg	  func_cl_dashL "$2"
18388cd5fc2Smrg	  ;;
18488cd5fc2Smrg	-L*)
18588cd5fc2Smrg	  func_cl_dashL "${1#-L}"
18688cd5fc2Smrg	  ;;
18788cd5fc2Smrg	-static)
18888cd5fc2Smrg	  shared=false
18988cd5fc2Smrg	  ;;
19088cd5fc2Smrg	-Wl,*)
19188cd5fc2Smrg	  arg=${1#-Wl,}
19288cd5fc2Smrg	  save_ifs="$IFS"; IFS=','
19388cd5fc2Smrg	  for flag in $arg; do
19488cd5fc2Smrg	    IFS="$save_ifs"
19588cd5fc2Smrg	    linker_opts="$linker_opts $flag"
19688cd5fc2Smrg	  done
19788cd5fc2Smrg	  IFS="$save_ifs"
19888cd5fc2Smrg	  ;;
19988cd5fc2Smrg	-Xlinker)
20088cd5fc2Smrg	  eat=1
20188cd5fc2Smrg	  linker_opts="$linker_opts $2"
20288cd5fc2Smrg	  ;;
20388cd5fc2Smrg	-*)
20488cd5fc2Smrg	  set x "$@" "$1"
20588cd5fc2Smrg	  shift
20688cd5fc2Smrg	  ;;
20788cd5fc2Smrg	*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
20888cd5fc2Smrg	  func_file_conv "$1"
20988cd5fc2Smrg	  set x "$@" -Tp"$file"
21088cd5fc2Smrg	  shift
21188cd5fc2Smrg	  ;;
21288cd5fc2Smrg	*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
21388cd5fc2Smrg	  func_file_conv "$1" mingw
21488cd5fc2Smrg	  set x "$@" "$file"
21588cd5fc2Smrg	  shift
21688cd5fc2Smrg	  ;;
21788cd5fc2Smrg	*)
21888cd5fc2Smrg	  set x "$@" "$1"
21988cd5fc2Smrg	  shift
22088cd5fc2Smrg	  ;;
22188cd5fc2Smrg      esac
22288cd5fc2Smrg    fi
22388cd5fc2Smrg    shift
22488cd5fc2Smrg  done
22588cd5fc2Smrg  if test -n "$linker_opts"; then
22688cd5fc2Smrg    linker_opts="-link$linker_opts"
22788cd5fc2Smrg  fi
22888cd5fc2Smrg  exec "$@" $linker_opts
22988cd5fc2Smrg  exit 1
23088cd5fc2Smrg}
23188cd5fc2Smrg
23288cd5fc2Smrgeat=
23388cd5fc2Smrg
23488cd5fc2Smrgcase $1 in
23588cd5fc2Smrg  '')
23688cd5fc2Smrg     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
23788cd5fc2Smrg     exit 1;
23888cd5fc2Smrg     ;;
23988cd5fc2Smrg  -h | --h*)
24088cd5fc2Smrg    cat <<\EOF
24188cd5fc2SmrgUsage: compile [--help] [--version] PROGRAM [ARGS]
24288cd5fc2Smrg
24388cd5fc2SmrgWrapper for compilers which do not understand '-c -o'.
24488cd5fc2SmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining
24588cd5fc2Smrgarguments, and rename the output as expected.
24688cd5fc2Smrg
24788cd5fc2SmrgIf you are trying to build a whole package this is not the
24888cd5fc2Smrgright script to run: please start by reading the file 'INSTALL'.
24988cd5fc2Smrg
25088cd5fc2SmrgReport bugs to <bug-automake@gnu.org>.
25188cd5fc2SmrgEOF
25288cd5fc2Smrg    exit $?
25388cd5fc2Smrg    ;;
25488cd5fc2Smrg  -v | --v*)
25588cd5fc2Smrg    echo "compile $scriptversion"
25688cd5fc2Smrg    exit $?
25788cd5fc2Smrg    ;;
258a33c354dSmrg  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \
259a33c354dSmrg  icl | *[/\\]icl | icl.exe | *[/\\]icl.exe )
26088cd5fc2Smrg    func_cl_wrapper "$@"      # Doesn't return...
26188cd5fc2Smrg    ;;
26288cd5fc2Smrgesac
26388cd5fc2Smrg
26488cd5fc2Smrgofile=
26588cd5fc2Smrgcfile=
26688cd5fc2Smrg
26788cd5fc2Smrgfor arg
26888cd5fc2Smrgdo
26988cd5fc2Smrg  if test -n "$eat"; then
27088cd5fc2Smrg    eat=
27188cd5fc2Smrg  else
27288cd5fc2Smrg    case $1 in
27388cd5fc2Smrg      -o)
27488cd5fc2Smrg	# configure might choose to run compile as 'compile cc -o foo foo.c'.
27588cd5fc2Smrg	# So we strip '-o arg' only if arg is an object.
27688cd5fc2Smrg	eat=1
27788cd5fc2Smrg	case $2 in
27888cd5fc2Smrg	  *.o | *.obj)
27988cd5fc2Smrg	    ofile=$2
28088cd5fc2Smrg	    ;;
28188cd5fc2Smrg	  *)
28288cd5fc2Smrg	    set x "$@" -o "$2"
28388cd5fc2Smrg	    shift
28488cd5fc2Smrg	    ;;
28588cd5fc2Smrg	esac
28688cd5fc2Smrg	;;
28788cd5fc2Smrg      *.c)
28888cd5fc2Smrg	cfile=$1
28988cd5fc2Smrg	set x "$@" "$1"
29088cd5fc2Smrg	shift
29188cd5fc2Smrg	;;
29288cd5fc2Smrg      *)
29388cd5fc2Smrg	set x "$@" "$1"
29488cd5fc2Smrg	shift
29588cd5fc2Smrg	;;
29688cd5fc2Smrg    esac
29788cd5fc2Smrg  fi
29888cd5fc2Smrg  shift
29988cd5fc2Smrgdone
30088cd5fc2Smrg
30188cd5fc2Smrgif test -z "$ofile" || test -z "$cfile"; then
30288cd5fc2Smrg  # If no '-o' option was seen then we might have been invoked from a
30388cd5fc2Smrg  # pattern rule where we don't need one.  That is ok -- this is a
30488cd5fc2Smrg  # normal compilation that the losing compiler can handle.  If no
30588cd5fc2Smrg  # '.c' file was seen then we are probably linking.  That is also
30688cd5fc2Smrg  # ok.
30788cd5fc2Smrg  exec "$@"
30888cd5fc2Smrgfi
30988cd5fc2Smrg
31088cd5fc2Smrg# Name of file we expect compiler to create.
31188cd5fc2Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
31288cd5fc2Smrg
31388cd5fc2Smrg# Create the lock directory.
31488cd5fc2Smrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name
31588cd5fc2Smrg# that we are using for the .o file.  Also, base the name on the expected
31688cd5fc2Smrg# object file name, since that is what matters with a parallel build.
31788cd5fc2Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
31888cd5fc2Smrgwhile true; do
31988cd5fc2Smrg  if mkdir "$lockdir" >/dev/null 2>&1; then
32088cd5fc2Smrg    break
32188cd5fc2Smrg  fi
32288cd5fc2Smrg  sleep 1
32388cd5fc2Smrgdone
32488cd5fc2Smrg# FIXME: race condition here if user kills between mkdir and trap.
32588cd5fc2Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15
32688cd5fc2Smrg
32788cd5fc2Smrg# Run the compile.
32888cd5fc2Smrg"$@"
32988cd5fc2Smrgret=$?
33088cd5fc2Smrg
33188cd5fc2Smrgif test -f "$cofile"; then
33288cd5fc2Smrg  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
33388cd5fc2Smrgelif test -f "${cofile}bj"; then
33488cd5fc2Smrg  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
33588cd5fc2Smrgfi
33688cd5fc2Smrg
33788cd5fc2Smrgrmdir "$lockdir"
33888cd5fc2Smrgexit $ret
33988cd5fc2Smrg
34088cd5fc2Smrg# Local Variables:
34188cd5fc2Smrg# mode: shell-script
34288cd5fc2Smrg# sh-indentation: 2
343a33c354dSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
34488cd5fc2Smrg# time-stamp-start: "scriptversion="
34588cd5fc2Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
346a33c354dSmrg# time-stamp-time-zone: "UTC0"
34788cd5fc2Smrg# time-stamp-end: "; # UTC"
34888cd5fc2Smrg# End:
349