xref: /openbsd/share/mk/bsd.README (revision 17df1aa7)
1#	$OpenBSD: bsd.README,v 1.41 2010/03/02 20:33:55 jmc Exp $
2#	$NetBSD: bsd.README,v 1.17 1996/04/13 02:08:08 thorpej Exp $
3#	@(#)bsd.README	5.1 (Berkeley) 5/11/90
4
5This is the README file for the new make "include" files for the BSD
6source tree.  The files are installed in /usr/share/mk, and are, by
7convention, named with the suffix ".mk".
8
9bsd.dep.mk		- handle Makefile dependencies
10bsd.doc.mk		- building troff system documents
11bsd.lib.mk		- support for building libraries
12bsd.lkm.mk		- building loadable kernel modules
13bsd.man.mk		- installing manual pages and their links
14bsd.nls.mk		- National Language Support
15bsd.obj.mk		- creating 'obj' directories and cleaning up
16bsd.own.mk		- define common variables
17bsd.port.mk		- building ports
18bsd.port.subdir.mk	- targets for building subdirectories for ports
19bsd.prog.mk		- building programs from source files
20bsd.regress.mk		- regression tests
21bsd.subdir.mk		- targets for building subdirectories
22bsd.sys.mk		- building bsd from the source tree
23
24Note, this file is not intended to replace reading through the .mk
25files for anything tricky.
26
27=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
28
29RANDOM THINGS WORTH KNOWING:
30
31The files are simply C-style #include files, and pretty much behave like
32you'd expect.  The syntax is slightly different in that a single '.' is
33used instead of the hash mark, i.e. ".include <bsd.prog.mk>".
34
35One difference that will save you lots of debugging time is that inclusion
36of the file is normally done at the *end* of the Makefile.  The reason for
37this is because .mk files often modify variables and behavior based on the
38values of variables set in the Makefile.  To make this work, remember that
39the FIRST target found is the target that is used, i.e. if the Makefile has:
40
41	a:
42		echo a
43	a:
44		echo a number two
45
46the command "make a" will echo "a".  To make things confusing, the SECOND
47variable assignment is the overriding one, i.e. if the Makefile has:
48
49	a=	foo
50	a=	bar
51
52	b:
53		echo ${a}
54
55the command "make b" will echo "bar".  This is for compatibility with the
56way the V7 make behaved.
57
58To make things even more confusing, make uses lazy evaluation. All
59variables are expanded only when needed. Which means that, in
60
61	a=	foo
62
63	b: $(a)
64		echo $(.ALLSRC)
65		echo $(a)
66
67	foo:
68		touch foo
69
70   	a=	bar
71
72the command "make b" will echo "foo"; echo "bar".  The first $(a) means
73"foo", because it's needed to generate the dependency rule when it's read,
74but the second $(a) is only expanded when needed, at which point a contains
75bar.
76
77It's fairly difficult to make the BSD .mk files work when you're building
78multiple programs in a single directory.  It's a lot easier to split up the
79programs than to deal with the problem.  Most of the agony comes from making
80the "obj" directory stuff work right, not because we switched to a new version
81of make.  So, don't get mad at us, figure out a better way to handle multiple
82architectures so we can quit using the symbolic link stuff.  (Imake doesn't
83count.)
84
85The file .depend in the source directory is expected to contain dependencies
86for the source files.  This file is read automatically by make after reading
87the Makefile.
88
89The variable DESTDIR works as before.  It's not set anywhere but will change
90the tree where the file gets installed.
91
92The profiled libraries are no longer built in a different directory than
93the regular libraries.  A new suffix, ".po", is used to denote a profiled
94object.
95
96=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
97
98The include file <sys.mk> has the default rules for all makes, in the BSD
99environment or otherwise.  You probably don't want to touch this file.
100
101=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
102
103The include file <bsd.man.mk> handles installing manual pages and their
104links.
105
106It has a single target:
107
108	maninstall:
109		Install the manual pages and their links.
110
111It sets/uses the following variables:
112
113MANDIR		Base path for manual installation.
114
115MANGRP		Manual group.
116
117MANOWN		Manual owner.
118
119MANMODE		Manual mode.
120
121MANSUBDIR	Subdirectory under the manual page section, i.e. "vax"
122		or "tahoe" for machine specific manual pages.
123
124MAN		The manual pages to be installed (use a .1 - .9 suffix).
125
126MLINKS		List of manual page links (using a .1 - .9 suffix).  The
127		linked-to file must come first, the linked file second,
128		and there may be multiple pairs.  The files are soft-linked.
129
130BEFOREMAN	List of extra targets that must be already built before the
131		man target can be run. Those targets must be real files (and
132		not .PHONY targets).
133
134The include file <bsd.man.mk> includes a file named "../Makefile.inc" if
135it exists.
136
137=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
138
139The include file <bsd.own.mk> contains source tree configuration parameters,
140such as the owners, groups, etc. for both manual pages and binaries, and
141a few global "feature configuration" parameters.
142
143It has no targets.
144
145To get system-specific configuration parameters, bsd.own.mk will try to
146include the file specified by the "MAKECONF" variable.  If MAKECONF is not
147set, or no such file exists, the system make configuration file, /etc/mk.conf
148is included.  These files may define any of the variables described below.
149
150bsd.own.mk sets the following variables, if they are not already defined
151(defaults are in brackets):
152
153BSDSRCDIR	The real path to the system sources, so that 'make obj'
154		will work correctly. [/usr/src]
155
156BSDOBJDIR	The real path to the system 'obj' tree, so that 'make obj'
157		will work correctly. [/usr/obj]
158
159BINGRP		Binary group. [bin]
160
161BINOWN		Binary owner. [root]
162
163BINMODE		Binary mode. [555]
164
165NONBINMODE	Mode for non-executable files. [444]
166
167DIRMODE		Mode for new directories. [755]
168
169MANDIR		Base path for manual installation. [/usr/share/man/cat]
170
171MANGRP		Manual group. [bin]
172
173MANOWN		Manual owner. [root]
174
175MANMODE		Manual mode. [${NONBINMODE}]
176
177LIBDIR		Base path for library installation. [/usr/lib]
178
179LINTLIBDIR	Base path for lint(1) library installation. [/usr/libdata/lint]
180
181LIBGRP		Library group. [${BINGRP}]
182
183LIBOWN		Library owner. [${BINOWN}]
184
185LIBMODE		Library mode. [${NONBINMODE}]
186
187DOCDIR		Base path for system documentation (e.g. PSD, USD, etc.)
188	        installation. [/usr/share/doc]
189
190DOCGRP		Documentation group. [bin]
191
192DOCOWN		Documentation owner. [root]
193
194DOCMODE		Documentation mode. [${NONBINMODE}]
195
196NLSDIR		Base path for National Language Support files installation.
197		[/usr/share/nls]
198
199NLSGRP		National Language Support files group. [bin]
200
201NLSOWN		National Language Support files owner. [root]
202
203NLSMODE		National Language Support files mode. [${NONBINMODE}]
204
205INSTALL_STRIP	The flag passed to the install program to cause the binary
206		to be stripped.  This is to be used when building your
207		own install script so that the entire system can be made
208		stripped/not-stripped using a single knob.  Note that
209		INSTALL_STRIP is not set if ${DEBUG} is defined. [-s]
210
211INSTALL_COPY	The old usage of this flag is obsolescent since install(1)
212		now copies by default.  However, it can also be used to
213		specify that a file not be copied unless it is different
214		(via the -p option).  See install(1) for details.  This
215		is to be used when building our own install script so
216		that the entire system can either be installed with copies,
217		or copy-if-different using a single knob. [-c]
218
219Additionally, the following variables may be set by bsd.own.mk or in a
220make configuration file to modify the behaviour of the system build
221process (default values are in brackets along with comments, if set by
222bsd.own.mk):
223
224AFS		Compile support for AFS.
225
226SKEY		Compile in support for S/key authentication. [yes, set
227		unconditionally]
228
229KERBEROS5	Compile in support for Kerberos 5 authentication.
230
231MANZ		Compress manual pages at installation time.
232
233MANPS		Define to have PostScript manual pages generated.
234
235SYS_INCLUDE	Copy or symlink kernel include files into /usr/include.
236		Possible values are "symlinks" or "copies" (which is
237		the same as the variable being unset).
238
239NOPROFILE	Do not build profiled versions of system libraries.
240
241NOPIC		Do not build PIC versions of system libraries, and
242		do not build shared libraries.
243
244WANTLINT	Build lint libraries.
245
246DEBUG		Add -g to assembly, C compiler and linking passes.  Also
247		doesn't	set STRIP to -s per default if defined.
248
249DEBUGLIBS	Create libraries with -g debug information, and install
250		them in /usr/lib/debug.
251
252WARNINGS	Adds appropriate warning flags (defined in CDIAGFLAGS,
253		e.g., -Wall...) to compiles. [no]
254
255SUDO		Command to run when doing "make install" portion of
256		"make build".  If set to sudo, this allows one to run
257		"make build" as a user other than root (assuming sudo
258		is setup for that user).
259
260PIPE		If set to "-pipe" gcc will be given the -pipe option
261		which can speed up compiles on machines with memory
262		to spare.  Instead of using temp files, gcc uses pipes
263		for the temporary data.
264
265GLOBAL_AUTOCONF_CACHE
266		Set to the name of a file that all cached GNU autoconf
267		test results will be saved in.	Reduces redundant tests.
268		Be careful!  Redundant tests may not be redundant if you
269		are installing substantially updated gnu programs.
270
271bsd.own.mk is generally useful when building your own Makefiles so that
272they use the same default owners etc. as the rest of the tree.
273
274=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
275
276The include file <bsd.prog.mk> handles building programs from one or
277more source files, along with their manual pages.  It has a limited number
278of suffixes, consistent with the current needs of the BSD tree.
279
280It has eight targets:
281
282	all:
283		build the program and its manual page
284	clean:
285		remove the program, any object files and the files a.out,
286		Errs, errs, mklog, and core.
287	cleandir:
288		remove all of the files removed by the target clean, as
289		well as .depend, tags, and any manual pages.
290	depend:
291		make the dependencies for the source files, and store
292		them in the file .depend.
293	includes:
294		install any header files.
295	install:
296		install the program and its manual pages; if the Makefile
297		does not itself define the target install, the targets
298		beforeinstall and afterinstall may also be used to cause
299		actions immediately before and after the install target
300		is executed.
301	lint:
302		run lint on the source files
303	tags:
304		create a tags file for the source files.
305
306It sets/uses the following variables:
307
308BINGRP		Binary group.
309
310BINOWN		Binary owner.
311
312BINMODE		Binary mode.
313
314CLEANFILES	Additional files to remove for the clean and cleandir targets.
315
316COPTS		Additional flags to the compiler when creating C objects.
317
318LDADD		Additional loader objects.  Usually used for libraries.
319		For example, to load with the compatibility and utility
320		libraries, use:
321
322			LDADD+=-lutil -lcompat
323
324LDFLAGS		Additional loader flags.
325
326LINKS		The list of binary links; should be full pathnames, the
327		linked-to file coming first, followed by the linked
328		file.  The files are hard-linked.  For example, to link
329		/bin/test and /bin/[, use:
330
331			LINKS=	${DESTDIR}/bin/test ${DESTDIR}/bin/[
332
333MAN		Manual pages (should end in .1 - .9).  If no MAN variable is
334		defined, "MAN=${PROG}.1" is assumed.
335
336PROG		The name of the program to build.  If not supplied, nothing
337		is built.
338
339SRCS		List of source files to build the program.  If it's not
340		defined, it's assumed to be ${PROG}.c.
341
342DPADD		Additional dependencies for the program.  Usually used for
343		libraries.  For example, to depend on the compatibility and
344		utility libraries use:
345
346			DPADD+=${LIBCOMPAT} ${LIBUTIL}
347
348		The following libraries are predefined for DPADD:
349
350			LIB45		/usr/lib/lib45.a
351			LIBASN1		/usr/lib/libasn1.a
352			LIBC		/usr/lib/libc.a
353			LIBCOMPAT	/usr/lib/libcompat.a
354			LIBCRYPTO	/usr/lib/libcrypto.a
355			LIBCURSES	/usr/lib/libcurses.a
356			LIBDES		/usr/lib/libdes.a
357			LIBEDIT		/usr/lib/libedit.a
358			LIBEVENT	/usr/lib/libevent.a
359			LIBGCC		/usr/lib/libgcc.a
360			LIBGSSAPI	/usr/lib/libgssapi.a
361			LIBHDB		/usr/lib/libhdb.a
362			LIBKADM		/usr/lib/libkadm.a
363			LIBKADM5CLNT	/usr/lib/libkadm5clnt.a
364			LIBKADM5SRV	/usr/lib/libkadm5srv.a
365			LIBKAFS		/usr/lib/libkafs.a
366			LIBKDB		/usr/lib/libkdb.a
367			LIBKEYNOTE	/usr/lib/libkeynote.a
368			LIBKRB		/usr/lib/libkrb.a
369			LIBKRB5		/usr/lib/libkrb5.a
370			LIBKVM		/usr/lib/libkvm.a
371			LIBL		/usr/lib/libl.a
372			LIBM		/usr/lib/libm.a
373			LIBOLDCURSES	/usr/lib/libocurses.a
374			LIBPCAP		/usr/lib/libpcap.a
375			LIBPERL		/usr/lib/libperl.a
376			LIBRPCSVC	/usr/lib/librpcsvc.a
377			LIBSECTOK	/usr/lib/libsectok.a
378			LIBSKEY		/usr/lib/libskey.a
379			LIBSSL		/usr/lib/libssl.a
380			LIBTELNET	/usr/lib/libtelnet.a
381			LIBTERMCAP	/usr/lib/libtermcap.a
382			LIBTERMLIB	/usr/lib/libtermlib.a
383			LIBUSB		/usr/lib/libusbhid.a
384			LIBUTIL		/usr/lib/libutil.a
385			LIBWRAP		/usr/lib/libwrap.a
386			LIBY		/usr/lib/liby.a
387			LIBZ		/usr/lib/libz.a
388			LIBARCH		arch-dependent stuff
389
390STRIP		The flag passed to the install program to cause the binary
391		to be stripped.
392
393SUBDIR		A list of subdirectories that should be built as well.
394		Each of the targets will execute the same target in the
395		subdirectories.
396
397The include file <bsd.prog.mk> includes the file named "../Makefile.inc"
398if it exists, as well as the include file <bsd.man.mk>.
399
400Some simple examples:
401
402To build foo from foo.c with a manual page foo.1, use:
403
404	PROG=	foo
405
406	.include <bsd.prog.mk>
407
408To build foo from foo.c with a manual page foo.2, add the line:
409
410	MAN=	foo.2
411
412If foo does not have a manual page at all, add the line:
413
414	NOMAN=	noman
415
416If foo has multiple source files, add the line:
417
418	SRCS=	a.c b.c c.c d.c
419
420=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
421
422The include file <bsd.subdir.mk> contains the default targets for building
423subdirectories.  It has the same eight targets as <bsd.prog.mk>: all,
424clean, cleandir, depend, includes, install, lint, and tags.  For all of
425the directories listed in the variable SUBDIR, the specified directory
426will be visited and the target made.  There is also a default target which
427allows the command "make subdir" where subdir is any directory listed in
428the variable SUBDIR.
429
430=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
431
432The include file <bsd.sys.mk> is used by <bsd.prog.mk> and
433<bsd.lib.mk>.  It contains overrides that are used when building
434the OpenBSD source tree.  For instance, if "PARALLEL" is defined by
435the program/library Makefile, it includes a set of rules for lex and
436yacc that allow multiple lex and yacc targets to be built in parallel.
437
438=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
439
440The include file <bsd.lib.mk> has support for building libraries.  It has
441the same eight targets as <bsd.prog.mk>: all, clean, cleandir, depend,
442includes, install, lint, and tags.  It has a limited number of suffixes,
443consistent with the current needs of the BSD tree.
444
445It sets/uses the following variables:
446
447LIB		The name of the library to build.
448
449LIBDIR		Target directory for libraries.
450
451LINTLIBDIR	Target directory for lint libraries.
452
453LIBGRP		Library group.
454
455LIBOWN		Library owner.
456
457LIBMODE		Library mode.
458
459LDADD		Additional loader objects.
460
461MAN		The manual pages to be installed (use a .1 - .9 suffix).
462
463SRCS		List of source files to build the library.  Suffix types
464		.s, .c, and .f are supported.  Note, .s files are preferred
465		to .c files of the same name.  (This is not the default for
466		versions of make.)
467
468The include file <bsd.lib.mk> includes the file named "../Makefile.inc"
469if it exists, as well as the include file <bsd.man.mk>.
470
471It has rules for building profiled objects; profiled libraries are
472built by default.
473
474Libraries are ranlib'd when made.
475
476=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
477
478The include file <bsd.lkm.mk> has support for building the LKM's. It has
479the same seven targets as <bsd.prog.mk>: all, clean, cleandir, depend,
480install, lint, and tags. In addition two targets are made available
481that is specific to the LKM's: load, unload.
482
483It sets/uses the following variables (in addition to the <bsd.prog.mk>'s):
484
485LKM		LKM name to build.
486
487LKMGRP		Module group.
488
489LKMOWN		Module owner.
490
491LKMMODE		Module mode.
492
493POSTINSTALL	Program to pass with '-p' flag to the modload.
494		If not defined,
495			POSTINSTALL=${LKM}install
496		is assumed.
497
498The include file <bsd.lkm.mk> includes the file named "../Makefile.inc"
499if it exists, as well as the include file <bsd.man.mk>.
500