depcomp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. #! /bin/sh
  2. # depcomp - compile a program generating dependencies as side-effects
  3. scriptversion=2013-05-30.07; # UTC
  4. # Copyright (C) 1999-2014 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, see <http://www.gnu.org/licenses/>.
  15. # As a special exception to the GNU General Public License, if you
  16. # distribute this file as part of a program that contains a
  17. # configuration script generated by Autoconf, you may include it under
  18. # the same distribution terms that you use for the rest of that program.
  19. # Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
  20. case $1 in
  21. '')
  22. echo "$0: No command. Try '$0 --help' for more information." 1>&2
  23. exit 1;
  24. ;;
  25. -h | --h*)
  26. cat <<\EOF
  27. Usage: depcomp [--help] [--version] PROGRAM [ARGS]
  28. Run PROGRAMS ARGS to compile a file, generating dependencies
  29. as side-effects.
  30. Environment variables:
  31. depmode Dependency tracking mode.
  32. source Source file read by 'PROGRAMS ARGS'.
  33. object Object file output by 'PROGRAMS ARGS'.
  34. DEPDIR directory where to store dependencies.
  35. depfile Dependency file to output.
  36. tmpdepfile Temporary file to use when outputting dependencies.
  37. libtool Whether libtool is used (yes/no).
  38. Report bugs to <bug-automake@gnu.org>.
  39. EOF
  40. exit $?
  41. ;;
  42. -v | --v*)
  43. echo "depcomp $scriptversion"
  44. exit $?
  45. ;;
  46. esac
  47. # Get the directory component of the given path, and save it in the
  48. # global variables '$dir'. Note that this directory component will
  49. # be either empty or ending with a '/' character. This is deliberate.
  50. set_dir_from ()
  51. {
  52. case $1 in
  53. */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
  54. *) dir=;;
  55. esac
  56. }
  57. # Get the suffix-stripped basename of the given path, and save it the
  58. # global variable '$base'.
  59. set_base_from ()
  60. {
  61. base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
  62. }
  63. # If no dependency file was actually created by the compiler invocation,
  64. # we still have to create a dummy depfile, to avoid errors with the
  65. # Makefile "include basename.Plo" scheme.
  66. make_dummy_depfile ()
  67. {
  68. echo "#dummy" > "$depfile"
  69. }
  70. # Factor out some common post-processing of the generated depfile.
  71. # Requires the auxiliary global variable '$tmpdepfile' to be set.
  72. aix_post_process_depfile ()
  73. {
  74. # If the compiler actually managed to produce a dependency file,
  75. # post-process it.
  76. if test -f "$tmpdepfile"; then
  77. # Each line is of the form 'foo.o: dependency.h'.
  78. # Do two passes, one to just change these to
  79. # $object: dependency.h
  80. # and one to simply output
  81. # dependency.h:
  82. # which is needed to avoid the deleted-header problem.
  83. { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
  84. sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
  85. } > "$depfile"
  86. rm -f "$tmpdepfile"
  87. else
  88. make_dummy_depfile
  89. fi
  90. }
  91. # A tabulation character.
  92. tab=' '
  93. # A newline character.
  94. nl='
  95. '
  96. # Character ranges might be problematic outside the C locale.
  97. # These definitions help.
  98. upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
  99. lower=abcdefghijklmnopqrstuvwxyz
  100. digits=0123456789
  101. alpha=${upper}${lower}
  102. if test -z "$depmode" || test -z "$source" || test -z "$object"; then
  103. echo "depcomp: Variables source, object and depmode must be set" 1>&2
  104. exit 1
  105. fi
  106. # Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
  107. depfile=${depfile-`echo "$object" |
  108. sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
  109. tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
  110. rm -f "$tmpdepfile"
  111. # Avoid interferences from the environment.
  112. gccflag= dashmflag=
  113. # Some modes work just like other modes, but use different flags. We
  114. # parameterize here, but still list the modes in the big case below,
  115. # to make depend.m4 easier to write. Note that we *cannot* use a case
  116. # here, because this file can only contain one case statement.
  117. if test "$depmode" = hp; then
  118. # HP compiler uses -M and no extra arg.
  119. gccflag=-M
  120. depmode=gcc
  121. fi
  122. if test "$depmode" = dashXmstdout; then
  123. # This is just like dashmstdout with a different argument.
  124. dashmflag=-xM
  125. depmode=dashmstdout
  126. fi
  127. cygpath_u="cygpath -u -f -"
  128. if test "$depmode" = msvcmsys; then
  129. # This is just like msvisualcpp but w/o cygpath translation.
  130. # Just convert the backslash-escaped backslashes to single forward
  131. # slashes to satisfy depend.m4
  132. cygpath_u='sed s,\\\\,/,g'
  133. depmode=msvisualcpp
  134. fi
  135. if test "$depmode" = msvc7msys; then
  136. # This is just like msvc7 but w/o cygpath translation.
  137. # Just convert the backslash-escaped backslashes to single forward
  138. # slashes to satisfy depend.m4
  139. cygpath_u='sed s,\\\\,/,g'
  140. depmode=msvc7
  141. fi
  142. if test "$depmode" = xlc; then
  143. # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
  144. gccflag=-qmakedep=gcc,-MF
  145. depmode=gcc
  146. fi
  147. case "$depmode" in
  148. gcc3)
  149. ## gcc 3 implements dependency tracking that does exactly what
  150. ## we want. Yay! Note: for some reason libtool 1.4 doesn't like
  151. ## it if -MD -MP comes after the -MF stuff. Hmm.
  152. ## Unfortunately, FreeBSD c89 acceptance of flags depends upon
  153. ## the command line argument order; so add the flags where they
  154. ## appear in depend2.am. Note that the slowdown incurred here
  155. ## affects only configure: in makefiles, %FASTDEP% shortcuts this.
  156. for arg
  157. do
  158. case $arg in
  159. -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
  160. *) set fnord "$@" "$arg" ;;
  161. esac
  162. shift # fnord
  163. shift # $arg
  164. done
  165. "$@"
  166. stat=$?
  167. if test $stat -ne 0; then
  168. rm -f "$tmpdepfile"
  169. exit $stat
  170. fi
  171. mv "$tmpdepfile" "$depfile"
  172. ;;
  173. clang)
  174. ## clang implements dependency tracking that does exactly what
  175. ## we want. Yay! Note: for some reason libtool 1.4 doesn't like
  176. ## it if -MD -MP comes after the -MF stuff. Hmm.
  177. ## Unfortunately, FreeBSD c89 acceptance of flags depends upon
  178. ## the command line argument order; so add the flags where they
  179. ## appear in depend2.am. Note that the slowdown incurred here
  180. ## affects only configure: in makefiles, %FASTDEP% shortcuts this.
  181. for arg
  182. do
  183. case $arg in
  184. -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
  185. -std*) set fnord "$@" ;;
  186. *) set fnord "$@" "$arg" ;;
  187. esac
  188. shift # fnord
  189. shift # $arg
  190. done
  191. "$@"
  192. stat=$?
  193. if test $stat -ne 0; then
  194. rm -f "$tmpdepfile"
  195. exit $stat
  196. fi
  197. mv "$tmpdepfile" "$depfile"
  198. ;;
  199. gcc)
  200. ## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
  201. ## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
  202. ## (see the conditional assignment to $gccflag above).
  203. ## There are various ways to get dependency output from gcc. Here's
  204. ## why we pick this rather obscure method:
  205. ## - Don't want to use -MD because we'd like the dependencies to end
  206. ## up in a subdir. Having to rename by hand is ugly.
  207. ## (We might end up doing this anyway to support other compilers.)
  208. ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
  209. ## -MM, not -M (despite what the docs say). Also, it might not be
  210. ## supported by the other compilers which use the 'gcc' depmode.
  211. ## - Using -M directly means running the compiler twice (even worse
  212. ## than renaming).
  213. if test -z "$gccflag"; then
  214. gccflag=-MD,
  215. fi
  216. "$@" -Wp,"$gccflag$tmpdepfile"
  217. stat=$?
  218. if test $stat -ne 0; then
  219. rm -f "$tmpdepfile"
  220. exit $stat
  221. fi
  222. rm -f "$depfile"
  223. echo "$object : \\" > "$depfile"
  224. # The second -e expression handles DOS-style file names with drive
  225. # letters.
  226. sed -e 's/^[^:]*: / /' \
  227. -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
  228. ## This next piece of magic avoids the "deleted header file" problem.
  229. ## The problem is that when a header file which appears in a .P file
  230. ## is deleted, the dependency causes make to die (because there is
  231. ## typically no way to rebuild the header). We avoid this by adding
  232. ## dummy dependencies for each header file. Too bad gcc doesn't do
  233. ## this for us directly.
  234. ## Some versions of gcc put a space before the ':'. On the theory
  235. ## that the space means something, we add a space to the output as
  236. ## well. hp depmode also adds that space, but also prefixes the VPATH
  237. ## to the object. Take care to not repeat it in the output.
  238. ## Some versions of the HPUX 10.20 sed can't process this invocation
  239. ## correctly. Breaking it into two sed invocations is a workaround.
  240. tr ' ' "$nl" < "$tmpdepfile" \
  241. | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
  242. | sed -e 's/$/ :/' >> "$depfile"
  243. rm -f "$tmpdepfile"
  244. ;;
  245. hp)
  246. # This case exists only to let depend.m4 do its work. It works by
  247. # looking at the text of this script. This case will never be run,
  248. # since it is checked for above.
  249. exit 1
  250. ;;
  251. sgi)
  252. if test "$libtool" = yes; then
  253. "$@" "-Wp,-MDupdate,$tmpdepfile"
  254. else
  255. "$@" -MDupdate "$tmpdepfile"
  256. fi
  257. stat=$?
  258. if test $stat -ne 0; then
  259. rm -f "$tmpdepfile"
  260. exit $stat
  261. fi
  262. rm -f "$depfile"
  263. if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
  264. echo "$object : \\" > "$depfile"
  265. # Clip off the initial element (the dependent). Don't try to be
  266. # clever and replace this with sed code, as IRIX sed won't handle
  267. # lines with more than a fixed number of characters (4096 in
  268. # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
  269. # the IRIX cc adds comments like '#:fec' to the end of the
  270. # dependency line.
  271. tr ' ' "$nl" < "$tmpdepfile" \
  272. | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
  273. | tr "$nl" ' ' >> "$depfile"
  274. echo >> "$depfile"
  275. # The second pass generates a dummy entry for each header file.
  276. tr ' ' "$nl" < "$tmpdepfile" \
  277. | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
  278. >> "$depfile"
  279. else
  280. make_dummy_depfile
  281. fi
  282. rm -f "$tmpdepfile"
  283. ;;
  284. xlc)
  285. # This case exists only to let depend.m4 do its work. It works by
  286. # looking at the text of this script. This case will never be run,
  287. # since it is checked for above.
  288. exit 1
  289. ;;
  290. aix)
  291. # The C for AIX Compiler uses -M and outputs the dependencies
  292. # in a .u file. In older versions, this file always lives in the
  293. # current directory. Also, the AIX compiler puts '$object:' at the
  294. # start of each line; $object doesn't have directory information.
  295. # Version 6 uses the directory in both cases.
  296. set_dir_from "$object"
  297. set_base_from "$object"
  298. if test "$libtool" = yes; then
  299. tmpdepfile1=$dir$base.u
  300. tmpdepfile2=$base.u
  301. tmpdepfile3=$dir.libs/$base.u
  302. "$@" -Wc,-M
  303. else
  304. tmpdepfile1=$dir$base.u
  305. tmpdepfile2=$dir$base.u
  306. tmpdepfile3=$dir$base.u
  307. "$@" -M
  308. fi
  309. stat=$?
  310. if test $stat -ne 0; then
  311. rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
  312. exit $stat
  313. fi
  314. for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
  315. do
  316. test -f "$tmpdepfile" && break
  317. done
  318. aix_post_process_depfile
  319. ;;
  320. tcc)
  321. # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
  322. # FIXME: That version still under development at the moment of writing.
  323. # Make that this statement remains true also for stable, released
  324. # versions.
  325. # It will wrap lines (doesn't matter whether long or short) with a
  326. # trailing '\', as in:
  327. #
  328. # foo.o : \
  329. # foo.c \
  330. # foo.h \
  331. #
  332. # It will put a trailing '\' even on the last line, and will use leading
  333. # spaces rather than leading tabs (at least since its commit 0394caf7
  334. # "Emit spaces for -MD").
  335. "$@" -MD -MF "$tmpdepfile"
  336. stat=$?
  337. if test $stat -ne 0; then
  338. rm -f "$tmpdepfile"
  339. exit $stat
  340. fi
  341. rm -f "$depfile"
  342. # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
  343. # We have to change lines of the first kind to '$object: \'.
  344. sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
  345. # And for each line of the second kind, we have to emit a 'dep.h:'
  346. # dummy dependency, to avoid the deleted-header problem.
  347. sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
  348. rm -f "$tmpdepfile"
  349. ;;
  350. ## The order of this option in the case statement is important, since the
  351. ## shell code in configure will try each of these formats in the order
  352. ## listed in this file. A plain '-MD' option would be understood by many
  353. ## compilers, so we must ensure this comes after the gcc and icc options.
  354. pgcc)
  355. # Portland's C compiler understands '-MD'.
  356. # Will always output deps to 'file.d' where file is the root name of the
  357. # source file under compilation, even if file resides in a subdirectory.
  358. # The object file name does not affect the name of the '.d' file.
  359. # pgcc 10.2 will output
  360. # foo.o: sub/foo.c sub/foo.h
  361. # and will wrap long lines using '\' :
  362. # foo.o: sub/foo.c ... \
  363. # sub/foo.h ... \
  364. # ...
  365. set_dir_from "$object"
  366. # Use the source, not the object, to determine the base name, since
  367. # that's sadly what pgcc will do too.
  368. set_base_from "$source"
  369. tmpdepfile=$base.d
  370. # For projects that build the same source file twice into different object
  371. # files, the pgcc approach of using the *source* file root name can cause
  372. # problems in parallel builds. Use a locking strategy to avoid stomping on
  373. # the same $tmpdepfile.
  374. lockdir=$base.d-lock
  375. trap "
  376. echo '$0: caught signal, cleaning up...' >&2
  377. rmdir '$lockdir'
  378. exit 1
  379. " 1 2 13 15
  380. numtries=100
  381. i=$numtries
  382. while test $i -gt 0; do
  383. # mkdir is a portable test-and-set.
  384. if mkdir "$lockdir" 2>/dev/null; then
  385. # This process acquired the lock.
  386. "$@" -MD
  387. stat=$?
  388. # Release the lock.
  389. rmdir "$lockdir"
  390. break
  391. else
  392. # If the lock is being held by a different process, wait
  393. # until the winning process is done or we timeout.
  394. while test -d "$lockdir" && test $i -gt 0; do
  395. sleep 1
  396. i=`expr $i - 1`
  397. done
  398. fi
  399. i=`expr $i - 1`
  400. done
  401. trap - 1 2 13 15
  402. if test $i -le 0; then
  403. echo "$0: failed to acquire lock after $numtries attempts" >&2
  404. echo "$0: check lockdir '$lockdir'" >&2
  405. exit 1
  406. fi
  407. if test $stat -ne 0; then
  408. rm -f "$tmpdepfile"
  409. exit $stat
  410. fi
  411. rm -f "$depfile"
  412. # Each line is of the form `foo.o: dependent.h',
  413. # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
  414. # Do two passes, one to just change these to
  415. # `$object: dependent.h' and one to simply `dependent.h:'.
  416. sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
  417. # Some versions of the HPUX 10.20 sed can't process this invocation
  418. # correctly. Breaking it into two sed invocations is a workaround.
  419. sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
  420. | sed -e 's/$/ :/' >> "$depfile"
  421. rm -f "$tmpdepfile"
  422. ;;
  423. hp2)
  424. # The "hp" stanza above does not work with aCC (C++) and HP's ia64
  425. # compilers, which have integrated preprocessors. The correct option
  426. # to use with these is +Maked; it writes dependencies to a file named
  427. # 'foo.d', which lands next to the object file, wherever that
  428. # happens to be.
  429. # Much of this is similar to the tru64 case; see comments there.
  430. set_dir_from "$object"
  431. set_base_from "$object"
  432. if test "$libtool" = yes; then
  433. tmpdepfile1=$dir$base.d
  434. tmpdepfile2=$dir.libs/$base.d
  435. "$@" -Wc,+Maked
  436. else
  437. tmpdepfile1=$dir$base.d
  438. tmpdepfile2=$dir$base.d
  439. "$@" +Maked
  440. fi
  441. stat=$?
  442. if test $stat -ne 0; then
  443. rm -f "$tmpdepfile1" "$tmpdepfile2"
  444. exit $stat
  445. fi
  446. for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
  447. do
  448. test -f "$tmpdepfile" && break
  449. done
  450. if test -f "$tmpdepfile"; then
  451. sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
  452. # Add 'dependent.h:' lines.
  453. sed -ne '2,${
  454. s/^ *//
  455. s/ \\*$//
  456. s/$/:/
  457. p
  458. }' "$tmpdepfile" >> "$depfile"
  459. else
  460. make_dummy_depfile
  461. fi
  462. rm -f "$tmpdepfile" "$tmpdepfile2"
  463. ;;
  464. tru64)
  465. # The Tru64 compiler uses -MD to generate dependencies as a side
  466. # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
  467. # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
  468. # dependencies in 'foo.d' instead, so we check for that too.
  469. # Subdirectories are respected.
  470. set_dir_from "$object"
  471. set_base_from "$object"
  472. if test "$libtool" = yes; then
  473. # Libtool generates 2 separate objects for the 2 libraries. These
  474. # two compilations output dependencies in $dir.libs/$base.o.d and
  475. # in $dir$base.o.d. We have to check for both files, because
  476. # one of the two compilations can be disabled. We should prefer
  477. # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
  478. # automatically cleaned when .libs/ is deleted, while ignoring
  479. # the former would cause a distcleancheck panic.
  480. tmpdepfile1=$dir$base.o.d # libtool 1.5
  481. tmpdepfile2=$dir.libs/$base.o.d # Likewise.
  482. tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504
  483. "$@" -Wc,-MD
  484. else
  485. tmpdepfile1=$dir$base.d
  486. tmpdepfile2=$dir$base.d
  487. tmpdepfile3=$dir$base.d
  488. "$@" -MD
  489. fi
  490. stat=$?
  491. if test $stat -ne 0; then
  492. rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
  493. exit $stat
  494. fi
  495. for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
  496. do
  497. test -f "$tmpdepfile" && break
  498. done
  499. # Same post-processing that is required for AIX mode.
  500. aix_post_process_depfile
  501. ;;
  502. msvc7)
  503. if test "$libtool" = yes; then
  504. showIncludes=-Wc,-showIncludes
  505. else
  506. showIncludes=-showIncludes
  507. fi
  508. "$@" $showIncludes > "$tmpdepfile"
  509. stat=$?
  510. grep -v '^Note: including file: ' "$tmpdepfile"
  511. if test $stat -ne 0; then
  512. rm -f "$tmpdepfile"
  513. exit $stat
  514. fi
  515. rm -f "$depfile"
  516. echo "$object : \\" > "$depfile"
  517. # The first sed program below extracts the file names and escapes
  518. # backslashes for cygpath. The second sed program outputs the file
  519. # name when reading, but also accumulates all include files in the
  520. # hold buffer in order to output them again at the end. This only
  521. # works with sed implementations that can handle large buffers.
  522. sed < "$tmpdepfile" -n '
  523. /^Note: including file: *\(.*\)/ {
  524. s//\1/
  525. s/\\/\\\\/g
  526. p
  527. }' | $cygpath_u | sort -u | sed -n '
  528. s/ /\\ /g
  529. s/\(.*\)/'"$tab"'\1 \\/p
  530. s/.\(.*\) \\/\1:/
  531. H
  532. $ {
  533. s/.*/'"$tab"'/
  534. G
  535. p
  536. }' >> "$depfile"
  537. echo >> "$depfile" # make sure the fragment doesn't end with a backslash
  538. rm -f "$tmpdepfile"
  539. ;;
  540. msvc7msys)
  541. # This case exists only to let depend.m4 do its work. It works by
  542. # looking at the text of this script. This case will never be run,
  543. # since it is checked for above.
  544. exit 1
  545. ;;
  546. #nosideeffect)
  547. # This comment above is used by automake to tell side-effect
  548. # dependency tracking mechanisms from slower ones.
  549. dashmstdout)
  550. # Important note: in order to support this mode, a compiler *must*
  551. # always write the preprocessed file to stdout, regardless of -o.
  552. "$@" || exit $?
  553. # Remove the call to Libtool.
  554. if test "$libtool" = yes; then
  555. while test "X$1" != 'X--mode=compile'; do
  556. shift
  557. done
  558. shift
  559. fi
  560. # Remove '-o $object'.
  561. IFS=" "
  562. for arg
  563. do
  564. case $arg in
  565. -o)
  566. shift
  567. ;;
  568. $object)
  569. shift
  570. ;;
  571. *)
  572. set fnord "$@" "$arg"
  573. shift # fnord
  574. shift # $arg
  575. ;;
  576. esac
  577. done
  578. test -z "$dashmflag" && dashmflag=-M
  579. # Require at least two characters before searching for ':'
  580. # in the target name. This is to cope with DOS-style filenames:
  581. # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
  582. "$@" $dashmflag |
  583. sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
  584. rm -f "$depfile"
  585. cat < "$tmpdepfile" > "$depfile"
  586. # Some versions of the HPUX 10.20 sed can't process this sed invocation
  587. # correctly. Breaking it into two sed invocations is a workaround.
  588. tr ' ' "$nl" < "$tmpdepfile" \
  589. | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
  590. | sed -e 's/$/ :/' >> "$depfile"
  591. rm -f "$tmpdepfile"
  592. ;;
  593. dashXmstdout)
  594. # This case only exists to satisfy depend.m4. It is never actually
  595. # run, as this mode is specially recognized in the preamble.
  596. exit 1
  597. ;;
  598. makedepend)
  599. "$@" || exit $?
  600. # Remove any Libtool call
  601. if test "$libtool" = yes; then
  602. while test "X$1" != 'X--mode=compile'; do
  603. shift
  604. done
  605. shift
  606. fi
  607. # X makedepend
  608. shift
  609. cleared=no eat=no
  610. for arg
  611. do
  612. case $cleared in
  613. no)
  614. set ""; shift
  615. cleared=yes ;;
  616. esac
  617. if test $eat = yes; then
  618. eat=no
  619. continue
  620. fi
  621. case "$arg" in
  622. -D*|-I*)
  623. set fnord "$@" "$arg"; shift ;;
  624. # Strip any option that makedepend may not understand. Remove
  625. # the object too, otherwise makedepend will parse it as a source file.
  626. -arch)
  627. eat=yes ;;
  628. -*|$object)
  629. ;;
  630. *)
  631. set fnord "$@" "$arg"; shift ;;
  632. esac
  633. done
  634. obj_suffix=`echo "$object" | sed 's/^.*\././'`
  635. touch "$tmpdepfile"
  636. ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
  637. rm -f "$depfile"
  638. # makedepend may prepend the VPATH from the source file name to the object.
  639. # No need to regex-escape $object, excess matching of '.' is harmless.
  640. sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
  641. # Some versions of the HPUX 10.20 sed can't process the last invocation
  642. # correctly. Breaking it into two sed invocations is a workaround.
  643. sed '1,2d' "$tmpdepfile" \
  644. | tr ' ' "$nl" \
  645. | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
  646. | sed -e 's/$/ :/' >> "$depfile"
  647. rm -f "$tmpdepfile" "$tmpdepfile".bak
  648. ;;
  649. cpp)
  650. # Important note: in order to support this mode, a compiler *must*
  651. # always write the preprocessed file to stdout.
  652. "$@" || exit $?
  653. # Remove the call to Libtool.
  654. if test "$libtool" = yes; then
  655. while test "X$1" != 'X--mode=compile'; do
  656. shift
  657. done
  658. shift
  659. fi
  660. # Remove '-o $object'.
  661. IFS=" "
  662. for arg
  663. do
  664. case $arg in
  665. -o)
  666. shift
  667. ;;
  668. $object)
  669. shift
  670. ;;
  671. *)
  672. set fnord "$@" "$arg"
  673. shift # fnord
  674. shift # $arg
  675. ;;
  676. esac
  677. done
  678. "$@" -E \
  679. | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
  680. -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
  681. | sed '$ s: \\$::' > "$tmpdepfile"
  682. rm -f "$depfile"
  683. echo "$object : \\" > "$depfile"
  684. cat < "$tmpdepfile" >> "$depfile"
  685. sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
  686. rm -f "$tmpdepfile"
  687. ;;
  688. msvisualcpp)
  689. # Important note: in order to support this mode, a compiler *must*
  690. # always write the preprocessed file to stdout.
  691. "$@" || exit $?
  692. # Remove the call to Libtool.
  693. if test "$libtool" = yes; then
  694. while test "X$1" != 'X--mode=compile'; do
  695. shift
  696. done
  697. shift
  698. fi
  699. IFS=" "
  700. for arg
  701. do
  702. case "$arg" in
  703. -o)
  704. shift
  705. ;;
  706. $object)
  707. shift
  708. ;;
  709. "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
  710. set fnord "$@"
  711. shift
  712. shift
  713. ;;
  714. *)
  715. set fnord "$@" "$arg"
  716. shift
  717. shift
  718. ;;
  719. esac
  720. done
  721. "$@" -E 2>/dev/null |
  722. sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
  723. rm -f "$depfile"
  724. echo "$object : \\" > "$depfile"
  725. sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
  726. echo "$tab" >> "$depfile"
  727. sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
  728. rm -f "$tmpdepfile"
  729. ;;
  730. msvcmsys)
  731. # This case exists only to let depend.m4 do its work. It works by
  732. # looking at the text of this script. This case will never be run,
  733. # since it is checked for above.
  734. exit 1
  735. ;;
  736. none)
  737. exec "$@"
  738. ;;
  739. *)
  740. echo "Unknown depmode $depmode" 1>&2
  741. exit 1
  742. ;;
  743. esac
  744. exit 0
  745. # Local Variables:
  746. # mode: shell-script
  747. # sh-indentation: 2
  748. # eval: (add-hook 'write-file-hooks 'time-stamp)
  749. # time-stamp-start: "scriptversion="
  750. # time-stamp-format: "%:y-%02m-%02d.%02H"
  751. # time-stamp-time-zone: "UTC"
  752. # time-stamp-end: "; # UTC"
  753. # End: