xref: /freebsd/share/mk/bsd.README (revision 5521ff5a4d1929056e7ffc982fac3341ca54df7c)
1#	@(#)bsd.README	8.2 (Berkeley) 4/2/94
2# $FreeBSD$
3
4XXX This document is seriously out of date, it is currenly being revised.
5
6This is the README file for the new make "include" files for the BSD
7source tree.  The files are installed in /usr/share/mk, and are, by
8convention, named with the suffix ".mk".
9
10bsd.dep.mk		- handle Makefile dependencies
11bsd.doc.mk		- building troff system documents
12bsd.info.mk		- building GNU Info hypertext system
13bsd.kern.mk		- define warning flags for compiling the kernel
14bsd.kmod.mk		- building loadable kernel modules
15bsd.lib.mk		- support for building libraries
16bsd.libnames.mk		- define library names
17bsd.man.mk		- installing manual pages and their links
18bsd.obj.mk		- creating 'obj' directories and cleaning up
19bsd.own.mk		- define common variables
20bsd.port.mk		- building ports
21bsd.port.subdir.mk	- targets for building subdirectories for ports
22bsd.prog.mk		- building programs from source files
23bsd.sgml.mk		- building SGML documents
24bsd.subdir.mk		- targets for building subdirectories
25
26
27Note, this file is not intended to replace reading through the .mk
28files for anything tricky.
29
30See also make(1), mkdep(1) and `PMake - A Tutorial',
31located in /usr/share/doc/psd/12.make.
32
33=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
34
35RANDOM THINGS WORTH KNOWING:
36
37The files are simply C-style #include files, and pretty much behave like
38you'd expect.  The syntax is slightly different in that a single '.' is
39used instead of the hash mark, i.e. ".include <bsd.prog.mk>".
40
41One difference that will save you lots of debugging time is that inclusion
42of the file is normally done at the *end* of the Makefile.  The reason for
43this is because .mk files often modify variables and behavior based on the
44values of variables set in the Makefile.  To make this work, remember that
45the FIRST target found is the target that is used, i.e. if the Makefile has:
46
47	a:
48		echo a
49	a:
50		echo a number two
51
52the command "make a" will echo "a".  To make things confusing, the SECOND
53variable assignment is the overriding one, i.e. if the Makefile has:
54
55	a=	foo
56	a=	bar
57
58	b:
59		echo ${a}
60
61the command "make b" will echo "bar".  This is for compatibility with the
62way the V7 make behaved.
63
64It's fairly difficult to make the BSD .mk files work when you're building
65multiple programs in a single directory.  It's a lot easier split up the
66programs than to deal with the problem.  Most of the agony comes from making
67the "obj" directory stuff work right, not because we switch to a new version
68of make.  So, don't get mad at us, figure out a better way to handle multiple
69architectures so we can quit using the symbolic link stuff.  (Imake doesn't
70count.)
71
72The file .depend in the source directory is expected to contain dependencies
73for the source files.  This file is read automatically by make after reading
74the Makefile.
75
76The variable DESTDIR works as before.  It's not set anywhere but will change
77the tree where the file gets installed.
78
79The profiled libraries are no longer built in a different directory than
80the regular libraries.  A new suffix, ".po", is used to denote a profiled
81object.
82
83=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
84
85The include file <sys.mk> has the default rules for all makes, in the BSD
86environment or otherwise.  You probably don't want to touch this file.
87
88=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
89
90The include file <bsd.man.mk> handles installing manual pages and their
91links.
92
93It has a single target:
94
95	maninstall:
96		Install the manual pages and their links.
97
98It sets/uses the following variables:
99
100MANDIR		Base path for manual installation.
101
102MANGRP		Manual group.
103
104MANOWN		Manual owner.
105
106MANMODE		Manual mode.
107
108MANSUBDIR	Subdirectory under the manual page section, i.e. "/vax"
109		or "/tahoe" for machine specific manual pages.
110
111MAN		The manual pages to be installed (use a .1 - .9 suffix).
112
113MLINKS		List of manual page links (using a .1 - .9 suffix).  The
114		linked-to file must come first, the linked file second,
115		and there may be multiple pairs.  The files are soft-linked.
116
117The include file <bsd.man.mk> includes a file named "../Makefile.inc" if
118it exists.
119
120=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
121
122The include file <bsd.own.mk> contains the owners, groups, etc. for both
123manual pages and binaries.
124
125It has no targets.
126
127It sets/uses the following variables:
128
129BINGRP		Binary group.
130
131BINOWN		Binary owner.
132
133BINMODE		Binary mode.
134
135STRIP		The flag passed to the install program to cause the binary
136		to be stripped.  This is to be used when building your
137		own install script so that the entire system can be made
138		stripped/not-stripped using a single nob.
139
140MANDIR		Base path for manual installation.
141
142MANGRP		Manual group.
143
144MANOWN		Manual owner.
145
146MANMODE		Manual mode.
147
148This file is generally useful when building your own Makefiles so that
149they use the same default owners etc. as the rest of the tree.
150
151=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
152
153The include file <bsd.prog.mk> handles building programs from one or
154more source files, along with their manual pages.  It has a limited number
155of suffixes, consistent with the current needs of the BSD tree.
156
157It has seven targets:
158
159	all:
160		build the program and its manual page
161	clean:
162		remove the program, any object files and the files a.out,
163		Errs, errs, mklog, and ${PROG}.core.
164	cleandir:
165		remove all of the files removed by the target clean, as
166		well as .depend, tags, and any manual pages.
167	depend:
168		make the dependencies for the source files, and store
169		them in the file .depend.
170	install:
171		install the program and its manual pages; if the Makefile
172		does not itself define the target install, the targets
173		beforeinstall and afterinstall may also be used to cause
174		actions immediately before and after the install target
175		is executed.
176	lint:
177		run lint on the source files
178	tags:
179		create a tags file for the source files.
180
181It sets/uses the following variables:
182
183BINGRP		Binary group.
184
185BINOWN		Binary owner.
186
187BINMODE		Binary mode.
188
189CLEANFILES	Additional files to remove and
190CLEANDIRS	additional directories to remove during clean and cleandir
191		targets.  "rm -f" and "rm -rf" used respectively.
192
193COPTS		Additional flags to the compiler when creating C objects.
194
195HIDEGAME	If HIDEGAME is defined, the binary is installed in
196		/usr/games/hide, and a symbolic link is created to
197		/usr/games/dm.
198
199LDADD		Additional loader objects.  Usually used for libraries.
200		For example, to load with the compatibility and utility
201		libraries, use:
202
203			LDFILES=-lutil -lcompat
204
205LDFLAGS		Additional loader flags.
206
207LINKS		The list of binary links; should be full pathnames, the
208		linked-to file coming first, followed by the linked
209		file.  The files are hard-linked.  For example, to link
210		/bin/test and /bin/[, use:
211
212			LINKS=	${DESTDIR}/bin/test ${DESTDIR}/bin/[
213
214MAN		Manual pages (should end in .1 - .9).  If no MAN variable
215		is defined, "MAN=${PROG}.1" is assumed.
216
217PROG		The name of the program to build.  If not supplied, nothing
218		is built.
219
220PROGNAME	The name that the above program will be installed as, if
221		different from ${PROG}.
222
223SRCS		List of source files to build the program.  If SRCS is not
224		defined, it's assumed to be ${PROG}.c.
225
226DPADD		Additional dependencies for the program.  Usually used for
227		libraries.  For example, to depend on the compatibility and
228		utility libraries use:
229
230			SRCLIB=${LIBCOMPAT} ${LIBUTIL}
231
232		There is a predefined identifier for each (non-profiled,
233		non-shared) library and object.  Library file names are
234		transformed to identifiers by removing the extension and
235		converting to upper case.
236
237		There are no special identifiers for profiled or shared
238		libraries or objects.  The identifiers for the standard
239		libraries are used in DPADD.  This works correctly iff all
240		the libraries are built at the same time.  Unfortunately,
241		it causes unnecessary relinks to shared libraries when
242		only the static libraries have changed.  Dependencies on
243		shared libraries should be only on the library version
244		numbers.
245
246STRIP		The flag passed to the install program to cause the binary
247		to be stripped.
248
249SUBDIR		A list of subdirectories that should be built as well.
250		Each of the targets will execute the same target in the
251		subdirectories.
252
253SCRIPTS		A list of interpreter scripts [file.{sh,csh,pl,awk,...}].
254		The installation is controlled by the SCRIPTSNAME, SCRIPTSOWN,
255		SCRIPTSGRP, SCRIPTSMODE, SCRIPTSDIR variables that can be
256		further specialized by SCRIPTS<VAR>_<script>.
257
258The include file <bsd.prog.mk> includes the file named "../Makefile.inc"
259if it exists, as well as the include file <bsd.man.mk>.
260
261Some simple examples:
262
263To build foo from foo.c with a manual page foo.1, use:
264
265	PROG=	foo
266
267	.include <bsd.prog.mk>
268
269To build foo from foo.c with a manual page foo.2, add the line:
270
271	MAN2=	foo.2
272
273If foo does not have a manual page at all, add the line:
274
275	NOMAN=	noman
276
277If foo has multiple source files, add the line:
278
279	SRCS=	a.c b.c c.c d.c
280
281=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
282
283The include file <bsd.subdir.mk> contains the default targets for building
284subdirectories.  It has the same seven targets as <bsd.prog.mk>: all, clean,
285cleandir, depend, install, lint, and tags.  For all of the directories
286listed in the variable SUBDIRS, the specified directory will be visited
287and the target made.  There is also a default target which allows the
288command "make subdir" where subdir is any directory listed in the variable
289SUBDIRS.
290
291=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
292
293The include file <bsd.lib.mk> has support for building libraries.  It has
294the same seven targets as <bsd.prog.mk>: all, clean, cleandir, depend,
295install, lint, and tags.  It has a limited number of suffixes, consistent
296with the current needs of the BSD tree.
297
298It sets/uses the following variables:
299
300LIBDIR		Target directory for libraries.
301
302LINTLIBDIR	Target directory for lint libraries.
303
304LIBGRP		Library group.
305
306LIBOWN		Library owner.
307
308LIBMODE		Library mode.
309
310LDADD		Additional loader objects.
311
312MAN		The manual pages to be installed (use a .1 - .9 suffix).
313
314SRCS		List of source files to build the library.  Suffix types
315		.s, .c, and .f are supported.  Note, .s files are preferred
316		to .c files of the same name.  (This is not the default for
317		versions of make.)
318
319The include file <bsd.lib.mk> includes the file named "../Makefile.inc"
320if it exists, as well as the include file <bsd.man.mk>.
321
322It has rules for building profiled objects; profiled libraries are
323built by default.
324
325Libraries are ranlib'd before installation.
326