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