1#! /bin/sh
2
3# depcomp - compile a program generating dependencies as side-effects
4# Copyright 1999, 2000, 2003 Free Software Foundation, Inc.
5
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2, or (at your option)
9# any later version.
10
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19# 02111-1307, USA.
20
21# As a special exception to the GNU General Public License, if you
22# distribute this file as part of a program that contains a
23# configuration script generated by Autoconf, you may include it under
24# the same distribution terms that you use for the rest of that program.
25
26# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
27# Completely stripped for own purposes by Carlo Wood.
28
29if test -z "$depmode" || test -z "$source" || test -z "$object"; then
30  echo "depcomp: Variables source, object and depmode must be set" 1>&2
31  exit 1
32fi
33# `libtool' can also be set to `yes' or `no'.
34
35if test -z "$depfile"; then
36   base=`echo "$object" | sed -e 's,^.*/,,' -e 's,\.\([^.]*\)$,.P\1,'`
37   dir=`echo "$object" | sed 's,/.*$,/,'`
38   if test "$dir" = "$object"; then
39      dir=
40   fi
41   # FIXME: should be _deps on DOS.
42   depfile="$dir.deps/$base"
43fi
44
45tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
46
47rm -f "$tmpdepfile"
48
49case "$depmode" in
50pch)
51  # First compile file without dependency tracking.
52  "$@" || exit $?
53
54  # Remove the call to libtool its parameters.
55  if test "$libtool" = yes; then
56    while test $1 != '--mode=compile'; do
57      shift
58    done
59    shift
60    if expr "$1" : "--" >/dev/null; then
61      shift
62    fi
63  fi
64
65  # Remove `-o $object' and `-include pch.h'.
66  eatpch=
67  IFS=" "
68  for arg
69  do
70    case $arg in
71    -o)
72      shift
73      ;;
74    $object)
75      shift
76      ;;
77    -include)
78      shift
79      eatpch=yes
80      ;;
81    *)
82      if test x$eatpch = xyes; then
83        if test "$arg" = "pch.h"; then
84	  shift
85	else
86	  set fnord "$@" -include "$arg"
87	  shift # fnord
88	  shift # $arg
89	fi
90	eatpch=
91      else
92	set fnord "$@" "$arg"
93	shift # fnord
94	shift # $arg
95      fi
96      ;;
97    esac
98  done
99
100  # Generate dependency file.
101  "$@" -MT "$object" -MD -MF "$tmpdepfile"
102  stat=$?
103  if test $stat -eq 0; then :
104  else
105    rm -f "$tmpdepfile"
106    exit $stat
107  fi
108  mv "$tmpdepfile" "$depfile"
109  ;;
110
111*)
112  echo "Unknown depmode $depmode" 1>&2
113  exit 1
114  ;;
115esac
116
117exit 0
118