10974d292Smrg#! /bin/sh 243df4709Smrg# Wrapper for compilers which do not understand `-c -o'. 30974d292Smrg 443df4709Smrgscriptversion=2009-10-06.20; # UTC 50974d292Smrg 643df4709Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009 Free Software 743df4709Smrg# Foundation, Inc. 80974d292Smrg# Written by Tom Tromey <tromey@cygnus.com>. 90974d292Smrg# 100974d292Smrg# This program is free software; you can redistribute it and/or modify 110974d292Smrg# it under the terms of the GNU General Public License as published by 120974d292Smrg# the Free Software Foundation; either version 2, or (at your option) 130974d292Smrg# any later version. 140974d292Smrg# 150974d292Smrg# This program is distributed in the hope that it will be useful, 160974d292Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 170974d292Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 180974d292Smrg# GNU General Public License for more details. 190974d292Smrg# 200974d292Smrg# You should have received a copy of the GNU General Public License 210974d292Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 220974d292Smrg 230974d292Smrg# As a special exception to the GNU General Public License, if you 240974d292Smrg# distribute this file as part of a program that contains a 250974d292Smrg# configuration script generated by Autoconf, you may include it under 260974d292Smrg# the same distribution terms that you use for the rest of that program. 270974d292Smrg 280974d292Smrg# This file is maintained in Automake, please report 290974d292Smrg# bugs to <bug-automake@gnu.org> or send patches to 300974d292Smrg# <automake-patches@gnu.org>. 310974d292Smrg 320974d292Smrgcase $1 in 330974d292Smrg '') 3443df4709Smrg echo "$0: No command. Try \`$0 --help' for more information." 1>&2 350974d292Smrg exit 1; 360974d292Smrg ;; 370974d292Smrg -h | --h*) 380974d292Smrg cat <<\EOF 390974d292SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 400974d292Smrg 4143df4709SmrgWrapper for compilers which do not understand `-c -o'. 4243df4709SmrgRemove `-o dest.o' from ARGS, run PROGRAM with the remaining 430974d292Smrgarguments, and rename the output as expected. 440974d292Smrg 450974d292SmrgIf you are trying to build a whole package this is not the 4643df4709Smrgright script to run: please start by reading the file `INSTALL'. 470974d292Smrg 480974d292SmrgReport bugs to <bug-automake@gnu.org>. 490974d292SmrgEOF 500974d292Smrg exit $? 510974d292Smrg ;; 520974d292Smrg -v | --v*) 530974d292Smrg echo "compile $scriptversion" 540974d292Smrg exit $? 550974d292Smrg ;; 560974d292Smrgesac 570974d292Smrg 580974d292Smrgofile= 590974d292Smrgcfile= 6043df4709Smrgeat= 610974d292Smrg 620974d292Smrgfor arg 630974d292Smrgdo 640974d292Smrg if test -n "$eat"; then 650974d292Smrg eat= 660974d292Smrg else 670974d292Smrg case $1 in 680974d292Smrg -o) 6943df4709Smrg # configure might choose to run compile as `compile cc -o foo foo.c'. 7043df4709Smrg # So we strip `-o arg' only if arg is an object. 710974d292Smrg eat=1 720974d292Smrg case $2 in 730974d292Smrg *.o | *.obj) 740974d292Smrg ofile=$2 750974d292Smrg ;; 760974d292Smrg *) 770974d292Smrg set x "$@" -o "$2" 780974d292Smrg shift 790974d292Smrg ;; 800974d292Smrg esac 810974d292Smrg ;; 820974d292Smrg *.c) 830974d292Smrg cfile=$1 840974d292Smrg set x "$@" "$1" 850974d292Smrg shift 860974d292Smrg ;; 870974d292Smrg *) 880974d292Smrg set x "$@" "$1" 890974d292Smrg shift 900974d292Smrg ;; 910974d292Smrg esac 920974d292Smrg fi 930974d292Smrg shift 940974d292Smrgdone 950974d292Smrg 960974d292Smrgif test -z "$ofile" || test -z "$cfile"; then 9743df4709Smrg # If no `-o' option was seen then we might have been invoked from a 980974d292Smrg # pattern rule where we don't need one. That is ok -- this is a 990974d292Smrg # normal compilation that the losing compiler can handle. If no 10043df4709Smrg # `.c' file was seen then we are probably linking. That is also 1010974d292Smrg # ok. 1020974d292Smrg exec "$@" 1030974d292Smrgfi 1040974d292Smrg 1050974d292Smrg# Name of file we expect compiler to create. 1060974d292Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 1070974d292Smrg 1080974d292Smrg# Create the lock directory. 10943df4709Smrg# Note: use `[/\\:.-]' here to ensure that we don't use the same name 1100974d292Smrg# that we are using for the .o file. Also, base the name on the expected 1110974d292Smrg# object file name, since that is what matters with a parallel build. 1120974d292Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 1130974d292Smrgwhile true; do 1140974d292Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 1150974d292Smrg break 1160974d292Smrg fi 1170974d292Smrg sleep 1 1180974d292Smrgdone 1190974d292Smrg# FIXME: race condition here if user kills between mkdir and trap. 1200974d292Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 1210974d292Smrg 1220974d292Smrg# Run the compile. 1230974d292Smrg"$@" 1240974d292Smrgret=$? 1250974d292Smrg 1260974d292Smrgif test -f "$cofile"; then 1270974d292Smrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 1280974d292Smrgelif test -f "${cofile}bj"; then 1290974d292Smrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 1300974d292Smrgfi 1310974d292Smrg 1320974d292Smrgrmdir "$lockdir" 1330974d292Smrgexit $ret 1340974d292Smrg 1350974d292Smrg# Local Variables: 1360974d292Smrg# mode: shell-script 1370974d292Smrg# sh-indentation: 2 1380974d292Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 1390974d292Smrg# time-stamp-start: "scriptversion=" 1400974d292Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 1410974d292Smrg# time-stamp-time-zone: "UTC" 1420974d292Smrg# time-stamp-end: "; # UTC" 1430974d292Smrg# End: 144