home *** CD-ROM | disk | FTP | other *** search
/ ftp.cse.unsw.edu.au / 2014.06.ftp.cse.unsw.edu.au.tar / ftp.cse.unsw.edu.au / pub / doc / papers / misc / config-WRPRC-X11R4 / config-X11R4-1.02.ms < prev    next >
Encoding:
Text File  |  1992-10-18  |  53.7 KB  |  1,983 lines

  1. .\" format with
  2. .\" tbl % | xroff -ms | lpr
  3. .\"
  4. .\" revision date - change whenever this file is edited
  5. .ds Rd 1 August 1990
  6. .\" document revision number - change each time document is released
  7. .ds Rn 1.02
  8. .\"
  9. .nr PO 1.2i    \" page offset 1.2 inches
  10. .nr PD .7v    \" inter-paragraph distance
  11. .\"
  12. .EH 'Imake in X11R4'- % -''
  13. .OH ''- % -'Imake in X11R4'
  14. .OF 'Revision date:\0\0\*(Rd'\s+1\*-DRAFT SCRIBBLINGS\*-\s-1'Printed:\0\0\n(dy \*(MO 19\n(yr'
  15. .EF 'Revision date:\0\0\*(Rd'\s+1\*-DRAFT SCRIBBLINGS\*-\s-1'Printed:\0\0\n(dy \*(MO 19\n(yr'
  16. .\"
  17. .de Xw
  18. .ie \\n(Xw \{\
  19. \\$2X Window System\\$1
  20. .\}
  21. .el \{\
  22. \\$2X Window System\(dg\\$1
  23. .FS \(dg
  24. X Window System is a trademark of the Massachusetts Institute of Technology.
  25. .FE
  26. .nr Xw 1 \}
  27. ..
  28. .\"
  29. .\" I - italic font (taken from -ms and changed)
  30. .de I
  31. .nr PQ \\n(.f
  32. .if t \&\\$3\\f2\\$1\\fP\&\\$2
  33. .if n .if \\n(.$=1 \&\\$1
  34. .if n .if \\n(.$>1 \&\\$1\c
  35. .if n .if \\n(.$>1 \&\\$2
  36. ..
  37. .\" start block.  LP gives a bit extra space. Can say .Ds .IP C, etc.
  38. .de Ds
  39. .if \\n(.$<1 .LP
  40. .if \\n(.$>=1 \\$1
  41. .if \\n(.$<2 .DS
  42. .if \\n(.$>=2 .DS \\$2 \\$3 \\$4 \\$5
  43. ..
  44. .\" end block.  If arg is given, it replaces the .LP (e.g., .De .IP).
  45. .de De
  46. .DE
  47. .if \\n(.$<1 .LP
  48. .if \\n(.$>=1 \\$1 \\$2 \\$3 \\$4 \\$5
  49. ..
  50. .TL
  51. Use of Imake in the X Window System
  52. .br
  53. Version 11, Release 4
  54. .AU
  55. Paul DuBois
  56. dubois@primate.wisc.edu
  57. .AI
  58. Wisconsin Regional Primate Research Center
  59. Document revision:\0\0\*(Rn
  60. Revision date:\0\0\*(Rd
  61. .AB
  62. The
  63. .Xw
  64. is a large software project that, despite its size,
  65. is remarkable in its portability.
  66. Much of this is due to the method employed to configure the X
  67. distribution for building and installation: use of a small number of
  68. tools and isolation of machine dependencies into a small number of
  69. files that can be easily maintained and modified.
  70. This document discusses one of those tools,
  71. .I imake ,
  72. and the design of the configuration files used in conjunction with it.
  73. .AE
  74. .NH
  75. Introduction
  76. .LP
  77. This document describes how
  78. .I imake
  79. configuration files are set up in the
  80. .Xw .
  81. It is assumed that you know something about what
  82. .I imake
  83. is supposed to be used for (in general),
  84. and that you're reading this to find out something
  85. about how that is accomplished in X (in particular).
  86. The description applies to X Version 11, release 4 configuration files, which
  87. are organized quite differently than those from release 3.
  88. .LP
  89. Other documentation (from the X11R4 distribution) that you may find useful
  90. includes:
  91. .IP \(bu
  92. Section 2 of ``X Window System, Version 11 Release 4 Release Notes,''
  93. by Jim Fulton.
  94. .IP \(bu
  95. .I mit/doc/config/usenixws/paper.ms :
  96. ``Configuration Management in the X Window System,'' also by Jim Fulton.
  97. .IP \(bu
  98. .I mit/config/README :
  99. ``X Window System Imake Configuration Guide, Release 4.''
  100. .IP \(bu
  101. .I mit/config/imake.man :
  102. manual page for
  103. .I imake .
  104. .IP \(bu
  105. .I mit/util/makedepend/mkdepend.man :
  106. manual page for
  107. .I makedepend .
  108. .IP \(bu
  109. .I contrib/doc/imake/imake.tex :
  110. ``An
  111. .I Imake
  112. Tutorial,'' by Mark Moraes.
  113. .LP
  114. You should also have access to the X configuration files (in
  115. .I mit/config ).
  116. These are not really documentation as such,
  117. but it is expected that you have them at hand, for comparison
  118. against the descriptions below.
  119. .LP
  120. .I imake
  121. is generally conceded to have a pretty steep learning curve.
  122. The
  123. .I README
  124. referred to above notes that
  125. .I imake
  126. ``can be somewhat tricky to master,'' an observation attested to by
  127. many who use it.
  128. There seem to be three camps regarding
  129. .I imake ;
  130. those who think it's wonderful, those who think it's wretched, and those
  131. who suspect it might be useful (else why would it be used to configure
  132. a major publicly-available effort like X?) but are puzzled by it.
  133. The present document was written to fill in some of the gaps in the
  134. existing documentation, in order to try to swell the ranks of the first
  135. group by depleting the membership of the third.
  136. (Those who despise
  137. .I imake \*-members
  138. of the second group\*-have good reasons for doing so and the present
  139. effort is not likely to sway them.)
  140. .LP
  141. This document is independent of the efforts of the MIT X Consortium.
  142. There are no doubt errors lurking within, both of understanding and of fact;
  143. they are my own.
  144. Please send corrections, criticisms and comments to the address above.
  145. .NH
  146. The tools: imake, makedepend, xmkmf
  147. .LP
  148. .I imake
  149. is a configuration tool\*-the main tool used to configure X.
  150. It is not a replacement for the
  151. .I make
  152. program, but it works
  153. in an environment that assumes the availability of
  154. .I make
  155. as the tool used to direct project building and installation.
  156. .I imake
  157. eliminates the need to write
  158. .I Makefiles
  159. directly.
  160. The name means ``include-make''\*-\fIimake\fR
  161. uses the C preprocessor
  162. .I cpp ,
  163. taking advantage of its include-file and macro-processing
  164. facilities for the purpose of generating
  165. .I Makefiles
  166. suitable for
  167. .I make .
  168. .LP
  169. For each directory in the X distribution,
  170. .I imake
  171. reads a bunch of
  172. configuration files that go to a lot of trouble to compensate for and
  173. adjust to the individual characteristics of your system.
  174. These are combined with an
  175. .I Imakefile
  176. from the current directory and the whole mess is sent through
  177. .I cpp
  178. to build a
  179. .I Makefile
  180. there.
  181. The same configuration files are used to build every
  182. .I Makefile ;
  183. they are kept together in
  184. .I mit/config ,
  185. isolating machine dependencies in one location to ease development
  186. and maintenance.
  187. In contrast, the
  188. .I Imakefile
  189. is directory-specific (it specifies the targets to be built in that directory)
  190. and is machine-independent.
  191. .LP
  192. This means that when the distribution is built on a different machine,
  193. only the configuration files need be changed.
  194. The
  195. .I Imakefiles
  196. do not need to be.
  197. If X configuration were specified directly using
  198. .I Makefiles ,
  199. this would not be true.
  200. Because
  201. the configuration information in
  202. .I Makefiles
  203. is not portable, each one would have to be edited individually\*-bad
  204. enough for a single
  205. .I Makefile ,
  206. but an overwhelming prospect for a project the size of X.
  207. .LP
  208. Another tool,
  209. .I makedepend ,
  210. is used to generate dependencies for C source files in each directory
  211. after the
  212. .I Makefile
  213. has been built; the dependencies are tacked onto the end.
  214. .LP
  215. While X is being built,
  216. .I imake
  217. itself is located with the configuration files in
  218. .I mit/config .
  219. .I makedepend
  220. lives in
  221. .I util/makedepend
  222. if you use the compiled version (preferred),
  223. or in
  224. .I util/scripts
  225. if you use the shell script version (slower).
  226. .LP
  227. When X is installed, copies of
  228. .I imake ,
  229. .I makedepend ,
  230. and a related tool,
  231. .I xmkmf ,
  232. are placed in a public directory, and the configuration files are
  233. copied to
  234. .I /usr/lib/X11/config .
  235. .I xmkmf
  236. is used to bootstrap a
  237. .I Makefile
  238. from an
  239. .I Imakefile
  240. using the installed configuration files,\**
  241. .FS
  242. Normally a new
  243. .I Makefile
  244. is produced with ``make Makefile'', an operation that presumes you
  245. already have a properly configured
  246. .I Makefile
  247. containing the rules necessary to run
  248. .I imake .
  249. Hence the bootstrap problem.
  250. Obviously, if you know the proper incantation to utter, you can issue
  251. the appropriate
  252. .I imake
  253. command manually, but
  254. .I xmkmf
  255. eliminates the need.
  256. Besides, the only way you'd know which wand to wave is by having a
  257. reasonable understanding of
  258. .I imake
  259. in the first place\*-in which case you wouldn't be reading this!
  260. .FE
  261. and can be used to build
  262. programs from outside of the X source tree, such as you might write
  263. yourself or get from comp.sources.x on Usenet.
  264. .LP
  265. The X configuration files make very
  266. few assumptions about the capabilities of
  267. .I make
  268. itself.
  269. Although several enhanced versions of
  270. .I make
  271. provide special features or extensions, any
  272. .I Makefile
  273. that relies on universal availability of these features
  274. will fail on systems with less-capable versions of
  275. .I make .
  276. .I Makefiles
  277. produced by
  278. .I imake
  279. in X do not use any of these constructs, so they should work with
  280. even the most lowest-common-denominator
  281. .I make
  282. program.
  283. .LP
  284. Since
  285. .I imake
  286. passes its input through the C preprocessor
  287. .I cpp
  288. to produce a file suitable for
  289. .I make ,
  290. configuration files can be written
  291. to take advantage of several features that may not be present in the
  292. locally-available version of
  293. .I make ,
  294. such as parametrized macros (using #define), file inclusion (using
  295. #include) and conditional testing (using #if, #ifdef, #ifndef).
  296. .LP
  297. Use of
  298. .I cpp
  299. can produce problems, too, of course.
  300. .IP (1)
  301. How to specify comments that should end up in the
  302. .I Makefile .
  303. .I make
  304. comments are introduced by a ``#'' character, but
  305. .I cpp
  306. treats lines beginning with ``#'' as preprocessor directives.
  307. A comment of the form ``# if ...'' is gobbled up by
  308. .I cpp ,
  309. while a comment like
  310. ``# The next rule takes care of...'' generates a
  311. .I cpp
  312. error.
  313. To get around this, comments
  314. should be preceded by ``/**/#'' instead of just ``#''.
  315. .I cpp
  316. will strip off the ``/**/'' (the empty C comment)
  317. and won't treat the line as a directive (though it's
  318. still liable to symbol substitution).
  319. .IP
  320. The exception to this ``comment-commenting'' convention is in the
  321. .I Imakefile
  322. itself, where
  323. .I imake
  324. automatically adds ``/**/'' onto lines beginning with ``#'' that are not
  325. preprocessor directives.
  326. I presume the reason for this is to insulate the end user of
  327. .I imake
  328. (who simply writes the
  329. .I Imakefile
  330. and not the underlying configuration files) from the need to be aware
  331. of, or abide by, the commenting convention.
  332. I would hazard a guess that many people are not aware of this
  333. exception, given the high incidence of
  334. .I Imakefiles
  335. containing ``/**/#''.
  336. .IP
  337. Comments that are to be passed through to the
  338. .I Makefile
  339. can be written as normal C comments (text surrounded by ``/*'' and ``*/'')
  340. and will deleted by
  341. .I cpp .
  342. .IP (2)
  343. Several multiple-line macros are defined that are
  344. intended to produce multiple lines of output.
  345. .I cpp
  346. joins multi-line macros into a single line, so these must be
  347. post-processed.
  348. .IP (3)
  349. Sometimes the values of
  350. .I cpp
  351. symbols are to be concatenated.
  352. The symbol names cannot be concatenated in the configuration files,
  353. because that results in a different symbol name, so they must be kept
  354. apart with an empty C comment.
  355. For instance, if MyDir and MyProgram are defined as
  356. .I /usr/local/
  357. and
  358. .I xprogram ,
  359. respectively, to obtain the concatentation value
  360. .I /usr/local/xprogram
  361. one must write MyDir/**/MyProgram, not MyDirMyProgram.
  362. .NH
  363. Configuration file architecture
  364. .LP
  365. To produce a
  366. .I Makefile
  367. from an
  368. .I Imakefile ,
  369. the following configuration files are used:
  370. .Ds
  371. .ta 1.5i
  372. Imake.tmpl    master template
  373. \fIplatform\fR.cf    platform-specific definitions (the filename varies)
  374. site.def    site-specific definitions
  375. Project.tmpl    X-specific default definitions
  376. Imake.rules    \fIcpp\fR macros to generate \fImake\fR rules
  377. .De
  378. In general,
  379. if a port exists for your system, the only file that you should need to modify
  380. to build and install X is
  381. .I site.def .
  382. In some cases it may be necessary to modify the platform file.
  383. .I Imake.tmpl ,
  384. .I Project.tmpl
  385. and
  386. .I Imake.rules
  387. should be left alone.\**
  388. .FS
  389. It should be emphasized that ``should be left alone'' applies
  390. .I "only when you are building X itself" .
  391. If you are adapting the configuration files for use with another
  392. project, you will probably modify all of them somewhat.
  393. You may even find yourself in the position of having modified them to such
  394. an extent that they end up hacked to bits, incapable of configuring
  395. anything, with you left possessing only the faint hope that something useful
  396. will rise, Phoenix-like, from out of the remains.
  397. Be assured\*-it won't.
  398. But cheer up; start again and learn from your mistakes.
  399. .FE
  400. .LP
  401. If you are porting X to a new platform, you will need to write your
  402. own platform file, and modify the top part of
  403. .I Imake.tmpl
  404. slightly.
  405. If you are doing a new port of X,
  406. .I or
  407. porting the X configuration files for use with a different project, you
  408. are well-advised to study all of the configuration files thoroughly.
  409. Ignorance is not bliss in those instances.
  410. .LP
  411. .I Imake.tmpl
  412. contains an #include line for each of the other four configuration files and
  413. for the
  414. .I Imakefile
  415. in the current directory.
  416. It also contains in-line sections for global constant definitions,
  417. header block selection, description of system characteristics, build
  418. definitions, and extra
  419. .I make
  420. rules.
  421. The template is
  422. structured as follows to make everything fit together:
  423. .LP
  424. .TS
  425. box tab (%) ;
  426. l   l   s   l   l
  427. l   _   _   _   l
  428. l | l   l   s | l
  429. l | l   l   s | l
  430. l | l   _   l | l
  431. l | l | l | l | l
  432. l | l   _   l | l
  433. l | l   _   l | l
  434. l | l | l | l | l
  435. l | l   _   l | l
  436. l | l   l   l | l
  437. l | l   l   l | l
  438. l | l   _   l | l
  439. l | l | l | l | l
  440. l | l   _   l | l
  441. l | l   _   l | l
  442. l | l | l | l | l
  443. l | l   _   l | l
  444. l | l   _   l | l
  445. l | l | l | l | l
  446. l | l   _   l | l
  447. l | l   l   s | l
  448. l   _   _   _   l .
  449. \h'.01i'%Imake.tmpl:%\h'.01i'%\h'.01i'
  450. %
  451. %\h'.01i'%global constants
  452. %%header blocks
  453. %%
  454. %%#include <\fIplatform\fR.cf>
  455. %%
  456. %%
  457. %%#include <site.def>
  458. %%
  459. %%system description
  460. %%build definitions
  461. %%
  462. %%#include <Project.tmpl>
  463. %%
  464. %%
  465. %%#include <Imake.rules>
  466. %%
  467. %%
  468. %%#include "./Imakefile"
  469. %%
  470. %%extra \fImake\fR rules
  471. %
  472. .TE
  473. .LP
  474. Before these sections of the template are described, there are some general
  475. principles that should be kept in mind.
  476. .LP
  477. Much of the flexibility of the X configuration files is achieved
  478. through the use of the following construct, which defines
  479. .I symbol
  480. only if it has not already been defined:
  481. .Ds
  482. #ifndef \fIsymbol\fR
  483. #define \fIsymbol value\fR
  484. #endif
  485. .De
  486. This construct allows any system-, build- or project-related symbol to
  487. be given a default definition if none has been supplied earlier;
  488. coupled with support for inclusion of platform- and site-specific
  489. files prior to the section in which the default is defined,
  490. the default may be overridden
  491. by a definition occurring within those files.
  492. For example, the default for the C compiler symbol occurs in the build
  493. definitions section of
  494. .I Imake.tmpl
  495. and is defined thus:
  496. .Ds
  497. #ifndef CcCmd
  498. #define CcCmd cc
  499. #endif
  500. .De
  501. If the GNU C compiler is to be used instead, the default definition
  502. can be overridden
  503. simply by putting the following in
  504. .I site.def :
  505. .Ds
  506. #ifndef CcCmd
  507. #define CcCmd gcc
  508. #endif
  509. .De
  510. Use of the #ifndef/#endif construct is pervasive throughout the X11R4
  511. configuration files, to a much greater extent than in the X11R3 files.
  512. This is especially true in the platform-specific files.
  513. .LP
  514. A fairly consistent pattern followed within the files included by
  515. .I Imake.tmpl
  516. (and within the system/build section of
  517. .I Imake.tmpl
  518. itself) is that definitions for
  519. .I cpp
  520. symbols are listed, followed by definitions for
  521. .I make
  522. variables.
  523. I presume this is done because there is greater flexibility
  524. available in defining
  525. .I cpp
  526. symbols, e.g., through #ifndef conditional testing.
  527. Since
  528. .I cpp
  529. can't tell whether a
  530. .I make
  531. variable has previously been defined, the strategy adopted is to associate a
  532. .I cpp
  533. symbol with a given
  534. .I make
  535. variable, define the symbol conditionally to allow the possibility of
  536. overriding, then equate the
  537. variable to whatever value the symbol ends up with.
  538. For instance,
  539. .I Imake.tmpl
  540. contains:
  541. .Ds
  542. #ifndef CcCmd
  543. #define CcCmd cc
  544. #endif
  545. .sp .3v
  546. \&. . .
  547. .sp .3v
  548. CC = CcCmd
  549. .De
  550. If no earlier definition of CcCmd overrides the default (e.g., in
  551. .I site.def ),
  552. CC ends up as
  553. ``cc''.
  554. On the other hand, if the default is overridden, e.g., to use ``gcc''
  555. instead, CC ends up as ``gcc''.
  556. .LP
  557. Sometimes ``mixed'' symbol definitions occur, in which
  558. .I cpp
  559. symbols are defined in terms of
  560. .I make
  561. variables.
  562. There are at least two reasons to do this.
  563. .IP (1)
  564. To avoid order-of-definition problems.
  565. Consider the two sets of definitions below.
  566. .Ds
  567. .ta 3i
  568. #ifndef a    #ifndef a
  569. #define a b    #define a ${B}
  570. #endif    #endif
  571. A = a    A = a
  572. .sp .3v
  573. \&. . .    . . .
  574. .sp .3v
  575. #ifndef b    #ifndef b
  576. #define b z    #define b z
  577. #endif    #endif
  578. B = b    B = b
  579. .De .IP
  580. What ends up in the
  581. .I Makefile
  582. is:
  583. .Ds
  584. .ta 3i
  585. A = b    A = ${B}
  586. B = z    B = z
  587. .De .IP
  588. The example on the left defines a (and hence A) in terms of
  589. a symbol that hasn't been defined yet; both get the value of a
  590. literal ``b''.
  591. The example on the right works; b is defined as ``z'', B gets
  592. the same value.
  593. A becomes ``${B}'', which is not evaluated further until
  594. .I make
  595. is run.
  596. At that time A evaluates properly to ``z''\*-independently of the order in
  597. which a and b are defined in the configuration file.
  598. .IP (2)
  599. To allow for greater flexibility at installation time.
  600. For example, UsrLibDir and USRLIBDIR are defined as:
  601. .Ds
  602. #ifndef UsrLibDir
  603. #define UsrLibDir $(DESTDIR)/usr/lib
  604. #endif
  605. .sp .3v
  606. \&. . .
  607. .sp .3v
  608. USRLIBDIR = UsrLibDir
  609. .De .IP
  610. Symbols such as IncRoot, BinDir, AdmDir are defined similarly, even
  611. though DestDir (to which DESTDIR is eventually equated) is defined
  612. earlier (i.e., there is no order-of-definition problem here).
  613. If a user wants the install to take place under a different root than
  614. DestDir, the command ``make DESTDIR=/alternate/root install''
  615. suffices, by overriding the definition of DESTDIR in the
  616. .I Makefile .
  617. If UsrLibDir, etc., were defined directly in terms of DestDir rather
  618. than DESTDIR, this would not be possible.\**
  619. .FS
  620. Actually, it would be possible, but rather cumbersome: ``make
  621. BINDIR=/alt/bin/dir ADMDIR=/alt/adm/dir LIBDIR=/alt/lib/dir ...
  622. install''
  623. .FE
  624. .LP
  625. Each of the sections of
  626. .I Imake.tmpl
  627. is described below.
  628. The descriptions only contain representative examples of the symbols
  629. used in each configuration file.
  630. For exhaustive lists, consult the appendix.
  631. .NH 2
  632. Global constant definitions
  633. .LP
  634. This section of
  635. .I Imake.tmpl
  636. defines two symbols (YES as 1 and NO as 0).
  637. References to these symbols are legion
  638. throughout the rest of the configuration
  639. specification and their values should not be changed.
  640. .LP
  641. Note: symbols #define'd in the configuration files or the
  642. .I Imakefile
  643. have nothing to do with symbols #define'd in your programs; they
  644. are entirely independent.
  645. .NH 2
  646. Header block selection
  647. .LP
  648. The header block section of
  649. .I Imake.tmpl
  650. determines the type of machine on which
  651. .I imake
  652. is being run.
  653. This is done by looking for a
  654. .I trigger \*-a
  655. .I cpp
  656. preprocessor symbol that uniquely and unambiguously indicates a given platform.
  657. For instance, ``ultrix'' is defined only on Ultrix systems,
  658. ``sun'' only on Sun systems.
  659. The symbol might be predefined by
  660. .I cpp
  661. itself; if no such predefined symbol is available,\**
  662. .FS
  663. A goal ANSI C will help us reach?
  664. .FE
  665. .I imake
  666. is built to explicitly pass a definition for one to
  667. .I cpp .
  668. .LP
  669. A header block is selected if its trigger symbol is defined.
  670. If no trigger is defined, a generic configuration
  671. header block is selected instead.
  672. Since that means the platform wasn't
  673. properly determined, a warning is written into the
  674. .I Makefile :
  675. .Ds
  676. # WARNING:  Imake.tmpl not configured; guessing at definitions!!!
  677. # This might mean that BOOTSTRAPCFLAGS wasn't set when building imake.
  678. .De
  679. The resulting generically-configured
  680. .I Makefile
  681. will probably fail in one of a number of strange and wondrous ways, when
  682. used to try to build anything,
  683. With any luck, the hapless user will examine the
  684. .I Makefile
  685. to figure out
  686. what went wrong, see the warning, and realize that the platform wasn't
  687. determined properly.
  688. .LP
  689. Failure to determine the platform might occur because no port exists for
  690. the machine in question, and thus no header block exists.
  691. (Each time X is ported to a new platform, a new header block is added
  692. to this section of
  693. .I Imake.tmpl .)
  694. Failure will also occur if
  695. .I imake
  696. was not built properly (i.e., it doesn't pass the
  697. proper trigger symbol definition to
  698. .I cpp ).
  699. .LP
  700. Assuming the proper header block is triggered, several
  701. things happen inside of it.
  702. The name of the associated platform-specific
  703. .I .cf
  704. file is defined for later inclusion by the template; one or more architecture
  705. indicator symbols are defined that can be used
  706. by later configuration sections
  707. to test for particular software or hardware platforms; and
  708. the trigger symbol is undefined so it won't trigger any other header
  709. block.
  710. The Ultrix, Sun and Apollo header blocks look like this:
  711. .Ds
  712. .ta 3i
  713. \fBUltrix:\fR    \fBSun:\fR
  714. #ifdef ultrix    #ifdef sun
  715. #define MacroIncludeFile <ultrix.cf>    #define MacroIncludeFile <sun.cf>
  716. #define MacroFile ultrix.cf    #define MacroFile sun.cf
  717. #ifdef vax    #undef sun
  718. #undef vax    #define SunArchitecture
  719. #define VaxArchitecture    #endif /* sun */
  720. #endif
  721. #ifdef mips    \fBApollo:\fR
  722. #undef mips    #ifdef apollo
  723. #define MipsArchitecture    #define MacroIncludeFile <apollo.cf>
  724. #endif    #define MacroFile apollo.cf
  725. #undef ultrix    #undef apollo
  726. #define UltrixArchitecture    #define ApolloArchitecture
  727. #endif    #endif /* apollo */
  728. .De
  729. A header block may define a single architecture indicator symbol to refer
  730. both to the software and hardware,
  731. or separate indicators may be defined for an operating system that
  732. runs on multiple hardware types,
  733. For example, ``ultrix'' indicates an Ultrix system, but it is no longer
  734. true (as it once was) that a VAX can be assumed as the hardware
  735. platform\*-RISC Ultrix systems run on MIPS chips now.
  736. Thus UltrixArchitecture is defined as the software indicator symbol, and
  737. VaxArchitecture or MipsArchitecture as the hardware indicator.
  738. .LP
  739. Software indicator symbols should be unique.
  740. Hardware indicator symbols are not necessarily unique in themselves
  741. and may be shared across different software
  742. platforms, e.g., MipsArchitecture can be defined for Ultrix or SGI systems,
  743. VaxArchitecture for Ultrix or BSD systems.
  744. .LP
  745. The use of predefined or
  746. .I imake -supplied
  747. .I cpp
  748. trigger symbols is fraught with peril, and one must construct the
  749. header blocks carefully, for two reasons:
  750. .IP (1)
  751. Symbols may be ambiguous.
  752. For instance, ``vax'' is defined both under Ultrix and under BSD.
  753. Thus, the Ultrix header block must come first.
  754. It tests for ``ultrix'' and if that succeeds, defines UltrixArchitecture
  755. and undefines ``vax'' so the BSD block will fail.
  756. .IP (2)
  757. Symbols may become ambiguous in unanticipated ways in the
  758. future.
  759. The ``mips'' symbol is an example.
  760. In R3 it was used to unambiguously detect a true MIPS machine.
  761. This can no longer be done given the presence of that symbol on other
  762. systems that also run on MIPS chips now.
  763. .LP
  764. With respect to future ports of X to other platforms, it is sometimes
  765. difficult to know either what the trigger symbol should be, or what
  766. indicator symbol(s) to use.
  767. Consider MIPS machines running RISC/os.
  768. ``mips'' is insufficient as a trigger, because it is does not
  769. unambiguously define MIPS systems.
  770. The hardware indicator symbol is clear enough, MipsArchitecture, but
  771. the software indicator is less so.
  772. The name of the MIPS operating system suggests that
  773. RiscosArchitecture might be a good choice.
  774. Guess again.
  775. Acorn Computers Ltd. has an OS with a similar name, ``RISC OS''.
  776. .LP
  777. My own preference is to use ``mipsriscos'' as the trigger symbol,
  778. MipsArchitecture as the hardware indicator,
  779. and MipsRiscosArchitecture
  780. (which seems suitably unique, but has the disadvantage of being quite
  781. long, and uneuphonious to boot) as the software indicator.
  782. .NH 2
  783. platform.cf
  784. .LP
  785. After the header block section has determined which platform-specific
  786. file to use, that file is then included by
  787. .I Imake.tmpl :
  788. .Ds
  789. /**/################################################################
  790. /**/# platform-specific configuration parameters - edit MacroFile to change
  791. #include MacroIncludeFile
  792. .De
  793. where MacroIncludeFile has been defined properly by the header block.
  794. .LP
  795. The platform file contains definitions needed to make X build and
  796. install correctly on a particular system.
  797. Some common things found here are definitions for the operating
  798. system name version numbers (major and minor), C compiler version
  799. numbers, and workarounds for missing commands.
  800. But these files are, overall, really quite a hodgepodge of different things,
  801. and it is difficult to describe them in any general way.
  802. You really should read through the
  803. .I .cf
  804. file for your system before you try to compile anything, to get an
  805. idea what can be done with it.
  806. (It doesn't hurt to read
  807. .I all
  808. the
  809. .I .cf
  810. files, as a matter of fact.)
  811. .LP
  812. It is important that version numbers in the platform file
  813. accurately reflect your system.
  814. Some symbol definitions are contingent upon the OS or C
  815. compiler version, to accommodate system changes, deficiencies, or
  816. bugs, so you want to make sure you get the right definitions.
  817. For example,
  818. .I sun.cf
  819. contains the following:
  820. .Ds
  821. #if OSMajorVersion <= 3
  822. #define HasVoidSignalReturn NO
  823. #else
  824. #define HasVoidSignalReturn YES
  825. #endif
  826. .De
  827. Evidently the return type of the
  828. .I signal()
  829. system call on Sun systems changed from int to void beginning with SunOS 4.0.
  830. .LP
  831. A common command missing command workaround occurs for those systems
  832. that have no BSD-compatible
  833. .I install
  834. command, such as in
  835. .I cray.cf :
  836. .Ds
  837. #define InstallCmd sh $(SCRIPTSRC)/install.sh
  838. .De
  839. It is important to set the value of the SystemV symbol to either YES or NO
  840. in the platform file because
  841. (1) the value of parameters defined in
  842. .I site.def
  843. may depend on it, and the default value is not set until
  844. the system/build definition section (i.e., after
  845. .I site.def );
  846. (2)
  847. the default values of many parameters in later parts of the template
  848. depend on the value of SystemV.
  849. For instance, there is usually no
  850. .I ranlib
  851. under System V, so the default is defined as a no-op:
  852. .Ds
  853. #ifndef RanlibCmd
  854. #if SystemV
  855. #define RanlibCmd /bin/true
  856. #else
  857. #define RanlibCmd ranlib
  858. #endif
  859. #endif
  860. .De
  861. It is perhaps safer to rely on predefined
  862. .I cpp
  863. symbols (should they exist)
  864. in the platform-specific files than in the header block section of
  865. .I Imake.tmpl
  866. since the universe of such
  867. symbols is more constrained there and, since you know the system type,
  868. they will not clash with symbols defined on other vendors' systems.
  869. .LP
  870. The platform files were significantly reorganized between R3 and R4.
  871. In R3, each platform file was expected to contain a definition for
  872. each of the build parameters (C compiler, loader, link command,
  873. etc.).
  874. Whenever a change was made that affected one platform file, it usually
  875. affected them all.
  876. Since the definitions were usually broadly similar across platforms,
  877. this was more work than necessary.
  878. The approach adopted in R4 is to supply best-guess values as the
  879. default definitions for these parameters in the template, which
  880. individual platform files may override as necessary.
  881. This set of defaults defines a baseline configuration.
  882. There are two advantages to this method.
  883. The platform files need only specify where they
  884. .I differ
  885. from the baseline, by overriding the default definitions; and changes or
  886. additions to the baseline do not necessarily require all platform files to
  887. be changed.
  888. .NH 2
  889. site.def
  890. .LP
  891. This file contains site-specific definitions.
  892. It is used to reflect local site-wide conventions, at least in
  893. theory.
  894. Should you wish to override the defaults,
  895. this is the place to indicate installation directories, whether to
  896. build the server and example programs, any special versions of
  897. programs to use during the build, etc.
  898. .LP
  899. The name
  900. .I site.def
  901. seems, to me at least, something of a misnomer.
  902. For instance, one of the things that is likely to be set there
  903. is HasLargeTmp, to indicate whether you have a large temp file
  904. directory.
  905. .I site.def
  906. is the place for this definition (it depends on your particular
  907. file system layout, so it doesn't go in the platform-specific file,
  908. and it's not
  909. .I cpp -guessable,
  910. so it doesn't go in the system description section).
  911. But a ``site'' can be a location at which multiple hosts
  912. are administered, and which may be configured dissimilarly.
  913. Some may have a large temp directory, others may not.
  914. Similarly,
  915. .I site.def
  916. is the logical place to specify that you want to use the GNU C
  917. compiler,
  918. but you might not necessarily want to use it on all hosts at a site.
  919. In some ways
  920. .I host.def
  921. might be a better name for this file.
  922. .NH 2
  923. System description and build parameter definitions
  924. .LP
  925. The platform- and site-specific files are followed by a section containing
  926. a number of default definitions.
  927. Generally, these describe system characteristics
  928. (e.g., does it have
  929. .I vfork() ?
  930. does it have sockets?) or are related to management of the
  931. build and installation\**
  932. .FS
  933. Viz.,
  934. .I how
  935. things should be installed, not
  936. .I where ;
  937. defaults for the latter are in
  938. .I Project.tmpl .
  939. .FE
  940. processes (e.g., what is the name of the C compiler?
  941. does the loader need any special flags?).
  942. These are not X issues and so are segregated into their own section.
  943. .LP
  944. This section of
  945. .I Imake.tmpl
  946. should not be modified; definitions should be overridden
  947. in platform- or site-specific files.
  948. .NH 2
  949. Project.tmpl
  950. .LP
  951. This
  952. file contains definitions for parameters that are specific to X.
  953. Examples: whether to build debuggable versions of libraries, what the
  954. screen resolution is, what sorts of connections to accept (UNIX, TCP
  955. or DECnet sockets), where programs or libraries should be installed.
  956. .LP
  957. A number of the
  958. .I make
  959. variables in
  960. .I Project.tmpl
  961. are directory locations.
  962. Most of them are named in one of two ways, \fIXXX\fRDIR or \fIXXX\fRSRC.
  963. Variables of the first form are defined by equating them with
  964. .I cpp
  965. symbols having similar names (e.g., LIBDIR=LibDir).
  966. The
  967. .I cpp
  968. symbols are defined in the usual default-provided-but-override-allowed
  969. manner.
  970. This is because these variables refer to where things are to be placed
  971. at installation time, something which the installer might wish to
  972. change.
  973. .LP
  974. Variables of the second form, \fIXXX\fRSRC, indicate the layout of various
  975. source directories within the X distribution.
  976. They are not supposed to be changed, so there is no provision for
  977. overriding them; they are simply defined
  978. directly (e.g., SERVERSRC=$(TOP)/server), rather than being equated to
  979. .I cpp
  980. symbols.
  981. .LP
  982. .I Project.tmpl
  983. should not be modified; definitions should be overridden
  984. in platform- or site-specific files.
  985. .NH 2
  986. Imake.rules
  987. .LP
  988. This file contains
  989. .I cpp
  990. macros used to generate (sometimes quite complicated)
  991. .I make
  992. rules from concise descriptions of targets and dependencies.
  993. Since all the
  994. .I cpp
  995. symbol substitution functionality is available, these macros can be
  996. very powerful.
  997. On the other hand, the syntax used to express them is somewhat
  998. strange, in order to keep
  999. .I cpp
  1000. from totally destroying the usefulness of the output for
  1001. .I make
  1002. purposes.
  1003. In fact, one of the functions of
  1004. .I imake
  1005. is to undo some of the damage done by
  1006. .I cpp ;
  1007. an uneasy alliance indeed.
  1008. .LP
  1009. Rules may be defined over multiple lines by appending ``\e'' to the
  1010. end of all lines but the last.
  1011. Since
  1012. .I cpp
  1013. collapses all multi-line macros into a single line, a special trick is
  1014. used to allow
  1015. .I imake
  1016. to post-process
  1017. .I cpp
  1018. output to figure out where to put the newlines back so that proper
  1019. .I make
  1020. syntax is preserved:
  1021. ``@@'' in a rule is replaced by a newline in the resulting
  1022. .I Makefile .\**
  1023. .FS
  1024. This all seems quite natural and obvious, now that I have worked
  1025. with these things for a while.
  1026. I remember, though, that the first few times I looked at the X
  1027. .I imake
  1028. rules, especially the more complicated ones,
  1029. the formatting and syntax seemed so bizarre to me that
  1030. a switch flipped in my brain, which then refused to comprehend
  1031. anything at all.
  1032. Repeated exposure gradually inured me to the infelicities of the
  1033. syntax.
  1034. .FE
  1035. .LP
  1036. .B Example:
  1037. A simple rule to compile a program might be (this isn't an actual X
  1038. rule):
  1039. .Ds
  1040. .ta .5i +4i
  1041. # define CompileProgram(program,objects,libraries)    @@\e
  1042. program: objects    @@\e
  1043.     c \-o program objects libraries
  1044. .De
  1045. If invoked in an
  1046. .I Imakefile
  1047. as:
  1048. .Ds
  1049. CompileProgram (xproga, main.o, \-lm)
  1050. .De
  1051. this would expand in the
  1052. .I Makefile
  1053. to:
  1054. .Ds
  1055. .ta .5i
  1056. xproga: main.o
  1057.     cc \-o xproga main.o \-lm
  1058. .De
  1059. If invoked as:
  1060. .Ds
  1061. CompileProgram (xprogb, main.o parse.o scan.o, \-lm \-ll \-ly)
  1062. .De
  1063. this would expand to:
  1064. .Ds
  1065. .ta .5i
  1066. xproga: main.o parse.o scan.o
  1067.     cc \-o xproga main.o parse.o scan.o \-lm \-ll \-ly
  1068. .De
  1069. .LP
  1070. All the rules in
  1071. .I Imake.rules
  1072. are defined using the standard override
  1073. construct:
  1074. .Ds
  1075. #ifndef \fIrulename\fR
  1076. #define \fIrulename\fR ...
  1077. #endif
  1078. .De
  1079. Thus, even rules are subject to being overridden (something that was
  1080. not true in R3).
  1081. If a rule needs to be overridden for a particular platform,
  1082. the default definition will be placed in the
  1083. platform-specific
  1084. file (\fIsgi.cf\fR does this).
  1085. If a rule only needs redefining in a single directory, it may be
  1086. better to undefine it and redefine right it in that directory's
  1087. .I Imakefile
  1088. (see
  1089. .I mit/config/Imakefile
  1090. for an example).
  1091. .LP
  1092. .I Imake.rules
  1093. should not be modified; definitions should be overridden
  1094. in platform- or site-specific files.
  1095. .NH 2
  1096. \&./Imakefile
  1097. .LP
  1098. The last file included by the template is the
  1099. .I Imakefile
  1100. from the current directory.
  1101. As already mentioned,
  1102. .I make
  1103. comments in this file are made
  1104. .I cpp -safe
  1105. by preceding them with ``/**/'' if necessary.
  1106. The
  1107. .I Imakefile
  1108. indicates targets to be built and installed, and their
  1109. dependencies, in terms of the
  1110. .I cpp
  1111. macros defined in
  1112. .I Imake.rules .
  1113. There may also be targets for generating dependencies, creating
  1114. installation directories, creating lint libraries or tag files, etc.
  1115. .LP
  1116. .I Imakefile -writing
  1117. is described in more detail in a later section.
  1118. .NH 2
  1119. Extra make rules
  1120. .LP
  1121. The last section of
  1122. .I Imake.tmpl
  1123. adds some common targets to the
  1124. .I Makefile ,
  1125. such as a ``Makefile'' target to regenerate the
  1126. .I Makefile
  1127. itself, and a default ``clean'' target.
  1128. If the directory has subdirectories, rules to
  1129. recurse through them for the ``install'', ``install.man'', ``clean'',
  1130. ``tags'', ``Makefiles'' and ``includes'' targets are generated.
  1131. These rules are added if
  1132. IHaveSubdirs is defined and SUBDIRS is equated to the list of
  1133. subdirectories in the
  1134. .I Imakefile .
  1135. .NH
  1136. Building imake
  1137. .LP
  1138. Before you can build any part of X,
  1139. .I imake
  1140. itself must be built.
  1141. ``make World'' in the top-level X directory builds
  1142. .I imake
  1143. automatically (in
  1144. .I mit/config );
  1145. the following discussion explains what happens during that process.
  1146. You want to read this section if ``make World'' dies when you try it, or you
  1147. want to port X to another platform,
  1148. or you want to build
  1149. .I imake
  1150. or adapt the X configuration files for use with other projects.
  1151. It is best if you are willing to look at the following files during
  1152. this section:
  1153. .I Makefile.ini ;
  1154. .I imakemdep.h ;
  1155. .I ccimake.c ;
  1156. .I imake.c .
  1157. .NH 2
  1158. What you are going to do
  1159. .LP
  1160. When you build
  1161. .I imake
  1162. you want to
  1163. (1) get it to compile successfully, so you can use it;
  1164. (2) guarantee that it makes sure
  1165. .I cpp
  1166. knows the trigger symbol\*-whether
  1167. .I cpp
  1168. predefines it or not\*-so you don't end up with generically-configured
  1169. .I Makefiles .
  1170. .LP
  1171. Dilemma #1:
  1172. .I imake
  1173. generates
  1174. .I Makefiles
  1175. for use in compiling programs;
  1176. .I imake
  1177. is compiled using a
  1178. .I Makefile .
  1179. .LP
  1180. Dilemma #2:
  1181. .I imake
  1182. needs to know the trigger symbol in order to pass it along to
  1183. .I cpp
  1184. for proper
  1185. .I Makefile
  1186. generation.
  1187. But
  1188. .I imake
  1189. doesn't know the trigger itself if neither
  1190. .I cc
  1191. nor
  1192. .I cpp
  1193. predefine it.
  1194. .LP
  1195. Dilemma #3:
  1196. Some systems require special C compiler flags to ensure proper
  1197. compilation of all but the most trivial prorgrams.
  1198. One of the facilities provided by
  1199. .I imake -generated
  1200. .I Makefiles
  1201. is that these flags can be automatically specified.
  1202. That doesn't help when the program to be compiled is
  1203. .I imake \*-which
  1204. happens to be just such a non-trivial program itself.
  1205. .LP
  1206. The solution to the first dilemma is to use a handwritten minimal file
  1207. .I Makefile.ini
  1208. instead.\**
  1209. .FS
  1210. There might be a
  1211. .I Makefile
  1212. in
  1213. .I mit/config
  1214. already,
  1215. but it might not have been generated on your system, so it's not safe to
  1216. use.
  1217. .FE
  1218. You might need to hack
  1219. .I Makefile.ini
  1220. file slightly for your system\*-but only slightly.
  1221. If you find yourself making large changes, that is a symptom you don't
  1222. understand what you're supposed to be doing.\**
  1223. .FS
  1224. Or a symptom that I've not explained very clearly what is supposed to
  1225. happen...
  1226. .FE
  1227. Stop and think some more first.
  1228. .LP
  1229. The second and third dilemmas are solved by manually passing the trigger symbol
  1230. to the
  1231. .I imake
  1232. compilation and using a small bootstrap program that knows what
  1233. special flags are necessary to get
  1234. .I imake
  1235. to compile without error.
  1236. The commands in
  1237. .I Makefile.ini
  1238. that build
  1239. .I imake
  1240. look something like this:\**
  1241. .FS
  1242. The commands actually use CFLAGS, but that is defined in
  1243. .I Makefile.ini
  1244. as ``CFLAGS = $(BOOTSTRAPCFLAGS) $(CDEBUGFLAGS)''; you get the idea.
  1245. .FE
  1246. .Ds
  1247. $(CC) \-o ccimake $(BOOTSTRAPCFLAGS) $(CDEBUGFLAGS) ccimake.c
  1248. $(CC) \-o imake $(BOOTSTRAPCFLAGS) $(CDEBUGFLAGS) imake.c `./ccimake`
  1249. .De
  1250. BOOTSTRAPCFLAGS is a
  1251. .I make
  1252. variable that is used to pass the trigger symbol definition for your
  1253. system to
  1254. .I ccimake
  1255. and
  1256. .I imake
  1257. so they know the platform type.
  1258. .I ccimake
  1259. is the bootstrap program used to figure out any extra flags needed to
  1260. get
  1261. .I imake
  1262. to compile.
  1263. It is\*-by design\*-so simple that it should compile
  1264. without any special treatment.
  1265. .LP
  1266. BOOTSTRAPCFLAGS is supplied to the
  1267. .I ccimake
  1268. build so it can select the necessary flags, based on the trigger.
  1269. Compiled with those flags, and
  1270. the trigger value supplied in BOOTSTRAPCFLAGS,
  1271. .I imake
  1272. builds correctly, and learns and memorizes the trigger symbol for
  1273. itself, to pass along to
  1274. .I cpp .
  1275. That in turn allows
  1276. .I cpp
  1277. to properly determine the correct header block in
  1278. .I Imake.tmpl
  1279. when
  1280. .I Makefiles
  1281. are generated.
  1282. .NH 2
  1283. Lay the groundwork
  1284. .LP
  1285. First, you need to determine what the trigger symbol is for your system,
  1286. as well as the value of BOOTSTRAPCFLAGS.
  1287. For existing ports, you can find out the trigger symbol by
  1288. examining the header block section of
  1289. .I Imake.tmpl .
  1290. The value of BOOTSTRAPCFLAGS can be found in the platform
  1291. .I .cf
  1292. file for your system.
  1293. Look for a line that defines BootstrapCFlags; if
  1294. .I cpp
  1295. predefines the trigger, there will likely be no such line.
  1296. This means BOOTSTRAPCFLAGS is empty.
  1297. Otherwise the value will be something like ``\-D\fItrigger\fR'', e.g.,
  1298. ``\-DmacII'', ``\-Datt'', ``\-Daix''.
  1299. .LP
  1300. For new ports, you need to invent a trigger symbol
  1301. that uniquely identifies your system and define
  1302. BOOTSTRAPCFLAGS accordingly.
  1303. Suppose you have a Brand X system.
  1304. You can use ``brandx'' as the trigger and ``\-Dbrandx'' for
  1305. BOOTSTRAPCFLAGS.
  1306. You also must modify
  1307. .I imakemdep.h .
  1308. .LP
  1309. .I imakemdep.h
  1310. is #include'd by three programs,
  1311. .I ccimake ,
  1312. .I imake
  1313. and
  1314. .I makedepend ,
  1315. and has one section for each.
  1316. .LP
  1317. The first section of
  1318. .I imakemdep.h
  1319. pertains to
  1320. .I ccimake ;
  1321. it consists of a bunch of #ifdef/#endif blocks that define
  1322. .I imake_ccflags
  1323. according to the trigger symbol.
  1324. .I imake_ccflags
  1325. is defined as the flags needed to compile
  1326. .I imake
  1327. on your platform.
  1328. For instance, if your Brand X system is System V-based, you need to
  1329. specify that:
  1330. .Ds
  1331. #ifdef brandx
  1332. #define imake_ccflags "\-DSYSV"
  1333. #endif
  1334. .De
  1335. .I ccimake
  1336. simply writes the value of
  1337. .I imake_ccflags
  1338. to its standard output.
  1339. Common flags in this definition are \-DSYSV or \-DUSG to indicate System
  1340. V or USG systems.
  1341. Other flags might also be necessary\*-see the ``hpux'' and ``umips''
  1342. blocks for some particularly unpleasant examples.
  1343. If no special flags are necessary to compile
  1344. .I imake
  1345. (e.g., under Ultrix or BSD),
  1346. there does not need to be any block for your trigger symbol, and
  1347. .I ccimake
  1348. simply writes out a default definition of
  1349. .I imake_ccflags
  1350. (currently \-O).
  1351. .LP
  1352. You might have to fool around trying to compile
  1353. .I imake
  1354. by hand to determine the correct flags before you know how to define
  1355. .I imake_ccflags .
  1356. .LP
  1357. The second section of
  1358. .I imakemdep.h
  1359. is for
  1360. .I imake .
  1361. It too has a set of #ifdef/#endif blocks, this time to select a
  1362. trigger symbol definition based on the trigger symbol.
  1363. That sounds circular and it is.
  1364. These blocks add entries to
  1365. .I cpp_argv [\|],
  1366. which is an array of strings to be passed to
  1367. .I cpp
  1368. by
  1369. .I imake .
  1370. If your
  1371. .I cpp
  1372. predefines the correct trigger symbol automatically, you don't need to
  1373. do anything to this.
  1374. Otherwise, this is where you want your trigger symbol to be listed,
  1375. and there should be a block something like this:
  1376. .Ds
  1377. #ifdef brandx
  1378.         "\-Dbrandx",        /* for Brand X systems */
  1379. #endif
  1380. .De
  1381. This causes
  1382. .I imake
  1383. to pass ``\-Dbrandx'' to
  1384. .I cpp
  1385. to make it simulate predefinition of the trigger.
  1386. When
  1387. .I cpp
  1388. reads the configuration files the trigger will have been defined and
  1389. the correct header block in
  1390. .I Imake.tmpl
  1391. will be selected.
  1392. .LP
  1393. Following the sections for
  1394. .I ccimake
  1395. and
  1396. .I imake ,
  1397. .I imakemdep.h
  1398. contains a third section for
  1399. .I makedepend
  1400. (the compiled version; if you use the shell script version of
  1401. .I makedepend
  1402. in
  1403. .I mit/util/scripts ,
  1404. this section of
  1405. .I imakemdep.h
  1406. is irrelevant).
  1407. It looks for various system- and compiler-related definitions that may
  1408. be predefined by
  1409. .I cc
  1410. and/or
  1411. .I cpp .
  1412. .I makedepend
  1413. uses this information to be smart.
  1414. Consider the following C program fragment:
  1415. .Ds
  1416. #ifdef ultrix
  1417. #include "inca.h"
  1418. #else
  1419. #include "incb.h"
  1420. #endif /* ultrix */
  1421. .De
  1422. If ``ultrix'' is defined,
  1423. .I makedepend
  1424. knows to generate a dependency for ``inca.h'' and not
  1425. ``incb.h'';
  1426. a dumb
  1427. .I makedepend
  1428. has to to assume dependencies on both.
  1429. .LP
  1430. It's easiest simply to leave this section of
  1431. .I imakemdep.h
  1432. alone.
  1433. .NH 2
  1434. Build the program
  1435. .LP
  1436. You're ready to begin (this should actually be simple if you've done
  1437. the above correctly).
  1438. The first thing to do is ensure the absence of any detritus that might
  1439. be laying around from previous builds:
  1440. .Ds
  1441. make \-f Makefile.ini clean
  1442. .De
  1443. Then build
  1444. .I ccimake
  1445. and
  1446. .I imake .
  1447. If your
  1448. .I cpp
  1449. predefines the trigger, you can build with:
  1450. .Ds
  1451. make \-f Makefile.ini
  1452. or
  1453. make \-f Makefile.ini BOOTSTRAPCFLAGS=
  1454. .De
  1455. Otherwise, specify the trigger explicitly.
  1456. E.g., for Brand X, use:
  1457. .Ds
  1458. make \-f Makefile.ini BOOTSTRAPCFLAGS=\-Dbrandx
  1459. .De .NH 2
  1460. Test your handiwork
  1461. .LP
  1462. If
  1463. .I imake
  1464. is supposed to pass a trigger symbol definition to
  1465. .I cpp ,
  1466. you should test whether it actually does or not with:
  1467. .Ds
  1468. imake \-v \-T/dev/null \-s/dev/null
  1469. .De
  1470. The
  1471. .B \-v
  1472. causes
  1473. .I imake
  1474. to print out the
  1475. .I cpp
  1476. command that it executes.
  1477. If you don't see a \-D\fItrigger\fR
  1478. in that command,
  1479. .I imake
  1480. wasn't built properly.
  1481. (\fB\-T\fI/dev/null\fR provides an empty input template, and
  1482. \fB\-s\fI/dev/null\fR throws away the output so it doesn't clobber the
  1483. .I Makefile
  1484. in your current directory.)
  1485. .NH 2
  1486. Modifying other configuration files for a new platform
  1487. .LP
  1488. Having just built
  1489. .I imake ,
  1490. if you are developing a new port to another system,
  1491. you will want to be able to use it
  1492. in conjunction with the configuration files.
  1493. First, you must modify the header block section of
  1494. .I Imake.tmpl
  1495. to add a block for your system.
  1496. It will look something like this:
  1497. .Ds
  1498. #ifdef brandx
  1499. #define MacroIncludeFile <brandx.cf>
  1500. #define MacroFile brandx.cf
  1501. #undef brandx
  1502. #define BrandxArchitecture
  1503. #endif /* brandx */
  1504. .De
  1505. Second, you must create
  1506. .I brandx.cf .
  1507. At minimum, it probably should contain ``#define BootstrapCFlags \-Dbrandx''.
  1508. Most certainly it will have other things in it, too.
  1509. You will discover just what as you go through the process
  1510. of porting the server and/or clients.
  1511. .NH 2
  1512. Alternatives to BOOTSTRAPCFLAGS
  1513. .LP
  1514. There are two alternatives to specifying BOOTSTRAPCFLAGS on the
  1515. .I make
  1516. command line when you build
  1517. .I imake ,
  1518. both sneaky and both deprecated.
  1519. They are mentioned here in order to point out why you shouldn't use
  1520. them.
  1521. .LP
  1522. First, you can edit
  1523. .I Makefile.ini
  1524. manually to set the value of BOOTSTRAPCFLAGS directly.
  1525. The reason this is not a good idea is that if you give your X
  1526. distribution to somebody else that doesn't have the same kind of
  1527. machine, you've given away an explicitly misconfigured
  1528. .I Makefile.ini .
  1529. The recipient might fail to appreciate the subtle irony of this
  1530. gesture.
  1531. .LP
  1532. Second, you can forget about BOOTSTRAPCFLAGS entirely.
  1533. That's correct\*-you can build
  1534. .I imake
  1535. with wild abandon and total lack of regard for whether it knows about
  1536. the correct trigger symbol or not.
  1537. ``But on some systems,
  1538. .I imake
  1539. must pass the trigger definition to
  1540. .I cpp
  1541. explicitly,'' you say, ``and
  1542. .I imake
  1543. compiled in such a reckless and irresponsible manner may not do the job.''
  1544. Quite right.
  1545. However...
  1546. .I imake
  1547. also examines your environment, and the value of IMAKEINCLUDE, if
  1548. defined there, is passed to
  1549. .I cpp .
  1550. The value of IMAKEINCLUDE must begin with ``\-I'' (or
  1551. .I imake
  1552. will reject it), but you can set it to ``\-I. \-Dbrandx'' and the
  1553. trigger symbol will be passed through to
  1554. .I cpp
  1555. and your
  1556. .I Makefiles
  1557. will build happily.
  1558. .LP
  1559. This is sneaky because it uses the environment to affect the
  1560. build process in a way that is not evident.
  1561. Worse yet, if you actually install an
  1562. .I imake
  1563. built this way, it won't work for anyone else who isn't privy to the
  1564. IMAKEINCLUDE convention.
  1565. .LP
  1566. .I Imake.tmpl
  1567. contains some comments near its beginning pertaining to new ports.
  1568. These indicate that
  1569. .I imake.c ,
  1570. and
  1571. .I main.c
  1572. in the
  1573. .I makedepend
  1574. source, should be modified.
  1575. These comments are correct for R3 but evidently were not updated for R4;
  1576. in both cases the modifications should be made to
  1577. .I imakemdep.h .
  1578. Similarly, the
  1579. .I README
  1580. file refers to
  1581. .I ccflags.c ,
  1582. which is the R3 equivalent of
  1583. .I ccimake.c .
  1584. .NH
  1585. Building X
  1586. .LP
  1587. .B "Do this first:"
  1588. copy the top-level
  1589. .I Makefile
  1590. somewhere safe (outside of the source tree).
  1591. If something goes wrong and this file gets trashed before you've built
  1592. .I xmkmf ,
  1593. you want to be sure you can recover it.
  1594. .LP
  1595. If you can get
  1596. .I imake
  1597. to compile per the instructions above, you should be able to do the
  1598. ``World'' build in the top level X source directory.
  1599. It's important to pass the trigger definition in BOOTSTRAPCFLAGS.
  1600. The X release notes state that BOOTSTRAPCFLAGS is necessary when
  1601. .I cpp
  1602. doesn't predefine the trigger, thus you do the ``World'' build like so:
  1603. .Ds
  1604. make BOOTSTRAPCFLAGS=\-D\fItrigger\fR World
  1605. .De
  1606. I would take this further:
  1607. Even if
  1608. .I cpp
  1609. does predefine the trigger, you should, at least the first time you
  1610. build X in its entirety,
  1611. explicitly pass an empty value to the ``World'' build:
  1612. .Ds
  1613. make BOOTSTRAPCFLAGS= World
  1614. .De
  1615. Why?
  1616. Because the top-level
  1617. .I Makefile
  1618. will have a value for BOOTSTRAPCFLAGS in it already.
  1619. If you your X distribution was originally configured on some other
  1620. system with that used a non-empty BOOTSTRAPCFLAGS, that non-empty
  1621. value is the one that will be passed down through the
  1622. build, which is
  1623. .I not
  1624. what you want.
  1625. (You should pass an empty value explicitly even if you have built
  1626. .I imake
  1627. manually before you do ``make World''; the ``World''
  1628. build throws
  1629. .I imake
  1630. away and compiles it from scratch.)
  1631. .LP
  1632. If you have to specify BOOTSTRAPCFLAGS in order to build
  1633. .I imake ,
  1634. you must remember to specify it on
  1635. .I all
  1636. operations from the top-level
  1637. directory that rebuild
  1638. .I imake :
  1639. ``make World'', ``make Everything'', ``make Makefile'' and ``make Makefiles''.
  1640. These all throw
  1641. .I imake
  1642. away first before rebuilding it.
  1643. Otherwise, BOOTSTRAPCFLAGS need not be specified; its
  1644. only purpose (as far as I can tell) is to make sure that
  1645. .I imake
  1646. builds properly.
  1647. (Once the top-level
  1648. .I Makefile
  1649. gets the correct value of
  1650. BOOTSTRAPCFLAGS in it, that may be the last time you need to specify it,
  1651. actually.
  1652. Have to check on this.)
  1653. .LP
  1654. (Might want to discuss here how BOOTSTRAPCFLAGS propagates during
  1655. those
  1656. .I make
  1657. operations through use of the ImakeDependency() rule.)
  1658. .LP
  1659. Discuss
  1660. .I xmkmf ,
  1661. IMAKE_CMD and operation of UseInstalled here.
  1662. .NH
  1663. Imakeconoclasm\*-X configuration bugs
  1664. .LP
  1665. Problems moving distribution from one machine to another.
  1666. The make all config problem.
  1667. .LP
  1668. Some rules don't use correct version of top-level
  1669. .I Makefile .
  1670. This means problems can occur the first time you try ``make World'' that
  1671. mysteriously disappear the second time.
  1672. .LP
  1673. The IncRoot symbol is defined twice, once in
  1674. .I Imake.tmpl
  1675. and once in
  1676. .I Project.tmpl .
  1677. This is a minor nit, since neither file is supposed to be modified.
  1678. However, if you use the configuration files as a base for your own
  1679. projects, you probably
  1680. .I will
  1681. modify them; be aware that changing the definition in
  1682. .I Project.tmpl
  1683. has no effect if you leave both definitions in.
  1684. .LP
  1685. .I makedepend
  1686. has some hardwired pathnames.
  1687. This may bite you if you use
  1688. .I gcc
  1689. or compile on a MIPS system under BSD environment.
  1690. .NH
  1691. How to go wrong: courting disaster
  1692. .LP
  1693. .I imake
  1694. is wonderful for portability when everything is configured
  1695. properly.
  1696. However, since
  1697. .I Makefile
  1698. construction is more indirect, subtle syntax errors are often difficult
  1699. to track down when you begin to make any significant changes to
  1700. the configuration files.
  1701. This section describes some of the misfortunes that may beset you
  1702. should you make so bold as to engage in such...alchemy.
  1703. .LP
  1704. For X, the source of problems might be in any of
  1705. .I Imakefile ,
  1706. .I Imake.rules ,
  1707. .I Imake.tmpl ,
  1708. the platform
  1709. .I .cf
  1710. file, or
  1711. .I site.def .
  1712. The most likely candidates are
  1713. .I site.def
  1714. and the platform file, though, since those are the only ones you're supposed
  1715. to edit.
  1716. Just remember that effects of mistakes in the early files may
  1717. not be manifest until much later on.
  1718. Problems may appear to originate at locations far from the actual
  1719. cause.
  1720. .IP (1)
  1721. .I Makefile
  1722. trashing
  1723. .IP
  1724. A number of problems during ``make Makefile'' can result in a trashed
  1725. .I Makefile .
  1726. If you have
  1727. .I xmkmf
  1728. working, you can use that to regenerate the
  1729. .I Makefile
  1730. after fixing whatever the problem was.
  1731. Otherwise you must recover it somehow.
  1732. If you have a copy of
  1733. .I Makefile
  1734. stashed somewhere, you can use that.
  1735. If not:
  1736. the first thing that ``make Makefile'' does is to move the original
  1737. .I Makefile
  1738. to
  1739. .I Makefile.bak ;
  1740. if the new
  1741. .I  Makefile
  1742. isn't created properly, you can
  1743. usually recover it with ``cp Makefile.bak Makefile''.
  1744. Then you can fix
  1745. the problem and try again.
  1746. If
  1747. .I Makefile.bak
  1748. is trashed as well, you can
  1749. grab the
  1750. .I Makefile
  1751. from another directory at the same level and use that (this works because
  1752. they both contain the same ``make Makefile''
  1753. rule).
  1754. You can also use a
  1755. .I Makefile
  1756. from a directory at another level,
  1757. but you need to edit the line that sets TOP to reflect where the top
  1758. project directory is in relation to the current directory.
  1759. .IP (2)
  1760. Boolean vs. existent/nonexistent symbols
  1761. .IP
  1762. Some symbols are used in boolean fashion and are defined as
  1763. YES or NO.
  1764. They are tested by ``#if \fIsymbol\fR'' or ``#if !\fIsymbol\fR''.
  1765. Others are turned on simply by being defined.
  1766. They are tested by ``#ifdef \fIsymbol\fR'' or ``#ifndef \fIsymbol\fR''.
  1767. Failure to distinquish the sense in which a symbol is used can lead to
  1768. problems.
  1769. It is necessary to define symbols properly
  1770. .I and
  1771. to test them properly.
  1772. .IP
  1773. .B Example:
  1774. YES/NO symbols must be defined properly.
  1775. SystemV is such a symbol, and the test is ``#if SystemV''.
  1776. If you use ``#define SystemV'' thinking that will turn it on, you'll
  1777. have problems; ``#if SystemV'' turns into just ``#if'' and generates:
  1778. .Ds
  1779. cpp: /usr/tmp/tmp-imake.nnnn:line mmmm: syntax error
  1780. .De .IP
  1781. .B Example:
  1782. YES/NO symbols must be tested properly.
  1783. If you test such a symbol with #ifdef, the test will always succeed,
  1784. whether the value is YES or NO; the symbol is defined in
  1785. .I both
  1786. cases.
  1787. .IP
  1788. .B Example:
  1789. Existent/nonexistent symbols must be defined properly.
  1790. A symbol such as UseInstalled is simply defined (as nothing) or left undefined.
  1791. If you say ``#define UseInstalled NO'', thinking that will turn it
  1792. off, you will be surprised.
  1793. (The test ``#ifdef UseInstalled'' will succeed.)
  1794. .IP
  1795. .B Example:
  1796. Existent/nonexistent symbols must be properly.
  1797. Such a symbol may be defined as nothing.
  1798. If you test it, incorrectly, with ``#if symbol'', the test will fail.
  1799. Use #ifdef.
  1800. .IP (3)
  1801. Rule definition problems.
  1802. .IP
  1803. These can occur after ``make Makefile'', if a rule in
  1804. .I Imake.rules
  1805. is
  1806. #define'd with a space between the rule name and the argument list:
  1807. .Ds
  1808. #define rule(arglist)               right
  1809. #define rule (arglist)              wrong!
  1810. .De .IP
  1811. Some (all?)
  1812. .I cpp 's
  1813. will define rulename as ``(arglist)''.
  1814. When this happens, you'll see
  1815. .Ds
  1816. make:  line nnn: syntax error
  1817. .De .IP
  1818. and you'll find `` (arglist)'' on line nnn of the
  1819. .I Makefile
  1820. because ``rule'' wasn't expanded properly (or at least not the way you
  1821. expect).
  1822. Fix it and try again.
  1823. .IP
  1824. Other similar errors can occur if rules are defined or used with spaces
  1825. anywhere between the end of the macro name to the closing parenthesis of
  1826. the argument list.
  1827. This is particularly true if a macro argument is used
  1828. to generate a rule target name.
  1829. .B "Give example."
  1830. .IP (4)
  1831. Failure to supply
  1832. .I cpp
  1833. symbol default values
  1834. .IP
  1835. When a
  1836. .I make
  1837. variable is equated to a
  1838. .I cpp
  1839. symbol, that symbol must be defined somewhere, even if it's just
  1840. defined as nothing.
  1841. Otherwise the make variable will be set to the literal
  1842. .I cpp
  1843. symbol name.
  1844. That is, if you have ``MAKEVAR=CppSymbol'', then it must be preceded
  1845. somewhere by:
  1846. .Ds
  1847. #ifndef CppSymbol
  1848. #define CppSymbol \fIwhatever\fR
  1849. #endif
  1850. .De .IP
  1851. or MAKEVAR will end up with the value ``CppSymbol''\*-literally.
  1852. .NH
  1853. Writing Imakefiles.
  1854. .LP
  1855. This section assumes that
  1856. .I imake ,
  1857. .I makedepend
  1858. and
  1859. .I xmkmf
  1860. are installed in a public directory somewhere.
  1861. (implies configuration files are installed where
  1862. .I xmkmf
  1863. can get at them.)
  1864. This means, in particular, that you should be able to do ``xmkmf''
  1865. to build a
  1866. .I Makefile
  1867. from an
  1868. .I Imakefile
  1869. in the current directory.
  1870. Detailed
  1871. knowledge of the guts of the configuration process is
  1872. .I not
  1873. assumed.
  1874. .LP
  1875. Give example null
  1876. .I Imakefile
  1877. here.
  1878. .LP
  1879. To test the syntactic correctness of your
  1880. .I Imakefile :
  1881. .Ds
  1882. xmkmf ; make Makefile
  1883. .De
  1884. .I xmkmf
  1885. builds the
  1886. .I Makefile
  1887. from scratch and fails if the configuration is bad.
  1888. .I make
  1889. builds a new
  1890. .I Makefile
  1891. using the one built by
  1892. .I xmkmf ,
  1893. and fails if that one is not legal.
  1894. (say how that can happen.)
  1895. .LP
  1896. Note that the following command lines are not always equivalent:
  1897. .Ds
  1898. make Makefile Makefiles
  1899. make Makefile ; make Makefiles
  1900. .De
  1901. You normally want to build the ``Makefiles'' target when there are
  1902. subdirectories.
  1903. Suppose you add a new directory.
  1904. This is done by changing
  1905. SUBDIRS in the current directory's
  1906. .I Imakefile .
  1907. You then need to rebuild the
  1908. .I Makefile
  1909. so that the definition of SUBDIRS is reset, and then rebuild
  1910. .I Makefile
  1911. in each of those subdirectories.
  1912. The first command line above builds the ``Makefiles'' target using the
  1913. (old) value of SUBDIRS from the (current)
  1914. .I Makefile ,
  1915. which is incorrect.
  1916. The second command line rebuilds the
  1917. .I Makefile ,
  1918. then runs a second
  1919. .I make
  1920. process to build ``Makefiles''.
  1921. The second process sees the (new) value of SUBDIRS in the (new)
  1922. .I Makefile ,
  1923. which includes the new subdirectory, and has the intended result.
  1924. .B "[Need to check this further.]"
  1925. .NH
  1926. Other topics to be dealt with
  1927. .LP
  1928. Listed below are some other topics that should eventually find their
  1929. way into this document.
  1930. What do
  1931. .I you
  1932. want to see?
  1933. .LP
  1934. Shortcomings.
  1935. No provision for building non-shell scripts, especially if
  1936. ExecableScripts is NO.
  1937. List disadvantages of
  1938. .I cpp
  1939. scripts.
  1940. .LP
  1941. Some
  1942. .I cpp
  1943. symbols have no
  1944. .I make
  1945. variable equivalent are exist only to control construction of the
  1946. .I Makefile .
  1947. .LP
  1948. IHaveSubdirs,
  1949. IHaveSpecialMakefileTarget
  1950. .LP
  1951. PassCDebugFlags\*-but related to CDEBUGFLAGS
  1952. .LP
  1953. UseInstalled
  1954. .NH
  1955. Appendix
  1956. .LP
  1957. List of symbols defined in each configuration file
  1958. .NH 2
  1959. platform.cf
  1960. .NH 2
  1961. site.def
  1962. .NH 2
  1963. System/build section of Imake.tmpl
  1964. .NH 2
  1965. Project.tmpl
  1966. .NH 2
  1967. Imake.rules
  1968. .LP
  1969. Note that the ``Makefile'' and ``depend'' targets now contain support
  1970. for building the requisite
  1971. .I imake
  1972. and
  1973. .I makedepend
  1974. programs if the versions in the source tree are to be used and are not
  1975. found.
  1976. The R3 rules failed if the programs had been removed.
  1977. .LP
  1978. The ``Makefiles'' target now handles values of ${TOP} that are either
  1979. relative or absolute.
  1980. The R3 rule only handled relative values.
  1981. .NH 2
  1982. Imakefile
  1983.