147a64adfSmrg#! /bin/sh
247a64adfSmrg# Wrapper for compilers which do not understand '-c -o'.
347a64adfSmrg
42aafc1e6Smrgscriptversion=2018-03-07.03; # UTC
547a64adfSmrg
62aafc1e6Smrg# Copyright (C) 1999-2021 Free Software Foundation, Inc.
747a64adfSmrg# Written by Tom Tromey <tromey@cygnus.com>.
847a64adfSmrg#
947a64adfSmrg# This program is free software; you can redistribute it and/or modify
1047a64adfSmrg# it under the terms of the GNU General Public License as published by
1147a64adfSmrg# the Free Software Foundation; either version 2, or (at your option)
1247a64adfSmrg# any later version.
1347a64adfSmrg#
1447a64adfSmrg# This program is distributed in the hope that it will be useful,
1547a64adfSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1647a64adfSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1747a64adfSmrg# GNU General Public License for more details.
1847a64adfSmrg#
1947a64adfSmrg# You should have received a copy of the GNU General Public License
202aafc1e6Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2147a64adfSmrg
2247a64adfSmrg# As a special exception to the GNU General Public License, if you
2347a64adfSmrg# distribute this file as part of a program that contains a
2447a64adfSmrg# configuration script generated by Autoconf, you may include it under
2547a64adfSmrg# the same distribution terms that you use for the rest of that program.
2647a64adfSmrg
2747a64adfSmrg# This file is maintained in Automake, please report
2847a64adfSmrg# bugs to <bug-automake@gnu.org> or send patches to
2947a64adfSmrg# <automake-patches@gnu.org>.
3047a64adfSmrg
3147a64adfSmrgnl='
3247a64adfSmrg'
3347a64adfSmrg
3447a64adfSmrg# We need space, tab and new line, in precisely that order.  Quoting is
3547a64adfSmrg# there to prevent tools from complaining about whitespace usage.
3647a64adfSmrgIFS=" ""	$nl"
3747a64adfSmrg
3847a64adfSmrgfile_conv=
3947a64adfSmrg
4047a64adfSmrg# func_file_conv build_file lazy
4147a64adfSmrg# Convert a $build file to $host form and store it in $file
4247a64adfSmrg# Currently only supports Windows hosts. If the determined conversion
4347a64adfSmrg# type is listed in (the comma separated) LAZY, no conversion will
4447a64adfSmrg# take place.
4547a64adfSmrgfunc_file_conv ()
4647a64adfSmrg{
4747a64adfSmrg  file=$1
4847a64adfSmrg  case $file in
4947a64adfSmrg    / | /[!/]*) # absolute file, and not a UNC file
5047a64adfSmrg      if test -z "$file_conv"; then
5147a64adfSmrg	# lazily determine how to convert abs files
5247a64adfSmrg	case `uname -s` in
5347a64adfSmrg	  MINGW*)
5447a64adfSmrg	    file_conv=mingw
5547a64adfSmrg	    ;;
562aafc1e6Smrg	  CYGWIN* | MSYS*)
5747a64adfSmrg	    file_conv=cygwin
5847a64adfSmrg	    ;;
5947a64adfSmrg	  *)
6047a64adfSmrg	    file_conv=wine
6147a64adfSmrg	    ;;
6247a64adfSmrg	esac
6347a64adfSmrg      fi
6447a64adfSmrg      case $file_conv/,$2, in
6547a64adfSmrg	*,$file_conv,*)
6647a64adfSmrg	  ;;
6747a64adfSmrg	mingw/*)
6847a64adfSmrg	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
6947a64adfSmrg	  ;;
702aafc1e6Smrg	cygwin/* | msys/*)
7147a64adfSmrg	  file=`cygpath -m "$file" || echo "$file"`
7247a64adfSmrg	  ;;
7347a64adfSmrg	wine/*)
7447a64adfSmrg	  file=`winepath -w "$file" || echo "$file"`
7547a64adfSmrg	  ;;
7647a64adfSmrg      esac
7747a64adfSmrg      ;;
7847a64adfSmrg  esac
7947a64adfSmrg}
8047a64adfSmrg
8147a64adfSmrg# func_cl_dashL linkdir
8247a64adfSmrg# Make cl look for libraries in LINKDIR
8347a64adfSmrgfunc_cl_dashL ()
8447a64adfSmrg{
8547a64adfSmrg  func_file_conv "$1"
8647a64adfSmrg  if test -z "$lib_path"; then
8747a64adfSmrg    lib_path=$file
8847a64adfSmrg  else
8947a64adfSmrg    lib_path="$lib_path;$file"
9047a64adfSmrg  fi
9147a64adfSmrg  linker_opts="$linker_opts -LIBPATH:$file"
9247a64adfSmrg}
9347a64adfSmrg
9447a64adfSmrg# func_cl_dashl library
9547a64adfSmrg# Do a library search-path lookup for cl
9647a64adfSmrgfunc_cl_dashl ()
9747a64adfSmrg{
9847a64adfSmrg  lib=$1
9947a64adfSmrg  found=no
10047a64adfSmrg  save_IFS=$IFS
10147a64adfSmrg  IFS=';'
10247a64adfSmrg  for dir in $lib_path $LIB
10347a64adfSmrg  do
10447a64adfSmrg    IFS=$save_IFS
10547a64adfSmrg    if $shared && test -f "$dir/$lib.dll.lib"; then
10647a64adfSmrg      found=yes
10747a64adfSmrg      lib=$dir/$lib.dll.lib
10847a64adfSmrg      break
10947a64adfSmrg    fi
11047a64adfSmrg    if test -f "$dir/$lib.lib"; then
11147a64adfSmrg      found=yes
11247a64adfSmrg      lib=$dir/$lib.lib
11347a64adfSmrg      break
11447a64adfSmrg    fi
11547a64adfSmrg    if test -f "$dir/lib$lib.a"; then
11647a64adfSmrg      found=yes
11747a64adfSmrg      lib=$dir/lib$lib.a
11847a64adfSmrg      break
11947a64adfSmrg    fi
12047a64adfSmrg  done
12147a64adfSmrg  IFS=$save_IFS
12247a64adfSmrg
12347a64adfSmrg  if test "$found" != yes; then
12447a64adfSmrg    lib=$lib.lib
12547a64adfSmrg  fi
12647a64adfSmrg}
12747a64adfSmrg
12847a64adfSmrg# func_cl_wrapper cl arg...
12947a64adfSmrg# Adjust compile command to suit cl
13047a64adfSmrgfunc_cl_wrapper ()
13147a64adfSmrg{
13247a64adfSmrg  # Assume a capable shell
13347a64adfSmrg  lib_path=
13447a64adfSmrg  shared=:
13547a64adfSmrg  linker_opts=
13647a64adfSmrg  for arg
13747a64adfSmrg  do
13847a64adfSmrg    if test -n "$eat"; then
13947a64adfSmrg      eat=
14047a64adfSmrg    else
14147a64adfSmrg      case $1 in
14247a64adfSmrg	-o)
14347a64adfSmrg	  # configure might choose to run compile as 'compile cc -o foo foo.c'.
14447a64adfSmrg	  eat=1
14547a64adfSmrg	  case $2 in
14647a64adfSmrg	    *.o | *.[oO][bB][jJ])
14747a64adfSmrg	      func_file_conv "$2"
14847a64adfSmrg	      set x "$@" -Fo"$file"
14947a64adfSmrg	      shift
15047a64adfSmrg	      ;;
15147a64adfSmrg	    *)
15247a64adfSmrg	      func_file_conv "$2"
15347a64adfSmrg	      set x "$@" -Fe"$file"
15447a64adfSmrg	      shift
15547a64adfSmrg	      ;;
15647a64adfSmrg	  esac
15747a64adfSmrg	  ;;
15847a64adfSmrg	-I)
15947a64adfSmrg	  eat=1
16047a64adfSmrg	  func_file_conv "$2" mingw
16147a64adfSmrg	  set x "$@" -I"$file"
16247a64adfSmrg	  shift
16347a64adfSmrg	  ;;
16447a64adfSmrg	-I*)
16547a64adfSmrg	  func_file_conv "${1#-I}" mingw
16647a64adfSmrg	  set x "$@" -I"$file"
16747a64adfSmrg	  shift
16847a64adfSmrg	  ;;
16947a64adfSmrg	-l)
17047a64adfSmrg	  eat=1
17147a64adfSmrg	  func_cl_dashl "$2"
17247a64adfSmrg	  set x "$@" "$lib"
17347a64adfSmrg	  shift
17447a64adfSmrg	  ;;
17547a64adfSmrg	-l*)
17647a64adfSmrg	  func_cl_dashl "${1#-l}"
17747a64adfSmrg	  set x "$@" "$lib"
17847a64adfSmrg	  shift
17947a64adfSmrg	  ;;
18047a64adfSmrg	-L)
18147a64adfSmrg	  eat=1
18247a64adfSmrg	  func_cl_dashL "$2"
18347a64adfSmrg	  ;;
18447a64adfSmrg	-L*)
18547a64adfSmrg	  func_cl_dashL "${1#-L}"
18647a64adfSmrg	  ;;
18747a64adfSmrg	-static)
18847a64adfSmrg	  shared=false
18947a64adfSmrg	  ;;
19047a64adfSmrg	-Wl,*)
19147a64adfSmrg	  arg=${1#-Wl,}
19247a64adfSmrg	  save_ifs="$IFS"; IFS=','
19347a64adfSmrg	  for flag in $arg; do
19447a64adfSmrg	    IFS="$save_ifs"
19547a64adfSmrg	    linker_opts="$linker_opts $flag"
19647a64adfSmrg	  done
19747a64adfSmrg	  IFS="$save_ifs"
19847a64adfSmrg	  ;;
19947a64adfSmrg	-Xlinker)
20047a64adfSmrg	  eat=1
20147a64adfSmrg	  linker_opts="$linker_opts $2"
20247a64adfSmrg	  ;;
20347a64adfSmrg	-*)
20447a64adfSmrg	  set x "$@" "$1"
20547a64adfSmrg	  shift
20647a64adfSmrg	  ;;
20747a64adfSmrg	*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
20847a64adfSmrg	  func_file_conv "$1"
20947a64adfSmrg	  set x "$@" -Tp"$file"
21047a64adfSmrg	  shift
21147a64adfSmrg	  ;;
21247a64adfSmrg	*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
21347a64adfSmrg	  func_file_conv "$1" mingw
21447a64adfSmrg	  set x "$@" "$file"
21547a64adfSmrg	  shift
21647a64adfSmrg	  ;;
21747a64adfSmrg	*)
21847a64adfSmrg	  set x "$@" "$1"
21947a64adfSmrg	  shift
22047a64adfSmrg	  ;;
22147a64adfSmrg      esac
22247a64adfSmrg    fi
22347a64adfSmrg    shift
22447a64adfSmrg  done
22547a64adfSmrg  if test -n "$linker_opts"; then
22647a64adfSmrg    linker_opts="-link$linker_opts"
22747a64adfSmrg  fi
22847a64adfSmrg  exec "$@" $linker_opts
22947a64adfSmrg  exit 1
23047a64adfSmrg}
23147a64adfSmrg
23247a64adfSmrgeat=
23347a64adfSmrg
23447a64adfSmrgcase $1 in
23547a64adfSmrg  '')
23647a64adfSmrg     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
23747a64adfSmrg     exit 1;
23847a64adfSmrg     ;;
23947a64adfSmrg  -h | --h*)
24047a64adfSmrg    cat <<\EOF
24147a64adfSmrgUsage: compile [--help] [--version] PROGRAM [ARGS]
24247a64adfSmrg
24347a64adfSmrgWrapper for compilers which do not understand '-c -o'.
24447a64adfSmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining
24547a64adfSmrgarguments, and rename the output as expected.
24647a64adfSmrg
24747a64adfSmrgIf you are trying to build a whole package this is not the
24847a64adfSmrgright script to run: please start by reading the file 'INSTALL'.
24947a64adfSmrg
25047a64adfSmrgReport bugs to <bug-automake@gnu.org>.
25147a64adfSmrgEOF
25247a64adfSmrg    exit $?
25347a64adfSmrg    ;;
25447a64adfSmrg  -v | --v*)
25547a64adfSmrg    echo "compile $scriptversion"
25647a64adfSmrg    exit $?
25747a64adfSmrg    ;;
2582aafc1e6Smrg  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \
2592aafc1e6Smrg  icl | *[/\\]icl | icl.exe | *[/\\]icl.exe )
26047a64adfSmrg    func_cl_wrapper "$@"      # Doesn't return...
26147a64adfSmrg    ;;
26247a64adfSmrgesac
26347a64adfSmrg
26447a64adfSmrgofile=
26547a64adfSmrgcfile=
26647a64adfSmrg
26747a64adfSmrgfor arg
26847a64adfSmrgdo
26947a64adfSmrg  if test -n "$eat"; then
27047a64adfSmrg    eat=
27147a64adfSmrg  else
27247a64adfSmrg    case $1 in
27347a64adfSmrg      -o)
27447a64adfSmrg	# configure might choose to run compile as 'compile cc -o foo foo.c'.
27547a64adfSmrg	# So we strip '-o arg' only if arg is an object.
27647a64adfSmrg	eat=1
27747a64adfSmrg	case $2 in
27847a64adfSmrg	  *.o | *.obj)
27947a64adfSmrg	    ofile=$2
28047a64adfSmrg	    ;;
28147a64adfSmrg	  *)
28247a64adfSmrg	    set x "$@" -o "$2"
28347a64adfSmrg	    shift
28447a64adfSmrg	    ;;
28547a64adfSmrg	esac
28647a64adfSmrg	;;
28747a64adfSmrg      *.c)
28847a64adfSmrg	cfile=$1
28947a64adfSmrg	set x "$@" "$1"
29047a64adfSmrg	shift
29147a64adfSmrg	;;
29247a64adfSmrg      *)
29347a64adfSmrg	set x "$@" "$1"
29447a64adfSmrg	shift
29547a64adfSmrg	;;
29647a64adfSmrg    esac
29747a64adfSmrg  fi
29847a64adfSmrg  shift
29947a64adfSmrgdone
30047a64adfSmrg
30147a64adfSmrgif test -z "$ofile" || test -z "$cfile"; then
30247a64adfSmrg  # If no '-o' option was seen then we might have been invoked from a
30347a64adfSmrg  # pattern rule where we don't need one.  That is ok -- this is a
30447a64adfSmrg  # normal compilation that the losing compiler can handle.  If no
30547a64adfSmrg  # '.c' file was seen then we are probably linking.  That is also
30647a64adfSmrg  # ok.
30747a64adfSmrg  exec "$@"
30847a64adfSmrgfi
30947a64adfSmrg
31047a64adfSmrg# Name of file we expect compiler to create.
31147a64adfSmrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
31247a64adfSmrg
31347a64adfSmrg# Create the lock directory.
31447a64adfSmrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name
31547a64adfSmrg# that we are using for the .o file.  Also, base the name on the expected
31647a64adfSmrg# object file name, since that is what matters with a parallel build.
31747a64adfSmrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
31847a64adfSmrgwhile true; do
31947a64adfSmrg  if mkdir "$lockdir" >/dev/null 2>&1; then
32047a64adfSmrg    break
32147a64adfSmrg  fi
32247a64adfSmrg  sleep 1
32347a64adfSmrgdone
32447a64adfSmrg# FIXME: race condition here if user kills between mkdir and trap.
32547a64adfSmrgtrap "rmdir '$lockdir'; exit 1" 1 2 15
32647a64adfSmrg
32747a64adfSmrg# Run the compile.
32847a64adfSmrg"$@"
32947a64adfSmrgret=$?
33047a64adfSmrg
33147a64adfSmrgif test -f "$cofile"; then
33247a64adfSmrg  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
33347a64adfSmrgelif test -f "${cofile}bj"; then
33447a64adfSmrg  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
33547a64adfSmrgfi
33647a64adfSmrg
33747a64adfSmrgrmdir "$lockdir"
33847a64adfSmrgexit $ret
33947a64adfSmrg
34047a64adfSmrg# Local Variables:
34147a64adfSmrg# mode: shell-script
34247a64adfSmrg# sh-indentation: 2
3432aafc1e6Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
34447a64adfSmrg# time-stamp-start: "scriptversion="
34547a64adfSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
3462aafc1e6Smrg# time-stamp-time-zone: "UTC0"
34747a64adfSmrg# time-stamp-end: "; # UTC"
34847a64adfSmrg# End:
349