home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / notebook / makefiles < prev   
Text File  |  1994-11-30  |  12KB  |  344 lines

  1. .DA "30 Nov 1994"
  2. .TL
  3. C News Makefiles
  4. .AU
  5. Henry Spencer
  6. .SH
  7. Introduction
  8. .PP
  9. The Cleanup Release,
  10. unlike earlier C Newses,
  11. does most of its configuration via makefiles
  12. rather than via complex shell files generated in the configuration
  13. process.
  14. A major objective of this exercise is to make it possible to say
  15. things like ``make'' in a particular source directory and have this
  16. do something useful,
  17. \fIwith all the right options\fR.
  18. .SH
  19. Makefile Inclusion
  20. .PP
  21. To do this, it is absolutely necessary to have some sort of
  22. header-file mechanism for makefiles.
  23. The new makefiles rely on the quasi-standard convention that
  24. a line along the lines of
  25. .DS
  26. include ../include/config.make
  27. .DE
  28. is replaced by the contents of the named file.
  29. Since the syntax of such a line annoyingly varies somewhat,
  30. the \fIsubst\fR mechanism is used to make it possible to modify
  31. the makefiles as desired.
  32. The full inclusion should therefore look like:
  33. .DS
  34. # =(\&)<@<INCLUDE>@>()=
  35. include ../include/config.make
  36. .DE
  37. .PP
  38. The (few, I hope) sites whose \fImake\fR does not have anything like this
  39. can use the \fImaker\fR program (supplied in \fIconf\fR),
  40. which simulates a \fImake\fR with such a facility
  41. (it essentially does the \fIsubst\fR INCLUDE on the fly).
  42. .PP
  43. While this arrangement was originally motivated by configuration needs,
  44. it's also possible to do rather a lot to shorten and simplify the makefiles
  45. by judicious use of header-provided facilities.
  46. The rest of this document is essentially a guide to writing makefiles
  47. with the new facilities.
  48. One or two makefiles deviate from this because they are doing
  49. specialized things;
  50. such deviations should be avoided unless there are good reasons.
  51. .PP
  52. The top-level makefile uses none of this machinery,
  53. so that it can be invoked before any of it is operational.
  54. To make this work,
  55. it and the \fIconf\fR makefile are intimately interrelated,
  56. so that the top-level one can punt to the \fIconf\fR one at times.
  57. .SH
  58. 1. Preliminaries
  59. .PP
  60. The makefile may start with definitions intended to alter what goes on
  61. in the makefile header.
  62. Currently there are two variables that might be defined here:
  63. .IP MORECFLAGS \w'MORELINTFLAGS'u+1n
  64. things \fIspecific to this makefile\fR
  65. to be put into CFLAGS.
  66. Standard flags such as ``\-O'' are provided by the makefile header;
  67. MORECFLAGS should be defined only if something
  68. specific to \fIthis\fR makefile is needed.
  69. .IP MORELINTFLAGS
  70. things \fIspecific to this makefile\fR
  71. to be put into LINTFLAGS.
  72. Standard flags such as ``\-h'' are provided by the makefile header;
  73. MORELINTFLAGS should be defined only if something
  74. specific to \fIthis\fR makefile is needed.
  75. .SH
  76. 2. The Makefile Header
  77. .PP
  78. Next, the makefile header file,
  79. which provides configuration variables and a variety of other services,
  80. should be included:
  81. .DS
  82. # =(\&)<@<INCLUDE>@>()=
  83. include ../include/config.make
  84. .DE
  85. To avoid problems with context during patches, these lines should
  86. preferably be followed by three blank lines
  87. (and likewise preceded by three blank lines,
  88. if there is anything before them).
  89. .PP
  90. Among the definitions in the makefile header
  91. are the standard C News pathname variables (NEWSARTS, NEWSOV, etc.).
  92. There are a number of others:
  93. .IP SHELL \w'LINTFLAGS'u+1n
  94. ``/bin/sh'', a workaround for a System V \fImake\fR bug.
  95. .IP UIBIN
  96. directory where the user-interface programs are supposed to go,
  97. e.g. \fI/usr/bin\fR.
  98. .IP RBIN
  99. directory where the programs invoked by UUCP (e.g. \fIrnews\fR) are
  100. supposed to go.
  101. .IP LIB
  102. names of all the libraries needed for compilations
  103. (including \fIlibcnews.a\fR),
  104. in a form suitable for makefile dependency lists.
  105. .IP LIBS
  106. names of all the libraries needed for compilations
  107. (including \fIlibcnews.a\fR),
  108. in a form suitable for compiler arguments
  109. (this may include things like ``\-lcompat'',
  110. which are not legal in dependency lists).
  111. .IP CFLAGS
  112. C-compiler flags, including (e.g.) ``\-O'' and ``\-I../include'',
  113. needed to generate object files.
  114. Individual makefiles should not define their own CFLAGS.
  115. Anything defined in MORECFLAGS is included automatically in CFLAGS.
  116. .IP LDFLAGS
  117. C-compiler flags, including (e.g.) ``\-i'',
  118. needed to link object files into executable binaries.
  119. Individual makefiles should not define their own LDFLAGS.
  120. The contents of CFLAGS are included automatically in LDFLAGS.
  121. .IP LINTFLAGS
  122. C-compiler flags, including (e.g.) ``\-h'' and ``\-I../include'',
  123. needed to run \fIlint\fR.
  124. Individual makefiles should not define their own LINTFLAGS.
  125. Anything defined in MORELINTFLAGS is included automatically in LINTFLAGS.
  126. .IP MAKE
  127. the name of the make program, ``make'' by default.
  128. (The top-level makefile also has its own macro by this name.)
  129. .IP CONF
  130. the configuration directory (mostly as a utility definition for
  131. some of the things that come next).
  132. .IP TO
  133. command that installs its second and subsequent arguments
  134. in the directory identified by its first argument.
  135. If given the ``\-n'' flag, it installs only if the file to be
  136. installed is new, i.e. the installation would not overwrite an
  137. existing file.
  138. .IP IN
  139. command that compares its second and subsequent arguments
  140. to files of the same name in the directory identified by its first argument.
  141. If given the ``\-i'' flag,
  142. it reports differences but always yields a zero exit status,
  143. so that unimportant differences will not halt a \fImake\fR run.
  144. .IP MKDIR
  145. command that makes the directory(-ies) given as its arguments,
  146. if they do not already exist.
  147. Makefiles should assume that the directories identified by standard pathname
  148. variables are already present.
  149. .IP MX
  150. command that makes the files named as arguments executable.
  151. This is normally ``chmod\ +x'',
  152. but might be otherwise on strange systems.
  153. .IP UPDATE
  154. command that updates the C News library with the object modules
  155. named as arguments.
  156. This is normally ``ar\ ruv\ ../libcnews.a'',
  157. possibly with a ``ranlib'' run thrown in;
  158. there are two suitable shell files,
  159. \fIupdate.ran\fR (for systems which need \fIranlib\fR)
  160. and \fIupdate.sym\fR (for systems which don't,
  161. because they have the ``symdef'' feature in their archivers),
  162. in \fIconf\fR,
  163. and UPDATE will normally use one of them.
  164. .IP LIBCMP
  165. command that compares the object modules named as arguments with
  166. the C News library copies.
  167. .IP SPACEFOR
  168. which variant of the \fIspacefor\fR command is to be used.
  169. .IP DOSPACEFOR
  170. ``dospacefor'' if one of the C variants of the \fIspacefor\fR command
  171. is to be used, empty otherwise.
  172. This arranges for the auxiliary C program to get built.
  173. .IP QUEUELEN
  174. which variant of the \fIqueuelen\fR command is to be used.
  175. .IP UID
  176. the user name under which the news software is to run.
  177. .IP GID
  178. the group name under which the news software is to run.
  179. .IP SIZE
  180. ``big'' for a large (>16-bit) address space, ``small'' otherwise.
  181. Used to pick up the appropriate library routines.
  182. .IP DBZ
  183. ``libdbz'' if the \fIdbz\fR package should be used, empty otherwise.
  184. .IP STDIO
  185. ``ourstdio'' if our \fIstdio\fR enhancements should be used,
  186. ``sysstdio'' otherwise.
  187. Actually, they will be used only if they compile and pass their regression
  188. test, but that won't even be tried if this is empty.
  189. .IP SERVER
  190. ``server'' if a multi-host client-server setup is to be used,
  191. empty otherwise.
  192. .IP SERVERNAME
  193. name of the server host, if SERVER is non-empty.
  194. .IP REPORTTO
  195. mail address for non-urgent status reports from news system.
  196. .IP URGENTTO
  197. mail address for urgent problem reports from news system.
  198. .IP HERE
  199. a makefile command prefix suitable for use in testing,
  200. which defines all pathname variables to the current directory
  201. (except NEWSARTS and NEWSOV, which are defined to a subdirectory ``arts'' of
  202. the current directory) and generally sets things up for testing.
  203. .IP HFAKE
  204. list of the header files not present on the current machine that
  205. C News must supply fakes for.
  206. .IP OFAKE
  207. list of the library routines not present on the current machine that
  208. C News must supply fakes for.
  209. .SH
  210. 3. Definitions
  211. .PP
  212. After the header inclusion, makefile-specific definitions should appear,
  213. e.g. definitions of any filename (etc.) that will appear more than once.
  214. Also here should be
  215. definitions of variables whose contents are makefile-specific
  216. but whose purposes are standard:
  217. .IP BINS \w'PROGS'u+1n
  218. a list of the binaries the makefile generates for installation.
  219. .IP PROGS
  220. a list of all the programs the makefile wants to install,
  221. typically beginning with ``$(BINS)'' to include the binaries.
  222. .IP DEST
  223. where the programs should be installed,
  224. typically a subdirectory of ``$(NEWSBIN)''.
  225. .IP OBJS
  226. a list of all the library-routine object files the makefile generates.
  227. .IP ALL
  228. a list of all files the makefile generates,
  229. typically beginning with ``$(PROGS)'' or ``$(OBJS)''
  230. and including any control files the makefile builds.
  231. .SH
  232. 4. Standard Targets
  233. .PP
  234. After the definitions come makefile rules,
  235. including (and preferably starting with) rules with some standard targets.
  236. The set of standard targets depends somewhat on whether the makefile
  237. builds library routines or programs.
  238. (Makefiles that do both should be avoided.)
  239. For programs, the following standard targets should be defined;
  240. ``all'' should be first.
  241. .IP all \w'install'u+1n
  242. build everything (normally depends on ``$(ALL)'')
  243. and make all programs executable using $(MX).
  244. (The latter insures that shell files are executable.)
  245. .IP install
  246. build all programs (normally depends on ``$(PROGS)'') and
  247. install them.
  248. Body normally consists of:
  249. .DS
  250. $(MKDIR) $(DEST)
  251. $(TO) $(DEST) $(PROGS)
  252. .DE
  253. .IP setup
  254. build any control files and install them;
  255. also make any news-owned directories needed by the programs.
  256. Body may be empty if no control files are built;
  257. otherwise it should be analogous to the one for ``install''.
  258. .PP
  259. If the
  260. makefile wishes to install user-interface programs
  261. in $(UIBIN),
  262. this should not be done by ``install'',
  263. but by a separate ``ui'' target.
  264. .PP
  265. The bodies of ``install'', ``setup'', and ``ui''
  266. should be written on the assumption that the source directory
  267. and files are not writable;
  268. the ``build'' part is only meant to verify that the files are indeed
  269. present.
  270. The actual building will be done by the ``all'' target.
  271. .PP
  272. For library routines, the following standard targets should be defined;
  273. ``u'' should be first.
  274. The absence of an ``all'' or ``install'' rule is deliberate.
  275. .IP u \w'cmp'u+1n
  276. build everything (normally depends on ``$(ALL)'')
  277. and update the library using $(UPDATE).
  278. The body normally consists of:
  279. .DS
  280. $(UPDATE) $(OBJS)
  281. .DE
  282. .IP o
  283. build everything (normally depends on ``$(ALL)'')
  284. without updating the library.
  285. .PP
  286. Either form of makefile should also have
  287. some standard targets for common functions,
  288. including installation checking and cleanup:
  289. .IP cmp \w'clean'u+1n
  290. build all files (normally depends on ``$(ALL)'') and
  291. compare them to the installed copies.
  292. For programs, the body normally consists of:
  293. .DS
  294. @$(IN) $(DEST) $(PROGS)
  295. .DE
  296. plus any similar commands needed for control files.
  297. Everything installed by ``install'' or ``setup''
  298. should be checked.
  299. For libraries, the body normally consists of:
  300. .DS
  301. @$(LIBCMP) $(OBJS)
  302. .DE
  303. .IP clean
  304. remove all object files, core files, binaries, etc.
  305. .PP
  306. It is highly desirable for the makefile to include a regression test for
  307. the things it builds.
  308. Even a simple test that checks basic functioning can be quite helpful.
  309. If the makefile includes a regression test,
  310. this should be done by defining two more targets:
  311. .IP r \w'rclean'u+2n
  312. build any necessary test rigs and run the regression test.
  313. This should depend first on any programs/routines needed and
  314. second on ``rclean'',
  315. so that the test rigs are built on a clean foundation.
  316. ``$(HERE)'' may be useful for the test runs.
  317. .IP rclean
  318. remove all test rigs and other detritus from the regression test.
  319. ``clean'' should depend on
  320. ``rclean'',
  321. so that there don't have to be two copies of the regression-cleanup code.
  322. .SH
  323. 5. Misc. Rules
  324. .PP
  325. Somewhere there should be a dependency rule describing the way
  326. (typically) everything depends on the standard libraries
  327. listed in ``$(LIB)''.
  328. The normal form would be:
  329. .DS
  330. $(BINS):    $(LIB)
  331. .DE
  332. This avoids having to mention ``$(LIB)'' in every rule for building
  333. a program.
  334. .PP
  335. It is unfortunately necessary to have an explicit rule for building
  336. each program.
  337. There is no fully-standard way of defining a generic rule for this.
  338. The individual program-building rules should typically be of the
  339. form:
  340. .DS
  341. p:    p.o
  342.     $(CC) $(LDFLAGS) p.o $(LIBS) -o $@
  343. .DE
  344.