xref: /freebsd/crypto/heimdal/compile (revision 6a068746777241722b2b32c5d0bc443a2a64d80b)
14137ff4cSJacques Vidrine#! /bin/sh
24137ff4cSJacques Vidrine# Wrapper for compilers which do not understand `-c -o'.
34137ff4cSJacques Vidrine
4*ae771770SStanislav Sedovscriptversion=2009-10-06.20; # UTC
58d4ba808SJacques Vidrine
6*ae771770SStanislav Sedov# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009  Free Software
7*ae771770SStanislav Sedov# Foundation, Inc.
84137ff4cSJacques Vidrine# Written by Tom Tromey <tromey@cygnus.com>.
94137ff4cSJacques Vidrine#
104137ff4cSJacques Vidrine# This program is free software; you can redistribute it and/or modify
114137ff4cSJacques Vidrine# it under the terms of the GNU General Public License as published by
124137ff4cSJacques Vidrine# the Free Software Foundation; either version 2, or (at your option)
134137ff4cSJacques Vidrine# any later version.
144137ff4cSJacques Vidrine#
154137ff4cSJacques Vidrine# This program is distributed in the hope that it will be useful,
164137ff4cSJacques Vidrine# but WITHOUT ANY WARRANTY; without even the implied warranty of
174137ff4cSJacques Vidrine# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
184137ff4cSJacques Vidrine# GNU General Public License for more details.
194137ff4cSJacques Vidrine#
204137ff4cSJacques Vidrine# You should have received a copy of the GNU General Public License
21*ae771770SStanislav Sedov# along with this program.  If not, see <http://www.gnu.org/licenses/>.
224137ff4cSJacques Vidrine
234137ff4cSJacques Vidrine# As a special exception to the GNU General Public License, if you
244137ff4cSJacques Vidrine# distribute this file as part of a program that contains a
254137ff4cSJacques Vidrine# configuration script generated by Autoconf, you may include it under
264137ff4cSJacques Vidrine# the same distribution terms that you use for the rest of that program.
274137ff4cSJacques Vidrine
288d4ba808SJacques Vidrine# This file is maintained in Automake, please report
298d4ba808SJacques Vidrine# bugs to <bug-automake@gnu.org> or send patches to
308d4ba808SJacques Vidrine# <automake-patches@gnu.org>.
318d4ba808SJacques Vidrine
328d4ba808SJacques Vidrinecase $1 in
338d4ba808SJacques Vidrine  '')
348d4ba808SJacques Vidrine     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
358d4ba808SJacques Vidrine     exit 1;
368d4ba808SJacques Vidrine     ;;
378d4ba808SJacques Vidrine  -h | --h*)
388d4ba808SJacques Vidrine    cat <<\EOF
398d4ba808SJacques VidrineUsage: compile [--help] [--version] PROGRAM [ARGS]
408d4ba808SJacques Vidrine
418d4ba808SJacques VidrineWrapper for compilers which do not understand `-c -o'.
428d4ba808SJacques VidrineRemove `-o dest.o' from ARGS, run PROGRAM with the remaining
438d4ba808SJacques Vidrinearguments, and rename the output as expected.
448d4ba808SJacques Vidrine
458d4ba808SJacques VidrineIf you are trying to build a whole package this is not the
468d4ba808SJacques Vidrineright script to run: please start by reading the file `INSTALL'.
478d4ba808SJacques Vidrine
488d4ba808SJacques VidrineReport bugs to <bug-automake@gnu.org>.
498d4ba808SJacques VidrineEOF
50c19800e8SDoug Rabson    exit $?
518d4ba808SJacques Vidrine    ;;
528d4ba808SJacques Vidrine  -v | --v*)
538d4ba808SJacques Vidrine    echo "compile $scriptversion"
54c19800e8SDoug Rabson    exit $?
558d4ba808SJacques Vidrine    ;;
568d4ba808SJacques Vidrineesac
578d4ba808SJacques Vidrine
584137ff4cSJacques Vidrineofile=
594137ff4cSJacques Vidrinecfile=
60c19800e8SDoug Rabsoneat=
61c19800e8SDoug Rabson
62c19800e8SDoug Rabsonfor arg
63c19800e8SDoug Rabsondo
64c19800e8SDoug Rabson  if test -n "$eat"; then
65c19800e8SDoug Rabson    eat=
66c19800e8SDoug Rabson  else
67c19800e8SDoug Rabson    case $1 in
684137ff4cSJacques Vidrine      -o)
694137ff4cSJacques Vidrine	# configure might choose to run compile as `compile cc -o foo foo.c'.
70c19800e8SDoug Rabson	# So we strip `-o arg' only if arg is an object.
71c19800e8SDoug Rabson	eat=1
72c19800e8SDoug Rabson	case $2 in
734137ff4cSJacques Vidrine	  *.o | *.obj)
74c19800e8SDoug Rabson	    ofile=$2
754137ff4cSJacques Vidrine	    ;;
764137ff4cSJacques Vidrine	  *)
77c19800e8SDoug Rabson	    set x "$@" -o "$2"
78c19800e8SDoug Rabson	    shift
794137ff4cSJacques Vidrine	    ;;
804137ff4cSJacques Vidrine	esac
814137ff4cSJacques Vidrine	;;
824137ff4cSJacques Vidrine      *.c)
834137ff4cSJacques Vidrine	cfile=$1
84c19800e8SDoug Rabson	set x "$@" "$1"
85c19800e8SDoug Rabson	shift
864137ff4cSJacques Vidrine	;;
874137ff4cSJacques Vidrine      *)
88c19800e8SDoug Rabson	set x "$@" "$1"
89c19800e8SDoug Rabson	shift
904137ff4cSJacques Vidrine	;;
914137ff4cSJacques Vidrine    esac
92c19800e8SDoug Rabson  fi
934137ff4cSJacques Vidrine  shift
944137ff4cSJacques Vidrinedone
954137ff4cSJacques Vidrine
964137ff4cSJacques Vidrineif test -z "$ofile" || test -z "$cfile"; then
974137ff4cSJacques Vidrine  # If no `-o' option was seen then we might have been invoked from a
984137ff4cSJacques Vidrine  # pattern rule where we don't need one.  That is ok -- this is a
994137ff4cSJacques Vidrine  # normal compilation that the losing compiler can handle.  If no
1004137ff4cSJacques Vidrine  # `.c' file was seen then we are probably linking.  That is also
1014137ff4cSJacques Vidrine  # ok.
102c19800e8SDoug Rabson  exec "$@"
1034137ff4cSJacques Vidrinefi
1044137ff4cSJacques Vidrine
1054137ff4cSJacques Vidrine# Name of file we expect compiler to create.
106*ae771770SStanislav Sedovcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
1074137ff4cSJacques Vidrine
1084137ff4cSJacques Vidrine# Create the lock directory.
109*ae771770SStanislav Sedov# Note: use `[/\\:.-]' here to ensure that we don't use the same name
1104137ff4cSJacques Vidrine# that we are using for the .o file.  Also, base the name on the expected
1114137ff4cSJacques Vidrine# object file name, since that is what matters with a parallel build.
112*ae771770SStanislav Sedovlockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
1134137ff4cSJacques Vidrinewhile true; do
114c19800e8SDoug Rabson  if mkdir "$lockdir" >/dev/null 2>&1; then
1154137ff4cSJacques Vidrine    break
1164137ff4cSJacques Vidrine  fi
1174137ff4cSJacques Vidrine  sleep 1
1184137ff4cSJacques Vidrinedone
1194137ff4cSJacques Vidrine# FIXME: race condition here if user kills between mkdir and trap.
120c19800e8SDoug Rabsontrap "rmdir '$lockdir'; exit 1" 1 2 15
1214137ff4cSJacques Vidrine
1224137ff4cSJacques Vidrine# Run the compile.
123c19800e8SDoug Rabson"$@"
124c19800e8SDoug Rabsonret=$?
1254137ff4cSJacques Vidrine
1264137ff4cSJacques Vidrineif test -f "$cofile"; then
127*ae771770SStanislav Sedov  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
128c19800e8SDoug Rabsonelif test -f "${cofile}bj"; then
129*ae771770SStanislav Sedov  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
1304137ff4cSJacques Vidrinefi
1314137ff4cSJacques Vidrine
132c19800e8SDoug Rabsonrmdir "$lockdir"
133c19800e8SDoug Rabsonexit $ret
1348d4ba808SJacques Vidrine
1358d4ba808SJacques Vidrine# Local Variables:
1368d4ba808SJacques Vidrine# mode: shell-script
1378d4ba808SJacques Vidrine# sh-indentation: 2
1388d4ba808SJacques Vidrine# eval: (add-hook 'write-file-hooks 'time-stamp)
1398d4ba808SJacques Vidrine# time-stamp-start: "scriptversion="
1408d4ba808SJacques Vidrine# time-stamp-format: "%:y-%02m-%02d.%02H"
141*ae771770SStanislav Sedov# time-stamp-time-zone: "UTC"
142*ae771770SStanislav Sedov# time-stamp-end: "; # UTC"
1438d4ba808SJacques Vidrine# End:
144