home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume20 / dmake / patch02g < prev    next >
Encoding:
Text File  |  1991-06-29  |  38.5 KB  |  1,018 lines

  1. Newsgroups: comp.sources.misc
  2. From: Dennis Vadura <dvadura@watdragon.waterloo.edu>
  3. Subject:  v20i082:  dmake - dmake version 3.7, Patch02g/12
  4. Message-ID: <1991Jun29.222651.4388@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 6d3f583b9ae57a1c83d492d0bf4077f8
  6. Date: Sat, 29 Jun 1991 22:26:51 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Dennis Vadura <dvadura@watdragon.waterloo.edu>
  10. Posting-number: Volume 20, Issue 82
  11. Archive-name: dmake/patch02g
  12. Patch-To: dmake: Volume 19, Issue 22-58
  13.  
  14. #!/bin/sh
  15. # this is dp2.06 (part 6 of a multipart archive)
  16. # do not concatenate these parts, unpack them in order with /bin/sh
  17. # file dm37p2 continued
  18. #
  19. if test ! -r _shar_seq_.tmp; then
  20.     echo 'Please unpack part 1 first!'
  21.     exit 1
  22. fi
  23. (read Scheck
  24.  if test "$Scheck" != 6; then
  25.     echo Please unpack part "$Scheck" next!
  26.     exit 1
  27.  else
  28.     exit 0
  29.  fi
  30. ) < _shar_seq_.tmp || exit 1
  31. if test ! -f _shar_wnt_.tmp; then
  32.     echo 'x - still skipping dm37p2'
  33. else
  34. echo 'x - continuing file dm37p2'
  35. sed 's/^X//' << 'SHAR_EOF' >> 'dm37p2' &&
  36. Xcommand line flag.
  37. XIf a prerequisite name cannot be found in the environment
  38. Xan error message is issued.
  39. X\&.IMPORT accepts the .IGNORE attribute.  When given, it causes \fBdmake\fP
  40. Xto ignore the above error.
  41. XSee the MACROS section for a description of the processing of imported macro
  42. Xvalues.
  43. X.IP \fB.INCLUDE\fP 1.4i
  44. XParse another makefile just as if it had been located at the point of the
  45. X\&.INCLUDE in the current makefile.  The list of prerequisites gives the list of
  46. Xmakefiles to try to read.  If the list contains multiple makefiles then they
  47. Xare read in order from left to right.  The following search rules are used
  48. Xwhen trying to locate the file.  If the filename is surrounded by " or just
  49. Xby itself then it is searched for in the current directory.  If it is not
  50. Xfound it is then searched for in each of the directories specified for the
  51. X\&.INCLUDEDIRS special target.  If the file name is surrounded by < and >, (ie.
  52. X<my_spiffy_new_makefile>) then it is searched for only in the directories
  53. Xgiven by the .INCLUDEDIRS special target.  In both cases if the file name is a
  54. Xfully qualified name starting at the root of the file system then it is only
  55. Xsearched for once, and the .INCLUDEDIRS list is ignored.  .INCLUDE accepts
  56. Xthe .IGNORE and .SETDIR attributes.  If .IGNORE attribute is given and the file
  57. Xcannot be found then \fBdmake\fP continues processing,
  58. Xotherwise an error message is generated.
  59. XThe .SETDIR attribute causes
  60. X.B dmake
  61. Xto change directories to the specified directory prior to attempting the
  62. Xinclude operation.
  63. X.IP \fB.INCLUDEDIRS\fP 1.4i
  64. XThe list of prerequisites specified for this target defines the set of
  65. Xdirectories to search when trying to include a makefile.
  66. X.IP \fB.KEEP_STATE\fP 1.4i
  67. XThis special target is a synonym for the macro definition
  68. X.sp
  69. X\&\t.KEEP_STATE := _state.mk
  70. X.sp
  71. XIt's effect is to turn on STATE keeping and to define \fI_state.mk\fP
  72. Xas the state file.
  73. X.IP \fB.MAKEFILES\fP 1.4i
  74. XThe list of prerequisites is the set of files to try to read as the default
  75. Xmakefile.  By default this target is defined as: 
  76. X.sp
  77. X\t\&.MAKEFILES : makefile.mk Makefile makefile
  78. X.sp
  79. X.IP \fB.SOURCE\fP 1.4i
  80. XThe prerequisite list of this target defines a set of directories to check
  81. Xwhen trying to locate a target file name.  See the section on BINDING of
  82. Xtargets for more information.
  83. X.IP \fB.SOURCE.suff\fP 1.4i
  84. XThe same as .SOURCE, except that the .SOURCE.suff list is searched first when
  85. Xtrying to locate a file matching the a target whose name ends in the suffix
  86. X\&.suff.
  87. X.IP \fB.REMOVE\fP 1.4i
  88. XThe recipe of this target is used whenever \fBdmake\fP needs to remove
  89. Xintermediate targets that were made but do not need to be kept around.
  90. XSuch targets result from the application of transitive closure on the
  91. Xdependency graph.
  92. X.PP
  93. XIn addition to the special targets above,
  94. Xseveral other forms of targets are recognized and are considered special,
  95. Xtheir exact form and use is defined in the sections that follow.
  96. X.SH "SPECIAL MACROS"
  97. X.B dmake
  98. Xdefines a number of special macros.  They are divided into three classes:
  99. Xcontrol macros, run-time macros, and function macros.
  100. XThe control macros are used by
  101. X.B dmake
  102. Xto configure its actions, and are the preferred method of doing so.
  103. XIn the case when a control macro has the same function as a special 
  104. Xtarget or attribute they share the same name as the special target or
  105. Xattribute.
  106. XThe run-time macros are defined when
  107. X.B dmake
  108. Xmakes targets and may be used by the user inside recipes.
  109. XThe function macros provide higher level functions dealing with macro
  110. Xexpansion and diversion file processing.
  111. X.SH "CONTROL MACROS"
  112. XTo use the control macros simply assign them a value just like any other
  113. Xmacro.  The control macros are divided into three groups:
  114. Xstring valued macros, character valued macros, and boolean valued macros.
  115. X.PP
  116. XThe following are all of the string valued macros.
  117. XThis list is divided into two groups.  The first group gives the string
  118. Xvalued macros that are defined internally and cannot be directly set by the
  119. Xuser.
  120. X.IP \fBDIRBRKSTR\fP 1.4i
  121. XContains the string of chars used to terminate
  122. Xthe name of a directory in a pathname.
  123. XUnder UNIX its value is "/", under MSDOS its value is "/\e:".
  124. X.IP \fBINCDEPTH\fP 1.4i
  125. XThis macro's value is a string of digits representing
  126. Xthe current depth of makefile inclusion.
  127. XIn the first makefile level this value is zero.
  128. X.IP \fBMFLAGS\fP 1.4i
  129. XIs the list of flags
  130. Xthat were given on the command line including a leading switch character.
  131. XThe \-f flag is not included in this list.
  132. X.IP \fBMAKECMD\fP 1.4i
  133. XIs the name with which \fBdmake\fP was invoked.
  134. X.IP \fBMAKEDIR\fP 1.4i
  135. XIs the full path to the initial directory in which
  136. X.B dmake
  137. Xwas invoked.
  138. X.IP \fBMAKEFILE\fP 1.4i
  139. XContains the string "\-f \fImakefile\fP" where, \fImakefile\fP is the name
  140. Xof initial user makefile that was first read.
  141. X.IP \fBMAKEFLAGS\fP 1.4i
  142. XIs the same as $(MFLAGS) but has no leading switch
  143. Xcharacter. (ie. MFLAGS = \-$(MAKEFLAGS))
  144. X.IP \fBMAKEMACROS\fP 1.4i
  145. XContains the complete list of macro expressions that were specified on the
  146. Xcommand line.
  147. X.IP \fBMAKETARGETS\fP 1.4i
  148. XContains the name(s) of the target(s), if any, that were
  149. Xspecified on the command line.
  150. X.IP \fBMAXPROCESSLIMIT\fP 1.4i
  151. XIs a numeric string representing the maximum number of processes that 
  152. X\fBdmake\fP can use when making targets using parallel mode.
  153. X.IP \fBNULL\fP 1.4i
  154. XIs permanently defined to be the NULL string.
  155. XThis is useful when comparing a conditional expression to an NULL value.
  156. X.IP \fBPWD\fP 1.4i
  157. XIs the full path to the
  158. Xcurrent directory in which make is executing.
  159. X.IP \fBTMPFILE\fP 1.4i
  160. XIs set to the name of the most recent temporary file opened by \fBdmake\fP.
  161. XTemporary files are used for text diversions and for group recipe processing.
  162. X.IP \fBTMD\fP 1.4i
  163. XStands for "To Make Dir", and
  164. Xis the path from the present directory (value of $(PWD)) to the directory
  165. Xthat \fBdmake\fP was started up in (value of $(MAKEDIR)).
  166. XThis macro is modified when .SETDIR attributes are processed.
  167. X.IP \fBUSESHELL\fP 1.4i
  168. XThe value of this macro is set to "yes" if the current recipe is forced to
  169. Xuse a shell for its execution via the .USESHELL or '+' directives, its value
  170. Xis "no" otherwise.
  171. X.sp
  172. X.PP
  173. XThe second group of string valued macros control
  174. X.B dmake
  175. Xbehavior and may be set by the user.
  176. X.IP \fB.NOTABS\fP 1.6i
  177. XWhen set to non-NULL enables the use of spaces as well as <tabs> to begin
  178. Xrecipe lines.
  179. XBy default a non\-group recipe is terminated by a line without any leading
  180. Xwhite\-space or by a line not beggining with a <tab> character.
  181. XEnabling this mode modifies the first condition of
  182. Xthe above termination rule to terminate a
  183. Xnon\-group recipe with a line that contains only white\-space.
  184. XThis mode does not effect the parsing of group recipes bracketed by [].
  185. X.IP \fB.SETDIR\fP 1.6i
  186. XIf this macro is assigned a value then \fBdmake\fP will
  187. Xchange to the directory given by that value before making any targets.
  188. X.IP \fBAUGMAKE\fP 1.6i
  189. XIf set to a non NULL value will enable the transformation of special
  190. Xmeta targets to support special AUGMAKE inferences (See the COMPATIBILITY
  191. Xsection).
  192. X.IP \fBDIRSEPSTR\fP 1.6i
  193. XContains the string that is used to separate directory components when
  194. Xpath names are constructed.  It is defined with a default value at startup.
  195. X.IP \fBDIVFILE\fP 1.6i
  196. XIs defined in the startup file and gives the name that should be returned for
  197. Xthe diversion file name when used in
  198. X$(mktmp ...) expansions, see the TEXT DIVERSION section for details.
  199. X.IP \fB.KEEP_STATE\fP 1.6i
  200. XAssigning this macro a value tells
  201. X.B dmake
  202. Xthe name of the state file to use and turns on the keeping of state
  203. Xinformation for any targets that are brought up to date by the make.
  204. X.IP \fBGROUPFLAGS\fP 1.6i
  205. XThis macro gives the set of flags to pass to the shell when
  206. Xinvoking it to execute a group recipe.  The value of the macro is the
  207. Xlist of flags with a leading switch indicator.  (ie. `\-' under UNIX)
  208. X.IP \fBGROUPSHELL\fP 1.6i
  209. XThis macro defines the full
  210. Xpath to the executable image to be used as the shell when
  211. Xprocessing group recipes.  This macro must be defined if group recipes are
  212. Xused.  It is assigned a default value in the startup makefile.  Under UNIX
  213. Xthis value is /bin/sh.
  214. X.IP \fBGROUPSUFFIX\fP 1.6i
  215. XIf defined, this macro gives the string to use as a suffix
  216. Xwhen creating group recipe files to be handed to the command interpreter.
  217. XFor example, if it is defined as .sh, then all
  218. Xtemporary files created by \fBdmake\fP will end in the suffix .sh.
  219. XUnder MSDOS if you are using command.com as your GROUPSHELL, then this suffix
  220. Xmust be set to .bat in order for group recipes to function correctly.
  221. XThe setting of GROUPSUFFIX and GROUPSHELL is done automatically for
  222. Xcommand.com in the startup.mk files.
  223. X.IP \fBMAKE\fP 1.6i
  224. XIs defined in the startup file by default.
  225. XThe string $(MAKE) is recognized when
  226. Xusing the \-n option for single line recipes.  Initially this macro is defined
  227. Xto have the value "$(MAKECMD) $(MFLAGS)".
  228. X.IP \fBMAKESTARTUP\fP 1.6i
  229. XThis macro defines the full path to the initial startup
  230. Xmakefile.  Use the \fB\-V\fP command line option to discover its initial
  231. Xvalue.
  232. X.IP \fBMAXLINELENGTH\fP 1.6i
  233. XThis macro defines the maximum size of a single line of
  234. Xmakefile input text.  The size is specified as a number, the default value
  235. Xis defined internally and is shown via the \fB\-V\fP option.
  236. XA buffer of this size plus 2 is allocated for reading makefile text.  The
  237. Xbuffer is freed before any targets are made, thereby allowing files containing
  238. Xlong input lines to be processed without consuming memory during the actual
  239. Xmake.
  240. X.IP \fBMAXPROCESS\fP 1.6i
  241. XSpecify the maximum number of child processes to use when making targets.
  242. XThe default value of this macro is "1" and its value cannot exceed the value
  243. Xof the macro MAXPROCESSLIMIT.  Setting the value of MAXPROCESS on the command
  244. Xline or in the makefile is equivalent to supplying a corresponding value to
  245. Xthe -P flag on the command line.
  246. X.IP \fBPREP\fP 1.6i
  247. XThis macro defines the number of iterations to be expanded
  248. Xautomatically when processing % rule definitions of the form:
  249. X.sp
  250. X% : %.suff
  251. X.sp
  252. XSee the sections on PERCENT(%) RULES for details on how PREP is used.
  253. X.IP \fBSHELL\fP 1.6i
  254. XThis macro defines the full path to the executable
  255. Ximage to be used as the shell when
  256. Xprocessing single line recipes.  This macro must be defined if recipes
  257. Xrequiring the shell for execution are to be used.
  258. XIt is assigned a default value in the startup makefile.
  259. XUnder UNIX this value is /bin/sh.
  260. X.IP \fBSHELLFLAGS\fP 1.6i
  261. XThis macro gives the set of flags to pass to the shell when
  262. Xinvoking it to execute a single line recipe.  The value of the macro is the
  263. Xlist of flags with a leading switch indicator.  (ie. `\-' under UNIX)
  264. X.IP \fBSHELLMETAS\fP 1.6i
  265. XEach time
  266. X.B dmake
  267. Xexecutes a single recipe line (not a group recipe) the line is
  268. Xsearched for any occurrence of a character defined in the value of SHELLMETAS.
  269. XIf such a character is found the recipe line is defined to require a shell
  270. Xto ensure its correct execution.  In such instances
  271. Xa shell is used to invoke the recipe line.
  272. XIf no match is found the recipe line is executed without the use of a shell.
  273. X.sp
  274. X.PP
  275. XThere is only one character valued macro defined by \fBdmake\fP:
  276. X\fBSWITCHAR\fP contains the switch character used
  277. Xto introduce options on command lines.  For UNIX its value is `\-', and for
  278. XMSDOS its value may be `/' or `\-'.
  279. XThe macro is internally defined and is not user setable.
  280. XThe MSDOS version of \fBdmake\fP attempts to first extract SWITCHAR from an
  281. Xenvironment variable of the same name.  If that fails it then attempts to
  282. Xuse the undocumented getswitchar system call, and returns the result of
  283. Xthat.  Under MSDOS version 4.0 you must set the value of the environment
  284. Xmacro SWITCHAR to '/' to obtain predictable behavior.
  285. X.PP
  286. XAll boolean macros currently understood by 
  287. X.B dmake
  288. Xcorrespond directly to the previously defined attributes.
  289. XThese macros provide
  290. Xa second way to apply global attributes, and represent the
  291. Xpreferred method of doing so.  They are used by assigning them a
  292. Xvalue.  If the value is not a NULL string then the boolean condition
  293. Xis set to on.
  294. XIf the value is a NULL string then the condition is set to off.
  295. XThere are five conditions defined and they correspond directly to the
  296. Xattributes of the same name.  Their meanings are defined in the ATTRIBUTES
  297. Xsection above.
  298. XThe macros are:
  299. X\&\fB.EPILOG\fP,
  300. X\&\fB.IGNORE\fP,
  301. X\&\fB.MKSARGS\fP,
  302. X\&\fB.NOINFER\fP,
  303. X\&\fB.PRECIOUS\fP,
  304. X\&\fB.PROLOG\fP,
  305. X\&\fB.SEQUENTIAL\fP,
  306. X\&\fB.SILENT\fP,
  307. X\&\fB.SWAP\fP, and
  308. X\&\fB.USESHELL\fP.
  309. XAssigning any of these a non NULL value will globally set
  310. Xthe corresponding attribute to on.
  311. X.SH "RUN_TIME MACROS"
  312. XThese macros are defined
  313. Xwhen \fBdmake\fP is making targets, and may take on different values for each
  314. Xtarget.  \fB$@\fP is defined to be the full target name, \fB$?\fP is the
  315. Xlist of all out of date prerequisites, \fB$&\fP is the list of all
  316. Xprerequisites, \fB$>\fP is the name of the library if the current target is a
  317. Xlibrary member, and
  318. X\fB$<\fP is the list of prerequisites specified in the current rule.
  319. XIf the current target had a recipe inferred then \fB$<\fP is the name of the
  320. Xinferred prerequisite even if the target had a list of prerequisites supplied
  321. Xusing an explicit rule that did not provide a recipe.  In such situations
  322. X\fB$&\fP gives the full list of prerequisites.
  323. X.PP
  324. X\fB$*\fP is defined as
  325. X\fB$(@:db)\fP when making targets with explicit recipes and is defined as the
  326. Xvalue of % when making targets whose recipe is the result of an inference.
  327. XIn the first case \fB$*\fP is the target name with no suffix,
  328. Xand in the second case, is the value of the matched % pattern from
  329. Xthe associated %-rule.
  330. X\fB$^\fP expands to the set of out of date prerequisites taken from the
  331. Xcurrent value of \fB$<\fP.
  332. XIn addition to these,
  333. X\fB$$\fP expands to $, \fB{{\fP expands to {, \fB}}\fP expands to }, and the
  334. Xstrings \fB<+\fP and \fB+>\fP are recognized
  335. Xas respectively starting and terminating a text diversion when they appear
  336. Xliterally together in the same input line.
  337. X.PP
  338. XThe difference between $? and $^ can best be illustrated by an example,
  339. Xconsider:
  340. X.RS
  341. X.sp
  342. X.nf
  343. Xfred.out : joe amy hello
  344. X\trules for making fred
  345. XX
  346. Xfred.out : my.c your.h his.h her.h      # more prerequisites
  347. X.fi
  348. X.sp
  349. X.RE
  350. XAssume joe, amy, and my.c are newer then fred.out.  When
  351. X.B dmake
  352. Xexecutes the recipe for making fred.out the values of the following macros
  353. Xwill be:
  354. X.RS
  355. X.sp
  356. X.nf
  357. X.Is "$@ "
  358. X.Ii "$@"
  359. X--> fred.out
  360. X.Ii "$*"
  361. X--> fred
  362. X.Ii "$?"
  363. X--> joe amy my.c  # note the difference between $? and $^
  364. X.Ii "$^"
  365. X--> joe amy
  366. X.Ii "$<"
  367. X--> joe amy hello
  368. X.Ii "$&"
  369. X--> joe amy hello my.c your.h his.h her.h
  370. X.fi
  371. X.sp
  372. X.RE
  373. X.SH "FUNCTION MACROS"
  374. X.B dmake
  375. Xsupports a full set of functional macros.  One of these, the $(mktmp ...)
  376. Xmacro, is discussed in detail in the TEXT DIVERSION section and is not
  377. Xcovered here.
  378. X.RS
  379. X.sp
  380. X.IP "$(\fBnull\fP,\fItext\fP \fBtrue\fP \fBfalse\fP)"
  381. Xexpands the value of
  382. X.I text.
  383. XIf it is NULL then the macro returns the value of the expansion of \fBtrue\fP
  384. Xand the expansion of \fBfalse\fP otherwise.  The terms \fBtrue\fP, and
  385. X\fBfalse\fP must be strings containing no white\-space.
  386. X.IP "$(\fB!null\fP,\fItext\fP \fBtrue\fP \fBfalse\fP)"
  387. XBehaves identically to the previous macro except that the 
  388. X.B true
  389. Xstring is chosen if the expansion of
  390. X.I text
  391. Xis not NULL.
  392. X.IP "$(\fBeq\fP,\fItext_a\fP,\fItext_b\fP \fBtrue\fP \fBfalse\fP)"
  393. Xexpands
  394. X.I text_a
  395. Xand
  396. X.I text_b
  397. Xand compares their results.  If equal it returns the result of the expansion
  398. Xof the 
  399. X.B true
  400. Xterm, otherwise it returns the expansion of the
  401. X.B false
  402. Xterm.
  403. X.IP "$(\fB!eq\fP,\fItext_a\fP,\fItext_b\fP \fBtrue\fP \fBfalse\fP)"
  404. XBehaves identically to the previous macro except that the 
  405. X.B true
  406. Xstring is chosen if the expansions of the two strings are not equal
  407. X.IP "$(\fBshell\fP \fBcommand\fP)"
  408. XRuns \fIcommand\fP as if it were part of a recipe and returns,
  409. Xseparated by a single space, all the non-white
  410. Xspace terms written to stdout by the command.
  411. XFor example:
  412. X.RS
  413. X.RS
  414. X.sp
  415. X$(shell ls *.c)
  416. X.sp
  417. X.RE
  418. Xwill return \fI"a.c b.c c.c d.c"\fP if the files exist in the current
  419. Xdirectory.  The recipe modification flags \fB[+@%\-]\fP are honored if they
  420. Xappear as the first characters in the command.  For example:
  421. X.RS
  422. X.sp
  423. X$(shell +ls *.c)
  424. X.sp
  425. X.RE
  426. Xwill run the command using the current shell.
  427. X.RE
  428. X.IP "$(\fBsort\fP \fBlist\fP)"
  429. XWill take all white\-space separated tokens in \fIlist\fP and will
  430. Xreturn their sorted equivalent list.
  431. X.IP "$(\fBstrip\fP \fBdata\fP)"
  432. XWill replace all strings of white\-space in data by a single space.
  433. X.IP "$(\fBsubst\fP,\fIpat\fP,\fIreplacement\fP \fBdata\fP)"
  434. XWill search for \fIpat\fP in
  435. X.B data
  436. Xand will replace any occurrence of
  437. X.I pat
  438. Xwith the
  439. X.I replacement
  440. Xstring.
  441. X.RS
  442. XThe expansion
  443. X.RS
  444. X.sp
  445. X$(subst,.o,.c $(OBJECTS))
  446. X.sp
  447. X.RE
  448. Xis equivalent to:
  449. X.RS
  450. X.sp
  451. X$(OBJECTS:s/.o/.c/)
  452. X.sp
  453. X.RE
  454. X.RE
  455. X.SH "DYNAMIC PREREQUISITES"
  456. X.B dmake
  457. Xlooks for prerequisites whose names contain macro expansions during target
  458. Xprocessing.  Any such prerequisites are expanded and the result of the
  459. Xexpansion is used as the prerequisite name.  As an example the line:
  460. X.sp
  461. X\tfred : $$@.c
  462. X.sp
  463. Xcauses the $$@ to be expanded when \fBdmake\fP is making fred, and it resolves
  464. Xto the target \fIfred\fP.
  465. XThis enables dynamic prerequisites to be generated.  The value
  466. Xof @ may be modified by any of the valid macro modifiers.  So you can say for
  467. Xexample:
  468. X.sp
  469. X\tfred.out : $$(@:b).c
  470. X.sp
  471. Xwhere the $$(@:b) expands to \fIfred\fP.
  472. XNote the use of $$ instead of $ to indicate the dynamic expansion, this
  473. Xis due to the fact that the rule line is expanded when it is initially parsed,
  474. Xand $$ then returns $ which later triggers the dynamic prerequisite expansion.
  475. XIf you really want a $ to be part of a prerequisite name you must use $$$$.
  476. XDynamic macro expansion is performed in all user defined rules,
  477. Xand the special targets .SOURCE*, and .INCLUDEDIRS.
  478. X.SH "BINDING TARGETS"
  479. XThis operation takes a target name and binds it to an existing file, if
  480. Xpossible.
  481. X.B dmake
  482. Xmakes a distinction between the internal target name of a target and its
  483. Xassociated external file name.
  484. XThus it is possible for a target's internal name and its external
  485. Xfile name to differ.
  486. XTo perform the binding, the following set of rules is used.
  487. XAssume that we are
  488. Xtrying to bind a target whose name is of the form \fIX.suff\fP,
  489. Xwhere \fI.suff\fP is the suffix and \fIX\fP is the stem portion
  490. X(ie. that part which contains the directory and the basename).
  491. X.B dmake
  492. Xtakes this target name and performs a series of search operations that try to
  493. Xfind a suitably named file in the external file system.
  494. XThe search operation is user controlled
  495. Xvia the settings of the various .SOURCE targets.
  496. X.RS
  497. X.IP 1.
  498. XIf target has the .SYMBOL attribute set then look for it in the library.
  499. XIf found, replace the target name with the library member name and continue
  500. Xwith step 2.  If the name is not found then return.
  501. X.IP 2.
  502. XExtract the suffix portion (that following the `.') of the target name.
  503. XIf the suffix is not null, look up the special target .SOURCE.<suff>
  504. X(<suff> is the suffix).  
  505. XIf the special target exists then search each directory given in
  506. Xthe .SOURCE.<suff> prerequisite list for the target.
  507. XIf the target's suffix was null (ie. \fI.suff\fP was empty) then 
  508. Xperform the above search but use the special target .SOURCE.NULL instead.
  509. XIf at any point a match is found then terminate the search.
  510. XIf a directory in the prerequisite list is the special name `.NULL ' perform
  511. Xa search for the full target name without prepending any directory portion
  512. X(ie. prepend the NULL directory).
  513. X(a default target of '.SOURCE : .NULL' is defined by \fBdmake\fP at startup,
  514. Xand is user redefinable)
  515. X.IP 3.
  516. XThe search in step 2. failed.  Repeat the same search but this time
  517. Xuse the special target .SOURCE.
  518. X.IP 4.
  519. XThe search in step 3. failed.
  520. XIf the target has the library member attribute (.LIBMEMBER)
  521. Xset then try to find the target in the library which was passed along
  522. Xwith the .LIBMEMBER attribute (see the MAKING LIBRARIES section).
  523. XThe bound file name assigned to a target which is successfully
  524. Xlocated in a library is the same name that would be assigned had the search
  525. Xfailed (see 5.).
  526. X.IP 5.
  527. XThe search failed.  Either the target was not found in any of the search
  528. Xdirectories or no applicable .SOURCE special targets exist.
  529. XIf applicable .SOURCE special targets exist, but the target was not found,
  530. Xthen \fBdmake\fP assigns the first name searched as the bound file name.
  531. XIf no applicable .SOURCE special targets exist,
  532. Xthen the full original target name becomes the bound file name.
  533. X.RE
  534. X.PP
  535. XThere is potential here for a lot of search operations.  The trick is to
  536. Xdefine .SOURCE.x special targets with short search lists and leave .SOURCE
  537. Xas short as possible.
  538. XThe search algorithm has the following useful side effect.
  539. XWhen a target having the .LIBMEMBER (library member) attribute is searched for,
  540. Xit is first searched for as an ordinary file.
  541. XWhen a number of library members require updating it is desirable to compile
  542. Xall of them first and to update the library at the end in a single operation.
  543. XIf one of the members does not compile and \fBdmake\fP stops, then
  544. Xthe user may fix the error and make again.  \fBdmake\fP will not remake any
  545. Xof the targets whose object files have already been generated as long as
  546. Xnone of their prerequisite files have been modified as a result of the fix.
  547. X.PP
  548. XWhen defining .SOURCE and .SOURCE.x targets the construct
  549. X.sp
  550. X\t.SOURCE :
  551. X.br
  552. X\t.SOURCE : fred gery
  553. X.sp
  554. Xis equivalent to
  555. X.sp
  556. X\t.SOURCE :\- fred gery
  557. X.PP
  558. X\fBdmake\fP correctly handles the UNIX Make variable VPATH.  By definition VPATH
  559. Xcontains a list of ':' separated directories to search when looking for a
  560. Xtarget.  \fBdmake\fP maps VPATH to the following special rule:
  561. X.sp
  562. X\t.SOURCE :^ $(VPATH:s/:/ /)
  563. X.sp
  564. XWhich takes the value of VPATH and sets .SOURCE to the same set of directories
  565. Xas specified in VPATH.
  566. X.SH "PERCENT(%) RULES AND MAKING INFERENCES"
  567. XWhen \fBdmake\fP makes a target, the target's set of prerequisites (if any)
  568. Xmust exist and the target must have a recipe which \fBdmake\fP
  569. Xcan use to make it.
  570. XIf the makefile does not specify an explicit recipe for the target then
  571. X.B dmake
  572. Xuses special rules to try to infer a recipe which it can use
  573. Xto make the target.  Previous versions of Make perform this task by using
  574. Xrules that are defined by targets of the form .<suffix>.<suffix> and by
  575. Xusing the .SUFFIXES list of suffixes.  The exact workings of this mechanism
  576. Xwere sometimes difficult to understand and often limiting in their usefulness.
  577. XInstead, \fBdmake\fP supports the concept of \fI%-meta\fP rules.  
  578. XThe syntax and semantics of these rules differ from standard rule lines as
  579. Xfollows:
  580. X.sp
  581. X.nf
  582. X.RS
  583. X\fI<%-target>\fP [\fI<attributes>\fP] \fI<ruleop>\fP [\fI<%-prerequisites>\fP] [;\fI<recipe>\fP]
  584. X.RE
  585. X.fi
  586. X.sp
  587. Xwhere \fI%-target\fP is a target containing exactly a single `%' sign,
  588. X.I attributes
  589. Xis a list (possibly empty) of attributes,
  590. X.I ruleop
  591. Xis the standard set of rule operators,
  592. X.I "%-prerequisites"
  593. X\&, if present, is a list of prerequisites containing zero or more `%' signs,
  594. Xand
  595. X.I recipe,
  596. Xif present, is the first line of the recipe.
  597. X.PP
  598. XThe
  599. X.I %-target
  600. Xdefines a pattern against which a target whose recipe is
  601. Xbeing inferred gets matched.  The pattern match goes as follows:  all chars are
  602. Xmatched exactly from left to right up to but not including the % sign in the
  603. Xpattern, % then matches the longest string from the actual target name
  604. Xnot ending in
  605. Xthe suffix given after the % sign in the pattern.
  606. XConsider the following examples:
  607. X.RS
  608. X.sp
  609. X.nf
  610. X.Is "dir/%.c   "
  611. X.Ii "%.c"
  612. Xmatches fred.c but not joe.c.Z
  613. X.Ii "dir/%.c"
  614. Xmatches dir/fred.c but not dd/fred.c
  615. X.Ii "fred/%"
  616. Xmatches fred/joe.c but not f/joe.c
  617. X.Ii "%"
  618. Xmatches anything
  619. X.fi
  620. X.sp
  621. X.RE
  622. XIn each case the part of the target name that matched the % sign is retained
  623. Xand is substituted for any % signs in the prerequisite list of the %-meta rule
  624. Xwhen the rule is selected during inference and
  625. X.B dmake
  626. Xconstructs the new dependency.
  627. XAs an example the following %-meta rules describe the following:
  628. X.RS
  629. X.sp
  630. X%.c : %.y ; recipe...
  631. X.sp
  632. X.RE
  633. Xdescribes how to make any file ending in .c if a corresponding file ending
  634. Xin .y can be found.
  635. X.RS
  636. X.sp
  637. Xfoo%.o : fee%.k ; recipe...
  638. X.sp
  639. X.RE
  640. Xis used to describe how to make fooxxxx.o from feexxxx.k.
  641. X.RS
  642. X.sp
  643. X%.a :; recipe...
  644. X.sp
  645. X.RE
  646. Xdescribes how to make a file whose suffix is .a without inferring any
  647. Xprerequisites.
  648. X.RS
  649. X.sp
  650. X%.c : %.y yaccsrc/%.y ; recipe...
  651. X.sp
  652. X.RE
  653. Xis a short form for the construct:
  654. X.RS
  655. X.sp
  656. X%.c : %.y ; recipe...
  657. X.br
  658. X%.c : yaccsrc/%.y ; recipe...
  659. X.sp
  660. X.RE
  661. Xie. It is possible to specify the same recipe for two %-rules by giving
  662. Xmore than one prerequisite in the prerequisite list.
  663. XA more interesting example is:
  664. X.RS
  665. X.sp
  666. X% : RCS/%,v ; co $@
  667. X.sp
  668. X.RE
  669. Xwhich describes how to take any target and check it out of
  670. Xthe RCS directory if the corresponding file exists in the RCS directory.
  671. XThe equivalent SCCS rule would be:
  672. X.RS
  673. X.sp
  674. X% : s.% ; get $@
  675. X.sp
  676. X.RE
  677. X.PP
  678. XThe previous RCS example defines an infinite rule, because it says how to make
  679. X.I anything
  680. Xfrom RCS/%,v, and
  681. X.I anything
  682. Xalso includes RCS/fred.c,v.
  683. XTo limit the size of the graph that results from such rules
  684. X.B dmake
  685. Xuses the macro variable PREP (stands for % repetition).  By default the value
  686. Xof this variable is 0, which says that no repetitions of a %-rule are to be
  687. Xgenerated.  If it is set to something greater than 0, then that many
  688. Xrepetitions of any infinite %-rule are allowed.  If in the above
  689. Xexample PREP was set to 1, then \fBdmake\fP would generate the dependency
  690. Xgraph:
  691. X.RS
  692. X.sp
  693. X% --> RCS/%,v --> RCS/RCS/%,v,v
  694. X.sp
  695. X.RE
  696. XWhere each link is assigned the same recipe as the first link.
  697. XPREP should be used only in special cases, since it may result in
  698. Xa large increase in the number of possible prerequisites tested.
  699. X.B dmake
  700. Xfurther assumes that any target that has no suffix can be made from
  701. Xa prerequisite that has at least one suffix.
  702. X.PP
  703. X.B dmake
  704. Xsupports dynamic prerequisite generation for prerequisites of %-meta rules.
  705. XThis is best illustrated by an example.  The RCS rule shown above can infer
  706. Xhow to check out a file from a corresponding RCS file only if the target
  707. Xis a simple file name with no directory information.  That is, the above rule
  708. Xcan infer how to find \fIRCS/fred.c,v\fP from the target \fIfred.c\fP,
  709. Xbut cannot infer how to find \fIsrcdir/RCS/fred.c,v\fP from \fIsrcdir/fred.c\fP
  710. Xbecause the above rule will cause \fBdmake\fP to look for RCS/srcdir/fred.c,v;
  711. Xwhich does not exist (assume that srcdir has its own RCS directory as is the
  712. Xcommon case).
  713. X.PP
  714. XA more versatile formulation of the above RCS check out rule is the following:
  715. X.RS
  716. X.sp
  717. X% :  $$(@:d)RCS/$$(@:f),v : co $@
  718. X.sp
  719. X.RE
  720. XThis rule uses the dynamic macro $@ to specify the prerequisite to try to
  721. Xinfer.  During inference of this rule the macro $@ is set to the value of
  722. Xthe target of the %-meta rule and the appropriate prerequisite is generated by
  723. Xextracting the directory portion of the target name (if any), appending the
  724. Xstring \fIRCS/\fP to it, and appending the target file name with a trailing
  725. X\fI,v\fP attached to the previous result.
  726. X.PP
  727. X.B dmake
  728. Xcan also infer indirect prerequisites.
  729. XAn inferred target can have a list of prerequisites added that will not
  730. Xshow up in the value of $< but will show up in the value of $? and $&.
  731. XIndirect prerequisites are specified in an inference rule by quoting the
  732. Xprerequisite with single quotes.  For example, if you had the explicit
  733. Xdependency:
  734. X.RS
  735. X.sp
  736. X.nf
  737. Xfred.o : fred.c ; rule to make fred.o
  738. Xfred.o : local.h
  739. X.fi
  740. X.sp
  741. X.RE
  742. Xthen this can be inferred for fred.o from the following inference rule:
  743. X.RS
  744. X.sp
  745. X%.o : %.c 'local.h' ; rule to make a .o from a .c
  746. X.sp
  747. X.RE
  748. XYou may infer indirect prerequisites that are a function of the value of '%'
  749. Xin the current rule.  The meta-rule:
  750. X.RS
  751. X.sp
  752. X%.o : %.c '$(INC)/%.h' ; rule to make a .o from a .c
  753. X.sp
  754. X.RE
  755. Xinfers an indirect prerequisite found in the INC directory whose name is the
  756. Xsame as the expansion of $(INC), and the prerequisite name depends on the
  757. Xbase name of the current target.
  758. XThe set of indirect prerequisites is attached to the meta rule in which they
  759. Xare specified and are inferred only if the rule is used to infer a recipe
  760. Xfor a target.  They do not play an active role in driving the inference
  761. Xalgorithm.
  762. XThe construct:
  763. X.RS
  764. X.sp
  765. X%.o : %.c %.f 'local.h'; recipe
  766. X.sp
  767. X.RE
  768. Xis equivalent to:
  769. X.RS
  770. X.sp
  771. X.nf
  772. X%.o : %.c 'local.h' : recipe
  773. X%.o : %.f 'local.h' : recipe
  774. X.fi
  775. X.sp
  776. X.RE
  777. X.PP
  778. XIf any of the attributes .SETDIR, .EPILOG, .PROLOG, .SILENT,
  779. X\&.USESHELL, .SWAP, .PRECIOUS, .LIBRARY, .NOSTATE and .IGNORE
  780. Xare given for a %-rule then when that rule is bound to a target
  781. Xas the result of an inference, the target's set of attributes is augmented by
  782. Xthe attributes from the above set that are specified in the bound %-rule.
  783. XOther attributes specified for %-meta rules are not inherited by the target.
  784. XThe .SETDIR attribute is treated in a special way.
  785. XIf the target already had a .SETDIR attribute set then
  786. X.B dmake
  787. Xchanges to that directory prior to performing the inference.
  788. XDuring inference any .SETDIR attributes for the inferred prerequisite
  789. Xare honored.
  790. XThe directories must exist for a %-meta rule to be selected as a possible
  791. Xinference path.  If the directories do not exist no error message is issued,
  792. Xinstead the corresponding path in the inference graph is rejected.
  793. X.PP
  794. X.B dmake
  795. Xalso supports the old format special target .<suffix>.<suffix>
  796. Xby identifying any rules
  797. Xof this form and mapping them to the appropriate %-rule.  So for example if
  798. Xan old makefile contains the construct:
  799. X.RS
  800. X.sp
  801. X\&.c.o :; cc \-c $< \-o $@
  802. X.sp
  803. X.RE
  804. X.B dmake
  805. Xmaps this into the following %-rule:
  806. X.RS
  807. X.sp
  808. X%.o : %.c; cc \-c $< \-o $@
  809. X.sp
  810. X.RE
  811. XFurthermore,
  812. X.B dmake
  813. Xunderstands several SYSV AUGMAKE special targets and maps them into
  814. Xcorresponding %-meta rules.  These transformation must be enabled by providing
  815. Xthe \-A flag on the command line or by setting the value of AUGMAKE to
  816. Xnon\-NULL.
  817. XThe construct
  818. X.RS
  819. X.sp
  820. X\&.suff :; recipe
  821. X.sp
  822. X.RE
  823. Xgets mapped into:
  824. X.RS
  825. X.sp
  826. X% : %.suff; recipe
  827. X.sp
  828. X.RE
  829. Xand the construct
  830. X.RS
  831. X.sp
  832. X\&.c~.o :; recipe
  833. X.sp
  834. X.RE
  835. Xgets mapped into:
  836. X.RS
  837. X.sp
  838. X%.o : s.%.c ; recipe
  839. X.sp
  840. X.RE
  841. XIn general, a special target of the form .<str>~ is replaced by the %-rule
  842. Xconstruct s.%.<str>, thereby providing support for the syntax used by SYSV
  843. XAUGMAKE for providing SCCS support.
  844. XWhen enabled, these mappings allow processing of existing SYSV
  845. Xmakefiles without modifications.
  846. X.PP
  847. X.B dmake
  848. Xbases all of its inferences on the inference graph constructed from the
  849. X%-rules defined in the makefile.
  850. XIt knows exactly which targets can be made from which prerequisites by
  851. Xmaking queries on the inference graph.  For this reason .SUFFIXES is not
  852. Xneeded and is completely ignored.
  853. X.PP
  854. XFor a %-meta rule to be inferred as the
  855. Xrule whose recipe will be used to make a target, the target's name must match
  856. Xthe %-target pattern, and any inferred %-prerequisite must already exist or
  857. Xhave an explicit recipe so that the prerequisite can be made.
  858. XWithout \fItransitive closure\fP on the inference graph the above rule
  859. Xdescribes precisely when an inference match terminates the search.
  860. XIf transitive closure is enabled (the usual case), and a prerequisite does
  861. Xnot exist or cannot be made, then
  862. X.B dmake
  863. Xinvokes the inference algorithm recursively on the prerequisite to see if
  864. Xthere is some way the prerequisite can be manufactured.  For, if the
  865. Xprerequisite can be made then the current target can also be made using the
  866. Xcurrent %-meta rule.
  867. XThis means that there is no longer a need to give a rule
  868. Xfor making a .o from a .y if you have already given a rule for making a .o
  869. Xfrom a .c and a .c from a .y.  In such cases
  870. X.B dmake
  871. Xcan infer how to make the
  872. X\&.o from the .y via the intermediary .c and will remove the .c when the .o is
  873. Xmade.  Transitive closure can be disabled by giving the \-T switch on the
  874. Xcommand line.
  875. X.PP
  876. XA word of caution.
  877. X.B dmake
  878. Xbases its transitive closure on the %-meta rule targets.
  879. XWhen it performs transitive closure it infers how to make a target from a
  880. Xprerequisite by performing a pattern match as if the potential prerequisite
  881. Xwere a new target.
  882. XThe set of rules:
  883. X.RS
  884. X.nf
  885. X.sp
  886. X%.o : %.c :; rule for making .o from .c
  887. X%.c : %.y :; rule for making .c from .y
  888. X% : RCS/%,v :; check out of RCS file
  889. X.fi
  890. X.sp
  891. X.RE
  892. Xwill, by performing transitive closure, allow \fBdmake\fP to infer how to make
  893. Xa .o from a .y using a .c as an intermediate temporary file.  Additionally
  894. Xit will be able to infer how to make a .y from an RCS file, as long as that
  895. XRCS file is in the RCS directory and has a name which ends in .y,v.
  896. XThe transitivity computation is performed dynamically for each target that
  897. Xdoes not have a recipe.  This has potential to be costly if the %-meta
  898. Xrules are not carefully specified.  The .NOINFER attribute is used to mark
  899. Xa %-meta node as being a final target during inference.  Any node with this
  900. Xattribute set will not be used for subsequent inferences.  As an example
  901. Xthe node RCS/%,v is marked as a final node since we know that if the RCS file
  902. Xdoes not exist there likely is no other way to make it.  Thus the standard
  903. Xstartup makefile contains an entry similar to:
  904. X.RS
  905. X.nf
  906. X\&.NOINFER : RCS/%,v
  907. X.fi
  908. X.RE
  909. XThereby indicating that the RCS file is the end of the inference chain.
  910. XX
  911. XWhenever the inference algorithm determines that a target can be made from
  912. Xmore than one prerequisite and the inference chains for the two methods
  913. Xare the same length the algorithm reports an ambiguity and prints the
  914. Xambiguous inference chains.
  915. X.PP
  916. X.B dmake
  917. Xtries to
  918. Xremove intermediate files resulting from transitive closure if the file
  919. Xis not marked as being PRECIOUS, or the \fB\-u\fP flag was not given on the
  920. Xcommand line, and if the inferred intermediate did not previously exist.
  921. XIntermediate targets that existed prior to being made are never removed.
  922. XThis is in keeping with the philosophy that
  923. X.B dmake
  924. Xshould never remove things from the file system that it did not add.
  925. XIf the special target .REMOVE is defined and has a recipe then
  926. X.B dmake
  927. Xconstructs a list of the intermediate files to be removed and makes them
  928. Xprerequisites of .REMOVE.  It then makes .REMOVE thereby removing the
  929. Xprerequisites if the recipe of .REMOVE says to.  Typically .REMOVE is defined
  930. Xin the startup file as:
  931. X.sp
  932. X\t.REMOVE :; $(RM) $<
  933. X.SH "MAKING TARGETS"
  934. XIn order to update a target \fBdmake\fP must execute a recipe.
  935. XWhen a recipe needs to be executed it is first expanded so that any macros
  936. Xin the recipe text are expanded, and it is then either executed directly or
  937. Xpassed to a shell.
  938. X.B dmake
  939. Xsupports two types of recipes.  The regular recipes and group recipes.
  940. X.PP
  941. XWhen a regular recipe is invoked \fBdmake\fP executes each line of the recipe
  942. Xseparately using a new copy of a shell if a shell is required.
  943. XThus effects of commands do not generally persist across recipe lines.
  944. X(e.g. cd requests in a recipe line do not carry over to the next recipe line)
  945. XThe decision on whether a shell is required to execute a command is based on
  946. Xthe value of the macro SHELLMETAS or on the specification of '+' or .USESHELL
  947. Xfor the current recipe or target respectively.
  948. XIf any character in the value of
  949. XSHELLMETAS is found in the expanded recipe text-line or the use of a shell
  950. Xis requested explicitly via '+' or .USESHELL then the command is
  951. Xexecuted using a shell, otherwise the command is executed directly.
  952. XThe shell that is used for execution is given by the value of the macro SHELL.
  953. XThe flags that are passed to the shell are given by the value of SHELLFLAGS.
  954. XThus \fBdmake\fP constructs the command line:
  955. X.sp
  956. X\t$(SHELL) $(SHELLFLAGS) $(expanded_recipe_command)
  957. X.sp
  958. XNormally
  959. X.B dmake
  960. Xwrites the command line that it is about to invoke to standard output.
  961. XIf the .SILENT attribute is set for the target or for
  962. Xthe recipe line (via @), then the recipe line is not echoed.
  963. X.PP
  964. XGroup recipe processing is similar to that of regular recipes, except that
  965. Xa shell is always invoked.  The shell that is invoked is given by the value of
  966. Xthe macro GROUPSHELL, and its flags are taken from the value of the macro
  967. XGROUPFLAGS.  If a target has the .PROLOG attribute set then
  968. X.B dmake
  969. Xprepends to the shell script the recipe associated with the special target
  970. X\&.GROUPPROLOG, and if the attribute .EPILOG is set as well, then the recipe
  971. Xassociated with the special target .GROUPEPILOG is appended to the script
  972. Xfile.
  973. XThis facility can be used to always prepend a common header and common trailer
  974. Xto group recipes.
  975. XGroup recipes are echoed to standard output just like standard recipes, but
  976. Xare enclosed by lines beginning with [ and ].
  977. X.PP
  978. XThe recipe flags [+,\-,%,@] are recognized at the start of a recipe line
  979. Xeven if they appear in a macro.  For example:
  980. X.RS
  981. X.sp
  982. X.nf
  983. XSH = +
  984. Xall:
  985. X\t$(SH)echo hi
  986. X.fi
  987. X.sp
  988. X.RE
  989. Xis completely equivalent to writing
  990. X.RS
  991. X.sp
  992. X.nf
  993. XSH = +
  994. Xall:
  995. X\t+echo hi
  996. X.fi
  997. X.sp
  998. X.RE
  999. X.PP
  1000. XThe last step performed by
  1001. X.B dmake
  1002. Xprior to running a recipe is to set the macro CMNDNAME to the name of the
  1003. Xcommand to execute (determined by finding the first white\-space ending token
  1004. SHAR_EOF
  1005. true || echo 'restore of dm37p2 failed'
  1006. fi
  1007. echo 'End of  part 6'
  1008. echo 'File dm37p2 is continued in part 7'
  1009. echo 7 > _shar_seq_.tmp
  1010. exit 0
  1011.  
  1012. exit 0 # Just in case...
  1013. -- 
  1014. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1015. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1016. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1017. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1018.