compile revision 1.1 1 1.1 mrg #! /bin/sh
2 1.1 mrg
3 1.1 mrg # Wrapper for compilers which do not understand `-c -o'.
4 1.1 mrg
5 1.1 mrg # Copyright 1999, 2000 Free Software Foundation, Inc.
6 1.1 mrg # Written by Tom Tromey <tromey (at] cygnus.com>.
7 1.1 mrg #
8 1.1 mrg # This program is free software; you can redistribute it and/or modify
9 1.1 mrg # it under the terms of the GNU General Public License as published by
10 1.1 mrg # the Free Software Foundation; either version 2, or (at your option)
11 1.1 mrg # any later version.
12 1.1 mrg #
13 1.1 mrg # This program is distributed in the hope that it will be useful,
14 1.1 mrg # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 1.1 mrg # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 1.1 mrg # GNU General Public License for more details.
17 1.1 mrg #
18 1.1 mrg # You should have received a copy of the GNU General Public License
19 1.1 mrg # along with this program; if not, write to the Free Software
20 1.1 mrg # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 1.1 mrg
22 1.1 mrg # As a special exception to the GNU General Public License, if you
23 1.1 mrg # distribute this file as part of a program that contains a
24 1.1 mrg # configuration script generated by Autoconf, you may include it under
25 1.1 mrg # the same distribution terms that you use for the rest of that program.
26 1.1 mrg
27 1.1 mrg # Usage:
28 1.1 mrg # compile PROGRAM [ARGS]...
29 1.1 mrg # `-o FOO.o' is removed from the args passed to the actual compile.
30 1.1 mrg
31 1.1 mrg prog=$1
32 1.1 mrg shift
33 1.1 mrg
34 1.1 mrg ofile=
35 1.1 mrg cfile=
36 1.1 mrg args=
37 1.1 mrg while test $# -gt 0; do
38 1.1 mrg case "$1" in
39 1.1 mrg -o)
40 1.1 mrg # configure might choose to run compile as `compile cc -o foo foo.c'.
41 1.1 mrg # So we do something ugly here.
42 1.1 mrg ofile=$2
43 1.1 mrg shift
44 1.1 mrg case "$ofile" in
45 1.1 mrg *.o | *.obj)
46 1.1 mrg ;;
47 1.1 mrg *)
48 1.1 mrg args="$args -o $ofile"
49 1.1 mrg ofile=
50 1.1 mrg ;;
51 1.1 mrg esac
52 1.1 mrg ;;
53 1.1 mrg *.c)
54 1.1 mrg cfile=$1
55 1.1 mrg args="$args $1"
56 1.1 mrg ;;
57 1.1 mrg *)
58 1.1 mrg args="$args $1"
59 1.1 mrg ;;
60 1.1 mrg esac
61 1.1 mrg shift
62 1.1 mrg done
63 1.1 mrg
64 1.1 mrg if test -z "$ofile" || test -z "$cfile"; then
65 1.1 mrg # If no `-o' option was seen then we might have been invoked from a
66 1.1 mrg # pattern rule where we don't need one. That is ok -- this is a
67 1.1 mrg # normal compilation that the losing compiler can handle. If no
68 1.1 mrg # `.c' file was seen then we are probably linking. That is also
69 1.1 mrg # ok.
70 1.1 mrg exec "$prog" $args
71 1.1 mrg fi
72 1.1 mrg
73 1.1 mrg # Name of file we expect compiler to create.
74 1.1 mrg cofile=`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
75 1.1 mrg
76 1.1 mrg # Create the lock directory.
77 1.1 mrg # Note: use `[/.-]' here to ensure that we don't use the same name
78 1.1 mrg # that we are using for the .o file. Also, base the name on the expected
79 1.1 mrg # object file name, since that is what matters with a parallel build.
80 1.1 mrg lockdir=`echo $cofile | sed -e 's|[/.-]|_|g'`.d
81 1.1 mrg while true; do
82 1.1 mrg if mkdir $lockdir > /dev/null 2>&1; then
83 1.1 mrg break
84 1.1 mrg fi
85 1.1 mrg sleep 1
86 1.1 mrg done
87 1.1 mrg # FIXME: race condition here if user kills between mkdir and trap.
88 1.1 mrg trap "rmdir $lockdir; exit 1" 1 2 15
89 1.1 mrg
90 1.1 mrg # Run the compile.
91 1.1 mrg "$prog" $args
92 1.1 mrg status=$?
93 1.1 mrg
94 1.1 mrg if test -f "$cofile"; then
95 1.1 mrg mv "$cofile" "$ofile"
96 1.1 mrg fi
97 1.1 mrg
98 1.1 mrg rmdir $lockdir
99 1.1 mrg exit $status
100