11638Srgrimes# @(#)bsd.README 8.2 (Berkeley) 4/2/94 250476Speter# $FreeBSD$ 31638Srgrimes 4115103StrhodesThis is the README file for the "include" files for the FreeBSD 5115103Strhodessource tree. The files are installed in /usr/share/mk, and are by 6115103Strhodesconvention, named with the suffix ".mk". These files store several 7115103Strhodesbuild options and should be handled with caution. 83470Srgrimes 9115103StrhodesNote, this file is not intended to replace reading through the .mk 10115103Strhodesfiles for anything tricky. 111638Srgrimes 12115103StrhodesThere are two main types of make include files. One type is the generally 13115103Strhodesusable make include files, such as bsd.prog.mk and bsd.lib.mk. The other is 14115103Strhodesthe internal make include files, such as bsd.files.mk and bsd.man.mk, which 15115103Strhodescan not/should not be used directly but are used by the other make include 16115103Strhodesfiles. In most cases it is only interesting to include bsd.prog.mk or 17115103Strhodesbsd.lib.mk. 18115103Strhodes 19115103Strhodesbsd.cpu.mk - sets CPU/arch-related variables 2023559Swoschbsd.dep.mk - handle Makefile dependencies 2123559Swoschbsd.doc.mk - building troff system documents 22115103Strhodesbsd.files.mk - install of general purpose files 23115103Strhodesbsd.incs.mk - install of include files 2423559Swoschbsd.info.mk - building GNU Info hypertext system 25115103Strhodesbsd.init.mk - initialization for the make include files 2623559Swoschbsd.kmod.mk - building loadable kernel modules 2723559Swoschbsd.lib.mk - support for building libraries 2823559Swoschbsd.libnames.mk - define library names 29115103Strhodesbsd.links.mk - install of links (sym/hard) 30115103Strhodesbsd.man.mk - install of manual pages and their links 31115103Strhodesbsd.nls.mk - build and install of NLS catalogs 3223559Swoschbsd.obj.mk - creating 'obj' directories and cleaning up 3323559Swoschbsd.own.mk - define common variables 3423559Swoschbsd.port.mk - building ports 35115103Strhodesbsd.port.post.mk - building ports 36115103Strhodesbsd.port.pre.mk - building ports 3723559Swoschbsd.port.subdir.mk - targets for building subdirectories for ports 3823559Swoschbsd.prog.mk - building programs from source files 39152265Shartibsd.snmpmod.mk - building modules for the SNMP daemon bsnmpd 4023559Swoschbsd.subdir.mk - targets for building subdirectories 41115103Strhodesbsd.sys.mk - common settings used for building FreeBSD sources 42115103Strhodessys.mk - default rules for all makes 4323559Swosch 44115103StrhodesThis file does not document bsd.port*.mk. They are documented in ports(7). 4523559Swosch 46115103StrhodesSee also make(1), mkdep(1), style.Makefile(5) and `PMake - A 47115103StrhodesTutorial', located in /usr/share/doc/psd/12.make. 481638Srgrimes 49115103Strhodes=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 5023578Swosch 51115103StrhodesRandom things worth knowing about this document: 52115103Strhodes 53115103StrhodesIf appropriate when documenting the variables the default value is 54115103Strhodesindicated using square brackets e.g. [gzip]. 55115103StrhodesIn some cases the default value depend on other values (e.g. system 56115103Strhodesarchitecture). In these cases the most common value is indicated. 57115103Strhodes 58115103StrhodesThis document contains some simple examples of the usage of the BSD make 59115103Strhodesinclude files. For more examples look at the makefiles in the FreeBSD 60115103Strhodessource tree. 61115103Strhodes 621638Srgrimes=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 631638Srgrimes 641638SrgrimesRANDOM THINGS WORTH KNOWING: 651638Srgrimes 66115103StrhodesThe files are like C-style #include files, and pretty much behave like 671638Srgrimesyou'd expect. The syntax is slightly different in that a single '.' is 681638Srgrimesused instead of the hash mark, i.e. ".include <bsd.prog.mk>". 691638Srgrimes 701638SrgrimesOne difference that will save you lots of debugging time is that inclusion 711638Srgrimesof the file is normally done at the *end* of the Makefile. The reason for 721638Srgrimesthis is because .mk files often modify variables and behavior based on the 731638Srgrimesvalues of variables set in the Makefile. To make this work, remember that 741638Srgrimesthe FIRST target found is the target that is used, i.e. if the Makefile has: 751638Srgrimes 761638Srgrimes a: 771638Srgrimes echo a 781638Srgrimes a: 791638Srgrimes echo a number two 801638Srgrimes 811638Srgrimesthe command "make a" will echo "a". To make things confusing, the SECOND 821638Srgrimesvariable assignment is the overriding one, i.e. if the Makefile has: 831638Srgrimes 841638Srgrimes a= foo 851638Srgrimes a= bar 861638Srgrimes 871638Srgrimes b: 881638Srgrimes echo ${a} 891638Srgrimes 901638Srgrimesthe command "make b" will echo "bar". This is for compatibility with the 911638Srgrimesway the V7 make behaved. 921638Srgrimes 931638SrgrimesIt's fairly difficult to make the BSD .mk files work when you're building 94208420Smaximmultiple programs in a single directory. It's a lot easier to split up 95208420Smaximthe programs than to deal with the problem. Most of the agony comes from 96208420Smaximmaking the "obj" directory stuff work right, not because we switch to a new 97208420Smaximversion of make. So, don't get mad at us, figure out a better way to handle 98208420Smaximmultiple architectures so we can quit using the symbolic link stuff. 99208417Smaxim(Imake doesn't count.) 1001638Srgrimes 1011638SrgrimesThe file .depend in the source directory is expected to contain dependencies 1021638Srgrimesfor the source files. This file is read automatically by make after reading 1031638Srgrimesthe Makefile. 1041638Srgrimes 1051638SrgrimesThe variable DESTDIR works as before. It's not set anywhere but will change 1061638Srgrimesthe tree where the file gets installed. 1071638Srgrimes 1081638SrgrimesThe profiled libraries are no longer built in a different directory than 1091638Srgrimesthe regular libraries. A new suffix, ".po", is used to denote a profiled 1101638Srgrimesobject. 1111638Srgrimes 1121638Srgrimes=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 1131638Srgrimes 1141638SrgrimesThe include file <sys.mk> has the default rules for all makes, in the BSD 1151638Srgrimesenvironment or otherwise. You probably don't want to touch this file. 1161638Srgrimes 1171638Srgrimes=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 1181638Srgrimes 1191638SrgrimesThe include file <bsd.man.mk> handles installing manual pages and their 1201638Srgrimeslinks. 1211638Srgrimes 12283075SruIt has three targets: 1231638Srgrimes 12483075Sru all-man: 12583075Sru build manual pages. 1261638Srgrimes maninstall: 12783075Sru install the manual pages and their links. 12883075Sru manlint: 12983075Sru verify the validity of manual pages. 1301638Srgrimes 1311638SrgrimesIt sets/uses the following variables: 1321638Srgrimes 1331638SrgrimesMANDIR Base path for manual installation. 1341638Srgrimes 1351638SrgrimesMANGRP Manual group. 1361638Srgrimes 1371638SrgrimesMANOWN Manual owner. 1381638Srgrimes 1391638SrgrimesMANMODE Manual mode. 1401638Srgrimes 1411638SrgrimesMANSUBDIR Subdirectory under the manual page section, i.e. "/vax" 1421638Srgrimes or "/tahoe" for machine specific manual pages. 1431638Srgrimes 14474942SruMAN The manual pages to be installed (use a .1 - .9 suffix). 1451638Srgrimes 14658494SruMLINKS List of manual page links (using a .1 - .9 suffix). The 1471638Srgrimes linked-to file must come first, the linked file second, 1481638Srgrimes and there may be multiple pairs. The files are soft-linked. 1491638Srgrimes 15074942SruThe include file <bsd.man.mk> includes a file named "../Makefile.inc" if 15174942Sruit exists. 1521638Srgrimes 1531638Srgrimes=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 1541638Srgrimes 1551638SrgrimesThe include file <bsd.own.mk> contains the owners, groups, etc. for both 1561638Srgrimesmanual pages and binaries. 1571638Srgrimes 1581638SrgrimesIt has no targets. 1591638Srgrimes 1601638SrgrimesIt sets/uses the following variables: 1611638Srgrimes 1621638SrgrimesBINGRP Binary group. 1631638Srgrimes 1641638SrgrimesBINOWN Binary owner. 1651638Srgrimes 1661638SrgrimesBINMODE Binary mode. 1671638Srgrimes 1681638SrgrimesMANDIR Base path for manual installation. 1691638Srgrimes 1701638SrgrimesMANGRP Manual group. 1711638Srgrimes 1721638SrgrimesMANOWN Manual owner. 1731638Srgrimes 1741638SrgrimesMANMODE Manual mode. 1751638Srgrimes 1761638SrgrimesThis file is generally useful when building your own Makefiles so that 1771638Srgrimesthey use the same default owners etc. as the rest of the tree. 1781638Srgrimes 1791638Srgrimes=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 1801638Srgrimes 1811638SrgrimesThe include file <bsd.prog.mk> handles building programs from one or 1821638Srgrimesmore source files, along with their manual pages. It has a limited number 1831638Srgrimesof suffixes, consistent with the current needs of the BSD tree. 1841638Srgrimes 1851638SrgrimesIt has seven targets: 1861638Srgrimes 1871638Srgrimes all: 1881638Srgrimes build the program and its manual page 1891638Srgrimes clean: 190159721Syar remove the program and any object files. 1911638Srgrimes cleandir: 1921638Srgrimes remove all of the files removed by the target clean, as 1931638Srgrimes well as .depend, tags, and any manual pages. 1941638Srgrimes depend: 1951638Srgrimes make the dependencies for the source files, and store 1961638Srgrimes them in the file .depend. 1971638Srgrimes install: 1981638Srgrimes install the program and its manual pages; if the Makefile 1991638Srgrimes does not itself define the target install, the targets 2001638Srgrimes beforeinstall and afterinstall may also be used to cause 2011638Srgrimes actions immediately before and after the install target 2021638Srgrimes is executed. 2031638Srgrimes lint: 2041638Srgrimes run lint on the source files 2051638Srgrimes tags: 2061638Srgrimes create a tags file for the source files. 2071638Srgrimes 2081638SrgrimesIt sets/uses the following variables: 2091638Srgrimes 2101638SrgrimesBINGRP Binary group. 2111638Srgrimes 2121638SrgrimesBINOWN Binary owner. 2131638Srgrimes 2141638SrgrimesBINMODE Binary mode. 2151638Srgrimes 21616437SphkCLEANFILES Additional files to remove and 21716437SphkCLEANDIRS additional directories to remove during clean and cleandir 21816437Sphk targets. "rm -f" and "rm -rf" used respectively. 2191638Srgrimes 220133653SruCFLAGS Flags to the compiler when creating C objects. 2211638Srgrimes 22288055SruFILES A list of non-executable files. 22388055Sru The installation is controlled by the FILESNAME, FILESOWN, 22488055Sru FILESGRP, FILESMODE, FILESDIR variables that can be 22588055Sru further specialized by FILES<VAR>_<file>. 22688055Sru 2271638SrgrimesLDADD Additional loader objects. Usually used for libraries. 2281638Srgrimes For example, to load with the compatibility and utility 2291638Srgrimes libraries, use: 2301638Srgrimes 231235928Smarcel LDADD=-lutil -lcompat 2321638Srgrimes 2331638SrgrimesLDFLAGS Additional loader flags. 2341638Srgrimes 2351638SrgrimesLINKS The list of binary links; should be full pathnames, the 2361638Srgrimes linked-to file coming first, followed by the linked 2371638Srgrimes file. The files are hard-linked. For example, to link 2381638Srgrimes /bin/test and /bin/[, use: 2391638Srgrimes 2401638Srgrimes LINKS= ${DESTDIR}/bin/test ${DESTDIR}/bin/[ 2411638Srgrimes 24274942SruMAN Manual pages (should end in .1 - .9). If no MAN variable 24374942Sru is defined, "MAN=${PROG}.1" is assumed. 2441638Srgrimes 2451638SrgrimesPROG The name of the program to build. If not supplied, nothing 2461638Srgrimes is built. 2471638Srgrimes 24894424SruPROG_CXX If defined, the name of the program to build. Also 24994424Sru causes <bsd.prog.mk> to link the program with the 25094424Sru standard C++ library. PROG_CXX overrides the value 25194424Sru of PROG if PROG is also set. 25294424Sru 25375083SruPROGNAME The name that the above program will be installed as, if 25475083Sru different from ${PROG}. 25575083Sru 25653965SmharoSRCS List of source files to build the program. If SRCS is not 25794424Sru defined, it's assumed to be ${PROG}.c or, if PROG_CXX is 25894424Sru defined, ${PROG_CXX}.cc. 2591638Srgrimes 2601638SrgrimesDPADD Additional dependencies for the program. Usually used for 2611638Srgrimes libraries. For example, to depend on the compatibility and 2621638Srgrimes utility libraries use: 2631638Srgrimes 264235928Smarcel DPADD=${LIBCOMPAT} ${LIBUTIL} 2651638Srgrimes 26614701Sbde There is a predefined identifier for each (non-profiled, 26714701Sbde non-shared) library and object. Library file names are 26814701Sbde transformed to identifiers by removing the extension and 26914701Sbde converting to upper case. 2701638Srgrimes 27114701Sbde There are no special identifiers for profiled or shared 27214701Sbde libraries or objects. The identifiers for the standard 27314701Sbde libraries are used in DPADD. This works correctly iff all 27414701Sbde the libraries are built at the same time. Unfortunately, 27514701Sbde it causes unnecessary relinks to shared libraries when 27614701Sbde only the static libraries have changed. Dependencies on 27714701Sbde shared libraries should be only on the library version 27814701Sbde numbers. 2791638Srgrimes 2801638SrgrimesSTRIP The flag passed to the install program to cause the binary 281125493Sru to be stripped. This is to be used when building your 282125493Sru own install script so that the entire system can be made 283125493Sru stripped/not-stripped using a single nob. 2841638Srgrimes 2851638SrgrimesSUBDIR A list of subdirectories that should be built as well. 2861638Srgrimes Each of the targets will execute the same target in the 2871638Srgrimes subdirectories. 2881638Srgrimes 28975284SruSCRIPTS A list of interpreter scripts [file.{sh,csh,pl,awk,...}]. 29075284Sru The installation is controlled by the SCRIPTSNAME, SCRIPTSOWN, 29175284Sru SCRIPTSGRP, SCRIPTSMODE, SCRIPTSDIR variables that can be 29275284Sru further specialized by SCRIPTS<VAR>_<script>. 29375284Sru 29474942SruThe include file <bsd.prog.mk> includes the file named "../Makefile.inc" 29574942Sruif it exists, as well as the include file <bsd.man.mk>. 2961638Srgrimes 2971638SrgrimesSome simple examples: 2981638Srgrimes 2991638SrgrimesTo build foo from foo.c with a manual page foo.1, use: 3001638Srgrimes 3011638Srgrimes PROG= foo 3021638Srgrimes 3031638Srgrimes .include <bsd.prog.mk> 3041638Srgrimes 3051638SrgrimesTo build foo from foo.c with a manual page foo.2, add the line: 3061638Srgrimes 307156743Sru MAN= foo.2 3081638Srgrimes 3091638SrgrimesIf foo does not have a manual page at all, add the line: 3101638Srgrimes 311156502Simp NO_MAN= 3121638Srgrimes 3131638SrgrimesIf foo has multiple source files, add the line: 3141638Srgrimes 3151638Srgrimes SRCS= a.c b.c c.c d.c 3161638Srgrimes 3171638Srgrimes=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 3181638Srgrimes 3191638SrgrimesThe include file <bsd.subdir.mk> contains the default targets for building 3201638Srgrimessubdirectories. It has the same seven targets as <bsd.prog.mk>: all, clean, 3211638Srgrimescleandir, depend, install, lint, and tags. For all of the directories 3221638Srgrimeslisted in the variable SUBDIRS, the specified directory will be visited 3231638Srgrimesand the target made. There is also a default target which allows the 3241638Srgrimescommand "make subdir" where subdir is any directory listed in the variable 3251638SrgrimesSUBDIRS. 3261638Srgrimes 3271638Srgrimes=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 3281638Srgrimes 3291638SrgrimesThe include file <bsd.lib.mk> has support for building libraries. It has 3301638Srgrimesthe same seven targets as <bsd.prog.mk>: all, clean, cleandir, depend, 3311638Srgrimesinstall, lint, and tags. It has a limited number of suffixes, consistent 3321638Srgrimeswith the current needs of the BSD tree. 3331638Srgrimes 3341638SrgrimesIt sets/uses the following variables: 3351638Srgrimes 3361638SrgrimesLIBDIR Target directory for libraries. 3371638Srgrimes 3381638SrgrimesLINTLIBDIR Target directory for lint libraries. 3391638Srgrimes 3401638SrgrimesLIBGRP Library group. 3411638Srgrimes 3421638SrgrimesLIBOWN Library owner. 3431638Srgrimes 3441638SrgrimesLIBMODE Library mode. 3451638Srgrimes 3461638SrgrimesLDADD Additional loader objects. 3471638Srgrimes 34874942SruMAN The manual pages to be installed (use a .1 - .9 suffix). 3491638Srgrimes 3501638SrgrimesSRCS List of source files to build the library. Suffix types 3511638Srgrimes .s, .c, and .f are supported. Note, .s files are preferred 3521638Srgrimes to .c files of the same name. (This is not the default for 3531638Srgrimes versions of make.) 3541638Srgrimes 355235122SjlhSHLIB_LDSCRIPT Template file to generate shared library linker script. 356235122Sjlh Unless used, a simple symlink is created to the real 357235122Sjlh shared object. 358235122Sjlh 359245561SbrooksLIBRARIES_ONLY Do not build or install files other than the library. 360245561Sbrooks 36174942SruThe include file <bsd.lib.mk> includes the file named "../Makefile.inc" 36274942Sruif it exists, as well as the include file <bsd.man.mk>. 3631638Srgrimes 3641638SrgrimesIt has rules for building profiled objects; profiled libraries are 3651638Srgrimesbuilt by default. 3661638Srgrimes 3671638SrgrimesLibraries are ranlib'd before installation. 368