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