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