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