leo_sobral@2: #! /bin/sh
leo_sobral@2: # Wrapper for compilers which do not understand `-c -o'.
leo_sobral@2: 
leo_sobral@2: scriptversion=2003-11-09.00
leo_sobral@2: 
leo_sobral@2: # Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc.
leo_sobral@2: # Written by Tom Tromey <tromey@cygnus.com>.
leo_sobral@2: #
leo_sobral@2: # This program is free software; you can redistribute it and/or modify
leo_sobral@2: # it under the terms of the GNU General Public License as published by
leo_sobral@2: # the Free Software Foundation; either version 2, or (at your option)
leo_sobral@2: # any later version.
leo_sobral@2: #
leo_sobral@2: # This program is distributed in the hope that it will be useful,
leo_sobral@2: # but WITHOUT ANY WARRANTY; without even the implied warranty of
leo_sobral@2: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
leo_sobral@2: # GNU General Public License for more details.
leo_sobral@2: #
leo_sobral@2: # You should have received a copy of the GNU General Public License
leo_sobral@2: # along with this program; if not, write to the Free Software
leo_sobral@2: # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
leo_sobral@2: 
leo_sobral@2: # As a special exception to the GNU General Public License, if you
leo_sobral@2: # distribute this file as part of a program that contains a
leo_sobral@2: # configuration script generated by Autoconf, you may include it under
leo_sobral@2: # the same distribution terms that you use for the rest of that program.
leo_sobral@2: 
leo_sobral@2: # This file is maintained in Automake, please report
leo_sobral@2: # bugs to <bug-automake@gnu.org> or send patches to
leo_sobral@2: # <automake-patches@gnu.org>.
leo_sobral@2: 
leo_sobral@2: case $1 in
leo_sobral@2:   '')
leo_sobral@2:      echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
leo_sobral@2:      exit 1;
leo_sobral@2:      ;;
leo_sobral@2:   -h | --h*)
leo_sobral@2:     cat <<\EOF
leo_sobral@2: Usage: compile [--help] [--version] PROGRAM [ARGS]
leo_sobral@2: 
leo_sobral@2: Wrapper for compilers which do not understand `-c -o'.
leo_sobral@2: Remove `-o dest.o' from ARGS, run PROGRAM with the remaining
leo_sobral@2: arguments, and rename the output as expected.
leo_sobral@2: 
leo_sobral@2: If you are trying to build a whole package this is not the
leo_sobral@2: right script to run: please start by reading the file `INSTALL'.
leo_sobral@2: 
leo_sobral@2: Report bugs to <bug-automake@gnu.org>.
leo_sobral@2: EOF
leo_sobral@2:     exit 0
leo_sobral@2:     ;;
leo_sobral@2:   -v | --v*)
leo_sobral@2:     echo "compile $scriptversion"
leo_sobral@2:     exit 0
leo_sobral@2:     ;;
leo_sobral@2: esac
leo_sobral@2: 
leo_sobral@2: 
leo_sobral@2: prog=$1
leo_sobral@2: shift
leo_sobral@2: 
leo_sobral@2: ofile=
leo_sobral@2: cfile=
leo_sobral@2: args=
leo_sobral@2: while test $# -gt 0; do
leo_sobral@2:   case "$1" in
leo_sobral@2:     -o)
leo_sobral@2:       # configure might choose to run compile as `compile cc -o foo foo.c'.
leo_sobral@2:       # So we do something ugly here.
leo_sobral@2:       ofile=$2
leo_sobral@2:       shift
leo_sobral@2:       case "$ofile" in
leo_sobral@2: 	*.o | *.obj)
leo_sobral@2: 	  ;;
leo_sobral@2: 	*)
leo_sobral@2: 	  args="$args -o $ofile"
leo_sobral@2: 	  ofile=
leo_sobral@2: 	  ;;
leo_sobral@2:       esac
leo_sobral@2:        ;;
leo_sobral@2:     *.c)
leo_sobral@2:       cfile=$1
leo_sobral@2:       args="$args $1"
leo_sobral@2:       ;;
leo_sobral@2:     *)
leo_sobral@2:       args="$args $1"
leo_sobral@2:       ;;
leo_sobral@2:   esac
leo_sobral@2:   shift
leo_sobral@2: done
leo_sobral@2: 
leo_sobral@2: if test -z "$ofile" || test -z "$cfile"; then
leo_sobral@2:   # If no `-o' option was seen then we might have been invoked from a
leo_sobral@2:   # pattern rule where we don't need one.  That is ok -- this is a
leo_sobral@2:   # normal compilation that the losing compiler can handle.  If no
leo_sobral@2:   # `.c' file was seen then we are probably linking.  That is also
leo_sobral@2:   # ok.
leo_sobral@2:   exec "$prog" $args
leo_sobral@2: fi
leo_sobral@2: 
leo_sobral@2: # Name of file we expect compiler to create.
leo_sobral@2: cofile=`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
leo_sobral@2: 
leo_sobral@2: # Create the lock directory.
leo_sobral@2: # Note: use `[/.-]' here to ensure that we don't use the same name
leo_sobral@2: # that we are using for the .o file.  Also, base the name on the expected
leo_sobral@2: # object file name, since that is what matters with a parallel build.
leo_sobral@2: lockdir=`echo $cofile | sed -e 's|[/.-]|_|g'`.d
leo_sobral@2: while true; do
leo_sobral@2:   if mkdir $lockdir > /dev/null 2>&1; then
leo_sobral@2:     break
leo_sobral@2:   fi
leo_sobral@2:   sleep 1
leo_sobral@2: done
leo_sobral@2: # FIXME: race condition here if user kills between mkdir and trap.
leo_sobral@2: trap "rmdir $lockdir; exit 1" 1 2 15
leo_sobral@2: 
leo_sobral@2: # Run the compile.
leo_sobral@2: "$prog" $args
leo_sobral@2: status=$?
leo_sobral@2: 
leo_sobral@2: if test -f "$cofile"; then
leo_sobral@2:   mv "$cofile" "$ofile"
leo_sobral@2: fi
leo_sobral@2: 
leo_sobral@2: rmdir $lockdir
leo_sobral@2: exit $status
leo_sobral@2: 
leo_sobral@2: # Local Variables:
leo_sobral@2: # mode: shell-script
leo_sobral@2: # sh-indentation: 2
leo_sobral@2: # eval: (add-hook 'write-file-hooks 'time-stamp)
leo_sobral@2: # time-stamp-start: "scriptversion="
leo_sobral@2: # time-stamp-format: "%:y-%02m-%02d.%02H"
leo_sobral@2: # time-stamp-end: "$"
leo_sobral@2: # End: