xref: /aosp_15_r20/external/libconfig/aux-build/compile (revision 2e9d491483b805f09ea864149eadd5680efcc72a)
1*2e9d4914SAndroid Build Coastguard Worker#! /bin/sh
2*2e9d4914SAndroid Build Coastguard Worker# Wrapper for compilers which do not understand '-c -o'.
3*2e9d4914SAndroid Build Coastguard Worker
4*2e9d4914SAndroid Build Coastguard Workerscriptversion=2012-10-14.11; # UTC
5*2e9d4914SAndroid Build Coastguard Worker
6*2e9d4914SAndroid Build Coastguard Worker# Copyright (C) 1999-2013 Free Software Foundation, Inc.
7*2e9d4914SAndroid Build Coastguard Worker# Written by Tom Tromey <[email protected]>.
8*2e9d4914SAndroid Build Coastguard Worker#
9*2e9d4914SAndroid Build Coastguard Worker# This program is free software; you can redistribute it and/or modify
10*2e9d4914SAndroid Build Coastguard Worker# it under the terms of the GNU General Public License as published by
11*2e9d4914SAndroid Build Coastguard Worker# the Free Software Foundation; either version 2, or (at your option)
12*2e9d4914SAndroid Build Coastguard Worker# any later version.
13*2e9d4914SAndroid Build Coastguard Worker#
14*2e9d4914SAndroid Build Coastguard Worker# This program is distributed in the hope that it will be useful,
15*2e9d4914SAndroid Build Coastguard Worker# but WITHOUT ANY WARRANTY; without even the implied warranty of
16*2e9d4914SAndroid Build Coastguard Worker# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*2e9d4914SAndroid Build Coastguard Worker# GNU General Public License for more details.
18*2e9d4914SAndroid Build Coastguard Worker#
19*2e9d4914SAndroid Build Coastguard Worker# You should have received a copy of the GNU General Public License
20*2e9d4914SAndroid Build Coastguard Worker# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21*2e9d4914SAndroid Build Coastguard Worker
22*2e9d4914SAndroid Build Coastguard Worker# As a special exception to the GNU General Public License, if you
23*2e9d4914SAndroid Build Coastguard Worker# distribute this file as part of a program that contains a
24*2e9d4914SAndroid Build Coastguard Worker# configuration script generated by Autoconf, you may include it under
25*2e9d4914SAndroid Build Coastguard Worker# the same distribution terms that you use for the rest of that program.
26*2e9d4914SAndroid Build Coastguard Worker
27*2e9d4914SAndroid Build Coastguard Worker# This file is maintained in Automake, please report
28*2e9d4914SAndroid Build Coastguard Worker# bugs to <[email protected]> or send patches to
29*2e9d4914SAndroid Build Coastguard Worker# <[email protected]>.
30*2e9d4914SAndroid Build Coastguard Worker
31*2e9d4914SAndroid Build Coastguard Workernl='
32*2e9d4914SAndroid Build Coastguard Worker'
33*2e9d4914SAndroid Build Coastguard Worker
34*2e9d4914SAndroid Build Coastguard Worker# We need space, tab and new line, in precisely that order.  Quoting is
35*2e9d4914SAndroid Build Coastguard Worker# there to prevent tools from complaining about whitespace usage.
36*2e9d4914SAndroid Build Coastguard WorkerIFS=" ""	$nl"
37*2e9d4914SAndroid Build Coastguard Worker
38*2e9d4914SAndroid Build Coastguard Workerfile_conv=
39*2e9d4914SAndroid Build Coastguard Worker
40*2e9d4914SAndroid Build Coastguard Worker# func_file_conv build_file lazy
41*2e9d4914SAndroid Build Coastguard Worker# Convert a $build file to $host form and store it in $file
42*2e9d4914SAndroid Build Coastguard Worker# Currently only supports Windows hosts. If the determined conversion
43*2e9d4914SAndroid Build Coastguard Worker# type is listed in (the comma separated) LAZY, no conversion will
44*2e9d4914SAndroid Build Coastguard Worker# take place.
45*2e9d4914SAndroid Build Coastguard Workerfunc_file_conv ()
46*2e9d4914SAndroid Build Coastguard Worker{
47*2e9d4914SAndroid Build Coastguard Worker  file=$1
48*2e9d4914SAndroid Build Coastguard Worker  case $file in
49*2e9d4914SAndroid Build Coastguard Worker    / | /[!/]*) # absolute file, and not a UNC file
50*2e9d4914SAndroid Build Coastguard Worker      if test -z "$file_conv"; then
51*2e9d4914SAndroid Build Coastguard Worker	# lazily determine how to convert abs files
52*2e9d4914SAndroid Build Coastguard Worker	case `uname -s` in
53*2e9d4914SAndroid Build Coastguard Worker	  MINGW*)
54*2e9d4914SAndroid Build Coastguard Worker	    file_conv=mingw
55*2e9d4914SAndroid Build Coastguard Worker	    ;;
56*2e9d4914SAndroid Build Coastguard Worker	  CYGWIN*)
57*2e9d4914SAndroid Build Coastguard Worker	    file_conv=cygwin
58*2e9d4914SAndroid Build Coastguard Worker	    ;;
59*2e9d4914SAndroid Build Coastguard Worker	  *)
60*2e9d4914SAndroid Build Coastguard Worker	    file_conv=wine
61*2e9d4914SAndroid Build Coastguard Worker	    ;;
62*2e9d4914SAndroid Build Coastguard Worker	esac
63*2e9d4914SAndroid Build Coastguard Worker      fi
64*2e9d4914SAndroid Build Coastguard Worker      case $file_conv/,$2, in
65*2e9d4914SAndroid Build Coastguard Worker	*,$file_conv,*)
66*2e9d4914SAndroid Build Coastguard Worker	  ;;
67*2e9d4914SAndroid Build Coastguard Worker	mingw/*)
68*2e9d4914SAndroid Build Coastguard Worker	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
69*2e9d4914SAndroid Build Coastguard Worker	  ;;
70*2e9d4914SAndroid Build Coastguard Worker	cygwin/*)
71*2e9d4914SAndroid Build Coastguard Worker	  file=`cygpath -m "$file" || echo "$file"`
72*2e9d4914SAndroid Build Coastguard Worker	  ;;
73*2e9d4914SAndroid Build Coastguard Worker	wine/*)
74*2e9d4914SAndroid Build Coastguard Worker	  file=`winepath -w "$file" || echo "$file"`
75*2e9d4914SAndroid Build Coastguard Worker	  ;;
76*2e9d4914SAndroid Build Coastguard Worker      esac
77*2e9d4914SAndroid Build Coastguard Worker      ;;
78*2e9d4914SAndroid Build Coastguard Worker  esac
79*2e9d4914SAndroid Build Coastguard Worker}
80*2e9d4914SAndroid Build Coastguard Worker
81*2e9d4914SAndroid Build Coastguard Worker# func_cl_dashL linkdir
82*2e9d4914SAndroid Build Coastguard Worker# Make cl look for libraries in LINKDIR
83*2e9d4914SAndroid Build Coastguard Workerfunc_cl_dashL ()
84*2e9d4914SAndroid Build Coastguard Worker{
85*2e9d4914SAndroid Build Coastguard Worker  func_file_conv "$1"
86*2e9d4914SAndroid Build Coastguard Worker  if test -z "$lib_path"; then
87*2e9d4914SAndroid Build Coastguard Worker    lib_path=$file
88*2e9d4914SAndroid Build Coastguard Worker  else
89*2e9d4914SAndroid Build Coastguard Worker    lib_path="$lib_path;$file"
90*2e9d4914SAndroid Build Coastguard Worker  fi
91*2e9d4914SAndroid Build Coastguard Worker  linker_opts="$linker_opts -LIBPATH:$file"
92*2e9d4914SAndroid Build Coastguard Worker}
93*2e9d4914SAndroid Build Coastguard Worker
94*2e9d4914SAndroid Build Coastguard Worker# func_cl_dashl library
95*2e9d4914SAndroid Build Coastguard Worker# Do a library search-path lookup for cl
96*2e9d4914SAndroid Build Coastguard Workerfunc_cl_dashl ()
97*2e9d4914SAndroid Build Coastguard Worker{
98*2e9d4914SAndroid Build Coastguard Worker  lib=$1
99*2e9d4914SAndroid Build Coastguard Worker  found=no
100*2e9d4914SAndroid Build Coastguard Worker  save_IFS=$IFS
101*2e9d4914SAndroid Build Coastguard Worker  IFS=';'
102*2e9d4914SAndroid Build Coastguard Worker  for dir in $lib_path $LIB
103*2e9d4914SAndroid Build Coastguard Worker  do
104*2e9d4914SAndroid Build Coastguard Worker    IFS=$save_IFS
105*2e9d4914SAndroid Build Coastguard Worker    if $shared && test -f "$dir/$lib.dll.lib"; then
106*2e9d4914SAndroid Build Coastguard Worker      found=yes
107*2e9d4914SAndroid Build Coastguard Worker      lib=$dir/$lib.dll.lib
108*2e9d4914SAndroid Build Coastguard Worker      break
109*2e9d4914SAndroid Build Coastguard Worker    fi
110*2e9d4914SAndroid Build Coastguard Worker    if test -f "$dir/$lib.lib"; then
111*2e9d4914SAndroid Build Coastguard Worker      found=yes
112*2e9d4914SAndroid Build Coastguard Worker      lib=$dir/$lib.lib
113*2e9d4914SAndroid Build Coastguard Worker      break
114*2e9d4914SAndroid Build Coastguard Worker    fi
115*2e9d4914SAndroid Build Coastguard Worker    if test -f "$dir/lib$lib.a"; then
116*2e9d4914SAndroid Build Coastguard Worker      found=yes
117*2e9d4914SAndroid Build Coastguard Worker      lib=$dir/lib$lib.a
118*2e9d4914SAndroid Build Coastguard Worker      break
119*2e9d4914SAndroid Build Coastguard Worker    fi
120*2e9d4914SAndroid Build Coastguard Worker  done
121*2e9d4914SAndroid Build Coastguard Worker  IFS=$save_IFS
122*2e9d4914SAndroid Build Coastguard Worker
123*2e9d4914SAndroid Build Coastguard Worker  if test "$found" != yes; then
124*2e9d4914SAndroid Build Coastguard Worker    lib=$lib.lib
125*2e9d4914SAndroid Build Coastguard Worker  fi
126*2e9d4914SAndroid Build Coastguard Worker}
127*2e9d4914SAndroid Build Coastguard Worker
128*2e9d4914SAndroid Build Coastguard Worker# func_cl_wrapper cl arg...
129*2e9d4914SAndroid Build Coastguard Worker# Adjust compile command to suit cl
130*2e9d4914SAndroid Build Coastguard Workerfunc_cl_wrapper ()
131*2e9d4914SAndroid Build Coastguard Worker{
132*2e9d4914SAndroid Build Coastguard Worker  # Assume a capable shell
133*2e9d4914SAndroid Build Coastguard Worker  lib_path=
134*2e9d4914SAndroid Build Coastguard Worker  shared=:
135*2e9d4914SAndroid Build Coastguard Worker  linker_opts=
136*2e9d4914SAndroid Build Coastguard Worker  for arg
137*2e9d4914SAndroid Build Coastguard Worker  do
138*2e9d4914SAndroid Build Coastguard Worker    if test -n "$eat"; then
139*2e9d4914SAndroid Build Coastguard Worker      eat=
140*2e9d4914SAndroid Build Coastguard Worker    else
141*2e9d4914SAndroid Build Coastguard Worker      case $1 in
142*2e9d4914SAndroid Build Coastguard Worker	-o)
143*2e9d4914SAndroid Build Coastguard Worker	  # configure might choose to run compile as 'compile cc -o foo foo.c'.
144*2e9d4914SAndroid Build Coastguard Worker	  eat=1
145*2e9d4914SAndroid Build Coastguard Worker	  case $2 in
146*2e9d4914SAndroid Build Coastguard Worker	    *.o | *.[oO][bB][jJ])
147*2e9d4914SAndroid Build Coastguard Worker	      func_file_conv "$2"
148*2e9d4914SAndroid Build Coastguard Worker	      set x "$@" -Fo"$file"
149*2e9d4914SAndroid Build Coastguard Worker	      shift
150*2e9d4914SAndroid Build Coastguard Worker	      ;;
151*2e9d4914SAndroid Build Coastguard Worker	    *)
152*2e9d4914SAndroid Build Coastguard Worker	      func_file_conv "$2"
153*2e9d4914SAndroid Build Coastguard Worker	      set x "$@" -Fe"$file"
154*2e9d4914SAndroid Build Coastguard Worker	      shift
155*2e9d4914SAndroid Build Coastguard Worker	      ;;
156*2e9d4914SAndroid Build Coastguard Worker	  esac
157*2e9d4914SAndroid Build Coastguard Worker	  ;;
158*2e9d4914SAndroid Build Coastguard Worker	-I)
159*2e9d4914SAndroid Build Coastguard Worker	  eat=1
160*2e9d4914SAndroid Build Coastguard Worker	  func_file_conv "$2" mingw
161*2e9d4914SAndroid Build Coastguard Worker	  set x "$@" -I"$file"
162*2e9d4914SAndroid Build Coastguard Worker	  shift
163*2e9d4914SAndroid Build Coastguard Worker	  ;;
164*2e9d4914SAndroid Build Coastguard Worker	-I*)
165*2e9d4914SAndroid Build Coastguard Worker	  func_file_conv "${1#-I}" mingw
166*2e9d4914SAndroid Build Coastguard Worker	  set x "$@" -I"$file"
167*2e9d4914SAndroid Build Coastguard Worker	  shift
168*2e9d4914SAndroid Build Coastguard Worker	  ;;
169*2e9d4914SAndroid Build Coastguard Worker	-l)
170*2e9d4914SAndroid Build Coastguard Worker	  eat=1
171*2e9d4914SAndroid Build Coastguard Worker	  func_cl_dashl "$2"
172*2e9d4914SAndroid Build Coastguard Worker	  set x "$@" "$lib"
173*2e9d4914SAndroid Build Coastguard Worker	  shift
174*2e9d4914SAndroid Build Coastguard Worker	  ;;
175*2e9d4914SAndroid Build Coastguard Worker	-l*)
176*2e9d4914SAndroid Build Coastguard Worker	  func_cl_dashl "${1#-l}"
177*2e9d4914SAndroid Build Coastguard Worker	  set x "$@" "$lib"
178*2e9d4914SAndroid Build Coastguard Worker	  shift
179*2e9d4914SAndroid Build Coastguard Worker	  ;;
180*2e9d4914SAndroid Build Coastguard Worker	-L)
181*2e9d4914SAndroid Build Coastguard Worker	  eat=1
182*2e9d4914SAndroid Build Coastguard Worker	  func_cl_dashL "$2"
183*2e9d4914SAndroid Build Coastguard Worker	  ;;
184*2e9d4914SAndroid Build Coastguard Worker	-L*)
185*2e9d4914SAndroid Build Coastguard Worker	  func_cl_dashL "${1#-L}"
186*2e9d4914SAndroid Build Coastguard Worker	  ;;
187*2e9d4914SAndroid Build Coastguard Worker	-static)
188*2e9d4914SAndroid Build Coastguard Worker	  shared=false
189*2e9d4914SAndroid Build Coastguard Worker	  ;;
190*2e9d4914SAndroid Build Coastguard Worker	-Wl,*)
191*2e9d4914SAndroid Build Coastguard Worker	  arg=${1#-Wl,}
192*2e9d4914SAndroid Build Coastguard Worker	  save_ifs="$IFS"; IFS=','
193*2e9d4914SAndroid Build Coastguard Worker	  for flag in $arg; do
194*2e9d4914SAndroid Build Coastguard Worker	    IFS="$save_ifs"
195*2e9d4914SAndroid Build Coastguard Worker	    linker_opts="$linker_opts $flag"
196*2e9d4914SAndroid Build Coastguard Worker	  done
197*2e9d4914SAndroid Build Coastguard Worker	  IFS="$save_ifs"
198*2e9d4914SAndroid Build Coastguard Worker	  ;;
199*2e9d4914SAndroid Build Coastguard Worker	-Xlinker)
200*2e9d4914SAndroid Build Coastguard Worker	  eat=1
201*2e9d4914SAndroid Build Coastguard Worker	  linker_opts="$linker_opts $2"
202*2e9d4914SAndroid Build Coastguard Worker	  ;;
203*2e9d4914SAndroid Build Coastguard Worker	-*)
204*2e9d4914SAndroid Build Coastguard Worker	  set x "$@" "$1"
205*2e9d4914SAndroid Build Coastguard Worker	  shift
206*2e9d4914SAndroid Build Coastguard Worker	  ;;
207*2e9d4914SAndroid Build Coastguard Worker	*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
208*2e9d4914SAndroid Build Coastguard Worker	  func_file_conv "$1"
209*2e9d4914SAndroid Build Coastguard Worker	  set x "$@" -Tp"$file"
210*2e9d4914SAndroid Build Coastguard Worker	  shift
211*2e9d4914SAndroid Build Coastguard Worker	  ;;
212*2e9d4914SAndroid Build Coastguard Worker	*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
213*2e9d4914SAndroid Build Coastguard Worker	  func_file_conv "$1" mingw
214*2e9d4914SAndroid Build Coastguard Worker	  set x "$@" "$file"
215*2e9d4914SAndroid Build Coastguard Worker	  shift
216*2e9d4914SAndroid Build Coastguard Worker	  ;;
217*2e9d4914SAndroid Build Coastguard Worker	*)
218*2e9d4914SAndroid Build Coastguard Worker	  set x "$@" "$1"
219*2e9d4914SAndroid Build Coastguard Worker	  shift
220*2e9d4914SAndroid Build Coastguard Worker	  ;;
221*2e9d4914SAndroid Build Coastguard Worker      esac
222*2e9d4914SAndroid Build Coastguard Worker    fi
223*2e9d4914SAndroid Build Coastguard Worker    shift
224*2e9d4914SAndroid Build Coastguard Worker  done
225*2e9d4914SAndroid Build Coastguard Worker  if test -n "$linker_opts"; then
226*2e9d4914SAndroid Build Coastguard Worker    linker_opts="-link$linker_opts"
227*2e9d4914SAndroid Build Coastguard Worker  fi
228*2e9d4914SAndroid Build Coastguard Worker  exec "$@" $linker_opts
229*2e9d4914SAndroid Build Coastguard Worker  exit 1
230*2e9d4914SAndroid Build Coastguard Worker}
231*2e9d4914SAndroid Build Coastguard Worker
232*2e9d4914SAndroid Build Coastguard Workereat=
233*2e9d4914SAndroid Build Coastguard Worker
234*2e9d4914SAndroid Build Coastguard Workercase $1 in
235*2e9d4914SAndroid Build Coastguard Worker  '')
236*2e9d4914SAndroid Build Coastguard Worker     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
237*2e9d4914SAndroid Build Coastguard Worker     exit 1;
238*2e9d4914SAndroid Build Coastguard Worker     ;;
239*2e9d4914SAndroid Build Coastguard Worker  -h | --h*)
240*2e9d4914SAndroid Build Coastguard Worker    cat <<\EOF
241*2e9d4914SAndroid Build Coastguard WorkerUsage: compile [--help] [--version] PROGRAM [ARGS]
242*2e9d4914SAndroid Build Coastguard Worker
243*2e9d4914SAndroid Build Coastguard WorkerWrapper for compilers which do not understand '-c -o'.
244*2e9d4914SAndroid Build Coastguard WorkerRemove '-o dest.o' from ARGS, run PROGRAM with the remaining
245*2e9d4914SAndroid Build Coastguard Workerarguments, and rename the output as expected.
246*2e9d4914SAndroid Build Coastguard Worker
247*2e9d4914SAndroid Build Coastguard WorkerIf you are trying to build a whole package this is not the
248*2e9d4914SAndroid Build Coastguard Workerright script to run: please start by reading the file 'INSTALL'.
249*2e9d4914SAndroid Build Coastguard Worker
250*2e9d4914SAndroid Build Coastguard WorkerReport bugs to <bug-automake@gnu.org>.
251*2e9d4914SAndroid Build Coastguard WorkerEOF
252*2e9d4914SAndroid Build Coastguard Worker    exit $?
253*2e9d4914SAndroid Build Coastguard Worker    ;;
254*2e9d4914SAndroid Build Coastguard Worker  -v | --v*)
255*2e9d4914SAndroid Build Coastguard Worker    echo "compile $scriptversion"
256*2e9d4914SAndroid Build Coastguard Worker    exit $?
257*2e9d4914SAndroid Build Coastguard Worker    ;;
258*2e9d4914SAndroid Build Coastguard Worker  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
259*2e9d4914SAndroid Build Coastguard Worker    func_cl_wrapper "$@"      # Doesn't return...
260*2e9d4914SAndroid Build Coastguard Worker    ;;
261*2e9d4914SAndroid Build Coastguard Workeresac
262*2e9d4914SAndroid Build Coastguard Worker
263*2e9d4914SAndroid Build Coastguard Workerofile=
264*2e9d4914SAndroid Build Coastguard Workercfile=
265*2e9d4914SAndroid Build Coastguard Worker
266*2e9d4914SAndroid Build Coastguard Workerfor arg
267*2e9d4914SAndroid Build Coastguard Workerdo
268*2e9d4914SAndroid Build Coastguard Worker  if test -n "$eat"; then
269*2e9d4914SAndroid Build Coastguard Worker    eat=
270*2e9d4914SAndroid Build Coastguard Worker  else
271*2e9d4914SAndroid Build Coastguard Worker    case $1 in
272*2e9d4914SAndroid Build Coastguard Worker      -o)
273*2e9d4914SAndroid Build Coastguard Worker	# configure might choose to run compile as 'compile cc -o foo foo.c'.
274*2e9d4914SAndroid Build Coastguard Worker	# So we strip '-o arg' only if arg is an object.
275*2e9d4914SAndroid Build Coastguard Worker	eat=1
276*2e9d4914SAndroid Build Coastguard Worker	case $2 in
277*2e9d4914SAndroid Build Coastguard Worker	  *.o | *.obj)
278*2e9d4914SAndroid Build Coastguard Worker	    ofile=$2
279*2e9d4914SAndroid Build Coastguard Worker	    ;;
280*2e9d4914SAndroid Build Coastguard Worker	  *)
281*2e9d4914SAndroid Build Coastguard Worker	    set x "$@" -o "$2"
282*2e9d4914SAndroid Build Coastguard Worker	    shift
283*2e9d4914SAndroid Build Coastguard Worker	    ;;
284*2e9d4914SAndroid Build Coastguard Worker	esac
285*2e9d4914SAndroid Build Coastguard Worker	;;
286*2e9d4914SAndroid Build Coastguard Worker      *.c)
287*2e9d4914SAndroid Build Coastguard Worker	cfile=$1
288*2e9d4914SAndroid Build Coastguard Worker	set x "$@" "$1"
289*2e9d4914SAndroid Build Coastguard Worker	shift
290*2e9d4914SAndroid Build Coastguard Worker	;;
291*2e9d4914SAndroid Build Coastguard Worker      *)
292*2e9d4914SAndroid Build Coastguard Worker	set x "$@" "$1"
293*2e9d4914SAndroid Build Coastguard Worker	shift
294*2e9d4914SAndroid Build Coastguard Worker	;;
295*2e9d4914SAndroid Build Coastguard Worker    esac
296*2e9d4914SAndroid Build Coastguard Worker  fi
297*2e9d4914SAndroid Build Coastguard Worker  shift
298*2e9d4914SAndroid Build Coastguard Workerdone
299*2e9d4914SAndroid Build Coastguard Worker
300*2e9d4914SAndroid Build Coastguard Workerif test -z "$ofile" || test -z "$cfile"; then
301*2e9d4914SAndroid Build Coastguard Worker  # If no '-o' option was seen then we might have been invoked from a
302*2e9d4914SAndroid Build Coastguard Worker  # pattern rule where we don't need one.  That is ok -- this is a
303*2e9d4914SAndroid Build Coastguard Worker  # normal compilation that the losing compiler can handle.  If no
304*2e9d4914SAndroid Build Coastguard Worker  # '.c' file was seen then we are probably linking.  That is also
305*2e9d4914SAndroid Build Coastguard Worker  # ok.
306*2e9d4914SAndroid Build Coastguard Worker  exec "$@"
307*2e9d4914SAndroid Build Coastguard Workerfi
308*2e9d4914SAndroid Build Coastguard Worker
309*2e9d4914SAndroid Build Coastguard Worker# Name of file we expect compiler to create.
310*2e9d4914SAndroid Build Coastguard Workercofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
311*2e9d4914SAndroid Build Coastguard Worker
312*2e9d4914SAndroid Build Coastguard Worker# Create the lock directory.
313*2e9d4914SAndroid Build Coastguard Worker# Note: use '[/\\:.-]' here to ensure that we don't use the same name
314*2e9d4914SAndroid Build Coastguard Worker# that we are using for the .o file.  Also, base the name on the expected
315*2e9d4914SAndroid Build Coastguard Worker# object file name, since that is what matters with a parallel build.
316*2e9d4914SAndroid Build Coastguard Workerlockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
317*2e9d4914SAndroid Build Coastguard Workerwhile true; do
318*2e9d4914SAndroid Build Coastguard Worker  if mkdir "$lockdir" >/dev/null 2>&1; then
319*2e9d4914SAndroid Build Coastguard Worker    break
320*2e9d4914SAndroid Build Coastguard Worker  fi
321*2e9d4914SAndroid Build Coastguard Worker  sleep 1
322*2e9d4914SAndroid Build Coastguard Workerdone
323*2e9d4914SAndroid Build Coastguard Worker# FIXME: race condition here if user kills between mkdir and trap.
324*2e9d4914SAndroid Build Coastguard Workertrap "rmdir '$lockdir'; exit 1" 1 2 15
325*2e9d4914SAndroid Build Coastguard Worker
326*2e9d4914SAndroid Build Coastguard Worker# Run the compile.
327*2e9d4914SAndroid Build Coastguard Worker"$@"
328*2e9d4914SAndroid Build Coastguard Workerret=$?
329*2e9d4914SAndroid Build Coastguard Worker
330*2e9d4914SAndroid Build Coastguard Workerif test -f "$cofile"; then
331*2e9d4914SAndroid Build Coastguard Worker  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
332*2e9d4914SAndroid Build Coastguard Workerelif test -f "${cofile}bj"; then
333*2e9d4914SAndroid Build Coastguard Worker  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
334*2e9d4914SAndroid Build Coastguard Workerfi
335*2e9d4914SAndroid Build Coastguard Worker
336*2e9d4914SAndroid Build Coastguard Workerrmdir "$lockdir"
337*2e9d4914SAndroid Build Coastguard Workerexit $ret
338*2e9d4914SAndroid Build Coastguard Worker
339*2e9d4914SAndroid Build Coastguard Worker# Local Variables:
340*2e9d4914SAndroid Build Coastguard Worker# mode: shell-script
341*2e9d4914SAndroid Build Coastguard Worker# sh-indentation: 2
342*2e9d4914SAndroid Build Coastguard Worker# eval: (add-hook 'write-file-hooks 'time-stamp)
343*2e9d4914SAndroid Build Coastguard Worker# time-stamp-start: "scriptversion="
344*2e9d4914SAndroid Build Coastguard Worker# time-stamp-format: "%:y-%02m-%02d.%02H"
345*2e9d4914SAndroid Build Coastguard Worker# time-stamp-time-zone: "UTC"
346*2e9d4914SAndroid Build Coastguard Worker# time-stamp-end: "; # UTC"
347*2e9d4914SAndroid Build Coastguard Worker# End:
348