depcomp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. #! /bin/sh
  2. # depcomp - compile a program generating dependencies as side-effects
  3. scriptversion=2004-05-31.23
  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. 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 0
  43. ;;
  44. -v | --v*)
  45. echo "depcomp $scriptversion"
  46. exit 0
  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. # Dependencies are output in .lo.d with libtool 1.4.
  260. # With libtool 1.5 they are output both in $dir.libs/$base.o.d
  261. # and in $dir.libs/$base.o.d and $dir$base.o.d. We process the
  262. # latter, because the former will be cleaned when $dir.libs is
  263. # erased.
  264. tmpdepfile1="$dir.libs/$base.lo.d"
  265. tmpdepfile2="$dir$base.o.d"
  266. tmpdepfile3="$dir.libs/$base.d"
  267. "$@" -Wc,-MD
  268. else
  269. tmpdepfile1="$dir$base.o.d"
  270. tmpdepfile2="$dir$base.d"
  271. tmpdepfile3="$dir$base.d"
  272. "$@" -MD
  273. fi
  274. stat=$?
  275. if test $stat -eq 0; then :
  276. else
  277. rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
  278. exit $stat
  279. fi
  280. if test -f "$tmpdepfile1"; then
  281. tmpdepfile="$tmpdepfile1"
  282. elif test -f "$tmpdepfile2"; then
  283. tmpdepfile="$tmpdepfile2"
  284. else
  285. tmpdepfile="$tmpdepfile3"
  286. fi
  287. if test -f "$tmpdepfile"; then
  288. sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
  289. # That's a tab and a space in the [].
  290. sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
  291. else
  292. echo "#dummy" > "$depfile"
  293. fi
  294. rm -f "$tmpdepfile"
  295. ;;
  296. #nosideeffect)
  297. # This comment above is used by automake to tell side-effect
  298. # dependency tracking mechanisms from slower ones.
  299. dashmstdout)
  300. # Important note: in order to support this mode, a compiler *must*
  301. # always write the preprocessed file to stdout, regardless of -o.
  302. "$@" || exit $?
  303. # Remove the call to Libtool.
  304. if test "$libtool" = yes; then
  305. while test $1 != '--mode=compile'; do
  306. shift
  307. done
  308. shift
  309. fi
  310. # Remove `-o $object'.
  311. IFS=" "
  312. for arg
  313. do
  314. case $arg in
  315. -o)
  316. shift
  317. ;;
  318. $object)
  319. shift
  320. ;;
  321. *)
  322. set fnord "$@" "$arg"
  323. shift # fnord
  324. shift # $arg
  325. ;;
  326. esac
  327. done
  328. test -z "$dashmflag" && dashmflag=-M
  329. # Require at least two characters before searching for `:'
  330. # in the target name. This is to cope with DOS-style filenames:
  331. # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
  332. "$@" $dashmflag |
  333. sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
  334. rm -f "$depfile"
  335. cat < "$tmpdepfile" > "$depfile"
  336. tr ' ' '
  337. ' < "$tmpdepfile" | \
  338. ## Some versions of the HPUX 10.20 sed can't process this invocation
  339. ## correctly. Breaking it into two sed invocations is a workaround.
  340. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
  341. rm -f "$tmpdepfile"
  342. ;;
  343. dashXmstdout)
  344. # This case only exists to satisfy depend.m4. It is never actually
  345. # run, as this mode is specially recognized in the preamble.
  346. exit 1
  347. ;;
  348. makedepend)
  349. "$@" || exit $?
  350. # Remove any Libtool call
  351. if test "$libtool" = yes; then
  352. while test $1 != '--mode=compile'; do
  353. shift
  354. done
  355. shift
  356. fi
  357. # X makedepend
  358. shift
  359. cleared=no
  360. for arg in "$@"; do
  361. case $cleared in
  362. no)
  363. set ""; shift
  364. cleared=yes ;;
  365. esac
  366. case "$arg" in
  367. -D*|-I*)
  368. set fnord "$@" "$arg"; shift ;;
  369. # Strip any option that makedepend may not understand. Remove
  370. # the object too, otherwise makedepend will parse it as a source file.
  371. -*|$object)
  372. ;;
  373. *)
  374. set fnord "$@" "$arg"; shift ;;
  375. esac
  376. done
  377. obj_suffix="`echo $object | sed 's/^.*\././'`"
  378. touch "$tmpdepfile"
  379. ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
  380. rm -f "$depfile"
  381. cat < "$tmpdepfile" > "$depfile"
  382. sed '1,2d' "$tmpdepfile" | tr ' ' '
  383. ' | \
  384. ## Some versions of the HPUX 10.20 sed can't process this invocation
  385. ## correctly. Breaking it into two sed invocations is a workaround.
  386. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
  387. rm -f "$tmpdepfile" "$tmpdepfile".bak
  388. ;;
  389. cpp)
  390. # Important note: in order to support this mode, a compiler *must*
  391. # always write the preprocessed file to stdout.
  392. "$@" || exit $?
  393. # Remove the call to Libtool.
  394. if test "$libtool" = yes; then
  395. while test $1 != '--mode=compile'; do
  396. shift
  397. done
  398. shift
  399. fi
  400. # Remove `-o $object'.
  401. IFS=" "
  402. for arg
  403. do
  404. case $arg in
  405. -o)
  406. shift
  407. ;;
  408. $object)
  409. shift
  410. ;;
  411. *)
  412. set fnord "$@" "$arg"
  413. shift # fnord
  414. shift # $arg
  415. ;;
  416. esac
  417. done
  418. "$@" -E |
  419. sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
  420. sed '$ s: \\$::' > "$tmpdepfile"
  421. rm -f "$depfile"
  422. echo "$object : \\" > "$depfile"
  423. cat < "$tmpdepfile" >> "$depfile"
  424. sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
  425. rm -f "$tmpdepfile"
  426. ;;
  427. msvisualcpp)
  428. # Important note: in order to support this mode, a compiler *must*
  429. # always write the preprocessed file to stdout, regardless of -o,
  430. # because we must use -o when running libtool.
  431. "$@" || exit $?
  432. IFS=" "
  433. for arg
  434. do
  435. case "$arg" in
  436. "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
  437. set fnord "$@"
  438. shift
  439. shift
  440. ;;
  441. *)
  442. set fnord "$@" "$arg"
  443. shift
  444. shift
  445. ;;
  446. esac
  447. done
  448. "$@" -E |
  449. sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
  450. rm -f "$depfile"
  451. echo "$object : \\" > "$depfile"
  452. . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
  453. echo " " >> "$depfile"
  454. . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
  455. rm -f "$tmpdepfile"
  456. ;;
  457. none)
  458. exec "$@"
  459. ;;
  460. *)
  461. echo "Unknown depmode $depmode" 1>&2
  462. exit 1
  463. ;;
  464. esac
  465. exit 0
  466. # Local Variables:
  467. # mode: shell-script
  468. # sh-indentation: 2
  469. # eval: (add-hook 'write-file-hooks 'time-stamp)
  470. # time-stamp-start: "scriptversion="
  471. # time-stamp-format: "%:y-%02m-%02d.%02H"
  472. # time-stamp-end: "$"
  473. # End: