xref: /freebsd/share/mk/bsd.README (revision 59e2ff550c448126b988150ce800cdf73bb5103e)
1#	@(#)bsd.README	8.2 (Berkeley) 4/2/94
2# $FreeBSD$
3
4This is the README file for the "include" files for the FreeBSD
5source tree.  The files are installed in /usr/share/mk, and are by
6convention, named with the suffix ".mk".  These files store several
7build options and should be handled with caution.
8
9Note, this file is not intended to replace reading through the .mk
10files for anything tricky.
11
12There are two main types of make include files.  One type is the generally
13usable make include files, such as bsd.prog.mk and bsd.lib.mk.  The other is
14the internal make include files, such as bsd.files.mk and bsd.man.mk, which
15can not/should not be used directly but are used by the other make include
16files.  In most cases it is only interesting to include bsd.prog.mk or
17bsd.lib.mk.
18
19bsd.arch.inc.mk		- includes arch-specific Makefile.$arch
20bsd.compiler.mk		- defined based on current compiler
21bsd.confs.mk		- install of configuration files
22bsd.cpu.mk		- sets CPU/arch-related variables (included from sys.mk)
23bsd.dep.mk		- handle Makefile dependencies
24bsd.doc.mk		- building troff system documents
25bsd.endian.mk		- TARGET_ENDIAN=1234(little) or 4321 (big) for target
26bsd.files.mk		- install of general purpose files
27bsd.incs.mk		- install of include files
28bsd.info.mk		- building GNU Info hypertext system (deprecated)
29bsd.init.mk		- initialization for the make include files
30bsd.kmod.mk		- building loadable kernel modules
31bsd.lib.mk		- support for building libraries
32bsd.libnames.mk		- define library names
33bsd.links.mk		- install of links (sym/hard)
34bsd.man.mk		- install of manual pages and their links
35bsd.nls.mk		- build and install of NLS catalogs
36bsd.obj.mk		- creating 'obj' directories and cleaning up
37bsd.own.mk		- define common variables
38bsd.port.mk		- building ports
39bsd.port.post.mk	- building ports
40bsd.port.pre.mk		- building ports
41bsd.port.subdir.mk	- targets for building subdirectories for ports
42bsd.prog.mk		- building programs from source files
43bsd.progs.mk		- build multiple programs from sources
44bsd.snmpmod.mk		- building modules for the SNMP daemon bsnmpd
45bsd.subdir.mk		- targets for building subdirectories
46bsd.sys.mk		- common settings used for building FreeBSD sources
47bsd.test.mk		- building test programs from source files
48sys.mk			- default rules for all makes
49
50This file does not document bsd.port*.mk.  They are documented in ports(7).
51
52See also make(1), mkdep(1), style.Makefile(5) and `PMake - A
53Tutorial', located in /usr/share/doc/psd/12.make.
54
55=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
56
57Random things worth knowing about this document:
58
59If appropriate when documenting the variables the default value is
60indicated using square brackets e.g. [gzip].
61In some cases the default value depend on other values (e.g. system
62architecture).  In these cases the most common value is indicated.
63
64This document contains some simple examples of the usage of the BSD make
65include files.  For more examples look at the makefiles in the FreeBSD
66source tree.
67
68=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
69
70RANDOM THINGS WORTH KNOWING:
71
72The files are like C-style #include files, and pretty much behave like
73you'd expect.  The syntax is slightly different in that a single '.' is
74used instead of the hash mark, i.e. ".include <bsd.prog.mk>".
75
76One difference that will save you lots of debugging time is that inclusion
77of the file is normally done at the *end* of the Makefile.  The reason for
78this is because .mk files often modify variables and behavior based on the
79values of variables set in the Makefile.  To make this work, remember that
80the FIRST target found is the target that is used, i.e. if the Makefile has:
81
82	a:
83		echo a
84	a:
85		echo a number two
86
87the command "make a" will echo "a".  To make things confusing, the SECOND
88variable assignment is the overriding one, i.e. if the Makefile has:
89
90	a=	foo
91	a=	bar
92
93	b:
94		echo ${a}
95
96the command "make b" will echo "bar".  This is for compatibility with the
97way the V7 make behaved.
98
99It's fairly difficult to make the BSD .mk files work when you're building
100multiple programs in a single directory.  It's a lot easier to split up
101the programs than to deal with the problem.  Most of the agony comes from
102making the "obj" directory stuff work right, not because we switch to a new
103version of make.  So, don't get mad at us, figure out a better way to handle
104multiple architectures so we can quit using the symbolic link stuff.
105(Imake doesn't count.)
106
107The file .depend in the source directory is expected to contain dependencies
108for the source files.  This file is read automatically by make after reading
109the Makefile.
110
111The variable DESTDIR works as before.  It's not set anywhere but will change
112the tree where the file gets installed.
113
114The profiled libraries are no longer built in a different directory than
115the regular libraries.  A new suffix, ".po", is used to denote a profiled
116object.
117
118=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
119
120The following variables are common:
121
122CFLAGS.${COMPILER_TYPE}
123		Flags dependent on compiler added to CXXFLAGS.
124CFLAGS.${MACHINE_ARCH}
125		Architectural flags added to CFLAGS.
126CFLAGS_NO_SIMD	Add this to CFLAGS for programs that don't want any SIMD
127		instructions generated. It is setup in bsd.cpu.mk to an
128		appropriate value for the compiler and target.
129CXXFLAGS.${COMPILER_TYPE}
130		Flags dependent on compiler added to CXXFLAGS.
131CXXFLAGS.${MACHINE_ARCH}
132		Architectural flags added to CXXFLAGS.
133COMPILER_FEATURES
134		A list of features that the compiler supports. Zero or
135		more of:
136			c++11	Supports full C++ 11 standard.
137
138COMPILER_TYPE	Type of compiler, either clang or gcc, though other
139		values are possible. Don't assume != clang == gcc.
140
141COMPILER_VERSION
142		A numeric constant equal to:
143		     major * 10000 + minor * 100 + tiny
144		for the compiler's self-reported version.
145
146=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
147
148The include file <sys.mk> has the default rules for all makes, in the BSD
149environment or otherwise.  You probably don't want to touch this file.
150
151=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
152
153The include file <bsd.arch.inc.mk> includes other Makefiles for specific
154architectures, if they exist. It will include the first of the following
155files that it finds: Makefile.${MACHINE}, Makefile.${MACHINE_ARCH},
156Makefile.${MACHINE_CPUARCH}
157
158=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
159
160The include file <bsd.man.mk> handles installing manual pages and their
161links.
162
163It has three targets:
164
165	all-man:
166		build manual pages.
167	maninstall:
168		install the manual pages and their links.
169	manlint:
170		verify the validity of manual pages.
171
172It sets/uses the following variables:
173
174MANDIR		Base path for manual installation.
175
176MANGRP		Manual group.
177
178MANOWN		Manual owner.
179
180MANMODE		Manual mode.
181
182MANSUBDIR	Subdirectory under the manual page section, i.e. "/vax"
183		or "/tahoe" for machine specific manual pages.
184
185MAN		The manual pages to be installed (use a .1 - .9 suffix).
186
187MLINKS		List of manual page links (using a .1 - .9 suffix).  The
188		linked-to file must come first, the linked file second,
189		and there may be multiple pairs.  The files are hard-linked.
190
191The include file <bsd.man.mk> includes a file named "../Makefile.inc" if
192it exists.
193
194=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
195
196The include file <bsd.own.mk> contains the owners, groups, etc. for both
197manual pages and binaries.
198
199It has no targets.
200
201It sets/uses the following variables:
202
203BINGRP		Binary group.
204
205BINOWN		Binary owner.
206
207BINMODE		Binary mode.
208
209MANDIR		Base path for manual installation.
210
211MANGRP		Manual group.
212
213MANOWN		Manual owner.
214
215MANMODE		Manual mode.
216
217This file is generally useful when building your own Makefiles so that
218they use the same default owners etc. as the rest of the tree.
219
220=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
221
222The include file <bsd.prog.mk> handles building programs from one or
223more source files, along with their manual pages.  It has a limited number
224of suffixes, consistent with the current needs of the BSD tree.
225
226It has seven targets:
227
228	all:
229		build the program and its manual page
230	clean:
231		remove the program and any object files.
232	cleandir:
233		remove all of the files removed by the target clean, as
234		well as .depend, tags, and any manual pages.
235	depend:
236		make the dependencies for the source files, and store
237		them in the file .depend.
238	install:
239		install the program and its manual pages; if the Makefile
240		does not itself define the target install, the targets
241		beforeinstall and afterinstall may also be used to cause
242		actions immediately before and after the install target
243		is executed.
244	lint:
245		run lint on the source files
246	tags:
247		create a tags file for the source files.
248
249It sets/uses the following variables:
250
251BINGRP		Binary group.
252
253BINOWN		Binary owner.
254
255BINMODE		Binary mode.
256
257CLEANFILES	Additional files to remove and
258CLEANDIRS	additional directories to remove during clean and cleandir
259		targets.  "rm -f" and "rm -rf" used respectively.
260
261CFLAGS		Flags to the compiler when creating C objects.
262
263FILES		A list of non-executable files.
264		The installation is controlled by the FILESNAME, FILESOWN,
265		FILESGRP, FILESMODE, FILESDIR variables that can be
266		further specialized by FILES<VAR>_<file>.
267
268LDADD		Additional loader objects.  Usually used for libraries.
269		For example, to load with the compatibility and utility
270		libraries, use:
271
272			LDADD=-lutil -lcompat
273
274LIBADD		Additional libraries.  This is for base system libraries
275		and is only valid inside of the /usr/src tree.
276		Rather than use LDADD=-lname use LIBADD=name.
277
278LDFLAGS		Additional loader flags. Passed to the loader via CC,
279		since that's used to link programs as well, so loader
280		specific flags need to be prefixed with -Wl, to work.
281
282LINKS		The list of binary links; should be full pathnames, the
283		linked-to file coming first, followed by the linked
284		file.  The files are hard-linked.  For example, to link
285		/bin/test and /bin/[, use:
286
287			LINKS=	${DESTDIR}/bin/test ${DESTDIR}/bin/[
288
289MAN		Manual pages (should end in .1 - .9).  If no MAN variable
290		is defined, "MAN=${PROG}.1" is assumed.
291
292PROG		The name of the program to build.  If not supplied, nothing
293		is built.
294
295PROG_CXX	If defined, the name of the program to build.  Also
296		causes <bsd.prog.mk> to link the program with the
297		standard C++ library.  PROG_CXX overrides the value
298		of PROG if PROG is also set.
299
300PROGS		When used with <bsd.progs.mk>, allow building multiple
301PROGS_CXX	PROG and PROGS_CXX in one Makefile.  To define
302		individual variables for each program the VAR.prog
303		syntax should be used.  For example:
304
305		PROGS=		foo bar
306		SRCS.foo=	foo_src.c
307		LDADD.foo=	-lutil
308		SRCS.bar=	bar_src.c
309
310		The supported variables are BINDIR BINGRP BINMODE BINOWN
311		CFLAGS CPPFLAGS CXXFLAGS DPADD DPLIBS DPSRCS LDADD
312		LDFLAGS LIBADD MAN MLINKS PROGNAME SRCS.
313
314PROGNAME	The name that the above program will be installed as, if
315		different from ${PROG}.
316
317SRCS		List of source files to build the program.  If SRCS is not
318		defined, it's assumed to be ${PROG}.c or, if PROG_CXX is
319		defined, ${PROG_CXX}.cc.
320
321DPADD		Additional dependencies for the program.  Usually used for
322		libraries.  For example, to depend on the compatibility and
323		utility libraries use:
324
325			DPADD=${LIBCOMPAT} ${LIBUTIL}
326
327		There is a predefined identifier for each (non-profiled,
328		non-shared) library and object.  Library file names are
329		transformed to identifiers by removing the extension and
330		converting to upper case.
331
332		There are no special identifiers for profiled or shared
333		libraries or objects.  The identifiers for the standard
334		libraries are used in DPADD.  This works correctly iff all
335		the libraries are built at the same time.  Unfortunately,
336		it causes unnecessary relinks to shared libraries when
337		only the static libraries have changed.  Dependencies on
338		shared libraries should be only on the library version
339		numbers.
340
341STRIP		The flag passed to the install program to cause the binary
342		to be stripped.  This is to be used when building your
343		own install script so that the entire system can be made
344		stripped/not-stripped using a single nob.
345
346SUBDIR		A list of subdirectories that should be built as well.
347		Each of the targets will execute the same target in the
348		subdirectories.
349
350SCRIPTS		A list of interpreter scripts [file.{sh,csh,pl,awk,...}].
351		The installation is controlled by the SCRIPTSNAME, SCRIPTSOWN,
352		SCRIPTSGRP, SCRIPTSMODE, SCRIPTSDIR variables that can be
353		further specialized by SCRIPTS<VAR>_<script>.
354
355The include file <bsd.prog.mk> includes the file named "../Makefile.inc"
356if it exists, as well as the include file <bsd.man.mk>.
357
358Some simple examples:
359
360To build foo from foo.c with a manual page foo.1, use:
361
362	PROG=	foo
363
364	.include <bsd.prog.mk>
365
366To build foo from foo.c with a manual page foo.2, add the line:
367
368	MAN=	foo.2
369
370If foo does not have a manual page at all, add the line:
371
372	MAN=
373
374If foo has multiple source files, add the line:
375
376	SRCS=	a.c b.c c.c d.c
377
378=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
379
380The include file <bsd.subdir.mk> contains the default targets for building
381subdirectories.  It has the same seven targets as <bsd.prog.mk>: all, clean,
382cleandir, depend, install, lint, and tags.  For all of the directories
383listed in the variable SUBDIRS, the specified directory will be visited
384and the target made.  There is also a default target which allows the
385command "make subdir" where subdir is any directory listed in the variable
386SUBDIRS.
387
388=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
389
390The include file <bsd.lib.mk> has support for building libraries.  It has
391the same seven targets as <bsd.prog.mk>: all, clean, cleandir, depend,
392install, lint, and tags.  It has a limited number of suffixes, consistent
393with the current needs of the BSD tree.
394
395It sets/uses the following variables:
396
397LIB		The name of the library to build.
398
399LIB_CXX		The name of the library to build. It also causes
400		<bsd.lib.mk> to link the library with the
401		standard C++ library.  LIB_CXX overrides the value
402		of LIB if LIB is also set.
403
404LIBDIR		Target directory for libraries.
405
406LINTLIBDIR	Target directory for lint libraries.
407
408LIBGRP		Library group.
409
410LIBOWN		Library owner.
411
412LIBMODE		Library mode.
413
414LDADD		Additional loader objects.
415
416LIBADD		Additional libraries.  This is for base system libraries
417		and is only valid inside of the /usr/src tree.
418		Rather than use LDADD=-lname use LIBADD=name.
419
420MAN		The manual pages to be installed (use a .1 - .9 suffix).
421
422SRCS		List of source files to build the library.  Suffix types
423		.s, .c, and .f are supported.  Note, .s files are preferred
424		to .c files of the same name.  (This is not the default for
425		versions of make.)
426
427SHLIB_LDSCRIPT	Template file to generate shared library linker script.
428		Unless used, a simple symlink is created to the real
429		shared object.
430
431LIBRARIES_ONLY	Do not build or install files other than the library.
432
433The include file <bsd.lib.mk> includes the file named "../Makefile.inc"
434if it exists, as well as the include file <bsd.man.mk>.
435
436It has rules for building profiled objects; profiled libraries are
437built by default.
438
439Libraries are ranlib'd before installation.
440
441=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
442
443The include file <bsd.test.mk> handles building one or more test programs
444intended to be used in the FreeBSD Test Suite under /usr/tests/.
445
446It has seven targets:
447
448	all:
449		build the test programs.
450	clean:
451		remove the test programs and any object files.
452	cleandir:
453		remove all of the files removed by the target clean, as
454		well as .depend and tags.
455	depend:
456		make the dependencies for the source files, and store
457		them in the file .depend.
458	install:
459                install the test programs and their data files; if the
460                Makefile does not itself define the target install, the
461                targets beforeinstall and afterinstall may also be used
462                to cause actions immediately before and after the
463                install target is executed.
464	lint:
465		run lint on the source files.
466	tags:
467		create a tags file for the source files.
468	test:
469		runs the test programs from the object directory; if the
470		Makefile does not itself define the target test, the
471		targets beforetest and aftertest may also be used to
472		cause actions immediately before and after the test
473		target is executed.
474
475It sets/uses the following variables, among many others:
476
477TESTSBASE	Installation prefix for tests. Defaults to /usr/tests
478
479TESTSDIR	Path to the installed tests.  Must be a subdirectory of
480		TESTSBASE and the subpath should match the relative
481		location of the tests within the src tree.
482
483		The value of TESTSDIR defaults to
484		${TESTSBASE}/${RELDIR:H} , e.g. /usr/tests/bin/ls when
485		included from bin/ls/tests .
486
487KYUAFILE	If 'auto' (the default), generate a Kyuafile out of the
488		test programs defined in the Makefile.  If 'yes', then a
489		manually-crafted Kyuafile must be supplied with the
490		sources.  If 'no', no Kyuafile is installed (useful for
491		subdirectories providing helper programs or data files
492		only).
493
494ATF_TESTS_C	The names of the ATF C test programs to build.
495
496ATF_TESTS_CXX	The names of the ATF C++ test programs to build.
497
498ATF_TESTS_SH	The names of the ATF sh test programs to build.
499
500PLAIN_TESTS_C	The names of the plain (legacy) programs to build.
501
502PLAIN_TESTS_CXX	The names of the plain (legacy) test programs to build.
503
504PLAIN_TESTS_SH	The names of the plain (legacy) test programs to build.
505
506TAP_PERL_INTERPRETER
507		Path to the Perl interpreter to be used for
508		TAP-compliant test programs that are written in Perl.
509		Refer to TAP_TESTS_PERL for details.
510
511TAP_TESTS_C	The names of the TAP-compliant C test programs to build.
512
513TAP_TESTS_CXX	The names of the TAP-compliant C++ test programs to
514		build.
515
516TAP_TESTS_PERL	The names of the TAP-compliant Perl test programs to
517		build.  The corresponding source files should end with
518		the .pl extension; the test program is marked as
519		requiring Perl; and TAP_PERL_INTERPRETER is used in the
520		built scripts as the interpreter of choice.
521
522TAP_TESTS_SH	The names of the TAP-compliant sh test programs to
523		build.
524
525TESTS_SUBDIRS	List of subdirectories containing tests into which to
526		recurse.  Differs from SUBDIR in that these directories
527		get registered into the automatically-generated
528		Kyuafile (if any).
529
530NOT_FOR_TEST_SUITE
531		If defined, none of the built test programs get
532		installed under /usr/tests/ and no Kyuafile is
533		automatically generated.  Should not be used within the
534		FreeBSD source tree but is provided for the benefit of
535		third-parties.
536
537The actual building of the test programs is performed by <bsd.prog.mk>.
538Please see the documentation above for this other file for additional
539details on the behavior of <bsd.test.mk>.
540