113498266Sopenharmony_ci#! /bin/sh
213498266Sopenharmony_ci# Wrapper for compilers which do not understand '-c -o'.
313498266Sopenharmony_ci
413498266Sopenharmony_ciscriptversion=2018-03-07.03; # UTC
513498266Sopenharmony_ci
613498266Sopenharmony_ci# Copyright (C) 1999-2021 Free Software Foundation, Inc.
713498266Sopenharmony_ci# Written by Tom Tromey <tromey@cygnus.com>.
813498266Sopenharmony_ci#
913498266Sopenharmony_ci# This program is free software; you can redistribute it and/or modify
1013498266Sopenharmony_ci# it under the terms of the GNU General Public License as published by
1113498266Sopenharmony_ci# the Free Software Foundation; either version 2, or (at your option)
1213498266Sopenharmony_ci# any later version.
1313498266Sopenharmony_ci#
1413498266Sopenharmony_ci# This program is distributed in the hope that it will be useful,
1513498266Sopenharmony_ci# but WITHOUT ANY WARRANTY; without even the implied warranty of
1613498266Sopenharmony_ci# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1713498266Sopenharmony_ci# GNU General Public License for more details.
1813498266Sopenharmony_ci#
1913498266Sopenharmony_ci# You should have received a copy of the GNU General Public License
2013498266Sopenharmony_ci# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2113498266Sopenharmony_ci
2213498266Sopenharmony_ci# As a special exception to the GNU General Public License, if you
2313498266Sopenharmony_ci# distribute this file as part of a program that contains a
2413498266Sopenharmony_ci# configuration script generated by Autoconf, you may include it under
2513498266Sopenharmony_ci# the same distribution terms that you use for the rest of that program.
2613498266Sopenharmony_ci
2713498266Sopenharmony_ci# This file is maintained in Automake, please report
2813498266Sopenharmony_ci# bugs to <bug-automake@gnu.org> or send patches to
2913498266Sopenharmony_ci# <automake-patches@gnu.org>.
3013498266Sopenharmony_ci
3113498266Sopenharmony_cinl='
3213498266Sopenharmony_ci'
3313498266Sopenharmony_ci
3413498266Sopenharmony_ci# We need space, tab and new line, in precisely that order.  Quoting is
3513498266Sopenharmony_ci# there to prevent tools from complaining about whitespace usage.
3613498266Sopenharmony_ciIFS=" ""	$nl"
3713498266Sopenharmony_ci
3813498266Sopenharmony_cifile_conv=
3913498266Sopenharmony_ci
4013498266Sopenharmony_ci# func_file_conv build_file lazy
4113498266Sopenharmony_ci# Convert a $build file to $host form and store it in $file
4213498266Sopenharmony_ci# Currently only supports Windows hosts. If the determined conversion
4313498266Sopenharmony_ci# type is listed in (the comma separated) LAZY, no conversion will
4413498266Sopenharmony_ci# take place.
4513498266Sopenharmony_cifunc_file_conv ()
4613498266Sopenharmony_ci{
4713498266Sopenharmony_ci  file=$1
4813498266Sopenharmony_ci  case $file in
4913498266Sopenharmony_ci    / | /[!/]*) # absolute file, and not a UNC file
5013498266Sopenharmony_ci      if test -z "$file_conv"; then
5113498266Sopenharmony_ci	# lazily determine how to convert abs files
5213498266Sopenharmony_ci	case `uname -s` in
5313498266Sopenharmony_ci	  MINGW*)
5413498266Sopenharmony_ci	    file_conv=mingw
5513498266Sopenharmony_ci	    ;;
5613498266Sopenharmony_ci	  CYGWIN* | MSYS*)
5713498266Sopenharmony_ci	    file_conv=cygwin
5813498266Sopenharmony_ci	    ;;
5913498266Sopenharmony_ci	  *)
6013498266Sopenharmony_ci	    file_conv=wine
6113498266Sopenharmony_ci	    ;;
6213498266Sopenharmony_ci	esac
6313498266Sopenharmony_ci      fi
6413498266Sopenharmony_ci      case $file_conv/,$2, in
6513498266Sopenharmony_ci	*,$file_conv,*)
6613498266Sopenharmony_ci	  ;;
6713498266Sopenharmony_ci	mingw/*)
6813498266Sopenharmony_ci	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
6913498266Sopenharmony_ci	  ;;
7013498266Sopenharmony_ci	cygwin/* | msys/*)
7113498266Sopenharmony_ci	  file=`cygpath -m "$file" || echo "$file"`
7213498266Sopenharmony_ci	  ;;
7313498266Sopenharmony_ci	wine/*)
7413498266Sopenharmony_ci	  file=`winepath -w "$file" || echo "$file"`
7513498266Sopenharmony_ci	  ;;
7613498266Sopenharmony_ci      esac
7713498266Sopenharmony_ci      ;;
7813498266Sopenharmony_ci  esac
7913498266Sopenharmony_ci}
8013498266Sopenharmony_ci
8113498266Sopenharmony_ci# func_cl_dashL linkdir
8213498266Sopenharmony_ci# Make cl look for libraries in LINKDIR
8313498266Sopenharmony_cifunc_cl_dashL ()
8413498266Sopenharmony_ci{
8513498266Sopenharmony_ci  func_file_conv "$1"
8613498266Sopenharmony_ci  if test -z "$lib_path"; then
8713498266Sopenharmony_ci    lib_path=$file
8813498266Sopenharmony_ci  else
8913498266Sopenharmony_ci    lib_path="$lib_path;$file"
9013498266Sopenharmony_ci  fi
9113498266Sopenharmony_ci  linker_opts="$linker_opts -LIBPATH:$file"
9213498266Sopenharmony_ci}
9313498266Sopenharmony_ci
9413498266Sopenharmony_ci# func_cl_dashl library
9513498266Sopenharmony_ci# Do a library search-path lookup for cl
9613498266Sopenharmony_cifunc_cl_dashl ()
9713498266Sopenharmony_ci{
9813498266Sopenharmony_ci  lib=$1
9913498266Sopenharmony_ci  found=no
10013498266Sopenharmony_ci  save_IFS=$IFS
10113498266Sopenharmony_ci  IFS=';'
10213498266Sopenharmony_ci  for dir in $lib_path $LIB
10313498266Sopenharmony_ci  do
10413498266Sopenharmony_ci    IFS=$save_IFS
10513498266Sopenharmony_ci    if $shared && test -f "$dir/$lib.dll.lib"; then
10613498266Sopenharmony_ci      found=yes
10713498266Sopenharmony_ci      lib=$dir/$lib.dll.lib
10813498266Sopenharmony_ci      break
10913498266Sopenharmony_ci    fi
11013498266Sopenharmony_ci    if test -f "$dir/$lib.lib"; then
11113498266Sopenharmony_ci      found=yes
11213498266Sopenharmony_ci      lib=$dir/$lib.lib
11313498266Sopenharmony_ci      break
11413498266Sopenharmony_ci    fi
11513498266Sopenharmony_ci    if test -f "$dir/lib$lib.a"; then
11613498266Sopenharmony_ci      found=yes
11713498266Sopenharmony_ci      lib=$dir/lib$lib.a
11813498266Sopenharmony_ci      break
11913498266Sopenharmony_ci    fi
12013498266Sopenharmony_ci  done
12113498266Sopenharmony_ci  IFS=$save_IFS
12213498266Sopenharmony_ci
12313498266Sopenharmony_ci  if test "$found" != yes; then
12413498266Sopenharmony_ci    lib=$lib.lib
12513498266Sopenharmony_ci  fi
12613498266Sopenharmony_ci}
12713498266Sopenharmony_ci
12813498266Sopenharmony_ci# func_cl_wrapper cl arg...
12913498266Sopenharmony_ci# Adjust compile command to suit cl
13013498266Sopenharmony_cifunc_cl_wrapper ()
13113498266Sopenharmony_ci{
13213498266Sopenharmony_ci  # Assume a capable shell
13313498266Sopenharmony_ci  lib_path=
13413498266Sopenharmony_ci  shared=:
13513498266Sopenharmony_ci  linker_opts=
13613498266Sopenharmony_ci  for arg
13713498266Sopenharmony_ci  do
13813498266Sopenharmony_ci    if test -n "$eat"; then
13913498266Sopenharmony_ci      eat=
14013498266Sopenharmony_ci    else
14113498266Sopenharmony_ci      case $1 in
14213498266Sopenharmony_ci	-o)
14313498266Sopenharmony_ci	  # configure might choose to run compile as 'compile cc -o foo foo.c'.
14413498266Sopenharmony_ci	  eat=1
14513498266Sopenharmony_ci	  case $2 in
14613498266Sopenharmony_ci	    *.o | *.[oO][bB][jJ])
14713498266Sopenharmony_ci	      func_file_conv "$2"
14813498266Sopenharmony_ci	      set x "$@" -Fo"$file"
14913498266Sopenharmony_ci	      shift
15013498266Sopenharmony_ci	      ;;
15113498266Sopenharmony_ci	    *)
15213498266Sopenharmony_ci	      func_file_conv "$2"
15313498266Sopenharmony_ci	      set x "$@" -Fe"$file"
15413498266Sopenharmony_ci	      shift
15513498266Sopenharmony_ci	      ;;
15613498266Sopenharmony_ci	  esac
15713498266Sopenharmony_ci	  ;;
15813498266Sopenharmony_ci	-I)
15913498266Sopenharmony_ci	  eat=1
16013498266Sopenharmony_ci	  func_file_conv "$2" mingw
16113498266Sopenharmony_ci	  set x "$@" -I"$file"
16213498266Sopenharmony_ci	  shift
16313498266Sopenharmony_ci	  ;;
16413498266Sopenharmony_ci	-I*)
16513498266Sopenharmony_ci	  func_file_conv "${1#-I}" mingw
16613498266Sopenharmony_ci	  set x "$@" -I"$file"
16713498266Sopenharmony_ci	  shift
16813498266Sopenharmony_ci	  ;;
16913498266Sopenharmony_ci	-l)
17013498266Sopenharmony_ci	  eat=1
17113498266Sopenharmony_ci	  func_cl_dashl "$2"
17213498266Sopenharmony_ci	  set x "$@" "$lib"
17313498266Sopenharmony_ci	  shift
17413498266Sopenharmony_ci	  ;;
17513498266Sopenharmony_ci	-l*)
17613498266Sopenharmony_ci	  func_cl_dashl "${1#-l}"
17713498266Sopenharmony_ci	  set x "$@" "$lib"
17813498266Sopenharmony_ci	  shift
17913498266Sopenharmony_ci	  ;;
18013498266Sopenharmony_ci	-L)
18113498266Sopenharmony_ci	  eat=1
18213498266Sopenharmony_ci	  func_cl_dashL "$2"
18313498266Sopenharmony_ci	  ;;
18413498266Sopenharmony_ci	-L*)
18513498266Sopenharmony_ci	  func_cl_dashL "${1#-L}"
18613498266Sopenharmony_ci	  ;;
18713498266Sopenharmony_ci	-static)
18813498266Sopenharmony_ci	  shared=false
18913498266Sopenharmony_ci	  ;;
19013498266Sopenharmony_ci	-Wl,*)
19113498266Sopenharmony_ci	  arg=${1#-Wl,}
19213498266Sopenharmony_ci	  save_ifs="$IFS"; IFS=','
19313498266Sopenharmony_ci	  for flag in $arg; do
19413498266Sopenharmony_ci	    IFS="$save_ifs"
19513498266Sopenharmony_ci	    linker_opts="$linker_opts $flag"
19613498266Sopenharmony_ci	  done
19713498266Sopenharmony_ci	  IFS="$save_ifs"
19813498266Sopenharmony_ci	  ;;
19913498266Sopenharmony_ci	-Xlinker)
20013498266Sopenharmony_ci	  eat=1
20113498266Sopenharmony_ci	  linker_opts="$linker_opts $2"
20213498266Sopenharmony_ci	  ;;
20313498266Sopenharmony_ci	-*)
20413498266Sopenharmony_ci	  set x "$@" "$1"
20513498266Sopenharmony_ci	  shift
20613498266Sopenharmony_ci	  ;;
20713498266Sopenharmony_ci	*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
20813498266Sopenharmony_ci	  func_file_conv "$1"
20913498266Sopenharmony_ci	  set x "$@" -Tp"$file"
21013498266Sopenharmony_ci	  shift
21113498266Sopenharmony_ci	  ;;
21213498266Sopenharmony_ci	*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
21313498266Sopenharmony_ci	  func_file_conv "$1" mingw
21413498266Sopenharmony_ci	  set x "$@" "$file"
21513498266Sopenharmony_ci	  shift
21613498266Sopenharmony_ci	  ;;
21713498266Sopenharmony_ci	*)
21813498266Sopenharmony_ci	  set x "$@" "$1"
21913498266Sopenharmony_ci	  shift
22013498266Sopenharmony_ci	  ;;
22113498266Sopenharmony_ci      esac
22213498266Sopenharmony_ci    fi
22313498266Sopenharmony_ci    shift
22413498266Sopenharmony_ci  done
22513498266Sopenharmony_ci  if test -n "$linker_opts"; then
22613498266Sopenharmony_ci    linker_opts="-link$linker_opts"
22713498266Sopenharmony_ci  fi
22813498266Sopenharmony_ci  exec "$@" $linker_opts
22913498266Sopenharmony_ci  exit 1
23013498266Sopenharmony_ci}
23113498266Sopenharmony_ci
23213498266Sopenharmony_cieat=
23313498266Sopenharmony_ci
23413498266Sopenharmony_cicase $1 in
23513498266Sopenharmony_ci  '')
23613498266Sopenharmony_ci     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
23713498266Sopenharmony_ci     exit 1;
23813498266Sopenharmony_ci     ;;
23913498266Sopenharmony_ci  -h | --h*)
24013498266Sopenharmony_ci    cat <<\EOF
24113498266Sopenharmony_ciUsage: compile [--help] [--version] PROGRAM [ARGS]
24213498266Sopenharmony_ci
24313498266Sopenharmony_ciWrapper for compilers which do not understand '-c -o'.
24413498266Sopenharmony_ciRemove '-o dest.o' from ARGS, run PROGRAM with the remaining
24513498266Sopenharmony_ciarguments, and rename the output as expected.
24613498266Sopenharmony_ci
24713498266Sopenharmony_ciIf you are trying to build a whole package this is not the
24813498266Sopenharmony_ciright script to run: please start by reading the file 'INSTALL'.
24913498266Sopenharmony_ci
25013498266Sopenharmony_ciReport bugs to <bug-automake@gnu.org>.
25113498266Sopenharmony_ciEOF
25213498266Sopenharmony_ci    exit $?
25313498266Sopenharmony_ci    ;;
25413498266Sopenharmony_ci  -v | --v*)
25513498266Sopenharmony_ci    echo "compile $scriptversion"
25613498266Sopenharmony_ci    exit $?
25713498266Sopenharmony_ci    ;;
25813498266Sopenharmony_ci  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \
25913498266Sopenharmony_ci  icl | *[/\\]icl | icl.exe | *[/\\]icl.exe )
26013498266Sopenharmony_ci    func_cl_wrapper "$@"      # Doesn't return...
26113498266Sopenharmony_ci    ;;
26213498266Sopenharmony_ciesac
26313498266Sopenharmony_ci
26413498266Sopenharmony_ciofile=
26513498266Sopenharmony_cicfile=
26613498266Sopenharmony_ci
26713498266Sopenharmony_cifor arg
26813498266Sopenharmony_cido
26913498266Sopenharmony_ci  if test -n "$eat"; then
27013498266Sopenharmony_ci    eat=
27113498266Sopenharmony_ci  else
27213498266Sopenharmony_ci    case $1 in
27313498266Sopenharmony_ci      -o)
27413498266Sopenharmony_ci	# configure might choose to run compile as 'compile cc -o foo foo.c'.
27513498266Sopenharmony_ci	# So we strip '-o arg' only if arg is an object.
27613498266Sopenharmony_ci	eat=1
27713498266Sopenharmony_ci	case $2 in
27813498266Sopenharmony_ci	  *.o | *.obj)
27913498266Sopenharmony_ci	    ofile=$2
28013498266Sopenharmony_ci	    ;;
28113498266Sopenharmony_ci	  *)
28213498266Sopenharmony_ci	    set x "$@" -o "$2"
28313498266Sopenharmony_ci	    shift
28413498266Sopenharmony_ci	    ;;
28513498266Sopenharmony_ci	esac
28613498266Sopenharmony_ci	;;
28713498266Sopenharmony_ci      *.c)
28813498266Sopenharmony_ci	cfile=$1
28913498266Sopenharmony_ci	set x "$@" "$1"
29013498266Sopenharmony_ci	shift
29113498266Sopenharmony_ci	;;
29213498266Sopenharmony_ci      *)
29313498266Sopenharmony_ci	set x "$@" "$1"
29413498266Sopenharmony_ci	shift
29513498266Sopenharmony_ci	;;
29613498266Sopenharmony_ci    esac
29713498266Sopenharmony_ci  fi
29813498266Sopenharmony_ci  shift
29913498266Sopenharmony_cidone
30013498266Sopenharmony_ci
30113498266Sopenharmony_ciif test -z "$ofile" || test -z "$cfile"; then
30213498266Sopenharmony_ci  # If no '-o' option was seen then we might have been invoked from a
30313498266Sopenharmony_ci  # pattern rule where we don't need one.  That is ok -- this is a
30413498266Sopenharmony_ci  # normal compilation that the losing compiler can handle.  If no
30513498266Sopenharmony_ci  # '.c' file was seen then we are probably linking.  That is also
30613498266Sopenharmony_ci  # ok.
30713498266Sopenharmony_ci  exec "$@"
30813498266Sopenharmony_cifi
30913498266Sopenharmony_ci
31013498266Sopenharmony_ci# Name of file we expect compiler to create.
31113498266Sopenharmony_cicofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
31213498266Sopenharmony_ci
31313498266Sopenharmony_ci# Create the lock directory.
31413498266Sopenharmony_ci# Note: use '[/\\:.-]' here to ensure that we don't use the same name
31513498266Sopenharmony_ci# that we are using for the .o file.  Also, base the name on the expected
31613498266Sopenharmony_ci# object file name, since that is what matters with a parallel build.
31713498266Sopenharmony_cilockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
31813498266Sopenharmony_ciwhile true; do
31913498266Sopenharmony_ci  if mkdir "$lockdir" >/dev/null 2>&1; then
32013498266Sopenharmony_ci    break
32113498266Sopenharmony_ci  fi
32213498266Sopenharmony_ci  sleep 1
32313498266Sopenharmony_cidone
32413498266Sopenharmony_ci# FIXME: race condition here if user kills between mkdir and trap.
32513498266Sopenharmony_citrap "rmdir '$lockdir'; exit 1" 1 2 15
32613498266Sopenharmony_ci
32713498266Sopenharmony_ci# Run the compile.
32813498266Sopenharmony_ci"$@"
32913498266Sopenharmony_ciret=$?
33013498266Sopenharmony_ci
33113498266Sopenharmony_ciif test -f "$cofile"; then
33213498266Sopenharmony_ci  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
33313498266Sopenharmony_cielif test -f "${cofile}bj"; then
33413498266Sopenharmony_ci  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
33513498266Sopenharmony_cifi
33613498266Sopenharmony_ci
33713498266Sopenharmony_cirmdir "$lockdir"
33813498266Sopenharmony_ciexit $ret
33913498266Sopenharmony_ci
34013498266Sopenharmony_ci# Local Variables:
34113498266Sopenharmony_ci# mode: shell-script
34213498266Sopenharmony_ci# sh-indentation: 2
34313498266Sopenharmony_ci# eval: (add-hook 'before-save-hook 'time-stamp)
34413498266Sopenharmony_ci# time-stamp-start: "scriptversion="
34513498266Sopenharmony_ci# time-stamp-format: "%:y-%02m-%02d.%02H"
34613498266Sopenharmony_ci# time-stamp-time-zone: "UTC0"
34713498266Sopenharmony_ci# time-stamp-end: "; # UTC"
34813498266Sopenharmony_ci# End:
349