TIVI-153: add as dependency for iputils
[profile/ivi/xmlto.git] / depcomp
1 #! /bin/sh
2 # depcomp - compile a program generating dependencies as side-effects
3
4 scriptversion=2003-11-08.23
5
6 # Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc.
7
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, see <http://www.gnu.org/licenses/>.
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 <oliva@dcc.unicamp.br>.
27
28 case $1 in
29   '')
30      echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
31      exit 1;
32      ;;
33   -h | --h*)
34     cat <<\EOF
35 Usage: depcomp [--help] [--version] PROGRAM [ARGS]
36
37 Run PROGRAMS ARGS to compile a file, generating dependencies
38 as side-effects.
39
40 Environment variables:
41   depmode     Dependency tracking mode.
42   source      Source file read by `PROGRAMS ARGS'.
43   object      Object file output by `PROGRAMS ARGS'.
44   depfile     Dependency file to output.
45   tmpdepfile  Temporary file to use when outputing dependencies.
46   libtool     Whether libtool is used (yes/no).
47
48 Report bugs to <bug-automake@gnu.org>.
49 EOF
50     exit 0
51     ;;
52   -v | --v*)
53     echo "depcomp $scriptversion"
54     exit 0
55     ;;
56 esac
57
58 if test -z "$depmode" || test -z "$source" || test -z "$object"; then
59   echo "depcomp: Variables source, object and depmode must be set" 1>&2
60   exit 1
61 fi
62 # `libtool' can also be set to `yes' or `no'.
63
64 if test -z "$depfile"; then
65    base=`echo "$object" | sed -e 's,^.*/,,' -e 's,\.\([^.]*\)$,.P\1,'`
66    dir=`echo "$object" | sed 's,/.*$,/,'`
67    if test "$dir" = "$object"; then
68       dir=
69    fi
70    # FIXME: should be _deps on DOS.
71    depfile="$dir.deps/$base"
72 fi
73
74 tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
75
76 rm -f "$tmpdepfile"
77
78 # Some modes work just like other modes, but use different flags.  We
79 # parameterize here, but still list the modes in the big case below,
80 # to make depend.m4 easier to write.  Note that we *cannot* use a case
81 # here, because this file can only contain one case statement.
82 if test "$depmode" = hp; then
83   # HP compiler uses -M and no extra arg.
84   gccflag=-M
85   depmode=gcc
86 fi
87
88 if test "$depmode" = dashXmstdout; then
89    # This is just like dashmstdout with a different argument.
90    dashmflag=-xM
91    depmode=dashmstdout
92 fi
93
94 case "$depmode" in
95 gcc3)
96 ## gcc 3 implements dependency tracking that does exactly what
97 ## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
98 ## it if -MD -MP comes after the -MF stuff.  Hmm.
99   "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
100   stat=$?
101   if test $stat -eq 0; then :
102   else
103     rm -f "$tmpdepfile"
104     exit $stat
105   fi
106   mv "$tmpdepfile" "$depfile"
107   ;;
108
109 gcc)
110 ## There are various ways to get dependency output from gcc.  Here's
111 ## why we pick this rather obscure method:
112 ## - Don't want to use -MD because we'd like the dependencies to end
113 ##   up in a subdir.  Having to rename by hand is ugly.
114 ##   (We might end up doing this anyway to support other compilers.)
115 ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
116 ##   -MM, not -M (despite what the docs say).
117 ## - Using -M directly means running the compiler twice (even worse
118 ##   than renaming).
119   if test -z "$gccflag"; then
120     gccflag=-MD,
121   fi
122   "$@" -Wp,"$gccflag$tmpdepfile"
123   stat=$?
124   if test $stat -eq 0; then :
125   else
126     rm -f "$tmpdepfile"
127     exit $stat
128   fi
129   rm -f "$depfile"
130   echo "$object : \\" > "$depfile"
131   alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
132 ## The second -e expression handles DOS-style file names with drive letters.
133   sed -e 's/^[^:]*: / /' \
134       -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
135 ## This next piece of magic avoids the `deleted header file' problem.
136 ## The problem is that when a header file which appears in a .P file
137 ## is deleted, the dependency causes make to die (because there is
138 ## typically no way to rebuild the header).  We avoid this by adding
139 ## dummy dependencies for each header file.  Too bad gcc doesn't do
140 ## this for us directly.
141   tr ' ' '
142 ' < "$tmpdepfile" |
143 ## Some versions of gcc put a space before the `:'.  On the theory
144 ## that the space means something, we add a space to the output as
145 ## well.
146 ## Some versions of the HPUX 10.20 sed can't process this invocation
147 ## correctly.  Breaking it into two sed invocations is a workaround.
148     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
149   rm -f "$tmpdepfile"
150   ;;
151
152 hp)
153   # This case exists only to let depend.m4 do its work.  It works by
154   # looking at the text of this script.  This case will never be run,
155   # since it is checked for above.
156   exit 1
157   ;;
158
159 sgi)
160   if test "$libtool" = yes; then
161     "$@" "-Wp,-MDupdate,$tmpdepfile"
162   else
163     "$@" -MDupdate "$tmpdepfile"
164   fi
165   stat=$?
166   if test $stat -eq 0; then :
167   else
168     rm -f "$tmpdepfile"
169     exit $stat
170   fi
171   rm -f "$depfile"
172
173   if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
174     echo "$object : \\" > "$depfile"
175
176     # Clip off the initial element (the dependent).  Don't try to be
177     # clever and replace this with sed code, as IRIX sed won't handle
178     # lines with more than a fixed number of characters (4096 in
179     # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
180     # the IRIX cc adds comments like `#:fec' to the end of the
181     # dependency line.
182     tr ' ' '
183 ' < "$tmpdepfile" \
184     | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
185     tr '
186 ' ' ' >> $depfile
187     echo >> $depfile
188
189     # The second pass generates a dummy entry for each header file.
190     tr ' ' '
191 ' < "$tmpdepfile" \
192    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
193    >> $depfile
194   else
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"
199   fi
200   rm -f "$tmpdepfile"
201   ;;
202
203 aix)
204   # The C for AIX Compiler uses -M and outputs the dependencies
205   # in a .u file.  In older versions, this file always lives in the
206   # current directory.  Also, the AIX compiler puts `$object:' at the
207   # start of each line; $object doesn't have directory information.
208   # Version 6 uses the directory in both cases.
209   stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
210   tmpdepfile="$stripped.u"
211   if test "$libtool" = yes; then
212     "$@" -Wc,-M
213   else
214     "$@" -M
215   fi
216   stat=$?
217
218   if test -f "$tmpdepfile"; then :
219   else
220     stripped=`echo "$stripped" | sed 's,^.*/,,'`
221     tmpdepfile="$stripped.u"
222   fi
223
224   if test $stat -eq 0; then :
225   else
226     rm -f "$tmpdepfile"
227     exit $stat
228   fi
229
230   if test -f "$tmpdepfile"; then
231     outname="$stripped.o"
232     # Each line is of the form `foo.o: dependent.h'.
233     # Do two passes, one to just change these to
234     # `$object: dependent.h' and one to simply `dependent.h:'.
235     sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
236     sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
237   else
238     # The sourcefile does not contain any dependencies, so just
239     # store a dummy comment line, to avoid errors with the Makefile
240     # "include basename.Plo" scheme.
241     echo "#dummy" > "$depfile"
242   fi
243   rm -f "$tmpdepfile"
244   ;;
245
246 icc)
247   # Intel's C compiler understands `-MD -MF file'.  However on
248   #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
249   # ICC 7.0 will fill foo.d with something like
250   #    foo.o: sub/foo.c
251   #    foo.o: sub/foo.h
252   # which is wrong.  We want:
253   #    sub/foo.o: sub/foo.c
254   #    sub/foo.o: sub/foo.h
255   #    sub/foo.c:
256   #    sub/foo.h:
257   # ICC 7.1 will output
258   #    foo.o: sub/foo.c sub/foo.h
259   # and will wrap long lines using \ :
260   #    foo.o: sub/foo.c ... \
261   #     sub/foo.h ... \
262   #     ...
263
264   "$@" -MD -MF "$tmpdepfile"
265   stat=$?
266   if test $stat -eq 0; then :
267   else
268     rm -f "$tmpdepfile"
269     exit $stat
270   fi
271   rm -f "$depfile"
272   # Each line is of the form `foo.o: dependent.h',
273   # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
274   # Do two passes, one to just change these to
275   # `$object: dependent.h' and one to simply `dependent.h:'.
276   sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
277   # Some versions of the HPUX 10.20 sed can't process this invocation
278   # correctly.  Breaking it into two sed invocations is a workaround.
279   sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
280     sed -e 's/$/ :/' >> "$depfile"
281   rm -f "$tmpdepfile"
282   ;;
283
284 tru64)
285    # The Tru64 compiler uses -MD to generate dependencies as a side
286    # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
287    # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
288    # dependencies in `foo.d' instead, so we check for that too.
289    # Subdirectories are respected.
290    dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
291    test "x$dir" = "x$object" && dir=
292    base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
293
294    if test "$libtool" = yes; then
295       tmpdepfile1="$dir.libs/$base.lo.d"
296       tmpdepfile2="$dir.libs/$base.d"
297       "$@" -Wc,-MD
298    else
299       tmpdepfile1="$dir$base.o.d"
300       tmpdepfile2="$dir$base.d"
301       "$@" -MD
302    fi
303
304    stat=$?
305    if test $stat -eq 0; then :
306    else
307       rm -f "$tmpdepfile1" "$tmpdepfile2"
308       exit $stat
309    fi
310
311    if test -f "$tmpdepfile1"; then
312       tmpdepfile="$tmpdepfile1"
313    else
314       tmpdepfile="$tmpdepfile2"
315    fi
316    if test -f "$tmpdepfile"; then
317       sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
318       # That's a tab and a space in the [].
319       sed -e 's,^.*\.[a-z]*:[    ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
320    else
321       echo "#dummy" > "$depfile"
322    fi
323    rm -f "$tmpdepfile"
324    ;;
325
326 #nosideeffect)
327   # This comment above is used by automake to tell side-effect
328   # dependency tracking mechanisms from slower ones.
329
330 dashmstdout)
331   # Important note: in order to support this mode, a compiler *must*
332   # always write the preprocessed file to stdout, regardless of -o.
333   "$@" || exit $?
334
335   # Remove the call to Libtool.
336   if test "$libtool" = yes; then
337     while test $1 != '--mode=compile'; do
338       shift
339     done
340     shift
341   fi
342
343   # Remove `-o $object'.
344   IFS=" "
345   for arg
346   do
347     case $arg in
348     -o)
349       shift
350       ;;
351     $object)
352       shift
353       ;;
354     *)
355       set fnord "$@" "$arg"
356       shift # fnord
357       shift # $arg
358       ;;
359     esac
360   done
361
362   test -z "$dashmflag" && dashmflag=-M
363   # Require at least two characters before searching for `:'
364   # in the target name.  This is to cope with DOS-style filenames:
365   # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
366   "$@" $dashmflag |
367     sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
368   rm -f "$depfile"
369   cat < "$tmpdepfile" > "$depfile"
370   tr ' ' '
371 ' < "$tmpdepfile" | \
372 ## Some versions of the HPUX 10.20 sed can't process this invocation
373 ## correctly.  Breaking it into two sed invocations is a workaround.
374     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
375   rm -f "$tmpdepfile"
376   ;;
377
378 dashXmstdout)
379   # This case only exists to satisfy depend.m4.  It is never actually
380   # run, as this mode is specially recognized in the preamble.
381   exit 1
382   ;;
383
384 makedepend)
385   "$@" || exit $?
386   # Remove any Libtool call
387   if test "$libtool" = yes; then
388     while test $1 != '--mode=compile'; do
389       shift
390     done
391     shift
392   fi
393   # X makedepend
394   shift
395   cleared=no
396   for arg in "$@"; do
397     case $cleared in
398     no)
399       set ""; shift
400       cleared=yes ;;
401     esac
402     case "$arg" in
403     -D*|-I*)
404       set fnord "$@" "$arg"; shift ;;
405     # Strip any option that makedepend may not understand.  Remove
406     # the object too, otherwise makedepend will parse it as a source file.
407     -*|$object)
408       ;;
409     *)
410       set fnord "$@" "$arg"; shift ;;
411     esac
412   done
413   obj_suffix="`echo $object | sed 's/^.*\././'`"
414   touch "$tmpdepfile"
415   ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
416   rm -f "$depfile"
417   cat < "$tmpdepfile" > "$depfile"
418   sed '1,2d' "$tmpdepfile" | tr ' ' '
419 ' | \
420 ## Some versions of the HPUX 10.20 sed can't process this invocation
421 ## correctly.  Breaking it into two sed invocations is a workaround.
422     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
423   rm -f "$tmpdepfile" "$tmpdepfile".bak
424   ;;
425
426 cpp)
427   # Important note: in order to support this mode, a compiler *must*
428   # always write the preprocessed file to stdout.
429   "$@" || exit $?
430
431   # Remove the call to Libtool.
432   if test "$libtool" = yes; then
433     while test $1 != '--mode=compile'; do
434       shift
435     done
436     shift
437   fi
438
439   # Remove `-o $object'.
440   IFS=" "
441   for arg
442   do
443     case $arg in
444     -o)
445       shift
446       ;;
447     $object)
448       shift
449       ;;
450     *)
451       set fnord "$@" "$arg"
452       shift # fnord
453       shift # $arg
454       ;;
455     esac
456   done
457
458   "$@" -E |
459     sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
460     sed '$ s: \\$::' > "$tmpdepfile"
461   rm -f "$depfile"
462   echo "$object : \\" > "$depfile"
463   cat < "$tmpdepfile" >> "$depfile"
464   sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
465   rm -f "$tmpdepfile"
466   ;;
467
468 msvisualcpp)
469   # Important note: in order to support this mode, a compiler *must*
470   # always write the preprocessed file to stdout, regardless of -o,
471   # because we must use -o when running libtool.
472   "$@" || exit $?
473   IFS=" "
474   for arg
475   do
476     case "$arg" in
477     "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
478         set fnord "$@"
479         shift
480         shift
481         ;;
482     *)
483         set fnord "$@" "$arg"
484         shift
485         shift
486         ;;
487     esac
488   done
489   "$@" -E |
490   sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
491   rm -f "$depfile"
492   echo "$object : \\" > "$depfile"
493   . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::    \1 \\:p' >> "$depfile"
494   echo "        " >> "$depfile"
495   . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
496   rm -f "$tmpdepfile"
497   ;;
498
499 none)
500   exec "$@"
501   ;;
502
503 *)
504   echo "Unknown depmode $depmode" 1>&2
505   exit 1
506   ;;
507 esac
508
509 exit 0
510
511 # Local Variables:
512 # mode: shell-script
513 # sh-indentation: 2
514 # eval: (add-hook 'write-file-hooks 'time-stamp)
515 # time-stamp-start: "scriptversion="
516 # time-stamp-format: "%:y-%02m-%02d.%02H"
517 # time-stamp-end: "$"
518 # End: