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