1 |
#! /bin/sh |
#! /bin/sh |
2 |
# Wrapper for compilers which do not understand `-c -o'. |
# Wrapper for compilers which do not understand `-c -o'. |
3 |
|
|
4 |
scriptversion=2003-11-09.00 |
scriptversion=2004-10-12.08 |
5 |
|
|
6 |
# Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc. |
# Copyright (C) 1999, 2000, 2003, 2004 Free Software Foundation, Inc. |
7 |
# Written by Tom Tromey <tromey@cygnus.com>. |
# Written by Tom Tromey <tromey@cygnus.com>. |
8 |
# |
# |
9 |
# This program is free software; you can redistribute it and/or modify |
# This program is free software; you can redistribute it and/or modify |
55 |
;; |
;; |
56 |
esac |
esac |
57 |
|
|
|
|
|
|
prog=$1 |
|
|
shift |
|
|
|
|
58 |
ofile= |
ofile= |
59 |
cfile= |
cfile= |
60 |
args= |
eat= |
61 |
while test $# -gt 0; do |
|
62 |
case "$1" in |
for arg |
63 |
-o) |
do |
64 |
# configure might choose to run compile as `compile cc -o foo foo.c'. |
if test -n "$eat"; then |
65 |
# So we do something ugly here. |
eat= |
66 |
ofile=$2 |
else |
67 |
shift |
case $1 in |
68 |
case "$ofile" in |
-o) |
69 |
*.o | *.obj) |
# configure might choose to run compile as `compile cc -o foo foo.c'. |
70 |
;; |
# So we strip `-o arg' only if arg is an object. |
71 |
*) |
eat=1 |
72 |
args="$args -o $ofile" |
case $2 in |
73 |
ofile= |
*.o | *.obj) |
74 |
;; |
ofile=$2 |
75 |
esac |
;; |
76 |
;; |
*) |
77 |
*.c) |
set x "$@" -o "$2" |
78 |
cfile=$1 |
shift |
79 |
args="$args $1" |
;; |
80 |
;; |
esac |
81 |
*) |
;; |
82 |
args="$args $1" |
*.c) |
83 |
;; |
cfile=$1 |
84 |
esac |
set x "$@" "$1" |
85 |
|
shift |
86 |
|
;; |
87 |
|
*) |
88 |
|
set x "$@" "$1" |
89 |
|
shift |
90 |
|
;; |
91 |
|
esac |
92 |
|
fi |
93 |
shift |
shift |
94 |
done |
done |
95 |
|
|
99 |
# normal compilation that the losing compiler can handle. If no |
# normal compilation that the losing compiler can handle. If no |
100 |
# `.c' file was seen then we are probably linking. That is also |
# `.c' file was seen then we are probably linking. That is also |
101 |
# ok. |
# ok. |
102 |
exec "$prog" $args |
exec "$@" |
103 |
fi |
fi |
104 |
|
|
105 |
# Name of file we expect compiler to create. |
# Name of file we expect compiler to create. |
106 |
cofile=`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'` |
cofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'` |
107 |
|
|
108 |
# Create the lock directory. |
# Create the lock directory. |
109 |
# Note: use `[/.-]' here to ensure that we don't use the same name |
# Note: use `[/.-]' here to ensure that we don't use the same name |
110 |
# that we are using for the .o file. Also, base the name on the expected |
# that we are using for the .o file. Also, base the name on the expected |
111 |
# object file name, since that is what matters with a parallel build. |
# object file name, since that is what matters with a parallel build. |
112 |
lockdir=`echo $cofile | sed -e 's|[/.-]|_|g'`.d |
lockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d |
113 |
while true; do |
while true; do |
114 |
if mkdir $lockdir > /dev/null 2>&1; then |
if mkdir "$lockdir" >/dev/null 2>&1; then |
115 |
break |
break |
116 |
fi |
fi |
117 |
sleep 1 |
sleep 1 |
118 |
done |
done |
119 |
# FIXME: race condition here if user kills between mkdir and trap. |
# FIXME: race condition here if user kills between mkdir and trap. |
120 |
trap "rmdir $lockdir; exit 1" 1 2 15 |
trap "rmdir '$lockdir'; exit 1" 1 2 15 |
121 |
|
|
122 |
# Run the compile. |
# Run the compile. |
123 |
"$prog" $args |
"$@" |
124 |
status=$? |
ret=$? |
125 |
|
|
126 |
if test -f "$cofile"; then |
if test -f "$cofile"; then |
127 |
mv "$cofile" "$ofile" |
mv "$cofile" "$ofile" |
128 |
|
elif test -f "${cofile}bj"; then |
129 |
|
mv "${cofile}bj" "$ofile" |
130 |
fi |
fi |
131 |
|
|
132 |
rmdir $lockdir |
rmdir "$lockdir" |
133 |
exit $status |
exit $ret |
134 |
|
|
135 |
# Local Variables: |
# Local Variables: |
136 |
# mode: shell-script |
# mode: shell-script |