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