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