source: trunk/third/xntp/depcomp @ 17260

Revision 17260, 10.4 KB checked in by zacheiss, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r17259, 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 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
51gcc3)
52## gcc 3 implements dependency tracking that does exactly what
53## we want.  Yay!
54  if "$@" -MT "$object" -MF "$tmpdepfile" -MD -MP; then :
55  else
56    stat=$?
57    rm -f "$tmpdepfile"
58    exit $stat
59  fi
60  mv "$tmpdepfile" "$depfile"
61  ;;
62
63gcc)
64## There are various ways to get dependency output from gcc.  Here's
65## why we pick this rather obscure method:
66## - Don't want to use -MD because we'd like the dependencies to end
67##   up in a subdir.  Having to rename by hand is ugly.
68##   (We might end up doing this anyway to support other compilers.)
69## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
70##   -MM, not -M (despite what the docs say).
71## - Using -M directly means running the compiler twice (even worse
72##   than renaming).
73  if test -z "$gccflag"; then
74    gccflag=-MD,
75  fi
76  if "$@" -Wp,"$gccflag$tmpdepfile"; then :
77  else
78    stat=$?
79    rm -f "$tmpdepfile"
80    exit $stat
81  fi
82  rm -f "$depfile"
83  echo "$object : \\" > "$depfile"
84  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
85## The second -e expression handles DOS-style file names with drive letters.
86  sed -e 's/^[^:]*: / /' \
87      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
88## This next piece of magic avoids the `deleted header file' problem.
89## The problem is that when a header file which appears in a .P file
90## is deleted, the dependency causes make to die (because there is
91## typically no way to rebuild the header).  We avoid this by adding
92## dummy dependencies for each header file.  Too bad gcc doesn't do
93## this for us directly.
94  tr ' ' '
95' < "$tmpdepfile" |
96## Some versions of gcc put a space before the `:'.  On the theory
97## that the space means something, we add a space to the output as
98## well.
99## Some versions of the HPUX 10.20 sed can't process this invocation
100## correctly.  Breaking it into two sed invocations is a workaround.
101    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
102  rm -f "$tmpdepfile"
103  ;;
104
105hp)
106  # This case exists only to let depend.m4 do its work.  It works by
107  # looking at the text of this script.  This case will never be run,
108  # since it is checked for above.
109  exit 1
110  ;;
111
112sgi)
113  if test "$libtool" = yes; then
114    "$@" "-Wp,-MDupdate,$tmpdepfile"
115  else
116    "$@" -MDupdate "$tmpdepfile"
117  fi
118  stat=$?
119  if test $stat -eq 0; then :
120  else
121    rm -f "$tmpdepfile"
122    exit $stat
123  fi
124  rm -f "$depfile"
125
126  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
127    echo "$object : \\" > "$depfile"
128
129    # Clip off the initial element (the dependent). Don't try to be
130    # clever and replace this with sed code, as IRIX sed won't handle
131    # lines with more than a fixed number of characters (4096 in
132    # IRIX 6.2 sed, 8192 in IRIX 6.5).
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  else
143    # The sourcefile does not contain any dependencies, so just
144    # store a dummy comment line, to avoid errors with the Makefile
145    # "include basename.Plo" scheme.
146    echo "#dummy" > "$depfile"
147  fi
148  rm -f "$tmpdepfile"
149  ;;
150
151aix)
152  # The C for AIX Compiler uses -M and outputs the dependencies
153  # in a .u file.
154  tmpdepfile=`echo "$object" | sed 's/\(.*\)\..*$/\1.u/'`
155  if test "$libtool" = yes; then
156    "$@" -Wc,-M
157  else
158    "$@" -M
159  fi
160
161  stat=$?
162  if test $stat -eq 0; then :
163  else
164    rm -f "$tmpdepfile"
165    exit $stat
166  fi
167
168  if test -f "$tmpdepfile"; then
169    echo "$object : \\" > "$depfile"
170
171    # Clip off the initial element (the dependent). Don't try to be
172    # clever and replace this with sed code, as IRIX sed won't handle
173    # lines with more than a fixed number of characters (4096 in
174    # IRIX 6.2 sed, 8192 in IRIX 6.5).
175    tr ' ' '
176' < "$tmpdepfile" | sed 's/^[^\.]*\.o://' | tr '
177' ' ' >> $depfile
178
179    tr ' ' '
180' < "$tmpdepfile" | \
181## Some versions of the HPUX 10.20 sed can't process this invocation
182## correctly.  Breaking it into two sed invocations is a workaround.
183      sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
184  else
185    # The sourcefile does not contain any dependencies, so just
186    # store a dummy comment line, to avoid errors with the Makefile
187    # "include basename.Plo" scheme.
188    echo "#dummy" > "$depfile"
189  fi
190  rm -f "$tmpdepfile"
191  ;;
192
193#nosideeffect)
194  # This comment above is used by automake to tell side-effect
195  # dependency tracking mechanisms from slower ones.
196
197dashmstdout)
198  # Important note: in order to support this mode, a compiler *must*
199  # always write the proprocessed file to stdout, regardless of -o,
200  # because we must use -o when running libtool.
201  test -z "$dashmflag" && dashmflag=-M
202  ( IFS=" "
203    case " $* " in
204    *" --mode=compile "*) # this is libtool, let us make it quiet
205      for arg
206      do # cycle over the arguments
207        case "$arg" in
208        "--mode=compile")
209          # insert --quiet before "--mode=compile"
210          set fnord "$@" --quiet
211          shift # fnord
212          ;;
213        esac
214        set fnord "$@" "$arg"
215        shift # fnord
216        shift # "$arg"
217      done
218      ;;
219    esac
220    "$@" $dashmflag | sed 's:^[^:]*\:[  ]*:'"$object"'\: :' > "$tmpdepfile"
221  ) &
222  proc=$!
223  "$@"
224  stat=$?
225  wait "$proc"
226  if test "$stat" != 0; then exit $stat; fi
227  rm -f "$depfile"
228  cat < "$tmpdepfile" > "$depfile"
229  tr ' ' '
230' < "$tmpdepfile" | \
231## Some versions of the HPUX 10.20 sed can't process this invocation
232## correctly.  Breaking it into two sed invocations is a workaround.
233    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
234  rm -f "$tmpdepfile"
235  ;;
236
237dashXmstdout)
238  # This case only exists to satisfy depend.m4.  It is never actually
239  # run, as this mode is specially recognized in the preamble.
240  exit 1
241  ;;
242
243makedepend)
244  # X makedepend
245  (
246    shift
247    cleared=no
248    for arg in "$@"; do
249      case $cleared in no)
250        set ""; shift
251        cleared=yes
252      esac
253      case "$arg" in
254        -D*|-I*)
255          set fnord "$@" "$arg"; shift;;
256        -*)
257          ;;
258        *)
259          set fnord "$@" "$arg"; shift;;
260      esac
261    done
262    obj_suffix="`echo $object | sed 's/^.*\././'`"
263    touch "$tmpdepfile"
264    ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@"
265  ) &
266  proc=$!
267  "$@"
268  stat=$?
269  wait "$proc"
270  if test "$stat" != 0; then exit $stat; fi
271  rm -f "$depfile"
272  cat < "$tmpdepfile" > "$depfile"
273  tail +3 "$tmpdepfile" | tr ' ' '
274' | \
275## Some versions of the HPUX 10.20 sed can't process this invocation
276## correctly.  Breaking it into two sed invocations is a workaround.
277    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
278  rm -f "$tmpdepfile" "$tmpdepfile".bak
279  ;;
280
281cpp)
282  # Important note: in order to support this mode, a compiler *must*
283  # always write the proprocessed file to stdout, regardless of -o,
284  # because we must use -o when running libtool.
285  ( IFS=" "
286    case " $* " in
287    *" --mode=compile "*)
288      for arg
289      do # cycle over the arguments
290        case $arg in
291        "--mode=compile")
292          # insert --quiet before "--mode=compile"
293          set fnord "$@" --quiet
294          shift # fnord
295          ;;
296        esac
297        set fnord "$@" "$arg"
298        shift # fnord
299        shift # "$arg"
300      done
301      ;;
302    esac
303    "$@" -E |
304    sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
305    sed '$ s: \\$::' > "$tmpdepfile"
306  ) &
307  proc=$!
308  "$@"
309  stat=$?
310  wait "$proc"
311  if test "$stat" != 0; then exit $stat; fi
312  rm -f "$depfile"
313  echo "$object : \\" > "$depfile"
314  cat < "$tmpdepfile" >> "$depfile"
315  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
316  rm -f "$tmpdepfile"
317  ;;
318
319msvisualcpp)
320  # Important note: in order to support this mode, a compiler *must*
321  # always write the proprocessed file to stdout, regardless of -o,
322  # because we must use -o when running libtool.
323  ( IFS=" "
324    case " $* " in
325    *" --mode=compile "*)
326      for arg
327      do # cycle over the arguments
328        case $arg in
329        "--mode=compile")
330          # insert --quiet before "--mode=compile"
331          set fnord "$@" --quiet
332          shift # fnord
333          ;;
334        esac
335        set fnord "$@" "$arg"
336        shift # fnord
337        shift # "$arg"
338      done
339      ;;
340    esac
341    "$@" -E |
342    sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
343  ) &
344  proc=$!
345  "$@"
346  stat=$?
347  wait "$proc"
348  if test "$stat" != 0; then exit $stat; fi
349  rm -f "$depfile"
350  echo "$object : \\" > "$depfile"
351  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::    \1 \\:p' >> "$depfile"
352  echo "        " >> "$depfile"
353  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
354  rm -f "$tmpdepfile"
355  ;;
356
357none)
358  exec "$@"
359  ;;
360
361*)
362  echo "Unknown depmode $depmode" 1>&2
363  exit 1
364  ;;
365esac
366
367exit 0
Note: See TracBrowser for help on using the repository browser.