xref: /titanic_50/usr/src/grub/grub-0.97/compile (revision 1b8adde7ba7d5e04395c141c5400dc2cffd7d809)
1*1b8adde7SWilliam Kucharski#! /bin/sh
2*1b8adde7SWilliam Kucharski# Wrapper for compilers which do not understand `-c -o'.
3*1b8adde7SWilliam Kucharski
4*1b8adde7SWilliam Kucharskiscriptversion=2004-10-12.08
5*1b8adde7SWilliam Kucharski
6*1b8adde7SWilliam Kucharski# Copyright (C) 1999, 2000, 2003, 2004 Free Software Foundation, Inc.
7*1b8adde7SWilliam Kucharski# Written by Tom Tromey <tromey@cygnus.com>.
8*1b8adde7SWilliam Kucharski#
9*1b8adde7SWilliam Kucharski# This program is free software; you can redistribute it and/or modify
10*1b8adde7SWilliam Kucharski# it under the terms of the GNU General Public License as published by
11*1b8adde7SWilliam Kucharski# the Free Software Foundation; either version 2, or (at your option)
12*1b8adde7SWilliam Kucharski# any later version.
13*1b8adde7SWilliam Kucharski#
14*1b8adde7SWilliam Kucharski# This program is distributed in the hope that it will be useful,
15*1b8adde7SWilliam Kucharski# but WITHOUT ANY WARRANTY; without even the implied warranty of
16*1b8adde7SWilliam Kucharski# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*1b8adde7SWilliam Kucharski# GNU General Public License for more details.
18*1b8adde7SWilliam Kucharski#
19*1b8adde7SWilliam Kucharski# You should have received a copy of the GNU General Public License
20*1b8adde7SWilliam Kucharski# along with this program; if not, write to the Free Software
21*1b8adde7SWilliam Kucharski# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22*1b8adde7SWilliam Kucharski
23*1b8adde7SWilliam Kucharski# As a special exception to the GNU General Public License, if you
24*1b8adde7SWilliam Kucharski# distribute this file as part of a program that contains a
25*1b8adde7SWilliam Kucharski# configuration script generated by Autoconf, you may include it under
26*1b8adde7SWilliam Kucharski# the same distribution terms that you use for the rest of that program.
27*1b8adde7SWilliam Kucharski
28*1b8adde7SWilliam Kucharski# This file is maintained in Automake, please report
29*1b8adde7SWilliam Kucharski# bugs to <bug-automake@gnu.org> or send patches to
30*1b8adde7SWilliam Kucharski# <automake-patches@gnu.org>.
31*1b8adde7SWilliam Kucharski
32*1b8adde7SWilliam Kucharskicase $1 in
33*1b8adde7SWilliam Kucharski  '')
34*1b8adde7SWilliam Kucharski     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
35*1b8adde7SWilliam Kucharski     exit 1;
36*1b8adde7SWilliam Kucharski     ;;
37*1b8adde7SWilliam Kucharski  -h | --h*)
38*1b8adde7SWilliam Kucharski    cat <<\EOF
39*1b8adde7SWilliam KucharskiUsage: compile [--help] [--version] PROGRAM [ARGS]
40*1b8adde7SWilliam Kucharski
41*1b8adde7SWilliam KucharskiWrapper for compilers which do not understand `-c -o'.
42*1b8adde7SWilliam KucharskiRemove `-o dest.o' from ARGS, run PROGRAM with the remaining
43*1b8adde7SWilliam Kucharskiarguments, and rename the output as expected.
44*1b8adde7SWilliam Kucharski
45*1b8adde7SWilliam KucharskiIf you are trying to build a whole package this is not the
46*1b8adde7SWilliam Kucharskiright script to run: please start by reading the file `INSTALL'.
47*1b8adde7SWilliam Kucharski
48*1b8adde7SWilliam KucharskiReport bugs to <bug-automake@gnu.org>.
49*1b8adde7SWilliam KucharskiEOF
50*1b8adde7SWilliam Kucharski    exit 0
51*1b8adde7SWilliam Kucharski    ;;
52*1b8adde7SWilliam Kucharski  -v | --v*)
53*1b8adde7SWilliam Kucharski    echo "compile $scriptversion"
54*1b8adde7SWilliam Kucharski    exit 0
55*1b8adde7SWilliam Kucharski    ;;
56*1b8adde7SWilliam Kucharskiesac
57*1b8adde7SWilliam Kucharski
58*1b8adde7SWilliam Kucharskiofile=
59*1b8adde7SWilliam Kucharskicfile=
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
93*1b8adde7SWilliam Kucharski  shift
94*1b8adde7SWilliam Kucharskidone
95*1b8adde7SWilliam Kucharski
96*1b8adde7SWilliam Kucharskiif test -z "$ofile" || test -z "$cfile"; then
97*1b8adde7SWilliam Kucharski  # If no `-o' option was seen then we might have been invoked from a
98*1b8adde7SWilliam Kucharski  # pattern rule where we don't need one.  That is ok -- this is a
99*1b8adde7SWilliam Kucharski  # normal compilation that the losing compiler can handle.  If no
100*1b8adde7SWilliam Kucharski  # `.c' file was seen then we are probably linking.  That is also
101*1b8adde7SWilliam Kucharski  # ok.
102*1b8adde7SWilliam Kucharski  exec "$@"
103*1b8adde7SWilliam Kucharskifi
104*1b8adde7SWilliam Kucharski
105*1b8adde7SWilliam Kucharski# Name of file we expect compiler to create.
106*1b8adde7SWilliam Kucharskicofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
107*1b8adde7SWilliam Kucharski
108*1b8adde7SWilliam Kucharski# Create the lock directory.
109*1b8adde7SWilliam Kucharski# Note: use `[/.-]' here to ensure that we don't use the same name
110*1b8adde7SWilliam Kucharski# that we are using for the .o file.  Also, base the name on the expected
111*1b8adde7SWilliam Kucharski# object file name, since that is what matters with a parallel build.
112*1b8adde7SWilliam Kucharskilockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d
113*1b8adde7SWilliam Kucharskiwhile true; do
114*1b8adde7SWilliam Kucharski  if mkdir "$lockdir" >/dev/null 2>&1; then
115*1b8adde7SWilliam Kucharski    break
116*1b8adde7SWilliam Kucharski  fi
117*1b8adde7SWilliam Kucharski  sleep 1
118*1b8adde7SWilliam Kucharskidone
119*1b8adde7SWilliam Kucharski# FIXME: race condition here if user kills between mkdir and trap.
120*1b8adde7SWilliam Kucharskitrap "rmdir '$lockdir'; exit 1" 1 2 15
121*1b8adde7SWilliam Kucharski
122*1b8adde7SWilliam Kucharski# Run the compile.
123*1b8adde7SWilliam Kucharski"$@"
124*1b8adde7SWilliam Kucharskiret=$?
125*1b8adde7SWilliam Kucharski
126*1b8adde7SWilliam Kucharskiif test -f "$cofile"; then
127*1b8adde7SWilliam Kucharski  mv "$cofile" "$ofile"
128*1b8adde7SWilliam Kucharskielif test -f "${cofile}bj"; then
129*1b8adde7SWilliam Kucharski  mv "${cofile}bj" "$ofile"
130*1b8adde7SWilliam Kucharskifi
131*1b8adde7SWilliam Kucharski
132*1b8adde7SWilliam Kucharskirmdir "$lockdir"
133*1b8adde7SWilliam Kucharskiexit $ret
134*1b8adde7SWilliam Kucharski
135*1b8adde7SWilliam Kucharski# Local Variables:
136*1b8adde7SWilliam Kucharski# mode: shell-script
137*1b8adde7SWilliam Kucharski# sh-indentation: 2
138*1b8adde7SWilliam Kucharski# eval: (add-hook 'write-file-hooks 'time-stamp)
139*1b8adde7SWilliam Kucharski# time-stamp-start: "scriptversion="
140*1b8adde7SWilliam Kucharski# time-stamp-format: "%:y-%02m-%02d.%02H"
141*1b8adde7SWilliam Kucharski# time-stamp-end: "$"
142*1b8adde7SWilliam Kucharski# End:
143