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