]> git.lyx.org Git - lyx.git/blob - config/depcomp
update boost
[lyx.git] / config / depcomp
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 <oliva@dcc.unicamp.br>.
27
28 if 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
31 fi
32 # `libtool' can also be set to `yes' or `no'.
33
34 depfile=${depfile-`echo "$object" | sed 's,\([^/]*\)$,.deps/\1,;s/\.\([^.]*\)$/.P\1/'`}
35 tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
36
37 rm -f "$tmpdepfile"
38
39 # Some modes work just like other modes, but use different flags.  We
40 # parameterize here, but still list the modes in the big case below,
41 # to make depend.m4 easier to write.  Note that we *cannot* use a case
42 # here, because this file can only contain one case statement.
43 if test "$depmode" = hp; then
44   # HP compiler uses -M and no extra arg.
45   gccflag=-M
46   depmode=gcc
47 fi
48
49 if test "$depmode" = dashXmstdout; then
50    # This is just like dashmstdout with a different argument.
51    dashmflag=-xM
52    depmode=dashmstdout
53 fi
54
55 case "$depmode" in
56 gcc3)
57 ## gcc 3 implements dependency tracking that does exactly what
58 ## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
59 ## it if -MD -MP comes after the -MF stuff.  Hmm.
60   "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
61   stat=$?
62   if test $stat -eq 0; then :
63   else
64     rm -f "$tmpdepfile"
65     exit $stat
66   fi
67   mv "$tmpdepfile" "$depfile"
68   ;;
69
70 gcc)
71 ## There are various ways to get dependency output from gcc.  Here's
72 ## why we pick this rather obscure method:
73 ## - Don't want to use -MD because we'd like the dependencies to end
74 ##   up in a subdir.  Having to rename by hand is ugly.
75 ##   (We might end up doing this anyway to support other compilers.)
76 ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
77 ##   -MM, not -M (despite what the docs say).
78 ## - Using -M directly means running the compiler twice (even worse
79 ##   than renaming).
80   if test -z "$gccflag"; then
81     gccflag=-MD,
82   fi
83   "$@" -Wp,"$gccflag$tmpdepfile"
84   stat=$?
85   if test $stat -eq 0; then :
86   else
87     rm -f "$tmpdepfile"
88     exit $stat
89   fi
90   rm -f "$depfile"
91   echo "$object : \\" > "$depfile"
92   alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
93 ## The second -e expression handles DOS-style file names with drive letters.
94   sed -e 's/^[^:]*: / /' \
95       -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
96 ## This next piece of magic avoids the `deleted header file' problem.
97 ## The problem is that when a header file which appears in a .P file
98 ## is deleted, the dependency causes make to die (because there is
99 ## typically no way to rebuild the header).  We avoid this by adding
100 ## dummy dependencies for each header file.  Too bad gcc doesn't do
101 ## this for us directly.
102   tr ' ' '
103 ' < "$tmpdepfile" |
104 ## Some versions of gcc put a space before the `:'.  On the theory
105 ## that the space means something, we add a space to the output as
106 ## well.
107 ## Some versions of the HPUX 10.20 sed can't process this invocation
108 ## correctly.  Breaking it into two sed invocations is a workaround.
109     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
110   rm -f "$tmpdepfile"
111   ;;
112
113 hp)
114   # This case exists only to let depend.m4 do its work.  It works by
115   # looking at the text of this script.  This case will never be run,
116   # since it is checked for above.
117   exit 1
118   ;;
119
120 sgi)
121   if test "$libtool" = yes; then
122     "$@" "-Wp,-MDupdate,$tmpdepfile"
123   else
124     "$@" -MDupdate "$tmpdepfile"
125   fi
126   stat=$?
127   if test $stat -eq 0; then :
128   else
129     rm -f "$tmpdepfile"
130     exit $stat
131   fi
132   rm -f "$depfile"
133
134   if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
135     echo "$object : \\" > "$depfile"
136
137     # Clip off the initial element (the dependent).  Don't try to be
138     # clever and replace this with sed code, as IRIX sed won't handle
139     # lines with more than a fixed number of characters (4096 in
140     # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
141     # the IRIX cc adds comments like `#:fec' to the end of the
142     # dependency line.
143     tr ' ' '
144 ' < "$tmpdepfile" \
145     | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
146     tr '
147 ' ' ' >> $depfile
148     echo >> $depfile
149
150     # The second pass generates a dummy entry for each header file.
151     tr ' ' '
152 ' < "$tmpdepfile" \
153    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
154    >> $depfile
155   else
156     # The sourcefile does not contain any dependencies, so just
157     # store a dummy comment line, to avoid errors with the Makefile
158     # "include basename.Plo" scheme.
159     echo "#dummy" > "$depfile"
160   fi
161   rm -f "$tmpdepfile"
162   ;;
163
164 aix)
165   # The C for AIX Compiler uses -M and outputs the dependencies
166   # in a .u file.  This file always lives in the current directory.
167   # Also, the AIX compiler puts `$object:' at the start of each line;
168   # $object doesn't have directory information.
169   stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'`
170   tmpdepfile="$stripped.u"
171   outname="$stripped.o"
172   if test "$libtool" = yes; then
173     "$@" -Wc,-M
174   else
175     "$@" -M
176   fi
177
178   stat=$?
179   if test $stat -eq 0; then :
180   else
181     rm -f "$tmpdepfile"
182     exit $stat
183   fi
184
185   if test -f "$tmpdepfile"; then
186     # Each line is of the form `foo.o: dependent.h'.
187     # Do two passes, one to just change these to
188     # `$object: dependent.h' and one to simply `dependent.h:'.
189     sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
190     sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
191   else
192     # The sourcefile does not contain any dependencies, so just
193     # store a dummy comment line, to avoid errors with the Makefile
194     # "include basename.Plo" scheme.
195     echo "#dummy" > "$depfile"
196   fi
197   rm -f "$tmpdepfile"
198   ;;
199
200 tru64)
201    # The Tru64 DEC compiler uses -MD to generate dependencies as a side
202    # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
203    # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 
204    # dependencies in `foo.d' instead, so we check for that too.
205    # Subdirectories are respected.
206
207    # This is incorrect as it assumes that $object has a .o extension when
208    # it could well have a .lo one.
209    #tmpdepfile1="$object.d"
210    # This is just bad sed. The /.o$/ should be /\.o/, nonwithstanding the
211    # flawed logic, described above.
212    #tmpdepfile2=`echo "$object" | sed -e 's/.o$/.d/'`
213
214    # The correct way:
215    # Strip the (.o, or .lo) extension from $object
216    # (Same piece of sed magic as used for the AIX compiler above.)
217    stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'`
218    # Tru64 compiler dependency file.
219    tmpdepfile1="$stripped.o.d"
220    # Compaq CCC V6.2 dependency file.
221    tmpdepfile2="$stripped.d"
222
223    if test "$libtool" = yes; then
224       "$@" -Wc,-MD
225    else
226       "$@" -MD
227    fi
228
229    stat=$?
230    if test $stat -eq 0; then :
231    else
232       rm -f "$tmpdepfile1" "$tmpdepfile2"
233       exit $stat
234    fi
235
236    if test -f "$tmpdepfile1"; then
237       tmpdepfile="$tmpdepfile1"
238    else
239       tmpdepfile="$tmpdepfile2"
240    fi
241    if test -f "$tmpdepfile"; then
242       sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
243       # That's a space and a tab in the [].
244       sed -e 's,^.*\.[a-z]*:[   ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
245    else
246       echo "#dummy" > "$depfile"
247    fi
248    rm -f "$tmpdepfile"
249    ;;
250
251 #nosideeffect)
252   # This comment above is used by automake to tell side-effect
253   # dependency tracking mechanisms from slower ones.
254
255 dashmstdout)
256   # Important note: in order to support this mode, a compiler *must*
257   # always write the proprocessed file to stdout, regardless of -o,
258   # because we must use -o when running libtool.
259   test -z "$dashmflag" && dashmflag=-M
260   ( IFS=" "
261     case " $* " in
262     *" --mode=compile "*) # this is libtool, let us make it quiet
263       for arg
264       do # cycle over the arguments
265         case "$arg" in
266         "--mode=compile")
267           # insert --quiet before "--mode=compile"
268           set fnord "$@" --quiet
269           shift # fnord
270           ;;
271         esac
272         set fnord "$@" "$arg"
273         shift # fnord
274         shift # "$arg"
275       done
276       ;;
277     esac
278     "$@" $dashmflag | sed 's:^[^:]*\:[  ]*:'"$object"'\: :' > "$tmpdepfile"
279   ) &
280   proc=$!
281   "$@"
282   stat=$?
283   wait "$proc"
284   if test "$stat" != 0; then exit $stat; fi
285   rm -f "$depfile"
286   cat < "$tmpdepfile" > "$depfile"
287   tr ' ' '
288 ' < "$tmpdepfile" | \
289 ## Some versions of the HPUX 10.20 sed can't process this invocation
290 ## correctly.  Breaking it into two sed invocations is a workaround.
291     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
292   rm -f "$tmpdepfile"
293   ;;
294
295 dashXmstdout)
296   # This case only exists to satisfy depend.m4.  It is never actually
297   # run, as this mode is specially recognized in the preamble.
298   exit 1
299   ;;
300
301 makedepend)
302   # X makedepend
303   (
304     shift
305     cleared=no
306     for arg in "$@"; do
307       case $cleared in no)
308         set ""; shift
309         cleared=yes
310       esac
311       case "$arg" in
312         -D*|-I*)
313           set fnord "$@" "$arg"; shift;;
314         -*)
315           ;;
316         *)
317           set fnord "$@" "$arg"; shift;;
318       esac
319     done
320     obj_suffix="`echo $object | sed 's/^.*\././'`"
321     touch "$tmpdepfile"
322     ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@"
323   ) &
324   proc=$!
325   "$@"
326   stat=$?
327   wait "$proc"
328   if test "$stat" != 0; then exit $stat; fi
329   rm -f "$depfile"
330   cat < "$tmpdepfile" > "$depfile"
331   tail +3 "$tmpdepfile" | tr ' ' '
332 ' | \
333 ## Some versions of the HPUX 10.20 sed can't process this invocation
334 ## correctly.  Breaking it into two sed invocations is a workaround.
335     sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
336   rm -f "$tmpdepfile" "$tmpdepfile".bak
337   ;;
338
339 cpp)
340   # Important note: in order to support this mode, a compiler *must*
341   # always write the proprocessed file to stdout, regardless of -o,
342   # because we must use -o when running libtool.
343   ( IFS=" "
344     case " $* " in
345     *" --mode=compile "*)
346       for arg
347       do # cycle over the arguments
348         case $arg in
349         "--mode=compile")
350           # insert --quiet before "--mode=compile"
351           set fnord "$@" --quiet
352           shift # fnord
353           ;;
354         esac
355         set fnord "$@" "$arg"
356         shift # fnord
357         shift # "$arg"
358       done
359       ;;
360     esac
361     "$@" -E |
362     sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
363     sed '$ s: \\$::' > "$tmpdepfile"
364   ) &
365   proc=$!
366   "$@"
367   stat=$?
368   wait "$proc"
369   if test "$stat" != 0; then exit $stat; fi
370   rm -f "$depfile"
371   echo "$object : \\" > "$depfile"
372   cat < "$tmpdepfile" >> "$depfile"
373   sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
374   rm -f "$tmpdepfile"
375   ;;
376
377 msvisualcpp)
378   # Important note: in order to support this mode, a compiler *must*
379   # always write the proprocessed file to stdout, regardless of -o,
380   # because we must use -o when running libtool.
381   ( IFS=" "
382     case " $* " in
383     *" --mode=compile "*)
384       for arg
385       do # cycle over the arguments
386         case $arg in
387         "--mode=compile")
388           # insert --quiet before "--mode=compile"
389           set fnord "$@" --quiet
390           shift # fnord
391           ;;
392         esac
393         set fnord "$@" "$arg"
394         shift # fnord
395         shift # "$arg"
396       done
397       ;;
398     esac
399     "$@" -E |
400     sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
401   ) &
402   proc=$!
403   "$@"
404   stat=$?
405   wait "$proc"
406   if test "$stat" != 0; then exit $stat; fi
407   rm -f "$depfile"
408   echo "$object : \\" > "$depfile"
409   . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::    \1 \\:p' >> "$depfile"
410   echo "        " >> "$depfile"
411   . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
412   rm -f "$tmpdepfile"
413   ;;
414
415 none)
416   exec "$@"
417   ;;
418
419 *)
420   echo "Unknown depmode $depmode" 1>&2
421   exit 1
422   ;;
423 esac
424
425 exit 0