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