depcomp 16 KB

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