xref: /illumos-gate/usr/src/grub/grub-0.97/compile (revision 1b8adde7)
17c478bd9Sstevel@tonic-gate#! /bin/sh
27c478bd9Sstevel@tonic-gate# Wrapper for compilers which do not understand `-c -o'.
37c478bd9Sstevel@tonic-gate
4*1b8adde7SWilliam Kucharskiscriptversion=2004-10-12.08
57c478bd9Sstevel@tonic-gate
6*1b8adde7SWilliam Kucharski# Copyright (C) 1999, 2000, 2003, 2004 Free Software Foundation, Inc.
77c478bd9Sstevel@tonic-gate# Written by Tom Tromey <tromey@cygnus.com>.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# This program is free software; you can redistribute it and/or modify
107c478bd9Sstevel@tonic-gate# it under the terms of the GNU General Public License as published by
117c478bd9Sstevel@tonic-gate# the Free Software Foundation; either version 2, or (at your option)
127c478bd9Sstevel@tonic-gate# any later version.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# This program is distributed in the hope that it will be useful,
157c478bd9Sstevel@tonic-gate# but WITHOUT ANY WARRANTY; without even the implied warranty of
167c478bd9Sstevel@tonic-gate# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
177c478bd9Sstevel@tonic-gate# GNU General Public License for more details.
187c478bd9Sstevel@tonic-gate#
197c478bd9Sstevel@tonic-gate# You should have received a copy of the GNU General Public License
207c478bd9Sstevel@tonic-gate# along with this program; if not, write to the Free Software
217c478bd9Sstevel@tonic-gate# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
227c478bd9Sstevel@tonic-gate
237c478bd9Sstevel@tonic-gate# As a special exception to the GNU General Public License, if you
247c478bd9Sstevel@tonic-gate# distribute this file as part of a program that contains a
257c478bd9Sstevel@tonic-gate# configuration script generated by Autoconf, you may include it under
267c478bd9Sstevel@tonic-gate# the same distribution terms that you use for the rest of that program.
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate# This file is maintained in Automake, please report
297c478bd9Sstevel@tonic-gate# bugs to <bug-automake@gnu.org> or send patches to
307c478bd9Sstevel@tonic-gate# <automake-patches@gnu.org>.
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gatecase $1 in
337c478bd9Sstevel@tonic-gate  '')
347c478bd9Sstevel@tonic-gate     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
357c478bd9Sstevel@tonic-gate     exit 1;
367c478bd9Sstevel@tonic-gate     ;;
377c478bd9Sstevel@tonic-gate  -h | --h*)
387c478bd9Sstevel@tonic-gate    cat <<\EOF
397c478bd9Sstevel@tonic-gateUsage: compile [--help] [--version] PROGRAM [ARGS]
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gateWrapper for compilers which do not understand `-c -o'.
427c478bd9Sstevel@tonic-gateRemove `-o dest.o' from ARGS, run PROGRAM with the remaining
437c478bd9Sstevel@tonic-gatearguments, and rename the output as expected.
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gateIf you are trying to build a whole package this is not the
467c478bd9Sstevel@tonic-gateright script to run: please start by reading the file `INSTALL'.
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gateReport bugs to <bug-automake@gnu.org>.
497c478bd9Sstevel@tonic-gateEOF
507c478bd9Sstevel@tonic-gate    exit 0
517c478bd9Sstevel@tonic-gate    ;;
527c478bd9Sstevel@tonic-gate  -v | --v*)
537c478bd9Sstevel@tonic-gate    echo "compile $scriptversion"
547c478bd9Sstevel@tonic-gate    exit 0
557c478bd9Sstevel@tonic-gate    ;;
567c478bd9Sstevel@tonic-gateesac
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gateofile=
597c478bd9Sstevel@tonic-gatecfile=
60*1b8adde7SWilliam Kucharskieat=
61*1b8adde7SWilliam Kucharski
62*1b8adde7SWilliam Kucharskifor arg
63*1b8adde7SWilliam Kucharskido
64*1b8adde7SWilliam Kucharski  if test -n "$eat"; then
65*1b8adde7SWilliam Kucharski    eat=
66*1b8adde7SWilliam Kucharski  else
67*1b8adde7SWilliam Kucharski    case $1 in
68*1b8adde7SWilliam Kucharski      -o)
69*1b8adde7SWilliam Kucharski	# configure might choose to run compile as `compile cc -o foo foo.c'.
70*1b8adde7SWilliam Kucharski	# So we strip `-o arg' only if arg is an object.
71*1b8adde7SWilliam Kucharski	eat=1
72*1b8adde7SWilliam Kucharski	case $2 in
73*1b8adde7SWilliam Kucharski	  *.o | *.obj)
74*1b8adde7SWilliam Kucharski	    ofile=$2
75*1b8adde7SWilliam Kucharski	    ;;
76*1b8adde7SWilliam Kucharski	  *)
77*1b8adde7SWilliam Kucharski	    set x "$@" -o "$2"
78*1b8adde7SWilliam Kucharski	    shift
79*1b8adde7SWilliam Kucharski	    ;;
80*1b8adde7SWilliam Kucharski	esac
81*1b8adde7SWilliam Kucharski	;;
82*1b8adde7SWilliam Kucharski      *.c)
83*1b8adde7SWilliam Kucharski	cfile=$1
84*1b8adde7SWilliam Kucharski	set x "$@" "$1"
85*1b8adde7SWilliam Kucharski	shift
86*1b8adde7SWilliam Kucharski	;;
87*1b8adde7SWilliam Kucharski      *)
88*1b8adde7SWilliam Kucharski	set x "$@" "$1"
89*1b8adde7SWilliam Kucharski	shift
90*1b8adde7SWilliam Kucharski	;;
91*1b8adde7SWilliam Kucharski    esac
92*1b8adde7SWilliam Kucharski  fi
937c478bd9Sstevel@tonic-gate  shift
947c478bd9Sstevel@tonic-gatedone
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gateif test -z "$ofile" || test -z "$cfile"; then
977c478bd9Sstevel@tonic-gate  # If no `-o' option was seen then we might have been invoked from a
987c478bd9Sstevel@tonic-gate  # pattern rule where we don't need one.  That is ok -- this is a
997c478bd9Sstevel@tonic-gate  # normal compilation that the losing compiler can handle.  If no
1007c478bd9Sstevel@tonic-gate  # `.c' file was seen then we are probably linking.  That is also
1017c478bd9Sstevel@tonic-gate  # ok.
102*1b8adde7SWilliam Kucharski  exec "$@"
1037c478bd9Sstevel@tonic-gatefi
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gate# Name of file we expect compiler to create.
106*1b8adde7SWilliam Kucharskicofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate# Create the lock directory.
1097c478bd9Sstevel@tonic-gate# Note: use `[/.-]' here to ensure that we don't use the same name
1107c478bd9Sstevel@tonic-gate# that we are using for the .o file.  Also, base the name on the expected
1117c478bd9Sstevel@tonic-gate# object file name, since that is what matters with a parallel build.
112*1b8adde7SWilliam Kucharskilockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d
1137c478bd9Sstevel@tonic-gatewhile true; do
114*1b8adde7SWilliam Kucharski  if mkdir "$lockdir" >/dev/null 2>&1; then
1157c478bd9Sstevel@tonic-gate    break
1167c478bd9Sstevel@tonic-gate  fi
1177c478bd9Sstevel@tonic-gate  sleep 1
1187c478bd9Sstevel@tonic-gatedone
1197c478bd9Sstevel@tonic-gate# FIXME: race condition here if user kills between mkdir and trap.
120*1b8adde7SWilliam Kucharskitrap "rmdir '$lockdir'; exit 1" 1 2 15
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate# Run the compile.
123*1b8adde7SWilliam Kucharski"$@"
124*1b8adde7SWilliam Kucharskiret=$?
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gateif test -f "$cofile"; then
1277c478bd9Sstevel@tonic-gate  mv "$cofile" "$ofile"
128*1b8adde7SWilliam Kucharskielif test -f "${cofile}bj"; then
129*1b8adde7SWilliam Kucharski  mv "${cofile}bj" "$ofile"
1307c478bd9Sstevel@tonic-gatefi
1317c478bd9Sstevel@tonic-gate
132*1b8adde7SWilliam Kucharskirmdir "$lockdir"
133*1b8adde7SWilliam Kucharskiexit $ret
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate# Local Variables:
1367c478bd9Sstevel@tonic-gate# mode: shell-script
1377c478bd9Sstevel@tonic-gate# sh-indentation: 2
1387c478bd9Sstevel@tonic-gate# eval: (add-hook 'write-file-hooks 'time-stamp)
1397c478bd9Sstevel@tonic-gate# time-stamp-start: "scriptversion="
1407c478bd9Sstevel@tonic-gate# time-stamp-format: "%:y-%02m-%02d.%02H"
1417c478bd9Sstevel@tonic-gate# time-stamp-end: "$"
1427c478bd9Sstevel@tonic-gate# End:
143