makedepend-sh 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. #!/bin/sh
  2. #
  3. # Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
  4. # All rights reserved.
  5. #
  6. # This code is derived from software contributed to The NetBSD Foundation
  7. # by Lonhyn T. Jasinskyj.
  8. #
  9. # Redistribution and use in source and binary forms, with or without
  10. # modification, are permitted provided that the following conditions
  11. # are met:
  12. # 1. Redistributions of source code must retain the above copyright
  13. # notice, this list of conditions and the following disclaimer.
  14. # 2. Redistributions in binary form must reproduce the above copyright
  15. # notice, this list of conditions and the following disclaimer in the
  16. # documentation and/or other materials provided with the distribution.
  17. # 3. All advertising materials mentioning features or use of this software
  18. # must display the following acknowledgement:
  19. # This product includes software developed by the NetBSD
  20. # Foundation, Inc. and its contributors.
  21. # 4. Neither the name of The NetBSD Foundation nor the names of its
  22. # contributors may be used to endorse or promote products derived
  23. # from this software without specific prior written permission.
  24. #
  25. # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  26. # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  27. # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28. # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  29. # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33. # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. # POSSIBILITY OF SUCH DAMAGE.
  36. #
  37. #
  38. # This is a shell script that behaves rather like the makedepend(1)
  39. # that comes with X11 except that it also understands VPATH
  40. #
  41. # makedepend-sh takes three sets of arguments. It parse the line of
  42. # arguments left to right and until it encounters a '--' it
  43. # applies command line switches to itself. After the first '--' all
  44. # args are accumulated and will be used as arguments to a C preprocessor
  45. # (such as cc -E). All arguments after the second '--' are filenames,
  46. # usually object files. More formally:
  47. #
  48. # makedepend [-a] [-s varname] [-v] [-f file] [-p preprocessor] [-V pathlist]
  49. # [-e scriptfile] [-m mrulesfile [-x excludeobjs]] --
  50. # [preprocessor args] -- file1 [file2 [...]]
  51. #
  52. # Flags:
  53. #
  54. # -a
  55. # append to the end of the output file (usually Makefile) instead
  56. # of replacing anything following a marker that looks like:
  57. # "# DO NOT DELETE THIS LINE -- makedepend-sh depends on it"
  58. # Appending is generally not the desired behavior but may be
  59. # useful if makedepend needs multiple, different invocations.
  60. #
  61. # -s varname
  62. # generate a 'varname = filenames...' line in the output that is
  63. # derived from the files given to makedepend. In this way a list
  64. # of object files can be given and they will be searched for
  65. # (possibly in a VPATH) and then their full pathnames will be
  66. # given computed and accumulated in a 'varname=' line. Thus, in a
  67. # Makefile the writer need only write 'OBJS=' (and possibly
  68. # give a VPATH if the source and object trees are seperate) and
  69. # makedepend will do the rest. It is often useful to choose
  70. # varname as "SRCS" or "CSRCS". Only C files are candidates
  71. # for inclusion in the source list.
  72. #
  73. # -v
  74. # be verbose, can be repeated for more verbosity.
  75. #
  76. # -f file
  77. # instead of using Makefile, write to this file
  78. #
  79. # -m mrulesfile
  80. # a file in the style of a Makefile containing suffix rules
  81. # with transformations. Since stock make is incapable of
  82. # applying a transformation rule if both files are not
  83. # in the local directory, a specific rules has to be generated
  84. # by makedepend in this case. If the -m flag is given the
  85. # appropriate suffix rule will be extracted and an explicit
  86. # command will be generated.
  87. #
  88. # -x excludeobjs
  89. # if the -m flag is given then this should contain a list
  90. # of objects that should not have a rule generated for them.
  91. #
  92. # -i ignorefiles
  93. # these files will simply be ignored, this is useful if you
  94. # give makedepend a list of files to process but not all of
  95. # the files exist yet.
  96. #
  97. # -p preprocessor
  98. # the command to invoke the preprocessor if 'cc -E' is not
  99. # appropriate. Normally one should quote this (e.g. -p "gcc -E")
  100. #
  101. # -V pathlist
  102. # the path is a colon-seperated list of paths that will be searched
  103. # for the source file. Normally only '.' is searched.
  104. #
  105. # -e scriptfile
  106. # the regular expression is treated as the path of an arbitrary
  107. # sed program that will be applied to the list of dependencies.
  108. # This will happen after all of the dependencies are composed
  109. # but before they are appended or any effects of the -s flag
  110. # are added. This is useful for excluding files in "/usr/include"
  111. # and "gcc-lib".
  112. #
  113. # -c cksumfile
  114. # compute a checksum (using "cksum") of this file. If a
  115. # file called .dep_cksum exists in the local directory then
  116. # also compare the new cksum output with the contents of that
  117. # file. If they are the same and a file called .depends also
  118. # exists locally then one need not redo the makedepend
  119. # dependency processing and can instead take .depends and
  120. # either append it to the Makefile or replace the previous
  121. # dependencies (as appropriate depending on the -a flag)
  122. # Finally, if new dependencies are generated, place a copy in
  123. # the file given as cksumfile.
  124. #
  125. # --
  126. #
  127. # -preprocessor_args
  128. # whatever arguments appear in this section get passed on to the
  129. # pre-processor.
  130. #
  131. # --
  132. #
  133. # file1 [file2 [...]]
  134. # the filenames given to makedepend. These are often object files
  135. # whose names will first be transformed to source files by
  136. # replacing final '.o' with '.c'. These will then be sought in
  137. # either '.' or a list of paths given with the -V flag.
  138. #
  139. #
  140. # Output:
  141. #
  142. # For each file listed makedepend will output:
  143. #
  144. # 1. if the file was an object file, then a line like
  145. # file.o: dirname/file.c
  146. #
  147. # 2. multiple lines of the form:
  148. # dirname/file.c: inc1.h inc2.h
  149. # dirname/file.c: inc3.h inc4.h
  150. # etc.
  151. #
  152. # 3. if the -s flag was given, then a set of lines like
  153. # SRCS = \
  154. # dirname/file1.c \
  155. # dirname/file2.c \
  156. # etc.
  157. #
  158. # 4. if the -m flag is give then for each source file that is
  159. # not in the local directory, an explicit rule will be
  160. # generated. The actions will be derived from a parsed
  161. # makefile-style file.
  162. #
  163. P=`basename $0`; export P
  164. CPP="cc -E"
  165. MARKER="# DO NOT DELETE THIS LINE -- makedepend-sh depends on it"
  166. CKSUM=cksum
  167. CKSUM_STORE=.dep_cksum
  168. DEPEND_STORE=.depends
  169. init_mode() {
  170. mode="md_args";
  171. }
  172. incr_mode() {
  173. if [ "$mode" = "md_args" ] ; then
  174. mode="cc_args";
  175. else
  176. if [ "$mode" = "cc_args" ] ; then
  177. mode="fn_args";
  178. fi
  179. fi
  180. }
  181. append_arg() {
  182. case "$mode" in
  183. md_*) arg_md="$arg_md $1" ;;
  184. cc_*) arg_cc="$arg_cc $1" ;;
  185. fn_*) arg_fn="$arg_fn $1" ;;
  186. esac
  187. }
  188. append_srcs() {
  189. append_to="$1"
  190. srcs_file="$2"
  191. #
  192. # since there is no way to echo a backslash reliably
  193. # with builtin echo or /bin/echo (not knowing their pedigree)
  194. # echo must be avoided for output. Use printf or, in this case, awk.
  195. #
  196. cat $srcs_file | \
  197. awk 'BEGIN { printf("\n#\n# '$mksrcs' generated by makedepend\n#\n'$mksrcs' = ")} \
  198. {} { for (i = 1; i <= NF; i++) { printf("\\\n %s ", $i) }} \
  199. END { printf("\n\n") }' >> $append_to
  200. }
  201. append_rules() {
  202. append_to="$1"
  203. rules_in="$2"
  204. ( \
  205. echo; echo '#'; \
  206. echo '# generated rules for source files that are not local'; \
  207. echo '# to this directory.'; \
  208. echo '#'; \
  209. cat $rules_in; \
  210. echo; echo; echo) >> $append_to
  211. }
  212. generate_awk() {
  213. cat > $1 <<!
  214. #
  215. # this old-style awk script will read a makefile where suffix
  216. # rules are being defined and generate a shell script defining
  217. # each rule as a variable. Thus a rule such as ".c.o:" would
  218. # be transformed such that after evaluating the resulting
  219. # piece of Bourne shell code the variable "mkrule__c_o" will
  220. # be set to the action for that suffix. As is obvious, the
  221. # escaping mechanism is very primitive and will not do well
  222. # for many characters encountered in suffix rules. However, it
  223. # is sufficient for disambiguating all the common suffixes
  224. # and is good enough.
  225. #
  226. # Note that what defines a field depends on the implementation. As
  227. # an example, under HP-UX 10.x a trailing field separator with
  228. # nothing after it gives an NF that is one less than all of
  229. # the other awks that I have seen.
  230. #
  231. BEGIN { FS=":" }
  232. \$1 ~ /^\.[a-zA-Z]+\.[a-zA-Z]+$/ {
  233. # if we have not seen this suffix rule before record it and
  234. # go into rule collecting mode
  235. if (exists[\$1] == 0) {
  236. exists[\$1] = 1
  237. names[\$1] = \$1
  238. cur_suf = \$1 # the current suffix to collect into
  239. suff_list=suff_list " " cur_suf
  240. collect = 1
  241. } else {
  242. collect = 0
  243. }
  244. next
  245. }
  246. /^[\t#].*/ {
  247. if (collect) {
  248. # remove the initial tab and put a \t there instead
  249. action[cur_suf]=action[cur_suf] "\t" substr(\$0,2) "\\\n"
  250. }
  251. next
  252. }
  253. /.*/ {
  254. # collection stops when we encounter the first
  255. # line that does not begin with a TAB or '#' sign
  256. collect = 0
  257. }
  258. END {
  259. # when done print out the shell code
  260. for (n in names) {
  261. printf("mkrule_");
  262. for (j = 1; j <= length(n); j++) {
  263. c = substr(n,j,1)
  264. if (c ~ /[a-zA-Z0-9]/) {
  265. printf("%s", c)
  266. } else {
  267. # replace all wierd characters with underscores
  268. printf("_")
  269. }
  270. }
  271. print "='" action[n] "'"
  272. }
  273. #
  274. # turn a string that looks like ".c.o .c .l.o .y.o" into
  275. # an array that contains the suffixes and then print
  276. # that array into a single varibale where each suffix
  277. # appears once
  278. #
  279. len = length(suff_list)
  280. for (j = 1; j <= len; j++) {
  281. #
  282. # if the character is not a seperator, accumulate it into the
  283. # current suffix, if it is, record the previously accumulated suffix
  284. #
  285. c = substr(suff_list,j,1)
  286. if (c ~ /[ .]/) {
  287. if (sfx !~ /^$/) {
  288. sfxs[sfx] = sfx
  289. sfx = ""
  290. }
  291. } else {
  292. sfx = sfx c
  293. }
  294. }
  295. # print out the line that will set the shell variable
  296. printf("mksuffixes='")
  297. first = 1
  298. for (s in sfxs) {
  299. if (first == 1) { printf("%s", s); first = 0 } else { printf(" %s", s) }
  300. }
  301. printf("'\n")
  302. }
  303. !
  304. } # end of generate_awk()
  305. #
  306. # if the mrules flag was given, go and generate and awk script,
  307. # run it on the file containing the make rules, and then set
  308. # shell variables containing make rules
  309. #
  310. eval_mrules()
  311. {
  312. mrulefile=$1
  313. eval `mktemp awkscr`
  314. eval `mktemp mkrule_scr`
  315. generate_awk $awkscr
  316. awk -f $awkscr < $mrulefile > $mkrule_scr
  317. . $mkrule_scr
  318. if test "$verbose" -gt 1; then
  319. (echo "make rules are:"; echo "==============="; \
  320. cat $mkrule_scr; echo "===============") | sed -e "s/^/$P: /"
  321. fi
  322. }
  323. #
  324. # exists_rule(): true if a rule exists for this src and product suffix
  325. #
  326. exists_rule()
  327. {
  328. # src and product suffixes
  329. s_sfx=$1
  330. p_sfx=$1
  331. rulename=\$mkrule__${s_sfx}_${prod_sfx}
  332. test -n "`eval echo $rulename`" && return 0
  333. return 1
  334. }
  335. #
  336. # called with a var name as an arg this will produce a line of
  337. # shell code to be evaluated. Thus to set the variable FOO to
  338. # the name of the next available temp file use
  339. # eval `mktemp FOO`
  340. # This is necessary to get the auto-increment of tmp_id since
  341. # things in single quotes are normally run in sub-shells
  342. #
  343. mktemp()
  344. {
  345. export tmp_id
  346. tmp_id=`expr ${tmp_id:-0} + 1`
  347. name=/tmp/mkdep.$$.${tmp_id}
  348. echo "$1=$name; tmp_id=$tmp_id"
  349. }
  350. #
  351. # explicit_rule():
  352. # this will take arguments with information about the source
  353. # file and the product to be generated. It then decides whether
  354. # an explicit rule needs to be made and if so adds it to a file
  355. # which can then be tacked onto the make file later.
  356. #
  357. explicit_rule()
  358. {
  359. src="$1"
  360. obj="$2"
  361. srcdir="$3"
  362. rulefile="$4"
  363. excludes="$5"
  364. test "$srcdir" = '.' && return
  365. src_suffix=`echo $src | sed -n -e 's/.*\.\([^.][^.]*\)$/\1/p'`
  366. obj_suffix=`echo $obj | sed -n -e 's/.*\.\([^.][^.]*\)$/\1/p'`
  367. # figure out the name of the variable where the action is stored
  368. rulename=\$mkrule__${src_suffix}_${obj_suffix}
  369. #
  370. # go and see if this object is one of the excluded objects, if
  371. # so, bag this phase
  372. #
  373. for x in $excludes; do
  374. test "$x" = "$obj" && {
  375. test "$verbose" -gt 1 && \
  376. echo $P: skipping explicit rule for: $obj; \
  377. return; \
  378. }
  379. done
  380. #
  381. # generate the explicit rule and add it to the rulefile if we
  382. # have a suffix transformation
  383. #
  384. if test -n "`eval echo $rulename`"; then
  385. echo ${obj}: ${srcdir}/${src} >> $rulefile
  386. #
  387. # use POSIX printf to get the newlines right, must use double quotes.
  388. # also replace all occurences of '$<' with the name of the
  389. # source file since '$<' is only appropriate in inference
  390. # rules and '$?' is not a correct substitute when the target
  391. # depends on multiple files, including .h files.
  392. #
  393. eval printf \"$rulename\" | \
  394. sed -e "s;\$<;$srcdir/$src;g" >> $rulefile
  395. fi
  396. }
  397. in_list_p()
  398. {
  399. f="$1"
  400. ignores="$2"
  401. for x in $ignores; do
  402. test "$x" = "$f" && return 0
  403. done
  404. return 1
  405. }
  406. #
  407. # see if we already have a file of dependencies and see if it is
  408. # usable (i.e. the cksum on the cksumfile is still the same)
  409. #
  410. have_usable_depends()
  411. {
  412. ckmatchfile="$1"
  413. if test -n "$ckmatchfile" -a -s "$CKSUM_STORE" -a -f "$DEPEND_STORE"; then
  414. $CKSUM $ckmatchfile > $CKS 2> /dev/null && \
  415. diff "$CKSUM_STORE" "$CKS" > /dev/null 2>&1 || \
  416. return 1 # no usable dependencies prestored
  417. test "$verbose" -gt 0 && echo $P: using dependencies from previous run
  418. return 0
  419. fi
  420. # return FALSE
  421. return 1
  422. }
  423. #
  424. # maybe_store_depends:
  425. # we should squirrel away the dependencies that have been generated
  426. # if the user has specified a -c flag on the command line (i.e. a
  427. # file to checksum against). If that is the case then store the
  428. # dependencies in DEPEND_STORE and calculate a new checksum into
  429. # CKSUM_STORE.
  430. #
  431. maybe_store_depends()
  432. {
  433. ckmatchfile="$1"
  434. depsfile="$2"
  435. if test -n "$ckmatchfile" ; then
  436. $CKSUM "$ckmatchfile" > $CKS 2> /dev/null && \
  437. test -s "$CKS" || return 1
  438. # only store if different
  439. diff "$CKS" "$CKSUM_STORE" > /dev/null 2>&1 || cdiff=yes
  440. diff "$depsfile" "$DEPEND_STORE" > /dev/null 2>&1 || ddiff=yes
  441. if test "$cdiff" = yes -o "$ddiff" = yes; then
  442. cp "$CKS" "$CKSUM_STORE" && cp "$depsfile" "$DEPEND_STORE" || \
  443. return 1
  444. test "$verbose" -gt 0 && echo $P: stored new dependencies for reuse
  445. fi
  446. fi
  447. # success unless we botched things above and returned a 1
  448. return 0
  449. }
  450. #
  451. # gen_depends():
  452. # generate the depend information into the file named in TMP.
  453. #
  454. gen_depends()
  455. {
  456. #
  457. # go through the source files. Find each in VPATH
  458. # do the compile there and accumulate the dependencies
  459. #
  460. true > $TMP # truncate TMP
  461. for f in $arg_fn; do
  462. # let us assume that all products are '.o' files
  463. prod_sfx='o'
  464. # figure out the stem: i.e. /a/b/c/foo.o --> foo
  465. stem=`echo $f | sed -e 's/.o$//'`
  466. # did we actually find a source file
  467. found_src=no
  468. # if this file is in the ignore list, skip it
  469. in_list_p "$f" "$ignobjs" && { test "$verbose" -gt 0 && \
  470. echo $P: ignoring file: $f; continue; }
  471. #
  472. # go through each possible directory and try each possible
  473. # source file
  474. #
  475. for d in $VPATH; do
  476. #
  477. # as soon as we find the first src file, we can go onto the
  478. # next argument (i.e. object file)
  479. #
  480. test "$found_src" = yes && break
  481. for src_sfx in $mksuffixes; do
  482. # cannot make a file from itself
  483. test "$prod_sfx" = "$src_sfx" && continue
  484. #
  485. # if we were given rules and there is no rule for this
  486. # transformation then skip this suffix combination
  487. #
  488. test -n "$mrules" && exists_rule $src_sfx $prod_sfx || continue
  489. s=${stem}.${src_sfx}
  490. test "$verbose" -gt 2 && echo "$P: checking for: $d/$s"
  491. if [ -f "$d/$s" ]; then
  492. found_src=yes
  493. test "$verbose" -gt 0 && echo $P: processing $d/$s
  494. case "$src_sfx" in
  495. c*|C*)
  496. #
  497. # This is a file that is a candidate for cpp:
  498. #
  499. # process the output of cpp and massage it, then sort
  500. # it uniquely and as a final step remove the trailing
  501. # numbers or any other cruft that various compilers
  502. # might generate. Then remove any lines that
  503. # make the file depend on itself by removing any
  504. # dependencies on files not ending in .h or .H
  505. #
  506. # also add it to the list of srcs
  507. #
  508. test -n "$mksrcs" && echo $d/$s >> $SRCS
  509. test "$verbose" -lt 2 && errout='2> /dev/null'
  510. eval $CPP $arg_cc $d/$s $errout | \
  511. sed -n -e "s;^\# [0-9][0-9 ]*\"\(/.*\)\";$f: \1;p" | \
  512. grep -v "//$" | \
  513. grep -v "$s\$" | \
  514. sed -e 's;\([^ :]*: [^ ]*\).*;\1;' \
  515. >> $TMP
  516. ;;
  517. *)
  518. test "$verbose" -gt 1 && echo "$P: no preprocessing for $s" ;;
  519. esac
  520. #
  521. # explicit rules can be generated for all sorts of sources
  522. #
  523. explicit_rule "$s" "$f" "$d" "$RULES" "$xobjs"
  524. break
  525. fi
  526. done
  527. done
  528. test "$found_src" = no && echo Did not find the source for: $f
  529. done
  530. #
  531. # optionally invoke a user-specified sed script on the output. In either
  532. # case, sort the output uniquely first.
  533. #
  534. if test -n "$sedprog"; then
  535. sort -u < "$TMP" | sed -f "$sedprog" > "$TMP"_a
  536. mv "$TMP"_a "$TMP" 2>&1 > /dev/null
  537. else
  538. sort -u -o "$TMP" "$TMP"
  539. fi
  540. #
  541. # now see if we want the SRCS= line and generation of
  542. # explicit rules per file for source files not in our
  543. # current directory
  544. #
  545. test -n "$mksrcs" && test -r "$SRCS" && append_srcs "$TMP" "$SRCS"
  546. #
  547. # if we wanted explicit rules then these have been diverted to
  548. # a seperate file, include them now
  549. #
  550. test -n "$mrules" && test -r "$RULES" && append_rules "$TMP" "$RULES"
  551. }
  552. #
  553. # this is the beginning of the main routine
  554. #
  555. init_mode
  556. eval `mktemp TMP`
  557. eval `mktemp RULES`
  558. eval `mktemp SRCS`
  559. eval `mktemp CKS`
  560. VP=.; export VP
  561. mksrcs=""; export mksrcs
  562. MF=Makefile; export MF
  563. append=no; export append
  564. verbose=0; export verbose
  565. sedprog=""; export sedprog
  566. mrules=""; export mrules
  567. xobjs=""; export xobjs
  568. ignobjs=""; export ignobjs
  569. cksumfile=""; export cksumfile
  570. trap '/bin/rm /tmp/mkdep.$$.* > /dev/null 2>&1' 0 1 2 3 15
  571. while [ $# -gt 0 ] ; do
  572. if [ "$mode" = "md_args" ]; then
  573. #
  574. # these are arguments to the makedepend script itself
  575. #
  576. case "$1" in
  577. -V*) shift; VP=$1 ;; # VPATH
  578. -s*) shift; mksrcs=$1 ;; # generate a SRCS= line based on OBJS
  579. -f*) shift; MF=$1 ;; # dependfile name
  580. -p*) shift; CPP="$1" ;; # pre-processor to use
  581. -e*) shift; sedprog="$1" ;;
  582. -c*) shift; cksumfile="$1" ;; # file to cksum (e.g. Makefile.in)
  583. -m*) shift; mrules="$1" ;; # the make rules file
  584. -x*) shift; xobjs="$1" ;; # no rules for this list of objs
  585. -i*) shift; ignobjs="$1" ;; # list of objs to be ignored
  586. -a*) append=yes ;;
  587. -v*) verbose=`expr $verbose + 1` ;;
  588. --) incr_mode ;;
  589. *) echo $P: Illegal argument \'"$1"\' >&2; exit 1 ;;
  590. esac
  591. shift
  592. else
  593. case "$1" in
  594. --) incr_mode ;;
  595. *) append_arg "$1" ;;
  596. esac
  597. shift;
  598. fi
  599. done
  600. if test -n "$xobjs" -a -z "$mrules"; then
  601. echo $P: cannot use -x without -m >&2
  602. exit 1
  603. fi
  604. if test "$append" = yes -a -n "$mrules"; then
  605. echo $P: cannot use append mode if -m is specified >$2
  606. echo $P: since multiple action definitions are prohibited >&2
  607. exit 1
  608. fi
  609. test -n "$mrules" && eval_mrules $mrules
  610. VPATH="`echo .:$VP | sed -e 's/:/ /g'`"
  611. test "$verbose" -gt 1 && echo "$P: CFLAGS are: $arg_cc"
  612. test "$verbose" -gt 1 && echo "$P: VPATH dirs are: $VPATH"
  613. #
  614. # the list of suffixes is either found in the make rules
  615. # and set by calling eval_mrules() earlier, or
  616. # if we did not process any, then '.c' will do
  617. #
  618. mksuffixes=${mksuffixes:-'c'}
  619. #
  620. # if we find that we can avoid generation of new dependency
  621. # rules by looking in prestored rules then do that. This
  622. # way, even though Makefile was regenerated and rules
  623. # removed we can use the old ones if Makefile.in was
  624. # not changed. Ideally, make would have an include directive
  625. # but that is not universally the case.
  626. #
  627. have_usable_depends "$cksumfile" && cp "$DEPEND_STORE" "$TMP" || gen_depends
  628. if [ "$append" = "yes" ]; then
  629. # if the marker is already in the file, do not put a second one in
  630. grep "^$MARKER" $MF > /dev/null 2>&1 || echo "$MARKER" >> $MF
  631. cat $TMP >> $MF
  632. else
  633. if grep "^$MARKER" $MF > /dev/null 2>&1 ; then
  634. #
  635. # we delete and then add since there may be no line .+1 if
  636. # the marker was the last line
  637. #
  638. tmp_mf="/tmp/mf.$$"
  639. sed "/^$MARKER/d" $MF > $tmp_mf; mv $tmp_mf $MF
  640. fi
  641. echo $MARKER >> $MF
  642. cat $TMP >> $MF
  643. fi
  644. #
  645. # decide whether we are using the checksum shortcut and storing depends
  646. # and if so store the new checksum and new depends
  647. #
  648. maybe_store_depends "$cksumfile" "$TMP" || \
  649. echo $P: error storing dependencies for later use
  650. /bin/rm $TMP > /dev/null 2>&1