3
# depcomp - compile a program generating dependencies as side-effects
4
# Copyright 1999, 2000 Free Software Foundation, Inc.
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)
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.
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
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.
26
# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
28
#echo "Calling depmode! I am stopping now!"
31
if test -z "$depmode" || test -z "$source" || test -z "$object"; then
32
echo "depcomp: Variables source, object and depmode must be set" 1>&2
35
# `libtool' can also be set to `yes' or `no'.
37
depfile=${depfile-`echo "$object" | sed 's,\([^/]*\)$,.deps/\1,;s/\.\([^.]*\)$/.P\1/'`}
38
tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
42
# Some modes work just like other modes, but use different flags. We
43
# parameterize here, but still list the modes in the big case below,
44
# to make depend.m4 easier to write. Note that we *cannot* use a case
45
# here, because this file can only contain one case statement.
46
if test "$depmode" = hp; then
47
# HP compiler uses -M and no extra arg.
52
if test "$depmode" = dashXmstdout; then
53
# This is just like dashmstdout with a different argument.
60
## gcc 3 implements dependency tracking that does exactly what
61
## we want. Yay! Note: for some reason libtool 1.4 doesn't like
62
## it if -MD -MP comes after the -MF stuff. Hmm.
63
"$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
65
if test $stat -eq 0; then :
70
mv "$tmpdepfile" "$depfile"
74
## There are various ways to get dependency output from gcc. Here's
75
## why we pick this rather obscure method:
76
## - Don't want to use -MD because we'd like the dependencies to end
77
## up in a subdir. Having to rename by hand is ugly.
78
## (We might end up doing this anyway to support other compilers.)
79
## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
80
## -MM, not -M (despite what the docs say).
81
## - Using -M directly means running the compiler twice (even worse
83
if test -z "$gccflag"; then
86
"$@" -Wp,"$gccflag$tmpdepfile"
88
if test $stat -eq 0; then :
94
echo "$object : \\" > "$depfile"
95
alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
96
## The second -e expression handles DOS-style file names with drive letters.
97
sed -e 's/^[^:]*: / /' \
98
-e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
99
## This next piece of magic avoids the `deleted header file' problem.
100
## The problem is that when a header file which appears in a .P file
101
## is deleted, the dependency causes make to die (because there is
102
## typically no way to rebuild the header). We avoid this by adding
103
## dummy dependencies for each header file. Too bad gcc doesn't do
104
## this for us directly.
107
## Some versions of gcc put a space before the `:'. On the theory
108
## that the space means something, we add a space to the output as
110
## Some versions of the HPUX 10.20 sed can't process this invocation
111
## correctly. Breaking it into two sed invocations is a workaround.
112
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
117
# This case exists only to let depend.m4 do its work. It works by
118
# looking at the text of this script. This case will never be run,
119
# since it is checked for above.
124
if test "$libtool" = yes; then
125
"$@" "-Wp,-MDupdate,$tmpdepfile"
127
"$@" -MDupdate "$tmpdepfile"
130
if test $stat -eq 0; then :
137
if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
138
echo "$object : \\" > "$depfile"
140
# Clip off the initial element (the dependent). Don't try to be
141
# clever and replace this with sed code, as IRIX sed won't handle
142
# lines with more than a fixed number of characters (4096 in
143
# IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
144
# the IRIX cc adds comments like `#:fec' to the end of the
148
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
153
# The second pass generates a dummy entry for each header file.
156
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
159
# The sourcefile does not contain any dependencies, so just
160
# store a dummy comment line, to avoid errors with the Makefile
161
# "include basename.Plo" scheme.
162
echo "#dummy" > "$depfile"
168
# The C for AIX Compiler uses -M and outputs the dependencies
169
# in a .u file. This file always lives in the current directory.
170
# Also, the AIX compiler puts `$object:' at the start of each line;
171
# $object doesn't have directory information.
172
stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'`
173
tmpdepfile="$stripped.u"
174
outname="$stripped.o"
175
if test "$libtool" = yes; then
182
if test $stat -eq 0; then :
188
if test -f "$tmpdepfile"; then
189
# Each line is of the form `foo.o: dependent.h'.
190
# Do two passes, one to just change these to
191
# `$object: dependent.h' and one to simply `dependent.h:'.
192
sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
193
sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
195
# The sourcefile does not contain any dependencies, so just
196
# store a dummy comment line, to avoid errors with the Makefile
197
# "include basename.Plo" scheme.
198
echo "#dummy" > "$depfile"
204
# The Tru64 AIX compiler uses -MD to generate dependencies as a side
205
# effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
206
# At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
207
# dependencies in `foo.d' instead, so we check for that too.
208
# Subdirectories are respected.
210
tmpdepfile1="$object.d"
211
tmpdepfile2=`echo "$object" | sed -e 's/.o$/.d/'`
212
if test "$libtool" = yes; then
219
if test $stat -eq 0; then :
221
rm -f "$tmpdepfile1" "$tmpdepfile2"
225
if test -f "$tmpdepfile1"; then
226
tmpdepfile="$tmpdepfile1"
228
tmpdepfile="$tmpdepfile2"
230
if test -f "$tmpdepfile"; then
231
sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
232
# That's a space and a tab in the [].
233
sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
235
echo "#dummy" > "$depfile"
241
# This comment above is used by automake to tell side-effect
242
# dependency tracking mechanisms from slower ones.
245
# Important note: in order to support this mode, a compiler *must*
246
# always write the proprocessed file to stdout, regardless of -o,
247
# because we must use -o when running libtool.
248
test -z "$dashmflag" && dashmflag=-M
251
*" --mode=compile "*) # this is libtool, let us make it quiet
253
do # cycle over the arguments
256
# insert --quiet before "--mode=compile"
257
set fnord "$@" --quiet
261
set fnord "$@" "$arg"
267
"$@" $dashmflag | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
273
if test "$stat" != 0; then exit $stat; fi
275
cat < "$tmpdepfile" > "$depfile"
277
' < "$tmpdepfile" | \
278
## Some versions of the HPUX 10.20 sed can't process this invocation
279
## correctly. Breaking it into two sed invocations is a workaround.
280
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
285
# This case only exists to satisfy depend.m4. It is never actually
286
# run, as this mode is specially recognized in the preamble.
302
set fnord "$@" "$arg"; shift;;
306
set fnord "$@" "$arg"; shift;;
309
obj_suffix="`echo $object | sed 's/^.*\././'`"
311
${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@"
317
if test "$stat" != 0; then exit $stat; fi
319
cat < "$tmpdepfile" > "$depfile"
320
tail +3 "$tmpdepfile" | tr ' ' '
322
## Some versions of the HPUX 10.20 sed can't process this invocation
323
## correctly. Breaking it into two sed invocations is a workaround.
324
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
325
rm -f "$tmpdepfile" "$tmpdepfile".bak
329
# Important note: in order to support this mode, a compiler *must*
330
# always write the proprocessed file to stdout, regardless of -o,
331
# because we must use -o when running libtool.
334
*" --mode=compile "*)
336
do # cycle over the arguments
339
# insert --quiet before "--mode=compile"
340
set fnord "$@" --quiet
344
set fnord "$@" "$arg"
351
sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
352
sed '$ s: \\$::' > "$tmpdepfile"
358
if test "$stat" != 0; then exit $stat; fi
360
echo "$object : \\" > "$depfile"
361
cat < "$tmpdepfile" >> "$depfile"
362
sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
367
# Important note: in order to support this mode, a compiler *must*
368
# always write the proprocessed file to stdout, regardless of -o,
369
# because we must use -o when running libtool.
372
*" --mode=compile "*)
374
do # cycle over the arguments
377
# insert --quiet before "--mode=compile"
378
set fnord "$@" --quiet
382
set fnord "$@" "$arg"
389
sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
395
if test "$stat" != 0; then exit $stat; fi
397
echo "$object : \\" > "$depfile"
398
. "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
399
echo " " >> "$depfile"
400
. "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
405
if test -n "$CYGWIN_INTEL_WINDOWS"; then
406
#echo "Using the intel compiler icl under Windows XP to generate dependency files!"
408
# First, generate the dependency file
409
"$@" -QM "$object" -QMM -QMF "$tmpdepfile"
410
# Next, actually compile the source file
413
if test $stat -eq 0; then :
419
echo "$object : \\" > "$depfile"
420
cat "$tmpdepfile" | sed 's%.* \([a-z]\):%/cygdrive/\1%' \
421
| perl -e 'foreach(<STDIN>) { $_=~s%\\%/%g; print $_; }' \
422
| sed 's%\(^.*$\)%\1 \\%' | sed 's%^.*: %%' >> "$depfile"
424
# Above I had to use perl since sed would refuse to replace
425
# the file path sep '\' correctly with '/'.
426
# Remove these two commands once you get the above figured out!
427
#mv "$depfile" "$tmpdepfile"
428
#echo "# dummy" > "$depfile"
430
echo "depcomp: depmode==none, not building in depeandency tracking!"
436
echo "Unknown depmode $depmode" 1>&2