13cbdda60SSimon J. Gerratymk-files 23cbdda60SSimon J. Gerraty******** 33cbdda60SSimon J. Gerraty 43cbdda60SSimon J. GerratyThe term ``mk-files`` refers to a collection of ``*.mk`` files. 53cbdda60SSimon J. Gerraty 63cbdda60SSimon J. GerratyYou need bmake_ or a *recent* NetBSD_ make. 73cbdda60SSimon J. GerratyIf in doubt use bmake_. 83cbdda60SSimon J. Gerraty 93cbdda60SSimon J. GerratyIntroduction 103cbdda60SSimon J. Gerraty============ 113cbdda60SSimon J. Gerraty 123cbdda60SSimon J. GerratyMany years ago, when building large software projects, I used GNU make 133cbdda60SSimon J. Gerraty(or my own patched version of it), and had developed a set of macros 143cbdda60SSimon J. Gerratyto simplify developing complex build trees. 153cbdda60SSimon J. Gerraty 163cbdda60SSimon J. GerratySince the early 90's my main development machines, run BSD 172c3632d1SSimon J. Gerraty(NetBSD_ to be precise, and more recently FreeBSD), and the BSD source 182c3632d1SSimon J. Gerratytree is good example of a large software project. 192c3632d1SSimon J. GerratyIt quickly became clear that ``/usr/share/mk/*.mk`` were a great 202c3632d1SSimon J. Gerratymodel, but at the time were quite tightly linked to building the BSD tree. 213cbdda60SSimon J. Gerraty 223cbdda60SSimon J. GerratyMuch as I liked using NetBSD, my customers were more likely to be 233cbdda60SSimon J. Gerratyusing SunOS, HP-UX etc, so I started on bmake_ and a portable collection 243cbdda60SSimon J. Gerratyof mk-files (mk.tar.gz_). NetBSD provided much of the original structure. 253cbdda60SSimon J. Gerraty 263cbdda60SSimon J. GerratySince then I've added a lot of features to NetBSD's make and hence to 273cbdda60SSimon J. Gerratybmake which is kept closely in sync. The mk-files however have 28dfd669abSSimon J. Gerratydiverged quite a bit, though ideas are still picked up from NetBSD 29dfd669abSSimon J. Gerratyand FreeBSD. 303cbdda60SSimon J. Gerraty 313cbdda60SSimon J. GerratyBasics 323cbdda60SSimon J. Gerraty------ 333cbdda60SSimon J. Gerraty 343cbdda60SSimon J. GerratyThe BSD build model is very simple. A directory produces one 353cbdda60SSimon J. Gerratycomponent, which is generally either a library or a program. 363cbdda60SSimon J. GerratyLibrary makefiles include ``lib.mk`` and programs include ``prog.mk`` 373cbdda60SSimon J. Gerratyand they *do the right thing*. 383cbdda60SSimon J. Gerraty 393cbdda60SSimon J. GerratyA simple library makefile might look like:: 403cbdda60SSimon J. Gerraty 413cbdda60SSimon J. Gerraty LIB = sig 423cbdda60SSimon J. Gerraty 433cbdda60SSimon J. Gerraty SRCS = \ 443cbdda60SSimon J. Gerraty sigaction.c \ 453cbdda60SSimon J. Gerraty sigcompat.c \ 463cbdda60SSimon J. Gerraty sighdl.c 473cbdda60SSimon J. Gerraty 483cbdda60SSimon J. Gerraty .include <lib.mk> 493cbdda60SSimon J. Gerraty 503cbdda60SSimon J. Gerratya simple program makefile:: 513cbdda60SSimon J. Gerraty 523cbdda60SSimon J. Gerraty PROG = cat 533cbdda60SSimon J. Gerraty 543cbdda60SSimon J. Gerraty SRCS = cat.c 553cbdda60SSimon J. Gerraty 563cbdda60SSimon J. Gerraty .include <prog.mk> 573cbdda60SSimon J. Gerraty 583cbdda60SSimon J. Gerratyin such cases even the ``SRCS`` line is unnecessary as ``prog.mk`` 593cbdda60SSimon J. Gerratywill default it to ``${PROG}.c``. 603cbdda60SSimon J. Gerraty 613cbdda60SSimon J. GerratyIt is the sensible use of defaults and the plethora of macro modifiers 622c3632d1SSimon J. Gerratyprovided by bmake_ that allow simple makefiles such as the above to 633cbdda60SSimon J. Gerraty*just work* on many different systems. 643cbdda60SSimon J. Gerraty 653cbdda60SSimon J. Gerraty 663cbdda60SSimon J. Gerratymk-files 673cbdda60SSimon J. Gerraty======== 683cbdda60SSimon J. Gerraty 693cbdda60SSimon J. GerratyThis section provides a brief description of some of the ``*.mk`` 703cbdda60SSimon J. Gerratyfiles. 713cbdda60SSimon J. Gerraty 72*98875883SSimon J. GerratyThe makefiles ``lib.mk``, ``prog.mk``, ``init.mk``, ``own.mk``, 73*98875883SSimon J. Gerraty``dep.mk`` and ``man.mk`` are more or less equivalent to ``bsd.*.mk`` 74*98875883SSimon J. Gerratyfound in BSD, and when installed on non-BSD platforms get symlinked as 75*98875883SSimon J. Gerraty``bsd.*.mk`` as well. 76*98875883SSimon J. Gerraty 77*98875883SSimon J. GerratyThe other makefiles (apart from ``sys.mk``) can be used in conjunction 78*98875883SSimon J. Gerratywith ``bsd.*.mk`` on BSD. 79*98875883SSimon J. Gerraty 803cbdda60SSimon J. Gerratysys.mk 813cbdda60SSimon J. Gerraty------ 823cbdda60SSimon J. Gerraty 833cbdda60SSimon J. GerratyWhen bmake starts, it looks for ``sys.mk`` and reads it before doing 843cbdda60SSimon J. Gerratyanything else. Thus, this is the place to setup the environment for 853cbdda60SSimon J. Gerratyeveryone else. 863cbdda60SSimon J. Gerraty 878c973ee2SSimon J. GerratyIn this distribution, ``sys.mk`` avoids doing anything platform or 888c973ee2SSimon J. Gerratysite dependent. 893cbdda60SSimon J. GerratyIt is quite short, and includes a number of other files (which may or 903cbdda60SSimon J. Gerratymay not exists) 913cbdda60SSimon J. Gerraty 923cbdda60SSimon J. Gerratysys.env.mk 933cbdda60SSimon J. Gerraty If it exists, is expected to do things like conditioning the 943cbdda60SSimon J. Gerraty environment. Since it will only be included by the initial 953cbdda60SSimon J. Gerraty instance of bmake, it should ``.export`` anything that 963cbdda60SSimon J. Gerraty sub-makes might need. 973cbdda60SSimon J. Gerraty 983cbdda60SSimon J. Gerratyexamples/sys.clean-env.mk 993cbdda60SSimon J. Gerraty An example of how to clean the environment. 1003cbdda60SSimon J. Gerraty See the file for all the details:: 1013cbdda60SSimon J. Gerraty 1023cbdda60SSimon J. Gerraty .if ${MAKE_VERSION} >= 20100606 && ${.MAKE.LEVEL} == 0 1033cbdda60SSimon J. Gerraty # we save any env var that starts with these 1043cbdda60SSimon J. Gerraty MAKE_SAVE_ENV_PREFIX += SB MK MAKE MACHINE NEED_ CCACHE DISTCC USE_ SSH 1053cbdda60SSimon J. Gerraty MAKE_SAVE_ENV_VARS += \ 1063cbdda60SSimon J. Gerraty PATH HOME USER LOGNAME \ 1073cbdda60SSimon J. Gerraty SRCTOP OBJTOP OBJROOT \ 1083cbdda60SSimon J. Gerraty ${_env_vars} 1093cbdda60SSimon J. Gerraty 1103cbdda60SSimon J. Gerraty _env_vars != env | egrep '^(${MAKE_SAVE_ENV_PREFIX:ts|})' | sed 's,=.*,,'; echo 1113cbdda60SSimon J. Gerraty _export_list = 1123cbdda60SSimon J. Gerraty .for v in ${MAKE_SAVE_ENV_VARS:O:u} 1133cbdda60SSimon J. Gerraty .if !empty($v) 1143cbdda60SSimon J. Gerraty _export_list += $v 1153cbdda60SSimon J. Gerraty $v := ${$v} 1163cbdda60SSimon J. Gerraty .endif 1173cbdda60SSimon J. Gerraty .endfor 1183cbdda60SSimon J. Gerraty # now clobber the environment 1193cbdda60SSimon J. Gerraty .unexport-env 1203cbdda60SSimon J. Gerraty 1213cbdda60SSimon J. Gerraty # list of vars that we handle specially below 1223cbdda60SSimon J. Gerraty _tricky_env_vars = MAKEOBJDIR 1233cbdda60SSimon J. Gerraty # export our selection - sans tricky ones 1243cbdda60SSimon J. Gerraty .export ${_export_list:${_tricky_env_vars:${M_ListToSkip}}} 1253cbdda60SSimon J. Gerraty 1263cbdda60SSimon J. Gerraty # this next bit may need tweaking 1273cbdda60SSimon J. Gerraty .if defined(MAKEOBJDIR) 1283cbdda60SSimon J. Gerraty srctop := ${SRCTOP:U${SB_SRC:U${SB}/src}} 1293cbdda60SSimon J. Gerraty objroot := ${OBJROOT:U${SB_OBJROOT:U${SB}/${SB_OBJPREFIX}}} 1303cbdda60SSimon J. Gerraty # we'll take care of MACHINE below 1313cbdda60SSimon J. Gerraty objtop := ${OBJTOP:U${objroot}${MACHINE}} 1323cbdda60SSimon J. Gerraty .if !empty(objtop) 1333cbdda60SSimon J. Gerraty # we would normally want something like (/bin/sh): 1343cbdda60SSimon J. Gerraty # MAKEOBJDIR="\${.CURDIR:S,${SRCTOP},${OBJROOT}\${MACHINE},}" 1353cbdda60SSimon J. Gerraty # the $$ below is how we achieve the same result here. 1363cbdda60SSimon J. Gerraty # since everything saved from the environment above 1373cbdda60SSimon J. Gerraty # has run through := we need to compensate for ${MACHINE} 1383cbdda60SSimon J. Gerraty MAKEOBJDIR = $${.CURDIR:S,${srctop},${objtop:S,${MACHINE},\${MACHINE},},} 1393cbdda60SSimon J. Gerraty 1403cbdda60SSimon J. Gerraty # export these as-is, and do not track... 1413cbdda60SSimon J. Gerraty .export-env ${_tricky_env_vars} 1423cbdda60SSimon J. Gerraty # now evaluate for ourselves 1433cbdda60SSimon J. Gerraty .for v in ${_tricky_env_vars} 1443cbdda60SSimon J. Gerraty $v := ${$v} 1453cbdda60SSimon J. Gerraty .endfor 1463cbdda60SSimon J. Gerraty 1473cbdda60SSimon J. Gerraty .endif 1483cbdda60SSimon J. Gerraty .endif 1493cbdda60SSimon J. Gerraty .endif 1503cbdda60SSimon J. Gerraty 1513cbdda60SSimon J. Gerraty 1523cbdda60SSimon J. Gerratyhost-target.mk 1533cbdda60SSimon J. Gerraty Is used to set macros like ``HOST_TARGET``, ``HOST_OS`` and 1543cbdda60SSimon J. Gerraty ``host_os`` which are used to find the next step. 1559f45a3c8SSimon J. Gerraty Note: since 20130303 bmake provides ``.MAKE.OS`` set to 1569f45a3c8SSimon J. Gerraty the equivalent of ``HOST_OS``. 1573cbdda60SSimon J. Gerraty 1583cbdda60SSimon J. Gerratysys/\*.mk 1593cbdda60SSimon J. Gerraty Platform specific additions, such as ``Darwin.mk`` or ``SunOS.mk`` 1603cbdda60SSimon J. Gerraty set things like ``HOST_LIBEXT = .dylib`` for Darwin or 1613cbdda60SSimon J. Gerraty ``SHLIB_FULLVERSION = ${SHLIB_MAJOR}`` for SunOS 5. 1623cbdda60SSimon J. Gerraty If there is no OS specific file, ``sys/Generic.mk`` is used. 1633cbdda60SSimon J. Gerraty 1643cbdda60SSimon J. Gerratylocal.sys.mk 1653cbdda60SSimon J. Gerraty Any ``local.*.mk`` file is not part of the distribution. 1663cbdda60SSimon J. Gerraty This provides a hook for sites to do extra setup without 1673cbdda60SSimon J. Gerraty having to edit the distributed files. 1683cbdda60SSimon J. Gerraty 1693cbdda60SSimon J. Gerraty 1703cbdda60SSimon J. GerratyThe above arrangement makes it easy for the mk files to be part of a 1713cbdda60SSimon J. Gerratysrc tree on an NFS volume and to allow building on multiple platforms. 1723cbdda60SSimon J. Gerraty 1739f45a3c8SSimon J. Gerratyoptions.mk 1749f45a3c8SSimon J. Gerraty---------- 1759f45a3c8SSimon J. Gerraty 1769f45a3c8SSimon J. GerratyInspired by FreeBSD's ``bsd.own.mk`` but more flexible. 1779f45a3c8SSimon J. GerratyFreeBSD now have similar functionality in ``bsd.mkopt.mk``. 1789f45a3c8SSimon J. Gerraty 1799f45a3c8SSimon J. GerratyIt allows users to express their intent with respect to options 1809f45a3c8SSimon J. Gerraty``MK_*`` by setting ``WITH_*`` or ``WITHOUT_*``. 1819f45a3c8SSimon J. Gerraty 1829f45a3c8SSimon J. GerratyNote: ``WITHOUT_*`` wins if both are set, and makefiles can set 1839f45a3c8SSimon J. Gerraty``NO_*`` to say they cannot handle that option, or even ``MK_*`` if 1849f45a3c8SSimon J. Gerratythey really need to. 1859f45a3c8SSimon J. Gerraty 1863cbdda60SSimon J. Gerratylib.mk 1873cbdda60SSimon J. Gerraty------ 1883cbdda60SSimon J. Gerraty 1893cbdda60SSimon J. GerratyThis file is used to build a number of different libraries from the 1903cbdda60SSimon J. Gerratysame SRCS. 1913cbdda60SSimon J. Gerraty 1929f45a3c8SSimon J. Gerraty``lib${LIB}.a`` 1933cbdda60SSimon J. Gerraty An archive lib of ``.o`` files, this is the default 1943cbdda60SSimon J. Gerraty 1959f45a3c8SSimon J. Gerraty``lib${LIB}_p.a`` 1963cbdda60SSimon J. Gerraty A profiled lib of ``.po`` files. 1973cbdda60SSimon J. Gerraty Still an archive lib, but all the objects are built with 1983cbdda60SSimon J. Gerraty profiling in mind - hence the different extension. 1999f45a3c8SSimon J. Gerraty It is skipped if ``MK_PROFILE`` is "no". 2003cbdda60SSimon J. Gerraty 2019f45a3c8SSimon J. Gerraty``lib${LIB}_pic.a`` 2023cbdda60SSimon J. Gerraty An archive of ``.so`` objects compiled for relocation. 2033cbdda60SSimon J. Gerraty On NetBSD this is the input to ``lib${LIB}.${LD_so}``, it is 2049f45a3c8SSimon J. Gerraty skipped if ``MK_PIC`` or ``MK_PICLIB`` are "no". 2053cbdda60SSimon J. Gerraty 2069f45a3c8SSimon J. Gerraty``lib${LIB}.${LD_so}`` 2073cbdda60SSimon J. Gerraty A shared library. The value of ``LD_so`` is very platform 2083cbdda60SSimon J. Gerraty specific. For example:: 2093cbdda60SSimon J. Gerraty 2103cbdda60SSimon J. Gerraty # SunOS 5 and most other ELF systems 2113cbdda60SSimon J. Gerraty libsslfd.so.1 2123cbdda60SSimon J. Gerraty 2133cbdda60SSimon J. Gerraty # Darwin 2143cbdda60SSimon J. Gerraty libsslfd.1.dylib 2153cbdda60SSimon J. Gerraty 2163cbdda60SSimon J. Gerraty This library will only be built if ``SHLIB_MAJOR`` has 2179f45a3c8SSimon J. Gerraty a value, and ``MK_PIC`` is not set to "no". 2183cbdda60SSimon J. Gerraty 2193cbdda60SSimon J. GerratyThere is a lot of platform specific tweaking in ``lib.mk``, largely the 2203cbdda60SSimon J. Gerratyresult of the original distributions trying to avoid interfering with 2213cbdda60SSimon J. Gerratythe system's ``sys.mk``. 2223cbdda60SSimon J. Gerraty 2233cbdda60SSimon J. Gerratylibnames.mk 2243cbdda60SSimon J. Gerraty----------- 2253cbdda60SSimon J. Gerraty 2263cbdda60SSimon J. GerratyThis is included by both ``prog.mk`` and ``lib.mk`` and tries to 2273cbdda60SSimon J. Gerratyinclude ``*.libnames.mk`` of which: 2283cbdda60SSimon J. Gerraty 2299f45a3c8SSimon J. Gerraty``local.libnames.mk`` 2303cbdda60SSimon J. Gerraty does not exist unless you create it. It is a handy way for you 2313cbdda60SSimon J. Gerraty to customize without touching the distributed files. 2323cbdda60SSimon J. Gerraty For example, on a test machine I needed to build openssl but 2333cbdda60SSimon J. Gerraty not install it, so put the following in ``local.libnames.mk``:: 2343cbdda60SSimon J. Gerraty 2353cbdda60SSimon J. Gerraty .if ${host_os} == "sunos" 2363cbdda60SSimon J. Gerraty LIBCRYPTO = ${OBJTOP}/openssl/lib/crypto/libcrypto${DLIBEXT} 2373cbdda60SSimon J. Gerraty LIBSSL = ${OBJTOP}/openssl/lib/ssl/libssl${DLIBEXT} 2383cbdda60SSimon J. Gerraty INCLUDES_libcrypto = -I${OBJ_libcrypto} 2393cbdda60SSimon J. Gerraty .endif 2403cbdda60SSimon J. Gerraty 2413cbdda60SSimon J. Gerraty The makefile created an openssl dir in ``${OBJ_libcrypto}`` to 2423cbdda60SSimon J. Gerraty gather all the headers. dpadd.mk_ did the rest. 2433cbdda60SSimon J. Gerraty 2449f45a3c8SSimon J. Gerraty``host.libnames.mk`` 2453cbdda60SSimon J. Gerraty contains logic to find any libs named in ``HOST_LIBS`` in 2463cbdda60SSimon J. Gerraty ``HOST_LIBDIRS``. 2473cbdda60SSimon J. Gerraty 2483cbdda60SSimon J. GerratyEach file above gets an opportunity to define things like:: 2493cbdda60SSimon J. Gerraty 2503cbdda60SSimon J. Gerraty LIBSSLFD ?= ${OBJTOP}/ssl/lib/sslfd/libsslfd${DLIBEXT} 2513cbdda60SSimon J. Gerraty INCLUDES_libsslfd = -I${SRC_libsslfd}/h -I${OBJ_libslfd} 2523cbdda60SSimon J. Gerraty 2533cbdda60SSimon J. Gerratythese are used by dpadd.mk_ and will be explained below. 2543cbdda60SSimon J. Gerraty 2553cbdda60SSimon J. Gerratydpadd.mk 2563cbdda60SSimon J. Gerraty-------- 2573cbdda60SSimon J. Gerraty 2583cbdda60SSimon J. GerratyThis file looks like line noise, and is best considered read-only. 2593cbdda60SSimon J. GerratyHowever it provides some very useful functionality, which simplifies the build. 2603cbdda60SSimon J. Gerraty 2613cbdda60SSimon J. GerratyMakefiles can use the LIB* macros defined via libnames.mk_ or anywhere 2623cbdda60SSimon J. Gerratyelse in various ways:: 2633cbdda60SSimon J. Gerraty 2643cbdda60SSimon J. Gerraty # indicate that we need to include headers from LIBCRYPTO 2653cbdda60SSimon J. Gerraty # this would result in ${INCLUDES_libcrypto} being added to CFLAGS. 2663cbdda60SSimon J. Gerraty SRC_LIBS += ${LIBCRYPTO} 2673cbdda60SSimon J. Gerraty 2683cbdda60SSimon J. Gerraty # indicate that libsslfd must be built already. 2693cbdda60SSimon J. Gerraty # it also has the same effect as SRC_LIBS 2703cbdda60SSimon J. Gerraty DPADD += ${LIBSSLFD} 2713cbdda60SSimon J. Gerraty 2723cbdda60SSimon J. Gerraty # indicate that not only must libsslfd be built, 2733cbdda60SSimon J. Gerraty # but that we need to link with it. 2743cbdda60SSimon J. Gerraty # this is almost exactly equivalent to 2753cbdda60SSimon J. Gerraty # DPADD += ${LIBSSLFD} 2763cbdda60SSimon J. Gerraty # LDADD += -L${LIBSSLFD:H} -lsslfd 2773cbdda60SSimon J. Gerraty # and mostly serves to ensure that DPADD and LDADD are in sync. 2783cbdda60SSimon J. Gerraty DPLIBS += ${LIBSSLFD} 2793cbdda60SSimon J. Gerraty 2803cbdda60SSimon J. GerratyAny library (referenced by its full path) in any of the above, is 2813cbdda60SSimon J. Gerratyadded to ``DPMAGIC_LIBS`` with the following results, for each lib *foo*. 2823cbdda60SSimon J. Gerraty 2839f45a3c8SSimon J. Gerraty``SRC_libfoo`` 2843cbdda60SSimon J. Gerraty Is set to indicate where the src for libfoo is. 2853cbdda60SSimon J. Gerraty By default it is derived from ``LIBFOO`` by replacing 2863cbdda60SSimon J. Gerraty ``${OBJTOP}`` with ``${SRCTOP}``. 2873cbdda60SSimon J. Gerraty 2889f45a3c8SSimon J. Gerraty``OBJ_libfoo`` 2893cbdda60SSimon J. Gerraty Not very exciting, is just the dir where libfoo lives. 2903cbdda60SSimon J. Gerraty 2919f45a3c8SSimon J. Gerraty``INCLUDES_libfoo`` 2923cbdda60SSimon J. Gerraty What to add to ``CFLAGS`` to find the public headers. 2933cbdda60SSimon J. Gerraty The default varies. If ``${SRC_libfoo}/h`` exists, it is assumed 2943cbdda60SSimon J. Gerraty to be the home of all public headers and thus the default is 2953cbdda60SSimon J. Gerraty ``-I${SRC_libfoo}/h`` 2963cbdda60SSimon J. Gerraty 2973cbdda60SSimon J. Gerraty Otherwise we make no assumptions and the default is 2983cbdda60SSimon J. Gerraty ``-I${SRC_libfoo} -I${OBJ_libfoo}`` 2993cbdda60SSimon J. Gerraty 3009f45a3c8SSimon J. Gerraty``LDADD_libfoo`` 3013cbdda60SSimon J. Gerraty This only applies to libs reference via ``DPLIBS``. 3023cbdda60SSimon J. Gerraty The default is ``-lfoo``, ``LDADD_*`` provides a hook to 3033cbdda60SSimon J. Gerraty instantiate other linker flags at the appropriate point 3043cbdda60SSimon J. Gerraty without losing the benfits of ``DPLIBS``. 3053cbdda60SSimon J. Gerraty 3063cbdda60SSimon J. Gerratyprog.mk 3073cbdda60SSimon J. Gerraty------- 3083cbdda60SSimon J. Gerraty 3093cbdda60SSimon J. GerratyCompiles the specified SRCS and links them and the nominated libraries 3103cbdda60SSimon J. Gerratyinto a program. Prog makefiles usually need to list the libraries 3113cbdda60SSimon J. Gerratythat need to be linked. We prefer use of ``DPLIBS`` but the more 3123cbdda60SSimon J. Gerratytraditional ``DPADD`` and ``LDADD`` work just as well. 3133cbdda60SSimon J. GerratyThat is:: 3143cbdda60SSimon J. Gerraty 3153cbdda60SSimon J. Gerraty DPLIBS += ${LIBCRYPTO} 3163cbdda60SSimon J. Gerraty 3173cbdda60SSimon J. Gerratyis equivalent to:: 3183cbdda60SSimon J. Gerraty 3193cbdda60SSimon J. Gerraty DPADD += ${LIBCRYPTO} 3203cbdda60SSimon J. Gerraty LDADD += -lcrypto 3213cbdda60SSimon J. Gerraty 3223cbdda60SSimon J. Gerratyobj.mk 3233cbdda60SSimon J. Gerraty------ 3243cbdda60SSimon J. Gerraty 3253cbdda60SSimon J. GerratyOne of the cool aspects of BSD make, is its support for separating 3263cbdda60SSimon J. Gerratyobject files from the src tree. This is also the source of much 3278c973ee2SSimon J. Gerratyconfusion for people unfamiliar with it. 3283cbdda60SSimon J. Gerraty 3293cbdda60SSimon J. GerratyTraditionally one had to do a separate ``make obj`` pass through the 3309f45a3c8SSimon J. Gerratytree. If ``MK_AUTO_OBJ`` is set we include auto.obj.mk_. 3319f45a3c8SSimon J. Gerraty 3329f45a3c8SSimon J. GerratyIn fact if ``MKOBJDIRS`` is set to "auto", `sys.mk`_ will set 3339f45a3c8SSimon J. Gerraty``MK_AUTO_OBJ=yes`` and include auto.obj.mk_ since it is best done early. 3343cbdda60SSimon J. Gerraty 3353cbdda60SSimon J. Gerratyauto.obj.mk 3363cbdda60SSimon J. Gerraty----------- 3373cbdda60SSimon J. Gerraty 3388c973ee2SSimon J. GerratyCreates object dirs and leverages the ``.OBJDIR`` target introduced 3398c973ee2SSimon J. Gerratysome years ago to NetBSD make, to use them. 3408c973ee2SSimon J. Gerraty 341*98875883SSimon J. GerratyNote that if ``auto.obj.mk`` is to be used it should be included 342*98875883SSimon J. Gerratyearly - before bmake has established ``.PATH``, thus we include it 343*98875883SSimon J. Gerratyfrom ``sys.mk`` rather than ``obj.mk``. 3443cbdda60SSimon J. Gerraty 3453cbdda60SSimon J. Gerratysubdir.mk 3463cbdda60SSimon J. Gerraty--------- 3473cbdda60SSimon J. Gerraty 3483cbdda60SSimon J. GerratyThis is the traditional means of walking the tree. A makefile sets 3493cbdda60SSimon J. Gerraty``SUBDIR`` to the list of sub-dirs to visit. 3503cbdda60SSimon J. Gerraty 3513cbdda60SSimon J. GerratyIf ``SUBDIR_MUST_EXIST`` is set, missing directories cause an error, 3523cbdda60SSimon J. Gerratyotherwise a warning is issued. If you don't even want the warning, 3533cbdda60SSimon J. Gerratyset ``MISSING_DIR=continue``. 3543cbdda60SSimon J. Gerraty 3552c3632d1SSimon J. GerratyTraditionally, ``subdir.mk`` prints clues as it visits each subdir:: 3563cbdda60SSimon J. Gerraty 3573cbdda60SSimon J. Gerraty ===> ssl 3583cbdda60SSimon J. Gerraty ===> ssl/lib 3593cbdda60SSimon J. Gerraty ===> ssl/lib/sslfd 3603cbdda60SSimon J. Gerraty 3613cbdda60SSimon J. Gerratyyou can suppress that - or enhance it by setting ``ECHO_DIR``:: 3623cbdda60SSimon J. Gerraty 3633cbdda60SSimon J. Gerraty # suppress subdir noise 3643cbdda60SSimon J. Gerraty ECHO_DIR=: 3653cbdda60SSimon J. Gerraty # print time stamps 3663cbdda60SSimon J. Gerraty ECHO_DIR=echo @ `date "+%s [%Y-%m-%d %T] "` 3673cbdda60SSimon J. Gerraty 3689f45a3c8SSimon J. GerratyI prefer to use `dirdeps.mk`_ which makes ``subdir.mk`` irrelevant. 3699f45a3c8SSimon J. Gerraty 3703cbdda60SSimon J. Gerratylinks.mk 3713cbdda60SSimon J. Gerraty-------- 3723cbdda60SSimon J. Gerraty 3733cbdda60SSimon J. GerratyProvides rules for processing lists of ``LINKS`` and ``SYMLINKS``. 3743cbdda60SSimon J. GerratyEach is expected to be a list of ``link`` and ``target`` pairs 3753cbdda60SSimon J. Gerraty(``link`` -> ``target``). 3763cbdda60SSimon J. Gerraty 3773cbdda60SSimon J. GerratyThe logic is generally in a ``_*_SCRIPT`` which is referenced in a 3783cbdda60SSimon J. Gerraty``_*_USE`` (``.USE``) target. 3793cbdda60SSimon J. Gerraty 3803cbdda60SSimon J. GerratyThe ``_BUILD_*`` forms are identical, but do not use ``${DESTDIR}`` 3813cbdda60SSimon J. Gerratyand so are useful for creating symlinks during the build phase. 3823cbdda60SSimon J. GerratyFor example:: 3833cbdda60SSimon J. Gerraty 3843cbdda60SSimon J. Gerraty SYMLINKS += ${.CURDIR}/${MACHINE_ARCH}/include machine 3853cbdda60SSimon J. Gerraty header_links: _BUILD_SYMLINKS_USE 3863cbdda60SSimon J. Gerraty 3873cbdda60SSimon J. Gerraty md.o: header_links 3883cbdda60SSimon J. Gerraty 3893cbdda60SSimon J. Gerratywould create a symlink called ``machine`` in ``${.OBJDIR}`` pointing to 3903cbdda60SSimon J. Gerraty``${.CURDIR}/${MACHINE_ARCH}/include`` before compiling ``md.o`` 3913cbdda60SSimon J. Gerraty 3923cbdda60SSimon J. Gerraty 3933cbdda60SSimon J. Gerratyautoconf.mk 3943cbdda60SSimon J. Gerraty----------- 3953cbdda60SSimon J. Gerraty 3963cbdda60SSimon J. GerratyDeals with running (or generating) GNU autoconf ``configure`` scripts. 3973cbdda60SSimon J. Gerraty 3983cbdda60SSimon J. Gerratydep.mk 3993cbdda60SSimon J. Gerraty------ 4003cbdda60SSimon J. Gerraty 4013cbdda60SSimon J. GerratyDeals with collecting dependencies. Another useful feature of BSD 4023cbdda60SSimon J. Gerratymake is the separation of this sort of information into a ``.depend`` 4039f45a3c8SSimon J. Gerratyfile. ``MKDEP_CMD`` needs to point to a suitable tool (like mkdeps.sh_) 4043cbdda60SSimon J. Gerraty 4059f45a3c8SSimon J. GerratyIf ``MK_AUTODEP`` is "yes" it sets ``MKDEP_MK`` to autodep.mk_ by default. 4069f45a3c8SSimon J. Gerraty 4079f45a3c8SSimon J. Gerraty``MKDEP_MK`` can also be set to `auto.dep.mk`_ which is more efficient 4089f45a3c8SSimon J. Gerratybut does not support an explicit ``depend`` target. 4093cbdda60SSimon J. Gerraty 4103cbdda60SSimon J. Gerratyautodep.mk 4113cbdda60SSimon J. Gerraty---------- 4123cbdda60SSimon J. Gerraty 4133cbdda60SSimon J. GerratyLeverages the ``-MD`` feature of recent GCC to collect dependency 4143cbdda60SSimon J. Gerratyinformation as a side effect of compilation. With this GCC puts 4153cbdda60SSimon J. Gerratydependency info into a ``.d`` file. 4163cbdda60SSimon J. Gerraty 4173cbdda60SSimon J. GerratyUnfortunately GCC bases the name of the ``.d`` file on the name of the 4183cbdda60SSimon J. Gerratyinput rather than the output file, which causes problems when the same 4193cbdda60SSimon J. Gerratysource is compiled different ways. The latest GCC supports ``-MF`` to 4203cbdda60SSimon J. Gerratyname the ``.d`` file and ``-MT`` to control the name to put as the 4213cbdda60SSimon J. Gerratydependent. 4223cbdda60SSimon J. Gerraty 4233cbdda60SSimon J. GerratyRecent bmake allows dependencies for the ``.END`` target (run at the 4243cbdda60SSimon J. Gerratyend if everything was successful), and ``autodep.mk`` uses this to 4253cbdda60SSimon J. Gerratypost process the ``.d`` files into ``.depend``. 4263cbdda60SSimon J. Gerraty 4273cbdda60SSimon J. Gerratyauto.dep.mk 4283cbdda60SSimon J. Gerraty----------- 4293cbdda60SSimon J. Gerraty 4303cbdda60SSimon J. GerratyA much simpler implementation than autodep.mk_ it uses 4313cbdda60SSimon J. Gerraty``-MF ${.TARGET:T}.d`` 4323cbdda60SSimon J. Gerratyto avoid possible conflicts during parallel builds. 4333cbdda60SSimon J. GerratyThis precludes the use of suffix rules to drive ``make depend``, so 4343cbdda60SSimon J. Gerratydep.mk_ handles that if specifically requested. 4353cbdda60SSimon J. Gerraty 4369f45a3c8SSimon J. GerratyIf ``bmake`` is 20160218 or newer, ``auto.dep.mk`` uses ``.dinclude`` 4379f45a3c8SSimon J. Gerratyto includes the ``*.d`` files directly thus avoiding the need to 4389f45a3c8SSimon J. Gerratycreate a ``.depend`` file from them. 439dfd669abSSimon J. Gerraty 4403cbdda60SSimon J. Gerratyown.mk 4413cbdda60SSimon J. Gerraty------ 4423cbdda60SSimon J. Gerraty 4433cbdda60SSimon J. GerratyNormally included by ``init.mk`` (included by ``lib.mk`` and 4443cbdda60SSimon J. Gerraty``prog.mk`` etc), sets macros for default ownership etc. 4453cbdda60SSimon J. Gerraty 4463cbdda60SSimon J. GerratyIt includes ``${MAKECONF}`` if it is defined and exists. 4473cbdda60SSimon J. Gerraty 448dfd669abSSimon J. Gerratyldorder.mk 449dfd669abSSimon J. Gerraty---------- 450dfd669abSSimon J. Gerraty 451dfd669abSSimon J. GerratyLeverages ``bmake`` to compute optimal link order for libraries. 452dfd669abSSimon J. GerratyThis works nicely and makes refactoring a breeze - so long as you 4539f45a3c8SSimon J. Gerratyhave no (or few) cicular dependencies between libraries. 454dfd669abSSimon J. Gerraty 455c1d01b5fSSimon J. GerratyConsider this experimental. 456c1d01b5fSSimon J. Gerraty 4573cbdda60SSimon J. Gerratyman.mk 4583cbdda60SSimon J. Gerraty------ 4593cbdda60SSimon J. Gerraty 4603cbdda60SSimon J. GerratyDeals with man pages. 4613cbdda60SSimon J. Gerraty 4623cbdda60SSimon J. Gerratywarnings.mk 4633cbdda60SSimon J. Gerraty----------- 4643cbdda60SSimon J. Gerraty 4653cbdda60SSimon J. GerratyThis provides a means of fine grained control over warnings on a per 4663cbdda60SSimon J. Gerraty``${MACHINE}`` or even file basis. 4673cbdda60SSimon J. Gerraty 4683cbdda60SSimon J. GerratyA makefile sets ``WARNINGS_SET`` to name a list of warnings 4693cbdda60SSimon J. Gerratyand individual ``W_*`` macros can be used to tweak them. 4703cbdda60SSimon J. GerratyFor example:: 4713cbdda60SSimon J. Gerraty 4723cbdda60SSimon J. Gerraty WARNINGS_SET = HIGH 4733cbdda60SSimon J. Gerraty W_unused_sparc = -Wno-unused 4743cbdda60SSimon J. Gerraty 4753cbdda60SSimon J. Gerratywould add all the warnings in ``${HIGH_WARNINGS}`` to CFLAGS, but 4763cbdda60SSimon J. Gerratyon sparc, ``-Wno-unused`` would replace ``-Wunused``. 4773cbdda60SSimon J. Gerraty 4783cbdda60SSimon J. GerratyYou should never need to edit ``warnings.mk``, it will include 4798c973ee2SSimon J. Gerraty``warnings-sets.mk`` and/or ``local.warnings.mk`` to pick up 4803cbdda60SSimon J. Gerratycustomizations. 4813cbdda60SSimon J. Gerraty 482db29cad8SSimon J. Gerratyrst2htm.mk 483db29cad8SSimon J. Gerraty---------- 484db29cad8SSimon J. Gerraty 485db29cad8SSimon J. GerratyLogic to simplify generating HTML (and PDF) documents from ReStructuredText. 486db29cad8SSimon J. Gerraty 487db29cad8SSimon J. Gerratycython.mk 488db29cad8SSimon J. Gerraty--------- 489db29cad8SSimon J. Gerraty 490db29cad8SSimon J. GerratyLogic to build Python C interface modules using Cython_ 491db29cad8SSimon J. Gerraty 492db29cad8SSimon J. Gerraty.. _Cython: http://www.cython.org/ 493db29cad8SSimon J. Gerraty 4949f45a3c8SSimon J. Gerratycc-wrap.mk 4959f45a3c8SSimon J. Gerraty---------- 4969f45a3c8SSimon J. Gerraty 4979f45a3c8SSimon J. GerratyThis makefile leverages two new features in bmake 20220126 and later. 4989f45a3c8SSimon J. Gerraty 4999f45a3c8SSimon J. GerratyFirst is the ablity to set target local variables (GNU make has done 5009f45a3c8SSimon J. Gerratythis for ages). 5019f45a3c8SSimon J. Gerraty 5029f45a3c8SSimon J. GerratyThe second (only intersting if using `meta mode`_) 5039f45a3c8SSimon J. Gerratyallows filtering commands before comparison with previous run to 5049f45a3c8SSimon J. Gerratydecide if a target is out-of-date. 5059f45a3c8SSimon J. Gerraty 5069f45a3c8SSimon J. GerratyIn the past, making use of compiler wrappers like ``ccache``, 5079f45a3c8SSimon J. Gerraty``distcc`` or the newer ``icecc`` could get quite ugly. 5089f45a3c8SSimon J. GerratyUsing ``cc-wrap.mk`` it could not be simpler. 5099f45a3c8SSimon J. Gerraty 5108c973ee2SSimon J. Gerratyjobs.mk 5118c973ee2SSimon J. Gerraty------- 5128c973ee2SSimon J. Gerraty 5138c973ee2SSimon J. GerratyThis should be included by the top-level makefile. 5148c973ee2SSimon J. GerratyIf you do:: 5158c973ee2SSimon J. Gerraty 5168c973ee2SSimon J. Gerraty make something-jobs 5178c973ee2SSimon J. Gerraty 5188c973ee2SSimon J. Gerratythen ``jobs.mk`` will run:: 5198c973ee2SSimon J. Gerraty 5208c973ee2SSimon J. Gerraty make -j${JOB_MAX} someting > ${JOB_LOGDIR}/something.log 2>&1 5218c973ee2SSimon J. Gerraty 5228c973ee2SSimon J. Gerratythis ensures you get a build log and JOB_MAX is assumed to be set 5238c973ee2SSimon J. Gerratyoptimally for the host. 5248c973ee2SSimon J. Gerraty 525c1d01b5fSSimon J. GerratyMETA_MODE 5263cbdda60SSimon J. Gerraty========= 5273cbdda60SSimon J. Gerraty 5283cbdda60SSimon J. GerratyThe 20110505 and later versions of ``mk-files`` include a number of 529db29cad8SSimon J. Gerratymakefiles contributed by Juniper Networks, Inc. 530db29cad8SSimon J. GerratyThese allow the latest version of bmake_ to run in `meta mode`_ 531c1d01b5fSSimon J. Gerratysee `dirdeps.mk`_ and DIRDEPS_BUILD_ below. 5323cbdda60SSimon J. Gerraty 533db29cad8SSimon J. Gerraty.. _`dirdeps.mk`: /help/sjg/dirdeps.htm 5343cbdda60SSimon J. Gerraty.. _`meta mode`: bmake-meta-mode.htm 5353cbdda60SSimon J. Gerraty 536c1d01b5fSSimon J. GerratyDIRDEPS_BUILD 537c1d01b5fSSimon J. Gerraty============= 538c1d01b5fSSimon J. Gerraty 539c1d01b5fSSimon J. GerratyWhen the `meta mode`_ was originally done, there was no distinction 540c1d01b5fSSimon J. Gerratybetween META_MODE_ and ``DIRDEPS_BUILD``, but as these were integrated 541c1d01b5fSSimon J. Gerratyinto FreeBSD it became clear that META_MODE_ could be useful to many 542c1d01b5fSSimon J. Gerratydevelopers independently of ``DIRDEPS_BUILD``. 543c1d01b5fSSimon J. Gerraty 544c1d01b5fSSimon J. GerratyThus today we distinguish between the two. 545c1d01b5fSSimon J. GerratyWe have the following makefiles which are relevant to 546c1d01b5fSSimon J. Gerraty``DIRDEPS_BUILD`` or META_MODE_:: 547c1d01b5fSSimon J. Gerraty 548c1d01b5fSSimon J. Gerraty share/mk/auto.obj.mk 549c1d01b5fSSimon J. Gerraty share/mk/dirdeps-cache-update.mk 550c1d01b5fSSimon J. Gerraty share/mk/dirdeps-options.mk 551c1d01b5fSSimon J. Gerraty share/mk/dirdeps-targets.mk 552c1d01b5fSSimon J. Gerraty share/mk/dirdeps.mk 553c1d01b5fSSimon J. Gerraty share/mk/gendirdeps.mk 554c1d01b5fSSimon J. Gerraty share/mk/host-target.mk 555c1d01b5fSSimon J. Gerraty share/mk/install-new.mk 556c1d01b5fSSimon J. Gerraty share/mk/meta.autodep.mk 557c1d01b5fSSimon J. Gerraty share/mk/meta.stage.mk 558c1d01b5fSSimon J. Gerraty share/mk/meta.sys.mk 559c1d01b5fSSimon J. Gerraty share/mk/meta2deps.py 560c1d01b5fSSimon J. Gerraty share/mk/meta2deps.sh 561c1d01b5fSSimon J. Gerraty share/mk/sys.dependfile.mk 562c1d01b5fSSimon J. Gerraty share/mk/sys.dirdeps.mk 563c1d01b5fSSimon J. Gerraty 564c1d01b5fSSimon J. Gerratyand the following are typically used for customization. 565c1d01b5fSSimon J. GerratySee `freebsd-meta-mode`_ and `netbsd-meta-mode`_:: 566c1d01b5fSSimon J. Gerraty 567c1d01b5fSSimon J. Gerraty share/mk/local.dirdeps-build.mk 568c1d01b5fSSimon J. Gerraty share/mk/local.dirdeps-missing.mk 569c1d01b5fSSimon J. Gerraty share/mk/local.dirdeps.mk 570c1d01b5fSSimon J. Gerraty share/mk/local.meta.sys.mk 571c1d01b5fSSimon J. Gerraty share/mk/local.sys.dirdeps.env.mk 572c1d01b5fSSimon J. Gerraty share/mk/local.sys.dirdeps.mk 573c1d01b5fSSimon J. Gerraty share/mk/local.sys.mk 574c1d01b5fSSimon J. Gerraty 575c1d01b5fSSimon J. Gerraty 5763cbdda60SSimon J. GerratyInstall 5773cbdda60SSimon J. Gerraty======= 5783cbdda60SSimon J. Gerraty 5793cbdda60SSimon J. GerratyYou can use the content of mk.tar.gz_ without installing at all. 5803cbdda60SSimon J. Gerraty 5813cbdda60SSimon J. GerratyThe script ``install-mk`` takes care of copying ``*.mk`` into a 5823cbdda60SSimon J. Gerratydestination directory, and unless told not to, create ``bsd.*.mk`` links 5833cbdda60SSimon J. Gerratyfor ``lib.mk`` etc. 5843cbdda60SSimon J. Gerraty 5853cbdda60SSimon J. GerratyIf you just want to create the ``bsd.*.mk`` links in the directory 586*98875883SSimon J. Gerratywhere you unpacked the tar file, you can use:: 5873cbdda60SSimon J. Gerraty 5883cbdda60SSimon J. Gerraty ./mk/install-mk ./mk 5893cbdda60SSimon J. Gerraty 5903cbdda60SSimon J. Gerraty------ 5913cbdda60SSimon J. Gerraty 5923cbdda60SSimon J. Gerraty.. _bmake: bmake.htm 5933cbdda60SSimon J. Gerraty.. _NetBSD: http://www.netbsd.org/ 594c1d01b5fSSimon J. Gerraty.. _mkdeps.sh: https://www.crufty.net/ftp/pub/sjg/mkdeps.sh 595c1d01b5fSSimon J. Gerraty.. _mk.tar.gz: https://www.crufty.net/ftp/pub/sjg/mk.tar.gz 596c1d01b5fSSimon J. Gerraty.. _`freebsd-meta-mode`: https://www.crufty.net/sjg/docs/freebsd-meta-mode.htm 597c1d01b5fSSimon J. Gerraty.. _`netbsd-meta-mode`: https://www.crufty.net/sjg/docs/netbsd-meta-mode.htm 5983cbdda60SSimon J. Gerraty 5993cbdda60SSimon J. Gerraty:Author: sjg@crufty.net 600*98875883SSimon J. Gerraty:Revision: $Id: mk-files.txt,v 1.25 2023/07/14 23:51:11 sjg Exp $ 6013cbdda60SSimon J. Gerraty:Copyright: Crufty.NET 602