Rev.
[official-gcc.git] / compile
blob3a1de1ede6096d4299e469bf916bc5b6f1d992ad
3 ##!/bin/bash
4 # Wrapper for compilers which do not understand `-c -o'.
6 scriptversion=2005-05-14.22
8 # Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
9 # Written by Tom Tromey <tromey@cygnus.com>.
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2, or (at your option)
14 # any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 # As a special exception to the GNU General Public License, if you
26 # distribute this file as part of a program that contains a
27 # configuration script generated by Autoconf, you may include it under
28 # the same distribution terms that you use for the rest of that program.
30 # This file is maintained in Automake, please report
31 # bugs to <bug-automake@gnu.org> or send patches to
32 # <automake-patches@gnu.org>.
34 case $1 in
35   '')
36      echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
37      exit 1;
38      ;;
39   -h | --h*)
40     cat <<\EOF
41 Usage: compile [--help] [--version] PROGRAM [ARGS]
43 Wrapper for compilers which do not understand `-c -o'.
44 Remove `-o dest.o' from ARGS, run PROGRAM with the remaining
45 arguments, and rename the output as expected.
47 If you are trying to build a whole package this is not the
48 right script to run: please start by reading the file `INSTALL'.
50 Report bugs to <bug-automake@gnu.org>.
51 EOF
52     exit $?
53     ;;
54   -v | --v*)
55     echo "compile $scriptversion"
56     exit $?
57     ;;
58 esac
60 ofile=
61 cfile=
62 eat=
64 for arg
66   if test -n "$eat"; then
67     eat=
68   else
69     case $1 in
70       -o)
71         # configure might choose to run compile as `compile cc -o foo foo.c'.
72         # So we strip `-o arg' only if arg is an object.
73         eat=1
74         case $2 in
75           *.o | *.obj)
76             ofile=$2
77             ;;
78           *)
79             set x "$@" -o "$2"
80             shift
81             ;;
82         esac
83         ;;
84       *.c)
85         cfile=$1
86         set x "$@" "$1"
87         shift
88         ;;
89       *)
90         set x "$@" "$1"
91         shift
92         ;;
93     esac
94   fi
95   shift
96 done
98 if test -z "$ofile" || test -z "$cfile"; then
99   # If no `-o' option was seen then we might have been invoked from a
100   # pattern rule where we don't need one.  That is ok -- this is a
101   # normal compilation that the losing compiler can handle.  If no
102   # `.c' file was seen then we are probably linking.  That is also
103   # ok.
104   exec "$@"
107 # Name of file we expect compiler to create.
108 cofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
110 # Create the lock directory.
111 # Note: use `[/.-]' here to ensure that we don't use the same name
112 # that we are using for the .o file.  Also, base the name on the expected
113 # object file name, since that is what matters with a parallel build.
114 lockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d
115 while true; do
116   if mkdir "$lockdir" >/dev/null 2>&1; then
117     break
118   fi
119   sleep 1
120 done
121 # FIXME: race condition here if user kills between mkdir and trap.
122 trap "rmdir '$lockdir'; exit 1" 1 2 15
124 # Run the compile.
125 "$@"
126 ret=$?
128 if test -f "$cofile"; then
129   mv "$cofile" "$ofile"
130 elif test -f "${cofile}bj"; then
131   mv "${cofile}bj" "$ofile"
134 rmdir "$lockdir"
135 exit $ret
137 # Local Variables:
138 # mode: shell-script
139 # sh-indentation: 2
140 # eval: (add-hook 'write-file-hooks 'time-stamp)
141 # time-stamp-start: "scriptversion="
142 # time-stamp-format: "%:y-%02m-%02d.%02H"
143 # time-stamp-end: "$"
144 # End: