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