xref: /third_party/lame/compile (revision 159b3361)
1159b3361Sopenharmony_ci#! /bin/sh
2159b3361Sopenharmony_ci# Wrapper for compilers which do not understand '-c -o'.
3159b3361Sopenharmony_ci
4159b3361Sopenharmony_ciscriptversion=2018-03-07.03; # UTC
5159b3361Sopenharmony_ci
6159b3361Sopenharmony_ci# Copyright (C) 1999-2020 Free Software Foundation, Inc.
7159b3361Sopenharmony_ci# Written by Tom Tromey <tromey@cygnus.com>.
8159b3361Sopenharmony_ci#
9159b3361Sopenharmony_ci# This program is free software; you can redistribute it and/or modify
10159b3361Sopenharmony_ci# it under the terms of the GNU General Public License as published by
11159b3361Sopenharmony_ci# the Free Software Foundation; either version 2, or (at your option)
12159b3361Sopenharmony_ci# any later version.
13159b3361Sopenharmony_ci#
14159b3361Sopenharmony_ci# This program is distributed in the hope that it will be useful,
15159b3361Sopenharmony_ci# but WITHOUT ANY WARRANTY; without even the implied warranty of
16159b3361Sopenharmony_ci# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17159b3361Sopenharmony_ci# GNU General Public License for more details.
18159b3361Sopenharmony_ci#
19159b3361Sopenharmony_ci# You should have received a copy of the GNU General Public License
20159b3361Sopenharmony_ci# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21159b3361Sopenharmony_ci
22159b3361Sopenharmony_ci# As a special exception to the GNU General Public License, if you
23159b3361Sopenharmony_ci# distribute this file as part of a program that contains a
24159b3361Sopenharmony_ci# configuration script generated by Autoconf, you may include it under
25159b3361Sopenharmony_ci# the same distribution terms that you use for the rest of that program.
26159b3361Sopenharmony_ci
27159b3361Sopenharmony_ci# This file is maintained in Automake, please report
28159b3361Sopenharmony_ci# bugs to <bug-automake@gnu.org> or send patches to
29159b3361Sopenharmony_ci# <automake-patches@gnu.org>.
30159b3361Sopenharmony_ci
31159b3361Sopenharmony_cinl='
32159b3361Sopenharmony_ci'
33159b3361Sopenharmony_ci
34159b3361Sopenharmony_ci# We need space, tab and new line, in precisely that order.  Quoting is
35159b3361Sopenharmony_ci# there to prevent tools from complaining about whitespace usage.
36159b3361Sopenharmony_ciIFS=" ""	$nl"
37159b3361Sopenharmony_ci
38159b3361Sopenharmony_cifile_conv=
39159b3361Sopenharmony_ci
40159b3361Sopenharmony_ci# func_file_conv build_file lazy
41159b3361Sopenharmony_ci# Convert a $build file to $host form and store it in $file
42159b3361Sopenharmony_ci# Currently only supports Windows hosts. If the determined conversion
43159b3361Sopenharmony_ci# type is listed in (the comma separated) LAZY, no conversion will
44159b3361Sopenharmony_ci# take place.
45159b3361Sopenharmony_cifunc_file_conv ()
46159b3361Sopenharmony_ci{
47159b3361Sopenharmony_ci  file=$1
48159b3361Sopenharmony_ci  case $file in
49159b3361Sopenharmony_ci    / | /[!/]*) # absolute file, and not a UNC file
50159b3361Sopenharmony_ci      if test -z "$file_conv"; then
51159b3361Sopenharmony_ci	# lazily determine how to convert abs files
52159b3361Sopenharmony_ci	case `uname -s` in
53159b3361Sopenharmony_ci	  MINGW*)
54159b3361Sopenharmony_ci	    file_conv=mingw
55159b3361Sopenharmony_ci	    ;;
56159b3361Sopenharmony_ci	  CYGWIN* | MSYS*)
57159b3361Sopenharmony_ci	    file_conv=cygwin
58159b3361Sopenharmony_ci	    ;;
59159b3361Sopenharmony_ci	  *)
60159b3361Sopenharmony_ci	    file_conv=wine
61159b3361Sopenharmony_ci	    ;;
62159b3361Sopenharmony_ci	esac
63159b3361Sopenharmony_ci      fi
64159b3361Sopenharmony_ci      case $file_conv/,$2, in
65159b3361Sopenharmony_ci	*,$file_conv,*)
66159b3361Sopenharmony_ci	  ;;
67159b3361Sopenharmony_ci	mingw/*)
68159b3361Sopenharmony_ci	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
69159b3361Sopenharmony_ci	  ;;
70159b3361Sopenharmony_ci	cygwin/* | msys/*)
71159b3361Sopenharmony_ci	  file=`cygpath -m "$file" || echo "$file"`
72159b3361Sopenharmony_ci	  ;;
73159b3361Sopenharmony_ci	wine/*)
74159b3361Sopenharmony_ci	  file=`winepath -w "$file" || echo "$file"`
75159b3361Sopenharmony_ci	  ;;
76159b3361Sopenharmony_ci      esac
77159b3361Sopenharmony_ci      ;;
78159b3361Sopenharmony_ci  esac
79159b3361Sopenharmony_ci}
80159b3361Sopenharmony_ci
81159b3361Sopenharmony_ci# func_cl_dashL linkdir
82159b3361Sopenharmony_ci# Make cl look for libraries in LINKDIR
83159b3361Sopenharmony_cifunc_cl_dashL ()
84159b3361Sopenharmony_ci{
85159b3361Sopenharmony_ci  func_file_conv "$1"
86159b3361Sopenharmony_ci  if test -z "$lib_path"; then
87159b3361Sopenharmony_ci    lib_path=$file
88159b3361Sopenharmony_ci  else
89159b3361Sopenharmony_ci    lib_path="$lib_path;$file"
90159b3361Sopenharmony_ci  fi
91159b3361Sopenharmony_ci  linker_opts="$linker_opts -LIBPATH:$file"
92159b3361Sopenharmony_ci}
93159b3361Sopenharmony_ci
94159b3361Sopenharmony_ci# func_cl_dashl library
95159b3361Sopenharmony_ci# Do a library search-path lookup for cl
96159b3361Sopenharmony_cifunc_cl_dashl ()
97159b3361Sopenharmony_ci{
98159b3361Sopenharmony_ci  lib=$1
99159b3361Sopenharmony_ci  found=no
100159b3361Sopenharmony_ci  save_IFS=$IFS
101159b3361Sopenharmony_ci  IFS=';'
102159b3361Sopenharmony_ci  for dir in $lib_path $LIB
103159b3361Sopenharmony_ci  do
104159b3361Sopenharmony_ci    IFS=$save_IFS
105159b3361Sopenharmony_ci    if $shared && test -f "$dir/$lib.dll.lib"; then
106159b3361Sopenharmony_ci      found=yes
107159b3361Sopenharmony_ci      lib=$dir/$lib.dll.lib
108159b3361Sopenharmony_ci      break
109159b3361Sopenharmony_ci    fi
110159b3361Sopenharmony_ci    if test -f "$dir/$lib.lib"; then
111159b3361Sopenharmony_ci      found=yes
112159b3361Sopenharmony_ci      lib=$dir/$lib.lib
113159b3361Sopenharmony_ci      break
114159b3361Sopenharmony_ci    fi
115159b3361Sopenharmony_ci    if test -f "$dir/lib$lib.a"; then
116159b3361Sopenharmony_ci      found=yes
117159b3361Sopenharmony_ci      lib=$dir/lib$lib.a
118159b3361Sopenharmony_ci      break
119159b3361Sopenharmony_ci    fi
120159b3361Sopenharmony_ci  done
121159b3361Sopenharmony_ci  IFS=$save_IFS
122159b3361Sopenharmony_ci
123159b3361Sopenharmony_ci  if test "$found" != yes; then
124159b3361Sopenharmony_ci    lib=$lib.lib
125159b3361Sopenharmony_ci  fi
126159b3361Sopenharmony_ci}
127159b3361Sopenharmony_ci
128159b3361Sopenharmony_ci# func_cl_wrapper cl arg...
129159b3361Sopenharmony_ci# Adjust compile command to suit cl
130159b3361Sopenharmony_cifunc_cl_wrapper ()
131159b3361Sopenharmony_ci{
132159b3361Sopenharmony_ci  # Assume a capable shell
133159b3361Sopenharmony_ci  lib_path=
134159b3361Sopenharmony_ci  shared=:
135159b3361Sopenharmony_ci  linker_opts=
136159b3361Sopenharmony_ci  for arg
137159b3361Sopenharmony_ci  do
138159b3361Sopenharmony_ci    if test -n "$eat"; then
139159b3361Sopenharmony_ci      eat=
140159b3361Sopenharmony_ci    else
141159b3361Sopenharmony_ci      case $1 in
142159b3361Sopenharmony_ci	-o)
143159b3361Sopenharmony_ci	  # configure might choose to run compile as 'compile cc -o foo foo.c'.
144159b3361Sopenharmony_ci	  eat=1
145159b3361Sopenharmony_ci	  case $2 in
146159b3361Sopenharmony_ci	    *.o | *.[oO][bB][jJ])
147159b3361Sopenharmony_ci	      func_file_conv "$2"
148159b3361Sopenharmony_ci	      set x "$@" -Fo"$file"
149159b3361Sopenharmony_ci	      shift
150159b3361Sopenharmony_ci	      ;;
151159b3361Sopenharmony_ci	    *)
152159b3361Sopenharmony_ci	      func_file_conv "$2"
153159b3361Sopenharmony_ci	      set x "$@" -Fe"$file"
154159b3361Sopenharmony_ci	      shift
155159b3361Sopenharmony_ci	      ;;
156159b3361Sopenharmony_ci	  esac
157159b3361Sopenharmony_ci	  ;;
158159b3361Sopenharmony_ci	-I)
159159b3361Sopenharmony_ci	  eat=1
160159b3361Sopenharmony_ci	  func_file_conv "$2" mingw
161159b3361Sopenharmony_ci	  set x "$@" -I"$file"
162159b3361Sopenharmony_ci	  shift
163159b3361Sopenharmony_ci	  ;;
164159b3361Sopenharmony_ci	-I*)
165159b3361Sopenharmony_ci	  func_file_conv "${1#-I}" mingw
166159b3361Sopenharmony_ci	  set x "$@" -I"$file"
167159b3361Sopenharmony_ci	  shift
168159b3361Sopenharmony_ci	  ;;
169159b3361Sopenharmony_ci	-l)
170159b3361Sopenharmony_ci	  eat=1
171159b3361Sopenharmony_ci	  func_cl_dashl "$2"
172159b3361Sopenharmony_ci	  set x "$@" "$lib"
173159b3361Sopenharmony_ci	  shift
174159b3361Sopenharmony_ci	  ;;
175159b3361Sopenharmony_ci	-l*)
176159b3361Sopenharmony_ci	  func_cl_dashl "${1#-l}"
177159b3361Sopenharmony_ci	  set x "$@" "$lib"
178159b3361Sopenharmony_ci	  shift
179159b3361Sopenharmony_ci	  ;;
180159b3361Sopenharmony_ci	-L)
181159b3361Sopenharmony_ci	  eat=1
182159b3361Sopenharmony_ci	  func_cl_dashL "$2"
183159b3361Sopenharmony_ci	  ;;
184159b3361Sopenharmony_ci	-L*)
185159b3361Sopenharmony_ci	  func_cl_dashL "${1#-L}"
186159b3361Sopenharmony_ci	  ;;
187159b3361Sopenharmony_ci	-static)
188159b3361Sopenharmony_ci	  shared=false
189159b3361Sopenharmony_ci	  ;;
190159b3361Sopenharmony_ci	-Wl,*)
191159b3361Sopenharmony_ci	  arg=${1#-Wl,}
192159b3361Sopenharmony_ci	  save_ifs="$IFS"; IFS=','
193159b3361Sopenharmony_ci	  for flag in $arg; do
194159b3361Sopenharmony_ci	    IFS="$save_ifs"
195159b3361Sopenharmony_ci	    linker_opts="$linker_opts $flag"
196159b3361Sopenharmony_ci	  done
197159b3361Sopenharmony_ci	  IFS="$save_ifs"
198159b3361Sopenharmony_ci	  ;;
199159b3361Sopenharmony_ci	-Xlinker)
200159b3361Sopenharmony_ci	  eat=1
201159b3361Sopenharmony_ci	  linker_opts="$linker_opts $2"
202159b3361Sopenharmony_ci	  ;;
203159b3361Sopenharmony_ci	-*)
204159b3361Sopenharmony_ci	  set x "$@" "$1"
205159b3361Sopenharmony_ci	  shift
206159b3361Sopenharmony_ci	  ;;
207159b3361Sopenharmony_ci	*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
208159b3361Sopenharmony_ci	  func_file_conv "$1"
209159b3361Sopenharmony_ci	  set x "$@" -Tp"$file"
210159b3361Sopenharmony_ci	  shift
211159b3361Sopenharmony_ci	  ;;
212159b3361Sopenharmony_ci	*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
213159b3361Sopenharmony_ci	  func_file_conv "$1" mingw
214159b3361Sopenharmony_ci	  set x "$@" "$file"
215159b3361Sopenharmony_ci	  shift
216159b3361Sopenharmony_ci	  ;;
217159b3361Sopenharmony_ci	*)
218159b3361Sopenharmony_ci	  set x "$@" "$1"
219159b3361Sopenharmony_ci	  shift
220159b3361Sopenharmony_ci	  ;;
221159b3361Sopenharmony_ci      esac
222159b3361Sopenharmony_ci    fi
223159b3361Sopenharmony_ci    shift
224159b3361Sopenharmony_ci  done
225159b3361Sopenharmony_ci  if test -n "$linker_opts"; then
226159b3361Sopenharmony_ci    linker_opts="-link$linker_opts"
227159b3361Sopenharmony_ci  fi
228159b3361Sopenharmony_ci  exec "$@" $linker_opts
229159b3361Sopenharmony_ci  exit 1
230159b3361Sopenharmony_ci}
231159b3361Sopenharmony_ci
232159b3361Sopenharmony_cieat=
233159b3361Sopenharmony_ci
234159b3361Sopenharmony_cicase $1 in
235159b3361Sopenharmony_ci  '')
236159b3361Sopenharmony_ci     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
237159b3361Sopenharmony_ci     exit 1;
238159b3361Sopenharmony_ci     ;;
239159b3361Sopenharmony_ci  -h | --h*)
240159b3361Sopenharmony_ci    cat <<\EOF
241159b3361Sopenharmony_ciUsage: compile [--help] [--version] PROGRAM [ARGS]
242159b3361Sopenharmony_ci
243159b3361Sopenharmony_ciWrapper for compilers which do not understand '-c -o'.
244159b3361Sopenharmony_ciRemove '-o dest.o' from ARGS, run PROGRAM with the remaining
245159b3361Sopenharmony_ciarguments, and rename the output as expected.
246159b3361Sopenharmony_ci
247159b3361Sopenharmony_ciIf you are trying to build a whole package this is not the
248159b3361Sopenharmony_ciright script to run: please start by reading the file 'INSTALL'.
249159b3361Sopenharmony_ci
250159b3361Sopenharmony_ciReport bugs to <bug-automake@gnu.org>.
251159b3361Sopenharmony_ciEOF
252159b3361Sopenharmony_ci    exit $?
253159b3361Sopenharmony_ci    ;;
254159b3361Sopenharmony_ci  -v | --v*)
255159b3361Sopenharmony_ci    echo "compile $scriptversion"
256159b3361Sopenharmony_ci    exit $?
257159b3361Sopenharmony_ci    ;;
258159b3361Sopenharmony_ci  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \
259159b3361Sopenharmony_ci  icl | *[/\\]icl | icl.exe | *[/\\]icl.exe )
260159b3361Sopenharmony_ci    func_cl_wrapper "$@"      # Doesn't return...
261159b3361Sopenharmony_ci    ;;
262159b3361Sopenharmony_ciesac
263159b3361Sopenharmony_ci
264159b3361Sopenharmony_ciofile=
265159b3361Sopenharmony_cicfile=
266159b3361Sopenharmony_ci
267159b3361Sopenharmony_cifor arg
268159b3361Sopenharmony_cido
269159b3361Sopenharmony_ci  if test -n "$eat"; then
270159b3361Sopenharmony_ci    eat=
271159b3361Sopenharmony_ci  else
272159b3361Sopenharmony_ci    case $1 in
273159b3361Sopenharmony_ci      -o)
274159b3361Sopenharmony_ci	# configure might choose to run compile as 'compile cc -o foo foo.c'.
275159b3361Sopenharmony_ci	# So we strip '-o arg' only if arg is an object.
276159b3361Sopenharmony_ci	eat=1
277159b3361Sopenharmony_ci	case $2 in
278159b3361Sopenharmony_ci	  *.o | *.obj)
279159b3361Sopenharmony_ci	    ofile=$2
280159b3361Sopenharmony_ci	    ;;
281159b3361Sopenharmony_ci	  *)
282159b3361Sopenharmony_ci	    set x "$@" -o "$2"
283159b3361Sopenharmony_ci	    shift
284159b3361Sopenharmony_ci	    ;;
285159b3361Sopenharmony_ci	esac
286159b3361Sopenharmony_ci	;;
287159b3361Sopenharmony_ci      *.c)
288159b3361Sopenharmony_ci	cfile=$1
289159b3361Sopenharmony_ci	set x "$@" "$1"
290159b3361Sopenharmony_ci	shift
291159b3361Sopenharmony_ci	;;
292159b3361Sopenharmony_ci      *)
293159b3361Sopenharmony_ci	set x "$@" "$1"
294159b3361Sopenharmony_ci	shift
295159b3361Sopenharmony_ci	;;
296159b3361Sopenharmony_ci    esac
297159b3361Sopenharmony_ci  fi
298159b3361Sopenharmony_ci  shift
299159b3361Sopenharmony_cidone
300159b3361Sopenharmony_ci
301159b3361Sopenharmony_ciif test -z "$ofile" || test -z "$cfile"; then
302159b3361Sopenharmony_ci  # If no '-o' option was seen then we might have been invoked from a
303159b3361Sopenharmony_ci  # pattern rule where we don't need one.  That is ok -- this is a
304159b3361Sopenharmony_ci  # normal compilation that the losing compiler can handle.  If no
305159b3361Sopenharmony_ci  # '.c' file was seen then we are probably linking.  That is also
306159b3361Sopenharmony_ci  # ok.
307159b3361Sopenharmony_ci  exec "$@"
308159b3361Sopenharmony_cifi
309159b3361Sopenharmony_ci
310159b3361Sopenharmony_ci# Name of file we expect compiler to create.
311159b3361Sopenharmony_cicofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
312159b3361Sopenharmony_ci
313159b3361Sopenharmony_ci# Create the lock directory.
314159b3361Sopenharmony_ci# Note: use '[/\\:.-]' here to ensure that we don't use the same name
315159b3361Sopenharmony_ci# that we are using for the .o file.  Also, base the name on the expected
316159b3361Sopenharmony_ci# object file name, since that is what matters with a parallel build.
317159b3361Sopenharmony_cilockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
318159b3361Sopenharmony_ciwhile true; do
319159b3361Sopenharmony_ci  if mkdir "$lockdir" >/dev/null 2>&1; then
320159b3361Sopenharmony_ci    break
321159b3361Sopenharmony_ci  fi
322159b3361Sopenharmony_ci  sleep 1
323159b3361Sopenharmony_cidone
324159b3361Sopenharmony_ci# FIXME: race condition here if user kills between mkdir and trap.
325159b3361Sopenharmony_citrap "rmdir '$lockdir'; exit 1" 1 2 15
326159b3361Sopenharmony_ci
327159b3361Sopenharmony_ci# Run the compile.
328159b3361Sopenharmony_ci"$@"
329159b3361Sopenharmony_ciret=$?
330159b3361Sopenharmony_ci
331159b3361Sopenharmony_ciif test -f "$cofile"; then
332159b3361Sopenharmony_ci  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
333159b3361Sopenharmony_cielif test -f "${cofile}bj"; then
334159b3361Sopenharmony_ci  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
335159b3361Sopenharmony_cifi
336159b3361Sopenharmony_ci
337159b3361Sopenharmony_cirmdir "$lockdir"
338159b3361Sopenharmony_ciexit $ret
339159b3361Sopenharmony_ci
340159b3361Sopenharmony_ci# Local Variables:
341159b3361Sopenharmony_ci# mode: shell-script
342159b3361Sopenharmony_ci# sh-indentation: 2
343159b3361Sopenharmony_ci# eval: (add-hook 'before-save-hook 'time-stamp)
344159b3361Sopenharmony_ci# time-stamp-start: "scriptversion="
345159b3361Sopenharmony_ci# time-stamp-format: "%:y-%02m-%02d.%02H"
346159b3361Sopenharmony_ci# time-stamp-time-zone: "UTC0"
347159b3361Sopenharmony_ci# time-stamp-end: "; # UTC"
348159b3361Sopenharmony_ci# End:
349