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