source: trunk/essentials/sys-apps/diffutils/config/depcomp@ 3137

Last change on this file since 3137 was 2556, checked in by bird, 20 years ago

diffutils 2.8.1

File size: 12.2 KB
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# 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 <[email protected]>.
27
28if test -z "$depmode" || test -z "$source" || test -z "$object"; then
29 echo "depcomp: Variables source, object and depmode must be set" 1>&2
30 exit 1
31fi
32# `libtool' can also be set to `yes' or `no'.
33
34if test -z "$depfile"; then
35 base=`echo "$object" | sed -e 's,^.*/,,' -e 's,\.\([^.]*\)$,.P\1,'`
36 dir=`echo "$object" | sed 's,/.*$,/,'`
37 if test "$dir" = "$object"; then
38 dir=
39 fi
40 # FIXME: should be _deps on DOS.
41 depfile="$dir.deps/$base"
42fi
43
44tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
45
46rm -f "$tmpdepfile"
47
48# Some modes work just like other modes, but use different flags. We
49# parameterize here, but still list the modes in the big case below,
50# to make depend.m4 easier to write. Note that we *cannot* use a case
51# here, because this file can only contain one case statement.
52if test "$depmode" = hp; then
53 # HP compiler uses -M and no extra arg.
54 gccflag=-M
55 depmode=gcc
56fi
57
58if test "$depmode" = dashXmstdout; then
59 # This is just like dashmstdout with a different argument.
60 dashmflag=-xM
61 depmode=dashmstdout
62fi
63
64case "$depmode" in
65gcc3)
66## gcc 3 implements dependency tracking that does exactly what
67## we want. Yay! Note: for some reason libtool 1.4 doesn't like
68## it if -MD -MP comes after the -MF stuff. Hmm.
69 "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
70 stat=$?
71 if test $stat -eq 0; then :
72 else
73 rm -f "$tmpdepfile"
74 exit $stat
75 fi
76 mv "$tmpdepfile" "$depfile"
77 ;;
78
79gcc)
80## There are various ways to get dependency output from gcc. Here's
81## why we pick this rather obscure method:
82## - Don't want to use -MD because we'd like the dependencies to end
83## up in a subdir. Having to rename by hand is ugly.
84## (We might end up doing this anyway to support other compilers.)
85## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
86## -MM, not -M (despite what the docs say).
87## - Using -M directly means running the compiler twice (even worse
88## than renaming).
89 if test -z "$gccflag"; then
90 gccflag=-MD,
91 fi
92 "$@" -Wp,"$gccflag$tmpdepfile"
93 stat=$?
94 if test $stat -eq 0; then :
95 else
96 rm -f "$tmpdepfile"
97 exit $stat
98 fi
99 rm -f "$depfile"
100 echo "$object : \\" > "$depfile"
101 alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
102## The second -e expression handles DOS-style file names with drive letters.
103 sed -e 's/^[^:]*: / /' \
104 -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
105## This next piece of magic avoids the `deleted header file' problem.
106## The problem is that when a header file which appears in a .P file
107## is deleted, the dependency causes make to die (because there is
108## typically no way to rebuild the header). We avoid this by adding
109## dummy dependencies for each header file. Too bad gcc doesn't do
110## this for us directly.
111 tr ' ' '
112' < "$tmpdepfile" |
113## Some versions of gcc put a space before the `:'. On the theory
114## that the space means something, we add a space to the output as
115## well.
116## Some versions of the HPUX 10.20 sed can't process this invocation
117## correctly. Breaking it into two sed invocations is a workaround.
118 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
119 rm -f "$tmpdepfile"
120 ;;
121
122hp)
123 # This case exists only to let depend.m4 do its work. It works by
124 # looking at the text of this script. This case will never be run,
125 # since it is checked for above.
126 exit 1
127 ;;
128
129sgi)
130 if test "$libtool" = yes; then
131 "$@" "-Wp,-MDupdate,$tmpdepfile"
132 else
133 "$@" -MDupdate "$tmpdepfile"
134 fi
135 stat=$?
136 if test $stat -eq 0; then :
137 else
138 rm -f "$tmpdepfile"
139 exit $stat
140 fi
141 rm -f "$depfile"
142
143 if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
144 echo "$object : \\" > "$depfile"
145
146 # Clip off the initial element (the dependent). Don't try to be
147 # clever and replace this with sed code, as IRIX sed won't handle
148 # lines with more than a fixed number of characters (4096 in
149 # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
150 # the IRIX cc adds comments like `#:fec' to the end of the
151 # dependency line.
152 tr ' ' '
153' < "$tmpdepfile" \
154 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
155 tr '
156' ' ' >> $depfile
157 echo >> $depfile