depcomp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. #! /bin/sh
  2. # depcomp - compile a program generating dependencies as side-effects
  3. # Copyright 1999, 2000 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. This file always lives in the current directory.
  156. # Also, the AIX compiler puts `$object:' at the start of each line;
  157. # $object doesn't have directory information.
  158. stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'`
  159. tmpdepfile="$stripped.u"
  160. outname="$stripped.o"
  161. if test "$libtool" = yes; then
  162. "$@" -Wc,-M
  163. else
  164. "$@" -M
  165. fi
  166. stat=$?
  167. if test $stat -eq 0; then :
  168. else
  169. rm -f "$tmpdepfile"
  170. exit $stat
  171. fi
  172. if test -f "$tmpdepfile"; then
  173. # Each line is of the form `foo.o: dependent.h'.
  174. # Do two passes, one to just change these to
  175. # `$object: dependent.h' and one to simply `dependent.h:'.
  176. sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
  177. sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
  178. else
  179. # The sourcefile does not contain any dependencies, so just
  180. # store a dummy comment line, to avoid errors with the Makefile
  181. # "include basename.Plo" scheme.
  182. echo "#dummy" > "$depfile"
  183. fi
  184. rm -f "$tmpdepfile"
  185. ;;
  186. tru64)
  187. # The Tru64 compiler uses -MD to generate dependencies as a side
  188. # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
  189. # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
  190. # dependencies in `foo.d' instead, so we check for that too.
  191. # Subdirectories are respected.
  192. base=`echo "$object" | sed -e 's/\.o$//' -e 's/\.lo$//'`
  193. tmpdepfile1="$base.o.d"
  194. tmpdepfile2="$base.d"
  195. if test "$libtool" = yes; then
  196. "$@" -Wc,-MD
  197. else
  198. "$@" -MD
  199. fi
  200. stat=$?
  201. if test $stat -eq 0; then :
  202. else
  203. rm -f "$tmpdepfile1" "$tmpdepfile2"
  204. exit $stat
  205. fi
  206. if test -f "$tmpdepfile1"; then
  207. tmpdepfile="$tmpdepfile1"
  208. else
  209. tmpdepfile="$tmpdepfile2"
  210. fi
  211. if test -f "$tmpdepfile"; then
  212. sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
  213. # That's a space and a tab in the [].
  214. sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
  215. else
  216. echo "#dummy" > "$depfile"
  217. fi
  218. rm -f "$tmpdepfile"
  219. ;;
  220. #nosideeffect)
  221. # This comment above is used by automake to tell side-effect
  222. # dependency tracking mechanisms from slower ones.
  223. dashmstdout)
  224. # Important note: in order to support this mode, a compiler *must*
  225. # always write the proprocessed file to stdout, regardless of -o,
  226. # because we must use -o when running libtool.
  227. test -z "$dashmflag" && dashmflag=-M
  228. ( IFS=" "
  229. case " $* " in
  230. *" --mode=compile "*) # this is libtool, let us make it quiet
  231. for arg
  232. do # cycle over the arguments
  233. case "$arg" in
  234. "--mode=compile")
  235. # insert --quiet before "--mode=compile"
  236. set fnord "$@" --quiet
  237. shift # fnord
  238. ;;
  239. esac
  240. set fnord "$@" "$arg"
  241. shift # fnord
  242. shift # "$arg"
  243. done
  244. ;;
  245. esac
  246. "$@" $dashmflag | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
  247. ) &
  248. proc=$!
  249. "$@"
  250. stat=$?
  251. wait "$proc"
  252. if test "$stat" != 0; then exit $stat; fi
  253. rm -f "$depfile"
  254. cat < "$tmpdepfile" > "$depfile"
  255. tr ' ' '
  256. ' < "$tmpdepfile" | \
  257. ## Some versions of the HPUX 10.20 sed can't process this invocation
  258. ## correctly. Breaking it into two sed invocations is a workaround.
  259. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
  260. rm -f "$tmpdepfile"
  261. ;;
  262. dashXmstdout)
  263. # This case only exists to satisfy depend.m4. It is never actually
  264. # run, as this mode is specially recognized in the preamble.
  265. exit 1
  266. ;;
  267. makedepend)
  268. # X makedepend
  269. (
  270. shift
  271. cleared=no
  272. for arg in "$@"; do
  273. case $cleared in no)
  274. set ""; shift
  275. cleared=yes
  276. esac
  277. case "$arg" in
  278. -D*|-I*)
  279. set fnord "$@" "$arg"; shift;;
  280. -*)
  281. ;;
  282. *)
  283. set fnord "$@" "$arg"; shift;;
  284. esac
  285. done
  286. obj_suffix="`echo $object | sed 's/^.*\././'`"
  287. touch "$tmpdepfile"
  288. ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@"
  289. ) &
  290. proc=$!
  291. "$@"
  292. stat=$?
  293. wait "$proc"
  294. if test "$stat" != 0; then exit $stat; fi
  295. rm -f "$depfile"
  296. cat < "$tmpdepfile" > "$depfile"
  297. sed '1,2d' "$tmpdepfile" | tr ' ' '
  298. ' | \
  299. ## Some versions of the HPUX 10.20 sed can't process this invocation
  300. ## correctly. Breaking it into two sed invocations is a workaround.
  301. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
  302. rm -f "$tmpdepfile" "$tmpdepfile".bak
  303. ;;
  304. cpp)
  305. # Important note: in order to support this mode, a compiler *must*
  306. # always write the proprocessed file to stdout, regardless of -o,
  307. # because we must use -o when running libtool.
  308. ( IFS=" "
  309. case " $* " in
  310. *" --mode=compile "*)
  311. for arg
  312. do # cycle over the arguments
  313. case $arg in
  314. "--mode=compile")
  315. # insert --quiet before "--mode=compile"
  316. set fnord "$@" --quiet
  317. shift # fnord
  318. ;;
  319. esac
  320. set fnord "$@" "$arg"
  321. shift # fnord
  322. shift # "$arg"
  323. done
  324. ;;
  325. esac
  326. "$@" -E |
  327. sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
  328. sed '$ s: \\$::' > "$tmpdepfile"
  329. ) &
  330. proc=$!
  331. "$@"
  332. stat=$?
  333. wait "$proc"
  334. if test "$stat" != 0; then exit $stat; fi
  335. rm -f "$depfile"
  336. echo "$object : \\" > "$depfile"
  337. cat < "$tmpdepfile" >> "$depfile"
  338. sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
  339. rm -f "$tmpdepfile"
  340. ;;
  341. msvisualcpp)
  342. # Important note: in order to support this mode, a compiler *must*
  343. # always write the proprocessed file to stdout, regardless of -o,
  344. # because we must use -o when running libtool.
  345. ( IFS=" "
  346. case " $* " in
  347. *" --mode=compile "*)
  348. for arg
  349. do # cycle over the arguments
  350. case $arg in
  351. "--mode=compile")
  352. # insert --quiet before "--mode=compile"
  353. set fnord "$@" --quiet
  354. shift # fnord
  355. ;;
  356. esac
  357. set fnord "$@" "$arg"
  358. shift # fnord
  359. shift # "$arg"
  360. done
  361. ;;
  362. esac
  363. for arg
  364. do
  365. case "$arg" in
  366. "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
  367. set fnord "$@"
  368. shift
  369. shift
  370. ;;
  371. *)
  372. set fnord "$@" "$arg"
  373. shift
  374. shift
  375. ;;
  376. esac
  377. done
  378. "$@" -E |
  379. sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
  380. ) &
  381. proc=$!
  382. "$@"
  383. stat=$?
  384. wait "$proc"
  385. if test "$stat" != 0; then exit $stat; fi
  386. rm -f "$depfile"
  387. echo "$object : \\" > "$depfile"
  388. . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
  389. echo " " >> "$depfile"
  390. . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
  391. rm -f "$tmpdepfile"
  392. ;;
  393. none)
  394. exec "$@"
  395. ;;
  396. *)
  397. echo "Unknown depmode $depmode" 1>&2
  398. exit 1
  399. ;;
  400. esac
  401. exit 0