compile revision 142403
190926Snectar#! /bin/sh
290926Snectar# Wrapper for compilers which do not understand `-c -o'.
390926Snectar
4142403Snectarscriptversion=2003-11-09.00
5142403Snectar
6142403Snectar# Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc.
790926Snectar# Written by Tom Tromey <tromey@cygnus.com>.
890926Snectar#
990926Snectar# This program is free software; you can redistribute it and/or modify
1090926Snectar# it under the terms of the GNU General Public License as published by
1190926Snectar# the Free Software Foundation; either version 2, or (at your option)
1290926Snectar# any later version.
1390926Snectar#
1490926Snectar# This program is distributed in the hope that it will be useful,
1590926Snectar# but WITHOUT ANY WARRANTY; without even the implied warranty of
1690926Snectar# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1790926Snectar# GNU General Public License for more details.
1890926Snectar#
1990926Snectar# You should have received a copy of the GNU General Public License
2090926Snectar# along with this program; if not, write to the Free Software
2190926Snectar# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2290926Snectar
2390926Snectar# As a special exception to the GNU General Public License, if you
2490926Snectar# distribute this file as part of a program that contains a
2590926Snectar# configuration script generated by Autoconf, you may include it under
2690926Snectar# the same distribution terms that you use for the rest of that program.
2790926Snectar
28142403Snectar# This file is maintained in Automake, please report
29142403Snectar# bugs to <bug-automake@gnu.org> or send patches to
30142403Snectar# <automake-patches@gnu.org>.
3190926Snectar
32142403Snectarcase $1 in
33142403Snectar  '')
34142403Snectar     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
35142403Snectar     exit 1;
36142403Snectar     ;;
37142403Snectar  -h | --h*)
38142403Snectar    cat <<\EOF
39142403SnectarUsage: compile [--help] [--version] PROGRAM [ARGS]
40142403Snectar
41142403SnectarWrapper for compilers which do not understand `-c -o'.
42142403SnectarRemove `-o dest.o' from ARGS, run PROGRAM with the remaining
43142403Snectararguments, and rename the output as expected.
44142403Snectar
45142403SnectarIf you are trying to build a whole package this is not the
46142403Snectarright script to run: please start by reading the file `INSTALL'.
47142403Snectar
48142403SnectarReport bugs to <bug-automake@gnu.org>.
49142403SnectarEOF
50142403Snectar    exit 0
51142403Snectar    ;;
52142403Snectar  -v | --v*)
53142403Snectar    echo "compile $scriptversion"
54142403Snectar    exit 0
55142403Snectar    ;;
56142403Snectaresac
57142403Snectar
58142403Snectar
5990926Snectarprog=$1
6090926Snectarshift
6190926Snectar
6290926Snectarofile=
6390926Snectarcfile=
6490926Snectarargs=
6590926Snectarwhile test $# -gt 0; do
66142403Snectar  case "$1" in
6790926Snectar    -o)
68142403Snectar      # configure might choose to run compile as `compile cc -o foo foo.c'.
69142403Snectar      # So we do something ugly here.
70142403Snectar      ofile=$2
71142403Snectar      shift
72142403Snectar      case "$ofile" in
7390926Snectar	*.o | *.obj)
74142403Snectar	  ;;
7590926Snectar	*)
76142403Snectar	  args="$args -o $ofile"
77142403Snectar	  ofile=
78142403Snectar	  ;;
79142403Snectar      esac
8090926Snectar       ;;
8190926Snectar    *.c)
82142403Snectar      cfile=$1
83142403Snectar      args="$args $1"
84142403Snectar      ;;
8590926Snectar    *)
86142403Snectar      args="$args $1"
87142403Snectar      ;;
88142403Snectar  esac
89142403Snectar  shift
9090926Snectardone
9190926Snectar
9290926Snectarif test -z "$ofile" || test -z "$cfile"; then
93142403Snectar  # If no `-o' option was seen then we might have been invoked from a
94142403Snectar  # pattern rule where we don't need one.  That is ok -- this is a
95142403Snectar  # normal compilation that the losing compiler can handle.  If no
96142403Snectar  # `.c' file was seen then we are probably linking.  That is also
97142403Snectar  # ok.
98142403Snectar  exec "$prog" $args
9990926Snectarfi
10090926Snectar
10190926Snectar# Name of file we expect compiler to create.
10290926Snectarcofile=`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
10390926Snectar
10490926Snectar# Create the lock directory.
10590926Snectar# Note: use `[/.-]' here to ensure that we don't use the same name
10690926Snectar# that we are using for the .o file.  Also, base the name on the expected
10790926Snectar# object file name, since that is what matters with a parallel build.
10890926Snectarlockdir=`echo $cofile | sed -e 's|[/.-]|_|g'`.d
10990926Snectarwhile true; do
110142403Snectar  if mkdir $lockdir > /dev/null 2>&1; then
111142403Snectar    break
112142403Snectar  fi
113142403Snectar  sleep 1
11490926Snectardone
11590926Snectar# FIXME: race condition here if user kills between mkdir and trap.
11690926Snectartrap "rmdir $lockdir; exit 1" 1 2 15
11790926Snectar
11890926Snectar# Run the compile.
11990926Snectar"$prog" $args
12090926Snectarstatus=$?
12190926Snectar
12290926Snectarif test -f "$cofile"; then
123142403Snectar  mv "$cofile" "$ofile"
12490926Snectarfi
12590926Snectar
12690926Snectarrmdir $lockdir
12790926Snectarexit $status
128142403Snectar
129142403Snectar# Local Variables:
130142403Snectar# mode: shell-script
131142403Snectar# sh-indentation: 2
132142403Snectar# eval: (add-hook 'write-file-hooks 'time-stamp)
133142403Snectar# time-stamp-start: "scriptversion="
134142403Snectar# time-stamp-format: "%:y-%02m-%02d.%02H"
135142403Snectar# time-stamp-end: "$"
136142403Snectar# End:
137