depcomp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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 <[email protected]>.
  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. depfile=${depfile-`echo "$object" | sed 's,\([^/]*\)$,.deps/\1,;s/\.\([^.]*\)$/.P\1/'`}
  27. tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
  28. rm -f "$tmpdepfile"
  29. # Some modes work just like other modes, but use different flags. We
  30. # parameterize here, but still list the modes in the big case below,
  31. # to make depend.m4 easier to write. Note that we *cannot* use a case
  32. # here, because this file can only contain one case statement.
  33. if test "$depmode" = hp; then
  34. # HP compiler uses -M and no extra arg.
  35. gccflag=-M
  36. depmode=gcc
  37. fi
  38. if test "$depmode" = dashXmstdout; then
  39. # This is just like dashmstdout with a different argument.
  40. dashmflag=-xM
  41. depmode=dashmstdout
  42. fi
  43. case "$depmode" in
  44. gcc3)
  45. ## gcc 3 implements dependency tracking that does exactly what
  46. ## we want. Yay! Note: for some reason libtool 1.4 doesn't like
  47. ## it if -MD -MP comes after the -MF stuff. Hmm.
  48. "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
  49. stat=$?
  50. if test $stat -eq 0; then :
  51. else
  52. rm -f "$tmpdepfile"
  53. exit $stat
  54. fi
  55. mv "$tmpdepfile" "$depfile"
  56. ;;
  57. gcc)
  58. ## There are various ways to get dependency output from gcc. Here's
  59. ## why we pick this rather obscure method:
  60. ## - Don't want to use -MD because we'd like the dependencies to end
  61. ## up in a subdir. Having to rename by hand is ugly.
  62. ## (We might end up doing this anyway to support other compilers.)
  63. ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
  64. ## -MM, not -M (despite what the docs say).
  65. ## - Using -M directly means running the compiler twice (even worse
  66. ## than renaming).
  67. if test -z "$gccflag"; then
  68. gccflag=-MD,
  69. fi
  70. "$@" -Wp,"$gccflag$tmpdepfile"
  71. stat=$?
  72. if test $stat -eq 0; then :
  73. else
  74. rm -f "$tmpdepfile"
  75. exit $stat
  76. fi
  77. rm -f "$depfile"
  78. echo "$object : \\" > "$depfile"
  79. alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
  80. ## The second -e expression handles DOS-style file names with drive letters.
  81. sed -e 's/^[^:]*: / /' \
  82. -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
  83. ## This next piece of magic avoids the `deleted header file' problem.
  84. ## The problem is that when a header file which appears in a .P file
  85. ## is deleted, the dependency causes make to die (because there is
  86. ## typically no way to rebuild the header). We avoid this by adding
  87. ## dummy dependencies for each header file. Too bad gcc doesn't do
  88. ## this for us directly.
  89. tr ' ' '
  90. ' < "$tmpdepfile" |
  91. ## Some versions of gcc put a space before the `:'. On the theory
  92. ## that the space means something, we add a space to the output as
  93. ## well.
  94. ## Some versions of the HPUX 10.20 sed can't process this invocation
  95. ## correctly. Breaking it into two sed invocations is a workaround.
  96. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
  97. rm -f "$tmpdepfile"
  98. ;;
  99. hp)
  100. # This case exists only to let depend.m4 do its work. It works by
  101. # looking at the text of this script. This case will never be run,
  102. # since it is checked for above.
  103. exit 1
  104. ;;
  105. sgi)
  106. if test "$libtool" = yes; then
  107. "$@" "-Wp,-MDupdate,$tmpdepfile"
  108. else
  109. "$@" -MDupdate "$tmpdepfile"
  110. fi
  111. stat=$?
  112. if test $stat -eq 0; then :
  113. else
  114. rm -f "$tmpdepfile"
  115. exit $stat
  116. fi
  117. rm -f "$depfile"
  118. if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
  119. echo "$object : \\" > "$depfile"
  120. # Clip off the initial element (the dependent). Don't try to be
  121. # clever and replace this with sed code, as IRIX sed won't handle
  122. # lines with more than a fixed number of characters (4096 in
  123. # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
  124. # the IRIX cc adds comments like `#:fec' to the end of the
  125. # dependency line.
  126. tr ' ' '
  127. ' < "$tmpdepfile" \
  128. | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
  129. tr '
  130. ' ' ' >> $depfile
  131. echo >> $depfile
  132. # The second pass generates a dummy entry for each header file.
  133. tr ' ' '
  134. ' < "$tmpdepfile" \
  135. | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
  136. >> $depfile
  137. else
  138. # The sourcefile does not contain any dependencies, so just
  139. # store a dummy comment line, to avoid errors with the Makefile
  140. # "include basename.Plo" scheme.
  141. echo "#dummy" > "$depfile"
  142. fi
  143. rm -f "$tmpdepfile"
  144. ;;
  145. aix)
  146. # The C for AIX Compiler uses -M and outputs the dependencies
  147. # in a .u file. This file always lives in the current directory.
  148. # Also, the AIX compiler puts `$object:' at the start of each line;
  149. # $object doesn't have directory information.
  150. stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'`
  151. tmpdepfile="$stripped.u"
  152. outname="$stripped.o"
  153. if test "$libtool" = yes; then
  154. "$@" -Wc,-M
  155. else
  156. "$@" -M
  157. fi
  158. stat=$?
  159. if test $stat -eq 0; then :
  160. else
  161. rm -f "$tmpdepfile"
  162. exit $stat
  163. fi
  164. if test -f "$tmpdepfile"; then
  165. # Each line is of the form `foo.o: dependent.h'.
  166. # Do two passes, one to just change these to
  167. # `$object: dependent.h' and one to simply `dependent.h:'.
  168. sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
  169. sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
  170. else
  171. # The sourcefile does not contain any dependencies, so just
  172. # store a dummy comment line, to avoid errors with the Makefile
  173. # "include basename.Plo" scheme.
  174. echo "#dummy" > "$depfile"
  175. fi
  176. rm -f "$tmpdepfile"
  177. ;;
  178. tru64)
  179. # The Tru64 AIX compiler uses -MD to generate dependencies as a side
  180. # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
  181. # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
  182. # dependencies in `foo.d' instead, so we check for that too.
  183. # Subdirectories are respected.
  184. tmpdepfile1="$object.d"
  185. tmpdepfile2=`echo "$object" | sed -e 's/.o$/.d/'`
  186. if test "$libtool" = yes; then
  187. "$@" -Wc,-MD
  188. else
  189. "$@" -MD
  190. fi
  191. stat=$?
  192. if test $stat -eq 0; then :
  193. else
  194. rm -f "$tmpdepfile1" "$tmpdepfile2"
  195. exit $stat
  196. fi
  197. if test -f "$tmpdepfile1"; then
  198. tmpdepfile="$tmpdepfile1"
  199. else
  200. tmpdepfile="$tmpdepfile2"
  201. fi
  202. if test -f "$tmpdepfile"; then
  203. sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
  204. # That's a space and a tab in the [].
  205. sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
  206. else
  207. echo "#dummy" > "$depfile"
  208. fi
  209. rm -f "$tmpdepfile"
  210. ;;
  211. #nosideeffect)
  212. # This comment above is used by automake to tell side-effect
  213. # dependency tracking mechanisms from slower ones.
  214. dashmstdout)
  215. # Important note: in order to support this mode, a compiler *must*
  216. # always write the proprocessed file to stdout, regardless of -o,
  217. # because we must use -o when running libtool.
  218. test -z "$dashmflag" && dashmflag=-M
  219. ( IFS=" "
  220. case " $* " in
  221. *" --mode=compile "*) # this is libtool, let us make it quiet
  222. for arg
  223. do # cycle over the arguments
  224. case "$arg" in
  225. "--mode=compile")
  226. # insert --quiet before "--mode=compile"
  227. set fnord "$@" --quiet
  228. shift # fnord
  229. ;;
  230. esac
  231. set fnord "$@" "$arg"
  232. shift # fnord
  233. shift # "$arg"
  234. done
  235. ;;
  236. esac
  237. "$@" $dashmflag | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
  238. ) &
  239. proc=$!
  240. "$@"
  241. stat=$?
  242. wait "$proc"
  243. if test "$stat" != 0; then exit $stat; fi
  244. rm -f "$depfile"
  245. cat < "$tmpdepfile" > "$depfile"
  246. tr ' ' '
  247. ' < "$tmpdepfile" | \
  248. ## Some versions of the HPUX 10.20 sed can't process this invocation
  249. ## correctly. Breaking it into two sed invocations is a workaround.
  250. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
  251. rm -f "$tmpdepfile"
  252. ;;
  253. dashXmstdout)
  254. # This case only exists to satisfy depend.m4. It is never actually
  255. # run, as this mode is specially recognized in the preamble.
  256. exit 1
  257. ;;
  258. makedepend)
  259. # X makedepend
  260. (
  261. shift
  262. cleared=no
  263. for arg in "$@"; do
  264. case $cleared in no)
  265. set ""; shift
  266. cleared=yes
  267. esac
  268. case "$arg" in
  269. -D*|-I*)
  270. set fnord "$@" "$arg"; shift;;
  271. -*)
  272. ;;
  273. *)
  274. set fnord "$@" "$arg"; shift;;
  275. esac
  276. done
  277. obj_suffix="`echo $object | sed 's/^.*\././'`"
  278. touch "$tmpdepfile"
  279. ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@"
  280. ) &
  281. proc=$!
  282. "$@"
  283. stat=$?
  284. wait "$proc"
  285. if test "$stat" != 0; then exit $stat; fi
  286. rm -f "$depfile"
  287. cat < "$tmpdepfile" > "$depfile"
  288. tail +3 "$tmpdepfile" | tr ' ' '
  289. ' | \
  290. ## Some versions of the HPUX 10.20 sed can't process this invocation
  291. ## correctly. Breaking it into two sed invocations is a workaround.
  292. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
  293. rm -f "$tmpdepfile" "$tmpdepfile".bak
  294. ;;
  295. cpp)
  296. # Important note: in order to support this mode, a compiler *must*
  297. # always write the proprocessed file to stdout, regardless of -o,
  298. # because we must use -o when running libtool.
  299. ( IFS=" "
  300. case " $* " in
  301. *" --mode=compile "*)
  302. for arg
  303. do # cycle over the arguments
  304. case $arg in
  305. "--mode=compile")
  306. # insert --quiet before "--mode=compile"
  307. set fnord "$@" --quiet
  308. shift # fnord
  309. ;;
  310. esac
  311. set fnord "$@" "$arg"
  312. shift # fnord
  313. shift # "$arg"
  314. done
  315. ;;
  316. esac
  317. "$@" -E |
  318. sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
  319. sed '$ s: \\$::' > "$tmpdepfile"
  320. ) &
  321. proc=$!
  322. "$@"
  323. stat=$?
  324. wait "$proc"
  325. if test "$stat" != 0; then exit $stat; fi
  326. rm -f "$depfile"
  327. echo "$object : \\" > "$depfile"
  328. cat < "$tmpdepfile" >> "$depfile"
  329. sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
  330. rm -f "$tmpdepfile"
  331. ;;
  332. msvisualcpp)
  333. # Important note: in order to support this mode, a compiler *must*
  334. # always write the proprocessed file to stdout, regardless of -o,
  335. # because we must use -o when running libtool.
  336. ( IFS=" "
  337. case " $* " in
  338. *" --mode=compile "*)
  339. for arg
  340. do # cycle over the arguments
  341. case $arg in
  342. "--mode=compile")
  343. # insert --quiet before "--mode=compile"
  344. set fnord "$@" --quiet
  345. shift # fnord
  346. ;;
  347. esac
  348. set fnord "$@" "$arg"
  349. shift # fnord
  350. shift # "$arg"
  351. done
  352. ;;
  353. esac
  354. "$@" -E |
  355. sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
  356. ) &
  357. proc=$!
  358. "$@"
  359. stat=$?
  360. wait "$proc"
  361. if test "$stat" != 0; then exit $stat; fi
  362. rm -f "$depfile"
  363. echo "$object : \\" > "$depfile"
  364. . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
  365. echo " " >> "$depfile"
  366. . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
  367. rm -f "$tmpdepfile"
  368. ;;
  369. none)
  370. exec "$@"
  371. ;;
  372. *)
  373. echo "Unknown depmode $depmode" 1>&2
  374. exit 1
  375. ;;
  376. esac
  377. exit 0