depcomp 15 KB

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