source: trunk/third/findutils/depcomp @ 18890

Revision 18890, 8.0 KB checked in by zacheiss, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18889, which included commits to RCS files with non-trunk default branches.
  • Property svn:executable set to *
Line 
1#! /bin/sh
2
3# depcomp - compile a program generating dependencies as side-effects
4# Copyright (C) 1999, 2000 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# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
22
23if test -z "$depmode" || test -z "$source" || test -z "$object"; then
24  echo "depcomp: Variables source, object and depmode must be set" 1>&2
25  exit 1
26fi
27# `libtool' can also be set to `yes' or `no'.
28
29depfile=${depfile-`echo "$object" | sed 's,\([^/]*\)$,.deps/\1,;s/\.\([^.]*\)$/.P\1/'`}
30tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
31
32rm -f "$tmpdepfile"
33
34# Some modes work just like other modes, but use different flags.  We
35# parameterize here, but still list the modes in the big case below,
36# to make depend.m4 easier to write.  Note that we *cannot* use a case
37# here, because this file can only contain one case statement.
38if test "$depmode" = hp; then
39  # HP compiler uses -M and no extra arg.
40  gccflag=-M
41  depmode=gcc
42fi
43
44if test "$depmode" = dashXmstdout; then
45   # This is just like dashmstdout with a different argument.
46   dashmflag=-xM
47   depmode=dashmstdout
48fi
49
50case "$depmode" in
51gcc)
52## There are various ways to get dependency output from gcc.  Here's
53## why we pick this rather obscure method:
54## - Don't want to use -MD because we'd like the dependencies to end
55##   up in a subdir.  Having to rename by hand is ugly.
56##   (We might end up doing this anyway to support other compilers.)
57## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
58##   -MM, not -M (despite what the docs say).
59## - Using -M directly means running the compiler twice (even worse
60##   than renaming).
61  if test -z "$gccflag"; then
62    gccflag=-MD,
63  fi
64  if "$@" -Wp,"$gccflag$tmpdepfile"; then :
65  else
66    stat=$?
67    rm -f "$tmpdepfile"
68    exit $stat
69  fi
70  rm -f "$depfile"
71  echo "$object : \\" > "$depfile"
72  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
73## The second -e expression handles DOS-style file names with drive letters.
74  sed -e 's/^[^:]*: / /' \
75      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
76## This next piece of magic avoids the `deleted header file' problem.
77## The problem is that when a header file which appears in a .P file
78## is deleted, the dependency causes make to die (because there is
79## typically no way to rebuild the header).  We avoid this by adding
80## dummy dependencies for each header file.  Too bad gcc doesn't do
81## this for us directly.
82  tr ' ' '
83' < "$tmpdepfile" |
84## Some versions of gcc put a space before the `:'.  On the theory
85## that the space means something, we add a space to the output as
86## well.
87## Some versions of the HPUX 10.20 sed can't process this invocation
88## correctly.  Breaking it into two sed invocations is a workaround.
89    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
90  rm -f "$tmpdepfile"
91  ;;
92
93hp)
94  # This case exists only to let depend.m4 do its work.  It works by
95  # looking at the text of this script.  This case will never be run,
96  # since it is checked for above.
97  exit 1
98  ;;
99
100dashmd)
101  # The Java front end to gcc doesn't run cpp, so we can't use the -Wp
102  # trick.  Instead we must use -M and then rename the resulting .d
103  # file.  This is also the case for older versions of gcc, which
104  # don't implement -Wp.
105  if "$@" -MD; then :
106  else
107    stat=$?
108    rm -f FIXME
109    exit $stat
110  fi
111  FIXME: rewrite the file
112  ;;
113
114sgi)
115  if test "$libtool" = yes; then
116    "$@" "-Wp,-MDupdate,$tmpdepfile"
117  else
118    "$@" -MDupdate "$tmpdepfile"
119  fi
120  stat=$?
121  if test $stat -eq 0; then :
122  else
123    stat=$?
124    rm -f "$tmpdepfile"
125    exit $stat
126  fi
127  rm -f "$depfile"
128  echo "$object : \\" > "$depfile"
129
130  # Clip off the initial element (the dependent). Don't try to be
131  # clever and remove the tr invocations, as IRIX sed won't handle
132  # lines with more than 8192 characters.
133  tr ' ' '
134' < "$tmpdepfile" | sed 's/^[^\.]*\.o://' | tr '
135' ' ' >> $depfile
136
137  tr ' ' '
138' < "$tmpdepfile" | \
139## Some versions of the HPUX 10.20 sed can't process this invocation
140## correctly.  Breaking it into two sed invocations is a workaround.
141    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
142  rm -f "$tmpdepfile"
143  ;;
144
145#nosideeffect)
146  # This comment above is used by automake to tell side-effect
147  # dependency tracking mechanisms from slower ones.
148
149dashmstdout)
150  # Important note: in order to support this mode, a compiler *must*
151  # always write the proprocessed file to stdout, regardless of -o,
152  # because we must use -o when running libtool.
153  test -z "$dashmflag" && dashmflag=-M
154  ( IFS=" "
155    case " $* " in
156    *" --mode=compile "*) # this is libtool, let us make it quiet
157      for arg
158      do # cycle over the arguments
159        case "$arg" in
160        "--mode=compile")
161          # insert --quiet before "--mode=compile"
162          set fnord "$@" --quiet
163          shift # fnord
164          ;;
165        esac
166        set fnord "$@" "$arg"
167        shift # fnord
168        shift # "$arg"
169      done
170      ;;
171    esac
172    "$@" $dashmflag | sed 's:^[^:]*\:[  ]*:'"$object"'\: :' > "$tmpdepfile"
173  ) &
174  proc=$!
175  "$@"
176  stat=$?
177  wait "$proc"
178  if test "$stat" != 0; then exit $stat; fi
179  rm -f "$depfile"
180  cat < "$tmpdepfile" > "$depfile"
181  tr ' ' '
182' < "$tmpdepfile" | \
183## Some versions of the HPUX 10.20 sed can't process this invocation
184## correctly.  Breaking it into two sed invocations is a workaround.
185    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
186  rm -f "$tmpdepfile"
187  ;;
188
189dashXmstdout)
190  # This case only exists to satisfy depend.m4.  It is never actually
191  # run, as this mode is specially recognized in the preamble.
192  exit 1
193  ;;
194
195makedepend)
196  # X makedepend
197  (
198    shift
199    cleared=no
200    for arg in "$@"; do
201      case $cleared in no)
202        set ""; shift
203        cleared=yes
204      esac
205      case "$arg" in
206        -D*|-I*)
207          set fnord "$@" "$arg"; shift;;
208        -*)
209          ;;
210        *)
211          set fnord "$@" "$arg"; shift;;
212      esac
213    done
214    obj_suffix="`echo $object | sed 's/^.*\././'`"
215    touch "$tmpdepfile"
216    ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@"
217  ) &
218  proc=$!
219  "$@"
220  stat=$?
221  wait "$proc"
222  if test "$stat" != 0; then exit $stat; fi
223  rm -f "$depfile"
224  cat < "$tmpdepfile" > "$depfile"
225  tail +3 "$tmpdepfile" | tr ' ' '
226' | \
227## Some versions of the HPUX 10.20 sed can't process this invocation
228## correctly.  Breaking it into two sed invocations is a workaround.
229    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
230  rm -f "$tmpdepfile" "$tmpdepfile".bak
231  ;;
232
233cpp)
234  # Important note: in order to support this mode, a compiler *must*
235  # always write the proprocessed file to stdout, regardless of -o,
236  # because we must use -o when running libtool.
237  ( IFS=" "
238    case " $* " in
239    *" --mode=compile "*)
240      for arg
241      do # cycle over the arguments
242        case "$arg" in
243        "--mode=compile")
244          # insert --quiet before "--mode=compile"
245          set fnord "$@" --quiet
246          shift # fnord
247          ;;
248        esac
249        set fnord "$@" "$arg"
250        shift # fnord
251        shift # "$arg"
252      done
253      ;;
254    esac
255    "$@" -E |
256    sed -n '/^# [0-9][0-9]* "\([^"]*\)"/ s::'"$object"'\: \1:p' > "$tmpdepfile"
257  ) &
258  proc=$!
259  "$@"
260  stat=$?
261  wait "$proc"
262  if test "$stat" != 0; then exit $stat; fi
263  rm -f "$depfile"
264  cat < "$tmpdepfile" > "$depfile"
265  sed < "$tmpdepfile" -e 's/^[^:]*: //' -e 's/$/ :/' >> "$depfile"
266  rm -f "$tmpdepfile"
267  ;;
268
269none)
270  exec "$@"
271  ;;
272
273*)
274  echo "Unknown depmode $depmode" 1>&2
275  exit 1
276  ;;
277esac
278
279exit 0
Note: See TracBrowser for help on using the repository browser.