15f1e34d9SAlexandre Perrinmk-files 25f1e34d9SAlexandre Perrin******** 35f1e34d9SAlexandre Perrin 45f1e34d9SAlexandre PerrinThe term ``mk-files`` refers to a collection of ``*.mk`` files. 55f1e34d9SAlexandre Perrin 65f1e34d9SAlexandre PerrinYou need bmake_ or a *recent* NetBSD_ make. 75f1e34d9SAlexandre PerrinIf in doubt use bmake_. 85f1e34d9SAlexandre Perrin 95f1e34d9SAlexandre PerrinIntroduction 105f1e34d9SAlexandre Perrin============ 115f1e34d9SAlexandre Perrin 125f1e34d9SAlexandre PerrinMany years ago, when building large software projects, I used GNU make 135f1e34d9SAlexandre Perrin(or my own patched version of it), and had developed a set of macros 145f1e34d9SAlexandre Perrinto simplify developing complex build trees. 155f1e34d9SAlexandre Perrin 165f1e34d9SAlexandre PerrinSince the early 90's my main development machines, run BSD 17a34d5fb1SAntonio Huete Jimenez(NetBSD_ to be precise, and more recently FreeBSD), and the BSD source 18a34d5fb1SAntonio Huete Jimeneztree is good example of a large software project. 19a34d5fb1SAntonio Huete JimenezIt quickly became clear that ``/usr/share/mk/*.mk`` were a great 20a34d5fb1SAntonio Huete Jimenezmodel, but at the time were quite tightly linked to building the BSD tree. 215f1e34d9SAlexandre Perrin 225f1e34d9SAlexandre PerrinMuch as I liked using NetBSD, my customers were more likely to be 235f1e34d9SAlexandre Perrinusing SunOS, HP-UX etc, so I started on bmake_ and a portable collection 245f1e34d9SAlexandre Perrinof mk-files (mk.tar.gz_). NetBSD provided much of the original structure. 255f1e34d9SAlexandre Perrin 265f1e34d9SAlexandre PerrinSince then I've added a lot of features to NetBSD's make and hence to 275f1e34d9SAlexandre Perrinbmake which is kept closely in sync. The mk-files however have 28ca58f742SDaniel Fojtdiverged quite a bit, though ideas are still picked up from NetBSD 29ca58f742SDaniel Fojtand FreeBSD. 305f1e34d9SAlexandre Perrin 315f1e34d9SAlexandre PerrinBasics 325f1e34d9SAlexandre Perrin------ 335f1e34d9SAlexandre Perrin 345f1e34d9SAlexandre PerrinThe BSD build model is very simple. A directory produces one 355f1e34d9SAlexandre Perrincomponent, which is generally either a library or a program. 365f1e34d9SAlexandre PerrinLibrary makefiles include ``lib.mk`` and programs include ``prog.mk`` 375f1e34d9SAlexandre Perrinand they *do the right thing*. 385f1e34d9SAlexandre Perrin 395f1e34d9SAlexandre PerrinA simple library makefile might look like:: 405f1e34d9SAlexandre Perrin 415f1e34d9SAlexandre Perrin LIB = sig 425f1e34d9SAlexandre Perrin 435f1e34d9SAlexandre Perrin SRCS = \ 445f1e34d9SAlexandre Perrin sigaction.c \ 455f1e34d9SAlexandre Perrin sigcompat.c \ 465f1e34d9SAlexandre Perrin sighdl.c 475f1e34d9SAlexandre Perrin 485f1e34d9SAlexandre Perrin .include <lib.mk> 495f1e34d9SAlexandre Perrin 505f1e34d9SAlexandre Perrina simple program makefile:: 515f1e34d9SAlexandre Perrin 525f1e34d9SAlexandre Perrin PROG = cat 535f1e34d9SAlexandre Perrin 545f1e34d9SAlexandre Perrin SRCS = cat.c 555f1e34d9SAlexandre Perrin 565f1e34d9SAlexandre Perrin .include <prog.mk> 575f1e34d9SAlexandre Perrin 585f1e34d9SAlexandre Perrinin such cases even the ``SRCS`` line is unnecessary as ``prog.mk`` 595f1e34d9SAlexandre Perrinwill default it to ``${PROG}.c``. 605f1e34d9SAlexandre Perrin 615f1e34d9SAlexandre PerrinIt is the sensible use of defaults and the plethora of macro modifiers 62a34d5fb1SAntonio Huete Jimenezprovided by bmake_ that allow simple makefiles such as the above to 635f1e34d9SAlexandre Perrin*just work* on many different systems. 645f1e34d9SAlexandre Perrin 655f1e34d9SAlexandre Perrin 665f1e34d9SAlexandre Perrinmk-files 675f1e34d9SAlexandre Perrin======== 685f1e34d9SAlexandre Perrin 695f1e34d9SAlexandre PerrinThis section provides a brief description of some of the ``*.mk`` 705f1e34d9SAlexandre Perrinfiles. 715f1e34d9SAlexandre Perrin 725f1e34d9SAlexandre Perrinsys.mk 735f1e34d9SAlexandre Perrin------ 745f1e34d9SAlexandre Perrin 755f1e34d9SAlexandre PerrinWhen bmake starts, it looks for ``sys.mk`` and reads it before doing 765f1e34d9SAlexandre Perrinanything else. Thus, this is the place to setup the environment for 775f1e34d9SAlexandre Perrineveryone else. 785f1e34d9SAlexandre Perrin 79a34d5fb1SAntonio Huete JimenezIn this distribution, ``sys.mk`` avoids doing anything platform dependent. 805f1e34d9SAlexandre PerrinIt is quite short, and includes a number of other files (which may or 815f1e34d9SAlexandre Perrinmay not exists) 825f1e34d9SAlexandre Perrin 835f1e34d9SAlexandre Perrinsys.env.mk 845f1e34d9SAlexandre Perrin If it exists, is expected to do things like conditioning the 855f1e34d9SAlexandre Perrin environment. Since it will only be included by the initial 865f1e34d9SAlexandre Perrin instance of bmake, it should ``.export`` anything that 875f1e34d9SAlexandre Perrin sub-makes might need. 885f1e34d9SAlexandre Perrin 895f1e34d9SAlexandre Perrinexamples/sys.clean-env.mk 905f1e34d9SAlexandre Perrin An example of how to clean the environment. 915f1e34d9SAlexandre Perrin See the file for all the details:: 925f1e34d9SAlexandre Perrin 935f1e34d9SAlexandre Perrin .if ${MAKE_VERSION} >= 20100606 && ${.MAKE.LEVEL} == 0 945f1e34d9SAlexandre Perrin # we save any env var that starts with these 955f1e34d9SAlexandre Perrin MAKE_SAVE_ENV_PREFIX += SB MK MAKE MACHINE NEED_ CCACHE DISTCC USE_ SSH 965f1e34d9SAlexandre Perrin MAKE_SAVE_ENV_VARS += \ 975f1e34d9SAlexandre Perrin PATH HOME USER LOGNAME \ 985f1e34d9SAlexandre Perrin SRCTOP OBJTOP OBJROOT \ 995f1e34d9SAlexandre Perrin ${_env_vars} 1005f1e34d9SAlexandre Perrin 1015f1e34d9SAlexandre Perrin _env_vars != env | egrep '^(${MAKE_SAVE_ENV_PREFIX:ts|})' | sed 's,=.*,,'; echo 1025f1e34d9SAlexandre Perrin _export_list = 1035f1e34d9SAlexandre Perrin .for v in ${MAKE_SAVE_ENV_VARS:O:u} 1045f1e34d9SAlexandre Perrin .if !empty($v) 1055f1e34d9SAlexandre Perrin _export_list += $v 1065f1e34d9SAlexandre Perrin $v := ${$v} 1075f1e34d9SAlexandre Perrin .endif 1085f1e34d9SAlexandre Perrin .endfor 1095f1e34d9SAlexandre Perrin # now clobber the environment 1105f1e34d9SAlexandre Perrin .unexport-env 1115f1e34d9SAlexandre Perrin 1125f1e34d9SAlexandre Perrin # list of vars that we handle specially below 1135f1e34d9SAlexandre Perrin _tricky_env_vars = MAKEOBJDIR 1145f1e34d9SAlexandre Perrin # export our selection - sans tricky ones 1155f1e34d9SAlexandre Perrin .export ${_export_list:${_tricky_env_vars:${M_ListToSkip}}} 1165f1e34d9SAlexandre Perrin 1175f1e34d9SAlexandre Perrin # this next bit may need tweaking 1185f1e34d9SAlexandre Perrin .if defined(MAKEOBJDIR) 1195f1e34d9SAlexandre Perrin srctop := ${SRCTOP:U${SB_SRC:U${SB}/src}} 1205f1e34d9SAlexandre Perrin objroot := ${OBJROOT:U${SB_OBJROOT:U${SB}/${SB_OBJPREFIX}}} 1215f1e34d9SAlexandre Perrin # we'll take care of MACHINE below 1225f1e34d9SAlexandre Perrin objtop := ${OBJTOP:U${objroot}${MACHINE}} 1235f1e34d9SAlexandre Perrin .if !empty(objtop) 1245f1e34d9SAlexandre Perrin # we would normally want something like (/bin/sh): 1255f1e34d9SAlexandre Perrin # MAKEOBJDIR="\${.CURDIR:S,${SRCTOP},${OBJROOT}\${MACHINE},}" 1265f1e34d9SAlexandre Perrin # the $$ below is how we achieve the same result here. 1275f1e34d9SAlexandre Perrin # since everything saved from the environment above 1285f1e34d9SAlexandre Perrin # has run through := we need to compensate for ${MACHINE} 1295f1e34d9SAlexandre Perrin MAKEOBJDIR = $${.CURDIR:S,${srctop},${objtop:S,${MACHINE},\${MACHINE},},} 1305f1e34d9SAlexandre Perrin 1315f1e34d9SAlexandre Perrin # export these as-is, and do not track... 1325f1e34d9SAlexandre Perrin .export-env ${_tricky_env_vars} 1335f1e34d9SAlexandre Perrin # now evaluate for ourselves 1345f1e34d9SAlexandre Perrin .for v in ${_tricky_env_vars} 1355f1e34d9SAlexandre Perrin $v := ${$v} 1365f1e34d9SAlexandre Perrin .endfor 1375f1e34d9SAlexandre Perrin 1385f1e34d9SAlexandre Perrin .endif 1395f1e34d9SAlexandre Perrin .endif 1405f1e34d9SAlexandre Perrin .endif 1415f1e34d9SAlexandre Perrin 1425f1e34d9SAlexandre Perrin 1435f1e34d9SAlexandre Perrinhost-target.mk 1445f1e34d9SAlexandre Perrin Is used to set macros like ``HOST_TARGET``, ``HOST_OS`` and 1455f1e34d9SAlexandre Perrin ``host_os`` which are used to find the next step. 146*6eef5f0cSAntonio Huete Jimenez Note: since 20130303 bmake provides ``.MAKE.OS`` set to 147*6eef5f0cSAntonio Huete Jimenez the equivalent of ``HOST_OS``. 1485f1e34d9SAlexandre Perrin 1495f1e34d9SAlexandre Perrinsys/\*.mk 1505f1e34d9SAlexandre Perrin Platform specific additions, such as ``Darwin.mk`` or ``SunOS.mk`` 1515f1e34d9SAlexandre Perrin set things like ``HOST_LIBEXT = .dylib`` for Darwin or 1525f1e34d9SAlexandre Perrin ``SHLIB_FULLVERSION = ${SHLIB_MAJOR}`` for SunOS 5. 1535f1e34d9SAlexandre Perrin If there is no OS specific file, ``sys/Generic.mk`` is used. 1545f1e34d9SAlexandre Perrin 1555f1e34d9SAlexandre Perrinlocal.sys.mk 1565f1e34d9SAlexandre Perrin Any ``local.*.mk`` file is not part of the distribution. 1575f1e34d9SAlexandre Perrin This provides a hook for sites to do extra setup without 1585f1e34d9SAlexandre Perrin having to edit the distributed files. 1595f1e34d9SAlexandre Perrin 1605f1e34d9SAlexandre Perrin 1615f1e34d9SAlexandre PerrinThe above arrangement makes it easy for the mk files to be part of a 1625f1e34d9SAlexandre Perrinsrc tree on an NFS volume and to allow building on multiple platforms. 1635f1e34d9SAlexandre Perrin 164*6eef5f0cSAntonio Huete Jimenezoptions.mk 165*6eef5f0cSAntonio Huete Jimenez---------- 166*6eef5f0cSAntonio Huete Jimenez 167*6eef5f0cSAntonio Huete JimenezInspired by FreeBSD's ``bsd.own.mk`` but more flexible. 168*6eef5f0cSAntonio Huete JimenezFreeBSD now have similar functionality in ``bsd.mkopt.mk``. 169*6eef5f0cSAntonio Huete Jimenez 170*6eef5f0cSAntonio Huete JimenezIt allows users to express their intent with respect to options 171*6eef5f0cSAntonio Huete Jimenez``MK_*`` by setting ``WITH_*`` or ``WITHOUT_*``. 172*6eef5f0cSAntonio Huete Jimenez 173*6eef5f0cSAntonio Huete JimenezNote: ``WITHOUT_*`` wins if both are set, and makefiles can set 174*6eef5f0cSAntonio Huete Jimenez``NO_*`` to say they cannot handle that option, or even ``MK_*`` if 175*6eef5f0cSAntonio Huete Jimenezthey really need to. 176*6eef5f0cSAntonio Huete Jimenez 1775f1e34d9SAlexandre Perrinlib.mk 1785f1e34d9SAlexandre Perrin------ 1795f1e34d9SAlexandre Perrin 1805f1e34d9SAlexandre PerrinThis file is used to build a number of different libraries from the 1815f1e34d9SAlexandre Perrinsame SRCS. 1825f1e34d9SAlexandre Perrin 183*6eef5f0cSAntonio Huete Jimenez``lib${LIB}.a`` 1845f1e34d9SAlexandre Perrin An archive lib of ``.o`` files, this is the default 1855f1e34d9SAlexandre Perrin 186*6eef5f0cSAntonio Huete Jimenez``lib${LIB}_p.a`` 1875f1e34d9SAlexandre Perrin A profiled lib of ``.po`` files. 1885f1e34d9SAlexandre Perrin Still an archive lib, but all the objects are built with 1895f1e34d9SAlexandre Perrin profiling in mind - hence the different extension. 190*6eef5f0cSAntonio Huete Jimenez It is skipped if ``MK_PROFILE`` is "no". 1915f1e34d9SAlexandre Perrin 192*6eef5f0cSAntonio Huete Jimenez``lib${LIB}_pic.a`` 1935f1e34d9SAlexandre Perrin An archive of ``.so`` objects compiled for relocation. 1945f1e34d9SAlexandre Perrin On NetBSD this is the input to ``lib${LIB}.${LD_so}``, it is 195*6eef5f0cSAntonio Huete Jimenez skipped if ``MK_PIC`` or ``MK_PICLIB`` are "no". 1965f1e34d9SAlexandre Perrin 197*6eef5f0cSAntonio Huete Jimenez``lib${LIB}.${LD_so}`` 1985f1e34d9SAlexandre Perrin A shared library. The value of ``LD_so`` is very platform 1995f1e34d9SAlexandre Perrin specific. For example:: 2005f1e34d9SAlexandre Perrin 2015f1e34d9SAlexandre Perrin # SunOS 5 and most other ELF systems 2025f1e34d9SAlexandre Perrin libsslfd.so.1 2035f1e34d9SAlexandre Perrin 2045f1e34d9SAlexandre Perrin # Darwin 2055f1e34d9SAlexandre Perrin libsslfd.1.dylib 2065f1e34d9SAlexandre Perrin 2075f1e34d9SAlexandre Perrin This library will only be built if ``SHLIB_MAJOR`` has 208*6eef5f0cSAntonio Huete Jimenez a value, and ``MK_PIC`` is not set to "no". 2095f1e34d9SAlexandre Perrin 2105f1e34d9SAlexandre PerrinThere is a lot of platform specific tweaking in ``lib.mk``, largely the 2115f1e34d9SAlexandre Perrinresult of the original distributions trying to avoid interfering with 2125f1e34d9SAlexandre Perrinthe system's ``sys.mk``. 2135f1e34d9SAlexandre Perrin 2145f1e34d9SAlexandre Perrinlibnames.mk 2155f1e34d9SAlexandre Perrin----------- 2165f1e34d9SAlexandre Perrin 2175f1e34d9SAlexandre PerrinThis is included by both ``prog.mk`` and ``lib.mk`` and tries to 2185f1e34d9SAlexandre Perrininclude ``*.libnames.mk`` of which: 2195f1e34d9SAlexandre Perrin 220*6eef5f0cSAntonio Huete Jimenez``local.libnames.mk`` 2215f1e34d9SAlexandre Perrin does not exist unless you create it. It is a handy way for you 2225f1e34d9SAlexandre Perrin to customize without touching the distributed files. 2235f1e34d9SAlexandre Perrin For example, on a test machine I needed to build openssl but 2245f1e34d9SAlexandre Perrin not install it, so put the following in ``local.libnames.mk``:: 2255f1e34d9SAlexandre Perrin 2265f1e34d9SAlexandre Perrin .if ${host_os} == "sunos" 2275f1e34d9SAlexandre Perrin LIBCRYPTO = ${OBJTOP}/openssl/lib/crypto/libcrypto${DLIBEXT} 2285f1e34d9SAlexandre Perrin LIBSSL = ${OBJTOP}/openssl/lib/ssl/libssl${DLIBEXT} 2295f1e34d9SAlexandre Perrin INCLUDES_libcrypto = -I${OBJ_libcrypto} 2305f1e34d9SAlexandre Perrin .endif 2315f1e34d9SAlexandre Perrin 2325f1e34d9SAlexandre Perrin The makefile created an openssl dir in ``${OBJ_libcrypto}`` to 2335f1e34d9SAlexandre Perrin gather all the headers. dpadd.mk_ did the rest. 2345f1e34d9SAlexandre Perrin 235*6eef5f0cSAntonio Huete Jimenez``host.libnames.mk`` 2365f1e34d9SAlexandre Perrin contains logic to find any libs named in ``HOST_LIBS`` in 2375f1e34d9SAlexandre Perrin ``HOST_LIBDIRS``. 2385f1e34d9SAlexandre Perrin 2395f1e34d9SAlexandre PerrinEach file above gets an opportunity to define things like:: 2405f1e34d9SAlexandre Perrin 2415f1e34d9SAlexandre Perrin LIBSSLFD ?= ${OBJTOP}/ssl/lib/sslfd/libsslfd${DLIBEXT} 2425f1e34d9SAlexandre Perrin INCLUDES_libsslfd = -I${SRC_libsslfd}/h -I${OBJ_libslfd} 2435f1e34d9SAlexandre Perrin 2445f1e34d9SAlexandre Perrinthese are used by dpadd.mk_ and will be explained below. 2455f1e34d9SAlexandre Perrin 2465f1e34d9SAlexandre Perrindpadd.mk 2475f1e34d9SAlexandre Perrin-------- 2485f1e34d9SAlexandre Perrin 2495f1e34d9SAlexandre PerrinThis file looks like line noise, and is best considered read-only. 2505f1e34d9SAlexandre PerrinHowever it provides some very useful functionality, which simplifies the build. 2515f1e34d9SAlexandre Perrin 2525f1e34d9SAlexandre PerrinMakefiles can use the LIB* macros defined via libnames.mk_ or anywhere 2535f1e34d9SAlexandre Perrinelse in various ways:: 2545f1e34d9SAlexandre Perrin 2555f1e34d9SAlexandre Perrin # indicate that we need to include headers from LIBCRYPTO 2565f1e34d9SAlexandre Perrin # this would result in ${INCLUDES_libcrypto} being added to CFLAGS. 2575f1e34d9SAlexandre Perrin SRC_LIBS += ${LIBCRYPTO} 2585f1e34d9SAlexandre Perrin 2595f1e34d9SAlexandre Perrin # indicate that libsslfd must be built already. 2605f1e34d9SAlexandre Perrin # it also has the same effect as SRC_LIBS 2615f1e34d9SAlexandre Perrin DPADD += ${LIBSSLFD} 2625f1e34d9SAlexandre Perrin 2635f1e34d9SAlexandre Perrin # indicate that not only must libsslfd be built, 2645f1e34d9SAlexandre Perrin # but that we need to link with it. 2655f1e34d9SAlexandre Perrin # this is almost exactly equivalent to 2665f1e34d9SAlexandre Perrin # DPADD += ${LIBSSLFD} 2675f1e34d9SAlexandre Perrin # LDADD += -L${LIBSSLFD:H} -lsslfd 2685f1e34d9SAlexandre Perrin # and mostly serves to ensure that DPADD and LDADD are in sync. 2695f1e34d9SAlexandre Perrin DPLIBS += ${LIBSSLFD} 2705f1e34d9SAlexandre Perrin 2715f1e34d9SAlexandre PerrinAny library (referenced by its full path) in any of the above, is 2725f1e34d9SAlexandre Perrinadded to ``DPMAGIC_LIBS`` with the following results, for each lib *foo*. 2735f1e34d9SAlexandre Perrin 274*6eef5f0cSAntonio Huete Jimenez``SRC_libfoo`` 2755f1e34d9SAlexandre Perrin Is set to indicate where the src for libfoo is. 2765f1e34d9SAlexandre Perrin By default it is derived from ``LIBFOO`` by replacing 2775f1e34d9SAlexandre Perrin ``${OBJTOP}`` with ``${SRCTOP}``. 2785f1e34d9SAlexandre Perrin 279*6eef5f0cSAntonio Huete Jimenez``OBJ_libfoo`` 2805f1e34d9SAlexandre Perrin Not very exciting, is just the dir where libfoo lives. 2815f1e34d9SAlexandre Perrin 282*6eef5f0cSAntonio Huete Jimenez``INCLUDES_libfoo`` 2835f1e34d9SAlexandre Perrin What to add to ``CFLAGS`` to find the public headers. 2845f1e34d9SAlexandre Perrin The default varies. If ``${SRC_libfoo}/h`` exists, it is assumed 2855f1e34d9SAlexandre Perrin to be the home of all public headers and thus the default is 2865f1e34d9SAlexandre Perrin ``-I${SRC_libfoo}/h`` 2875f1e34d9SAlexandre Perrin 2885f1e34d9SAlexandre Perrin Otherwise we make no assumptions and the default is 2895f1e34d9SAlexandre Perrin ``-I${SRC_libfoo} -I${OBJ_libfoo}`` 2905f1e34d9SAlexandre Perrin 291*6eef5f0cSAntonio Huete Jimenez``LDADD_libfoo`` 2925f1e34d9SAlexandre Perrin This only applies to libs reference via ``DPLIBS``. 2935f1e34d9SAlexandre Perrin The default is ``-lfoo``, ``LDADD_*`` provides a hook to 2945f1e34d9SAlexandre Perrin instantiate other linker flags at the appropriate point 2955f1e34d9SAlexandre Perrin without losing the benfits of ``DPLIBS``. 2965f1e34d9SAlexandre Perrin 2975f1e34d9SAlexandre Perrinprog.mk 2985f1e34d9SAlexandre Perrin------- 2995f1e34d9SAlexandre Perrin 3005f1e34d9SAlexandre PerrinCompiles the specified SRCS and links them and the nominated libraries 3015f1e34d9SAlexandre Perrininto a program. Prog makefiles usually need to list the libraries 3025f1e34d9SAlexandre Perrinthat need to be linked. We prefer use of ``DPLIBS`` but the more 3035f1e34d9SAlexandre Perrintraditional ``DPADD`` and ``LDADD`` work just as well. 3045f1e34d9SAlexandre PerrinThat is:: 3055f1e34d9SAlexandre Perrin 306117e566dSSascha Wildner DPLIBS += ${LIBCRYPTO} 3075f1e34d9SAlexandre Perrin 3085f1e34d9SAlexandre Perrinis equivalent to:: 3095f1e34d9SAlexandre Perrin 310117e566dSSascha Wildner DPADD += ${LIBCRYPTO} 3115b245968SMatthew Dillon LDADD += -lprivate_crypto 3125f1e34d9SAlexandre Perrin 3135f1e34d9SAlexandre Perrinobj.mk 3145f1e34d9SAlexandre Perrin------ 3155f1e34d9SAlexandre Perrin 3165f1e34d9SAlexandre PerrinOne of the cool aspects of BSD make, is its support for separating 3175f1e34d9SAlexandre Perrinobject files from the src tree. This is also the source of much 3185f1e34d9SAlexandre Perrinconfusion to some. 3195f1e34d9SAlexandre Perrin 3205f1e34d9SAlexandre PerrinTraditionally one had to do a separate ``make obj`` pass through the 321*6eef5f0cSAntonio Huete Jimeneztree. If ``MK_AUTO_OBJ`` is set we include auto.obj.mk_. 322*6eef5f0cSAntonio Huete Jimenez 323*6eef5f0cSAntonio Huete JimenezIn fact if ``MKOBJDIRS`` is set to "auto", `sys.mk`_ will set 324*6eef5f0cSAntonio Huete Jimenez``MK_AUTO_OBJ=yes`` and include auto.obj.mk_ since it is best done early. 3255f1e34d9SAlexandre Perrin 3265f1e34d9SAlexandre Perrinauto.obj.mk 3275f1e34d9SAlexandre Perrin----------- 3285f1e34d9SAlexandre Perrin 3295f1e34d9SAlexandre PerrinThis leverages the ``.OBJDIR`` target introduced some years ago to 330*6eef5f0cSAntonio Huete JimenezNetBSD make, to automatically create and use the desired object dir. 3315f1e34d9SAlexandre Perrin 3325f1e34d9SAlexandre Perrinsubdir.mk 3335f1e34d9SAlexandre Perrin--------- 3345f1e34d9SAlexandre Perrin 3355f1e34d9SAlexandre PerrinThis is the traditional means of walking the tree. A makefile sets 3365f1e34d9SAlexandre Perrin``SUBDIR`` to the list of sub-dirs to visit. 3375f1e34d9SAlexandre Perrin 3385f1e34d9SAlexandre PerrinIf ``SUBDIR_MUST_EXIST`` is set, missing directories cause an error, 3395f1e34d9SAlexandre Perrinotherwise a warning is issued. If you don't even want the warning, 3405f1e34d9SAlexandre Perrinset ``MISSING_DIR=continue``. 3415f1e34d9SAlexandre Perrin 342a34d5fb1SAntonio Huete JimenezTraditionally, ``subdir.mk`` prints clues as it visits each subdir:: 3435f1e34d9SAlexandre Perrin 3445f1e34d9SAlexandre Perrin ===> ssl 3455f1e34d9SAlexandre Perrin ===> ssl/lib 3465f1e34d9SAlexandre Perrin ===> ssl/lib/sslfd 3475f1e34d9SAlexandre Perrin 3485f1e34d9SAlexandre Perrinyou can suppress that - or enhance it by setting ``ECHO_DIR``:: 3495f1e34d9SAlexandre Perrin 3505f1e34d9SAlexandre Perrin # suppress subdir noise 3515f1e34d9SAlexandre Perrin ECHO_DIR=: 3525f1e34d9SAlexandre Perrin # print time stamps 3535f1e34d9SAlexandre Perrin ECHO_DIR=echo @ `date "+%s [%Y-%m-%d %T] "` 3545f1e34d9SAlexandre Perrin 355*6eef5f0cSAntonio Huete JimenezI prefer to use `dirdeps.mk`_ which makes ``subdir.mk`` irrelevant. 356*6eef5f0cSAntonio Huete Jimenez 3575f1e34d9SAlexandre Perrinlinks.mk 3585f1e34d9SAlexandre Perrin-------- 3595f1e34d9SAlexandre Perrin 3605f1e34d9SAlexandre PerrinProvides rules for processing lists of ``LINKS`` and ``SYMLINKS``. 3615f1e34d9SAlexandre PerrinEach is expected to be a list of ``link`` and ``target`` pairs 3625f1e34d9SAlexandre Perrin(``link`` -> ``target``). 3635f1e34d9SAlexandre Perrin 3645f1e34d9SAlexandre PerrinThe logic is generally in a ``_*_SCRIPT`` which is referenced in a 3655f1e34d9SAlexandre Perrin``_*_USE`` (``.USE``) target. 3665f1e34d9SAlexandre Perrin 3675f1e34d9SAlexandre PerrinThe ``_BUILD_*`` forms are identical, but do not use ``${DESTDIR}`` 3685f1e34d9SAlexandre Perrinand so are useful for creating symlinks during the build phase. 3695f1e34d9SAlexandre PerrinFor example:: 3705f1e34d9SAlexandre Perrin 3715f1e34d9SAlexandre Perrin SYMLINKS += ${.CURDIR}/${MACHINE_ARCH}/include machine 3725f1e34d9SAlexandre Perrin header_links: _BUILD_SYMLINKS_USE 3735f1e34d9SAlexandre Perrin 3745f1e34d9SAlexandre Perrin md.o: header_links 3755f1e34d9SAlexandre Perrin 3765f1e34d9SAlexandre Perrinwould create a symlink called ``machine`` in ``${.OBJDIR}`` pointing to 3775f1e34d9SAlexandre Perrin``${.CURDIR}/${MACHINE_ARCH}/include`` before compiling ``md.o`` 3785f1e34d9SAlexandre Perrin 3795f1e34d9SAlexandre Perrin 3805f1e34d9SAlexandre Perrinautoconf.mk 3815f1e34d9SAlexandre Perrin----------- 3825f1e34d9SAlexandre Perrin 3835f1e34d9SAlexandre PerrinDeals with running (or generating) GNU autoconf ``configure`` scripts. 3845f1e34d9SAlexandre Perrin 3855f1e34d9SAlexandre Perrindep.mk 3865f1e34d9SAlexandre Perrin------ 3875f1e34d9SAlexandre Perrin 3885f1e34d9SAlexandre PerrinDeals with collecting dependencies. Another useful feature of BSD 3895f1e34d9SAlexandre Perrinmake is the separation of this sort of information into a ``.depend`` 390*6eef5f0cSAntonio Huete Jimenezfile. ``MKDEP_CMD`` needs to point to a suitable tool (like mkdeps.sh_) 3915f1e34d9SAlexandre Perrin 392*6eef5f0cSAntonio Huete JimenezIf ``MK_AUTODEP`` is "yes" it sets ``MKDEP_MK`` to autodep.mk_ by default. 393*6eef5f0cSAntonio Huete Jimenez 394*6eef5f0cSAntonio Huete Jimenez``MKDEP_MK`` can also be set to `auto.dep.mk`_ which is more efficient 395*6eef5f0cSAntonio Huete Jimenezbut does not support an explicit ``depend`` target. 3965f1e34d9SAlexandre Perrin 3975f1e34d9SAlexandre Perrinautodep.mk 3985f1e34d9SAlexandre Perrin---------- 3995f1e34d9SAlexandre Perrin 4005f1e34d9SAlexandre PerrinLeverages the ``-MD`` feature of recent GCC to collect dependency 4015f1e34d9SAlexandre Perrininformation as a side effect of compilation. With this GCC puts 4025f1e34d9SAlexandre Perrindependency info into a ``.d`` file. 4035f1e34d9SAlexandre Perrin 4045f1e34d9SAlexandre PerrinUnfortunately GCC bases the name of the ``.d`` file on the name of the 4055f1e34d9SAlexandre Perrininput rather than the output file, which causes problems when the same 4065f1e34d9SAlexandre Perrinsource is compiled different ways. The latest GCC supports ``-MF`` to 4075f1e34d9SAlexandre Perrinname the ``.d`` file and ``-MT`` to control the name to put as the 4085f1e34d9SAlexandre Perrindependent. 4095f1e34d9SAlexandre Perrin 4105f1e34d9SAlexandre PerrinRecent bmake allows dependencies for the ``.END`` target (run at the 4115f1e34d9SAlexandre Perrinend if everything was successful), and ``autodep.mk`` uses this to 4125f1e34d9SAlexandre Perrinpost process the ``.d`` files into ``.depend``. 4135f1e34d9SAlexandre Perrin 4145f1e34d9SAlexandre Perrinauto.dep.mk 4155f1e34d9SAlexandre Perrin----------- 4165f1e34d9SAlexandre Perrin 4175f1e34d9SAlexandre PerrinA much simpler implementation than autodep.mk_ it uses 4185f1e34d9SAlexandre Perrin``-MF ${.TARGET:T}.d`` 4195f1e34d9SAlexandre Perrinto avoid possible conflicts during parallel builds. 4205f1e34d9SAlexandre PerrinThis precludes the use of suffix rules to drive ``make depend``, so 4215f1e34d9SAlexandre Perrindep.mk_ handles that if specifically requested. 4225f1e34d9SAlexandre Perrin 423*6eef5f0cSAntonio Huete JimenezIf ``bmake`` is 20160218 or newer, ``auto.dep.mk`` uses ``.dinclude`` 424*6eef5f0cSAntonio Huete Jimenezto includes the ``*.d`` files directly thus avoiding the need to 425*6eef5f0cSAntonio Huete Jimenezcreate a ``.depend`` file from them. 426ca58f742SDaniel Fojt 4275f1e34d9SAlexandre Perrinown.mk 4285f1e34d9SAlexandre Perrin------ 4295f1e34d9SAlexandre Perrin 4305f1e34d9SAlexandre PerrinNormally included by ``init.mk`` (included by ``lib.mk`` and 4315f1e34d9SAlexandre Perrin``prog.mk`` etc), sets macros for default ownership etc. 4325f1e34d9SAlexandre Perrin 4335f1e34d9SAlexandre PerrinIt includes ``${MAKECONF}`` if it is defined and exists. 4345f1e34d9SAlexandre Perrin 435ca58f742SDaniel Fojtldorder.mk 436ca58f742SDaniel Fojt---------- 437ca58f742SDaniel Fojt 438ca58f742SDaniel FojtLeverages ``bmake`` to compute optimal link order for libraries. 439ca58f742SDaniel FojtThis works nicely and makes refactoring a breeze - so long as you 440*6eef5f0cSAntonio Huete Jimenezhave no (or few) cicular dependencies between libraries. 441ca58f742SDaniel Fojt 4425f1e34d9SAlexandre Perrinman.mk 4435f1e34d9SAlexandre Perrin------ 4445f1e34d9SAlexandre Perrin 4455f1e34d9SAlexandre PerrinDeals with man pages. 4465f1e34d9SAlexandre Perrin 4475f1e34d9SAlexandre Perrinwarnings.mk 4485f1e34d9SAlexandre Perrin----------- 4495f1e34d9SAlexandre Perrin 4505f1e34d9SAlexandre PerrinThis provides a means of fine grained control over warnings on a per 4515f1e34d9SAlexandre Perrin``${MACHINE}`` or even file basis. 4525f1e34d9SAlexandre Perrin 4535f1e34d9SAlexandre PerrinA makefile sets ``WARNINGS_SET`` to name a list of warnings 4545f1e34d9SAlexandre Perrinand individual ``W_*`` macros can be used to tweak them. 4555f1e34d9SAlexandre PerrinFor example:: 4565f1e34d9SAlexandre Perrin 4575f1e34d9SAlexandre Perrin WARNINGS_SET = HIGH 4585f1e34d9SAlexandre Perrin W_unused_sparc = -Wno-unused 4595f1e34d9SAlexandre Perrin 4605f1e34d9SAlexandre Perrinwould add all the warnings in ``${HIGH_WARNINGS}`` to CFLAGS, but 4615f1e34d9SAlexandre Perrinon sparc, ``-Wno-unused`` would replace ``-Wunused``. 4625f1e34d9SAlexandre Perrin 4635f1e34d9SAlexandre PerrinYou should never need to edit ``warnings.mk``, it will include 4645f1e34d9SAlexandre Perrin``warnings-sets.mk`` if it exists and you use that to make any local 4655f1e34d9SAlexandre Perrincustomizations. 4665f1e34d9SAlexandre Perrin 4676a91b982SJohn Marinorst2htm.mk 4686a91b982SJohn Marino---------- 4696a91b982SJohn Marino 4706a91b982SJohn MarinoLogic to simplify generating HTML (and PDF) documents from ReStructuredText. 4716a91b982SJohn Marino 4726a91b982SJohn Marinocython.mk 4736a91b982SJohn Marino--------- 4746a91b982SJohn Marino 4756a91b982SJohn MarinoLogic to build Python C interface modules using Cython_ 4766a91b982SJohn Marino 4776a91b982SJohn Marino.. _Cython: http://www.cython.org/ 4786a91b982SJohn Marino 479*6eef5f0cSAntonio Huete Jimenezcc-wrap.mk 480*6eef5f0cSAntonio Huete Jimenez---------- 481*6eef5f0cSAntonio Huete Jimenez 482*6eef5f0cSAntonio Huete JimenezThis makefile leverages two new features in bmake 20220126 and later. 483*6eef5f0cSAntonio Huete Jimenez 484*6eef5f0cSAntonio Huete JimenezFirst is the ablity to set target local variables (GNU make has done 485*6eef5f0cSAntonio Huete Jimenezthis for ages). 486*6eef5f0cSAntonio Huete Jimenez 487*6eef5f0cSAntonio Huete JimenezThe second (only intersting if using `meta mode`_) 488*6eef5f0cSAntonio Huete Jimenezallows filtering commands before comparison with previous run to 489*6eef5f0cSAntonio Huete Jimenezdecide if a target is out-of-date. 490*6eef5f0cSAntonio Huete Jimenez 491*6eef5f0cSAntonio Huete JimenezIn the past, making use of compiler wrappers like ``ccache``, 492*6eef5f0cSAntonio Huete Jimenez``distcc`` or the newer ``icecc`` could get quite ugly. 493*6eef5f0cSAntonio Huete JimenezUsing ``cc-wrap.mk`` it could not be simpler. 494*6eef5f0cSAntonio Huete Jimenez 4955f1e34d9SAlexandre PerrinMeta mode 4965f1e34d9SAlexandre Perrin========= 4975f1e34d9SAlexandre Perrin 4985f1e34d9SAlexandre PerrinThe 20110505 and later versions of ``mk-files`` include a number of 4996a91b982SJohn Marinomakefiles contributed by Juniper Networks, Inc. 5006a91b982SJohn MarinoThese allow the latest version of bmake_ to run in `meta mode`_ 5016a91b982SJohn Marinosee `dirdeps.mk`_ 5025f1e34d9SAlexandre Perrin 5036a91b982SJohn Marino.. _`dirdeps.mk`: /help/sjg/dirdeps.htm 5045f1e34d9SAlexandre Perrin.. _`meta mode`: bmake-meta-mode.htm 5055f1e34d9SAlexandre Perrin 5065f1e34d9SAlexandre PerrinInstall 5075f1e34d9SAlexandre Perrin======= 5085f1e34d9SAlexandre Perrin 5095f1e34d9SAlexandre PerrinYou can use the content of mk.tar.gz_ without installing at all. 5105f1e34d9SAlexandre Perrin 5115f1e34d9SAlexandre PerrinThe script ``install-mk`` takes care of copying ``*.mk`` into a 5125f1e34d9SAlexandre Perrindestination directory, and unless told not to, create ``bsd.*.mk`` links 5135f1e34d9SAlexandre Perrinfor ``lib.mk`` etc. 5145f1e34d9SAlexandre Perrin 5155f1e34d9SAlexandre PerrinIf you just want to create the ``bsd.*.mk`` links in the directory 5165f1e34d9SAlexandre Perrinwhere you unpacked the tar file, you can:: 5175f1e34d9SAlexandre Perrin 5185f1e34d9SAlexandre Perrin ./mk/install-mk ./mk 5195f1e34d9SAlexandre Perrin 5205f1e34d9SAlexandre Perrin------ 5215f1e34d9SAlexandre Perrin 5225f1e34d9SAlexandre Perrin.. _bmake: bmake.htm 5235f1e34d9SAlexandre Perrin.. _NetBSD: http://www.netbsd.org/ 5245f1e34d9SAlexandre Perrin.. _mkdeps.sh: http://www.crufty.net/ftp/pub/sjg/mkdeps.sh 5255f1e34d9SAlexandre Perrin.. _mk.tar.gz: http://www.crufty.net/ftp/pub/sjg/mk.tar.gz 5265f1e34d9SAlexandre Perrin 5275f1e34d9SAlexandre Perrin:Author: sjg@crufty.net 528*6eef5f0cSAntonio Huete Jimenez:Revision: $Id: mk-files.txt,v 1.21 2022/02/04 19:01:05 sjg Exp $ 5295f1e34d9SAlexandre Perrin:Copyright: Crufty.NET 530