1
0

depcomp 14 KB

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