depcomp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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. dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
  193. test "x$dir" = "x$object" && dir=
  194. base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
  195. if test "$libtool" = yes; then
  196. tmpdepfile1="$dir.libs/$base.lo.d"
  197. tmpdepfile2="$dir.libs/$base.d"
  198. "$@" -Wc,-MD
  199. else
  200. tmpdepfile1="$dir$base.o.d"
  201. tmpdepfile2="$dir$base.d"
  202. "$@" -MD
  203. fi
  204. stat=$?
  205. if test $stat -eq 0; then :
  206. else
  207. rm -f "$tmpdepfile1" "$tmpdepfile2"
  208. exit $stat
  209. fi
  210. if test -f "$tmpdepfile1"; then
  211. tmpdepfile="$tmpdepfile1"
  212. else
  213. tmpdepfile="$tmpdepfile2"
  214. fi
  215. if test -f "$tmpdepfile"; then
  216. sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
  217. # That's a space and a tab in the [].
  218. sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
  219. else
  220. echo "#dummy" > "$depfile"
  221. fi
  222. rm -f "$tmpdepfile"
  223. ;;
  224. #nosideeffect)
  225. # This comment above is used by automake to tell side-effect
  226. # dependency tracking mechanisms from slower ones.
  227. dashmstdout)
  228. # Important note: in order to support this mode, a compiler *must*
  229. # always write the proprocessed file to stdout, regardless of -o.
  230. "$@" || exit $?
  231. # Remove the call to Libtool.
  232. if test "$libtool" = yes; then
  233. while test $1 != '--mode=compile'; do
  234. shift
  235. done
  236. shift
  237. fi
  238. # Remove `-o $object'. We will use -o /dev/null later,
  239. # however we can't do the remplacement now because
  240. # `-o $object' might simply not be used
  241. IFS=" "
  242. for arg
  243. do
  244. case $arg in
  245. -o)
  246. shift
  247. ;;
  248. $object)
  249. shift
  250. ;;
  251. *)
  252. set fnord "$@" "$arg"
  253. shift # fnord
  254. shift # $arg
  255. ;;
  256. esac
  257. done
  258. test -z "$dashmflag" && dashmflag=-M
  259. "$@" -o /dev/null $dashmflag | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
  260. rm -f "$depfile"
  261. cat < "$tmpdepfile" > "$depfile"
  262. tr ' ' '
  263. ' < "$tmpdepfile" | \
  264. ## Some versions of the HPUX 10.20 sed can't process this invocation
  265. ## correctly. Breaking it into two sed invocations is a workaround.
  266. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
  267. rm -f "$tmpdepfile"
  268. ;;
  269. dashXmstdout)
  270. # This case only exists to satisfy depend.m4. It is never actually
  271. # run, as this mode is specially recognized in the preamble.
  272. exit 1
  273. ;;
  274. makedepend)
  275. "$@" || exit $?
  276. # X makedepend
  277. shift
  278. cleared=no
  279. for arg in "$@"; do
  280. case $cleared in
  281. no)
  282. set ""; shift
  283. cleared=yes ;;
  284. esac
  285. case "$arg" in
  286. -D*|-I*)
  287. set fnord "$@" "$arg"; shift ;;
  288. -*)
  289. ;;
  290. *)
  291. set fnord "$@" "$arg"; shift ;;
  292. esac
  293. done
  294. obj_suffix="`echo $object | sed 's/^.*\././'`"
  295. touch "$tmpdepfile"
  296. ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
  297. rm -f "$depfile"
  298. cat < "$tmpdepfile" > "$depfile"
  299. sed '1,2d' "$tmpdepfile" | tr ' ' '
  300. ' | \
  301. ## Some versions of the HPUX 10.20 sed can't process this invocation
  302. ## correctly. Breaking it into two sed invocations is a workaround.
  303. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
  304. rm -f "$tmpdepfile" "$tmpdepfile".bak
  305. ;;
  306. cpp)
  307. # Important note: in order to support this mode, a compiler *must*
  308. # always write the proprocessed file to stdout.
  309. "$@" || exit $?
  310. # Remove the call to Libtool.
  311. if test "$libtool" = yes; then
  312. while test $1 != '--mode=compile'; do
  313. shift
  314. done
  315. shift
  316. fi
  317. # Remove `-o $object'.
  318. IFS=" "
  319. for arg
  320. do
  321. case $arg in
  322. -o)
  323. shift
  324. ;;
  325. $object)
  326. shift
  327. ;;
  328. *)
  329. set fnord "$@" "$arg"
  330. shift # fnord
  331. shift # $arg
  332. ;;
  333. esac
  334. done
  335. "$@" -E |
  336. sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
  337. sed '$ s: \\$::' > "$tmpdepfile"
  338. rm -f "$depfile"
  339. echo "$object : \\" > "$depfile"
  340. cat < "$tmpdepfile" >> "$depfile"
  341. sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
  342. rm -f "$tmpdepfile"
  343. ;;
  344. msvisualcpp)
  345. # Important note: in order to support this mode, a compiler *must*
  346. # always write the proprocessed file to stdout, regardless of -o,
  347. # because we must use -o when running libtool.
  348. "$@" || exit $?
  349. IFS=" "
  350. for arg
  351. do
  352. case "$arg" in
  353. "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
  354. set fnord "$@"
  355. shift
  356. shift
  357. ;;
  358. *)
  359. set fnord "$@" "$arg"
  360. shift
  361. shift
  362. ;;
  363. esac
  364. done
  365. "$@" -E |
  366. sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
  367. rm -f "$depfile"
  368. echo "$object : \\" > "$depfile"
  369. . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
  370. echo " " >> "$depfile"
  371. . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
  372. rm -f "$tmpdepfile"
  373. ;;
  374. none)
  375. exec "$@"
  376. ;;
  377. *)
  378. echo "Unknown depmode $depmode" 1>&2
  379. exit 1
  380. ;;
  381. esac
  382. exit 0