The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/conf/kern.post.mk

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 # $FreeBSD$
    2 
    3 # Part of a unified Makefile for building kernels.  This part includes all
    4 # the definitions that need to be after all the % directives except %RULES
    5 # and ones that act like they are part of %RULES.
    6 #
    7 # Most make variables should not be defined in this file.  Instead, they
    8 # should be defined in the kern.pre.mk so that port makefiles can
    9 # override or augment them.
   10 
   11 # In case the config had a makeoptions DESTDIR...
   12 .if defined(DESTDIR)
   13 MKMODULESENV+=  DESTDIR="${DESTDIR}"
   14 .endif
   15 SYSDIR?= ${S:C;^[^/];${.CURDIR}/&;:tA}
   16 MKMODULESENV+=  KERNBUILDDIR="${.CURDIR}" SYSDIR="${SYSDIR}"
   17 
   18 .if defined(CONF_CFLAGS)
   19 MKMODULESENV+=  CONF_CFLAGS="${CONF_CFLAGS}"
   20 .endif
   21 
   22 .if defined(WITH_CTF)
   23 MKMODULESENV+=  WITH_CTF="${WITH_CTF}"
   24 .endif
   25 
   26 .if defined(WITH_EXTRA_TCP_STACKS)
   27 MKMODULESENV+=  WITH_EXTRA_TCP_STACKS="${WITH_EXTRA_TCP_STACKS}"
   28 .endif
   29 
   30 # Allow overriding the kernel debug directory, so kernel and user debug may be
   31 # installed in different directories. Setting it to "" restores the historical
   32 # behavior of installing debug files in the kernel directory.
   33 KERN_DEBUGDIR?= ${DEBUGDIR}
   34 
   35 .MAIN: all
   36 
   37 .for target in all clean cleandepend cleandir clobber depend install \
   38     obj reinstall tags
   39 ${target}: kernel-${target}
   40 .if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules)
   41 ${target}: modules-${target}
   42 modules-${target}:
   43         cd $S/modules; ${MKMODULESENV} ${MAKE} \
   44             ${target:S/^reinstall$/install/:S/^clobber$/cleandir/}
   45 .endif
   46 .endfor
   47 
   48 # Handle ports (as defined by the user) that build kernel modules
   49 .if !defined(NO_MODULES) && defined(PORTS_MODULES)
   50 #
   51 # The ports tree needs some environment variables defined to match the new kernel
   52 #
   53 # Ports search for some dependencies in PATH, so add the location of the installed files
   54 LOCALBASE?=     /usr/local
   55 # SRC_BASE is how the ports tree refers to the location of the base source files
   56 .if !defined(SRC_BASE)
   57 SRC_BASE=       ${SYSDIR:H:tA}
   58 .endif
   59 # OSVERSION is used by some ports to determine build options
   60 .if !defined(OSRELDATE)
   61 # Definition copied from src/Makefile.inc1
   62 OSRELDATE!=     awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
   63                     ${MAKEOBJDIRPREFIX}${SRC_BASE}/include/osreldate.h
   64 .endif
   65 # Keep the related ports builds in the obj directory so that they are only rebuilt once per kernel build
   66 WRKDIRPREFIX?=  ${.OBJDIR}
   67 PORTSMODULESENV=\
   68         env \
   69         -u CC \
   70         -u CXX \
   71         -u CPP \
   72         -u MAKESYSPATH \
   73         -u MK_AUTO_OBJ \
   74         -u MAKEOBJDIR \
   75         MAKEFLAGS="${MAKEFLAGS:M*:tW:S/^-m /-m_/g:S/ -m / -m_/g:tw:N-m_*:NMK_AUTO_OBJ=*}" \
   76         SYSDIR=${SYSDIR} \
   77         PATH=${PATH}:${LOCALBASE}/bin:${LOCALBASE}/sbin \
   78         SRC_BASE=${SRC_BASE} \
   79         OSVERSION=${OSRELDATE} \
   80         WRKDIRPREFIX=${WRKDIRPREFIX}
   81 
   82 # The WRKDIR needs to be cleaned before building, and trying to change the target
   83 # with a :C pattern below results in install -> instclean
   84 all:
   85 .for __i in ${PORTS_MODULES}
   86         @${ECHO} "===> Ports module ${__i} (all)"
   87         cd $${PORTSDIR:-/usr/ports}/${__i}; ${PORTSMODULESENV} ${MAKE} -B clean build
   88 .endfor
   89 
   90 .for __target in install reinstall clean
   91 ${__target}: ports-${__target}
   92 ports-${__target}:
   93 .for __i in ${PORTS_MODULES}
   94         @${ECHO} "===> Ports module ${__i} (${__target})"
   95         cd $${PORTSDIR:-/usr/ports}/${__i}; ${PORTSMODULESENV} ${MAKE} -B ${__target:C/install/deinstall reinstall/:C/reinstall/deinstall reinstall/}
   96 .endfor
   97 .endfor
   98 .endif
   99 
  100 .ORDER: kernel-install modules-install
  101 
  102 beforebuild: .PHONY
  103 kernel-all: beforebuild .WAIT ${KERNEL_KO} ${KERNEL_EXTRA}
  104 
  105 kernel-cleandir: kernel-clean kernel-cleandepend
  106 
  107 kernel-clobber:
  108         find . -maxdepth 1 ! -type d ! -name version -delete
  109 
  110 kernel-obj:
  111 
  112 .if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists($S/modules)
  113 modules: modules-all
  114 modules-depend: beforebuild
  115 modules-all: beforebuild
  116 
  117 .if !defined(NO_MODULES_OBJ)
  118 modules-all modules-depend: modules-obj
  119 .endif
  120 .endif
  121 
  122 .if !defined(DEBUG)
  123 FULLKERNEL=     ${KERNEL_KO}
  124 .else
  125 FULLKERNEL=     ${KERNEL_KO}.full
  126 ${KERNEL_KO}: ${FULLKERNEL} ${KERNEL_KO}.debug
  127         ${OBJCOPY} --strip-debug --add-gnu-debuglink=${KERNEL_KO}.debug \
  128             ${FULLKERNEL} ${.TARGET}
  129 ${KERNEL_KO}.debug: ${FULLKERNEL}
  130         ${OBJCOPY} --only-keep-debug ${FULLKERNEL} ${.TARGET}
  131 install.debug reinstall.debug: gdbinit
  132         cd ${.CURDIR}; ${MAKE} ${.TARGET:R}
  133 
  134 # Install gdbinit files for kernel debugging.
  135 gdbinit:
  136         grep -v '# XXX' ${S}/../tools/debugscripts/dot.gdbinit | \
  137             sed "s:MODPATH:${.OBJDIR}/modules:" > .gdbinit
  138         cp ${S}/../tools/debugscripts/gdbinit.kernel ${.CURDIR}
  139 .if exists(${S}/../tools/debugscripts/gdbinit.${MACHINE_CPUARCH})
  140         cp ${S}/../tools/debugscripts/gdbinit.${MACHINE_CPUARCH} \
  141             ${.CURDIR}/gdbinit.machine
  142 .endif
  143 .endif
  144 
  145 ${FULLKERNEL}: ${SYSTEM_DEP} vers.o
  146         @rm -f ${.TARGET}
  147         @echo linking ${.TARGET}
  148         ${SYSTEM_LD}
  149 .if !empty(MD_ROOT_SIZE_CONFIGURED) && defined(MFS_IMAGE)
  150         @sh ${S}/tools/embed_mfs.sh ${.TARGET} ${MFS_IMAGE}
  151 .endif
  152 .if ${MK_CTF} != "no"
  153         @echo ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ...
  154         @${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SYSTEM_OBJS} vers.o
  155 .endif
  156 .if !defined(DEBUG)
  157         ${OBJCOPY} --strip-debug ${.TARGET}
  158 .endif
  159         ${SYSTEM_LD_TAIL}
  160 
  161 OBJS_DEPEND_GUESS+=     assym.s vnode_if.h ${BEFORE_DEPEND:M*.h} \
  162                         ${MFILES:T:S/.m$/.h/}
  163 LNFILES=        ${CFILES:T:S/.c$/.ln/}
  164 
  165 .for mfile in ${MFILES}
  166 # XXX the low quality .m.o rules gnerated by config are normally used
  167 # instead of the .m.c rules here.
  168 ${mfile:T:S/.m$/.c/}: ${mfile}
  169         ${AWK} -f $S/tools/makeobjops.awk ${mfile} -c
  170 ${mfile:T:S/.m$/.h/}: ${mfile}
  171         ${AWK} -f $S/tools/makeobjops.awk ${mfile} -h
  172 .endfor
  173 
  174 kernel-clean:
  175         rm -f *.o *.so *.pico *.ko *.s eddep errs \
  176             ${FULLKERNEL} ${KERNEL_KO} ${KERNEL_KO}.debug \
  177             linterrs tags vers.c \
  178             vnode_if.c vnode_if.h vnode_if_newproto.h vnode_if_typedef.h \
  179             ${MFILES:T:S/.m$/.c/} ${MFILES:T:S/.m$/.h/} \
  180             ${CLEAN}
  181 
  182 lint: ${LNFILES}
  183         ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC} 2>&1 | \
  184             tee -a linterrs
  185 
  186 # This is a hack.  BFD "optimizes" away dynamic mode if there are no
  187 # dynamic references.  We could probably do a '-Bforcedynamic' mode like
  188 # in the a.out ld.  For now, this works.
  189 HACK_EXTRA_FLAGS?= -shared
  190 hack.pico: Makefile
  191         :> hack.c
  192         ${CC} ${HACK_EXTRA_FLAGS} -nostdlib hack.c -o hack.pico
  193         rm -f hack.c
  194 
  195 assym.s: $S/kern/genassym.sh genassym.o
  196         NM='${NM}' NMFLAGS='${NMFLAGS}' sh $S/kern/genassym.sh genassym.o > ${.TARGET}
  197 
  198 genassym.o: $S/$M/$M/genassym.c
  199         ${CC} -c ${CFLAGS:N-flto:N-fno-common} -fcommon $S/$M/$M/genassym.c
  200 
  201 OBJS_DEPEND_GUESS+= opt_global.h
  202 genassym.o vers.o: opt_global.h
  203 
  204 .if !empty(.MAKE.MODE:Unormal:Mmeta) && empty(.MAKE.MODE:Unormal:Mnofilemon)
  205 _meta_filemon=  1
  206 .endif
  207 # Skip reading .depend when not needed to speed up tree-walks and simple
  208 # lookups.  For install, only do this if no other targets are specified.
  209 # Also skip generating or including .depend.* files if in meta+filemon mode
  210 # since it will track dependencies itself.  OBJS_DEPEND_GUESS is still used.
  211 .if !empty(.MAKEFLAGS:M-V${_V_READ_DEPEND}) || make(*obj) || \
  212     ${.TARGETS:M*clean*} == ${.TARGETS} || \
  213     ${.TARGETS:M*install*} == ${.TARGETS} || \
  214     defined(_meta_filemon)
  215 _SKIP_READ_DEPEND=      1
  216 .MAKE.DEPENDFILE=       /dev/null
  217 .endif
  218 
  219 kernel-depend: .depend
  220 SRCS=   assym.s vnode_if.h ${BEFORE_DEPEND} ${CFILES} \
  221         ${SYSTEM_CFILES} ${GEN_CFILES} ${SFILES} \
  222         ${MFILES:T:S/.m$/.h/}
  223 DEPENDFILES=    .depend .depend.*
  224 DEPENDOBJS+=    ${SYSTEM_OBJS} genassym.o
  225 DEPENDOBJS+=    ${CLEAN:M*.o}
  226 DEPENDFILES_OBJS=       ${DEPENDOBJS:O:u:C/^/.depend./}
  227 .if ${MAKE_VERSION} < 20160220
  228 DEPEND_MP?=     -MP
  229 .endif
  230 DEPEND_CFLAGS+= -MD ${DEPEND_MP} -MF.depend.${.TARGET}
  231 DEPEND_CFLAGS+= -MT${.TARGET}
  232 .if !defined(_meta_filemon)
  233 .if defined(.PARSEDIR)
  234 # Only add in DEPEND_CFLAGS for CFLAGS on files we expect from DEPENDOBJS
  235 # as those are the only ones we will include.
  236 DEPEND_CFLAGS_CONDITION= "${DEPENDOBJS:M${.TARGET}}" != ""
  237 CFLAGS+=        ${${DEPEND_CFLAGS_CONDITION}:?${DEPEND_CFLAGS}:}
  238 .else
  239 CFLAGS+=        ${DEPEND_CFLAGS}
  240 .endif
  241 .if !defined(_SKIP_READ_DEPEND)
  242 .for __depend_obj in ${DEPENDFILES_OBJS}
  243 .if ${MAKE_VERSION} < 20160220
  244 .sinclude "${.OBJDIR}/${__depend_obj}"
  245 .else
  246 .dinclude "${.OBJDIR}/${__depend_obj}"
  247 .endif
  248 .endfor
  249 .endif  # !defined(_SKIP_READ_DEPEND)
  250 .endif  # !defined(_meta_filemon)
  251 
  252 # Always run 'make depend' to generate dependencies early and to avoid the
  253 # need for manually running it.  For the kernel this is mostly a NOP since
  254 # all dependencies are correctly added or accounted for.  This is mostly to
  255 # ensure downstream uses of kernel-depend are handled.
  256 beforebuild: kernel-depend
  257 
  258 # Guess some dependencies for when no ${DEPENDFILE}.OBJ is generated yet.
  259 # For meta+filemon the .meta file is checked for since it is the dependency
  260 # file used.
  261 .for __obj in ${DEPENDOBJS:O:u}
  262 .if (defined(_meta_filemon) && !exists(${.OBJDIR}/${__obj}.meta)) || \
  263     (!defined(_meta_filemon) && !exists(${.OBJDIR}/.depend.${__obj}))
  264 .if ${SYSTEM_OBJS:M${__obj}}
  265 ${__obj}: ${OBJS_DEPEND_GUESS}
  266 .endif
  267 ${__obj}: ${OBJS_DEPEND_GUESS.${__obj}}
  268 .elif defined(_meta_filemon)
  269 # For meta mode we still need to know which file to depend on to avoid
  270 # ambiguous suffix transformation rules from .PATH.  Meta mode does not
  271 # use .depend files.  We really only need source files, not headers since
  272 # they are typically in SRCS/beforebuild already.  For target-specific
  273 # guesses do include headers though since they may not be in SRCS.
  274 .if ${SYSTEM_OBJS:M${__obj}}
  275 ${__obj}: ${OBJS_DEPEND_GUESS:N*.h}
  276 .endif
  277 ${__obj}: ${OBJS_DEPEND_GUESS.${__obj}}
  278 .endif
  279 .endfor
  280 
  281 .NOPATH: .depend ${DEPENDFILES_OBJS}
  282 
  283 .depend: .PRECIOUS ${SRCS}
  284 
  285 _ILINKS= machine
  286 .if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64"
  287 _ILINKS+= ${MACHINE_CPUARCH}
  288 .endif
  289 .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
  290 _ILINKS+= x86
  291 .endif
  292 
  293 # Ensure that the link exists without depending on it when it exists.
  294 .for _link in ${_ILINKS}
  295 .if !exists(${.OBJDIR}/${_link})
  296 ${SRCS} ${DEPENDOBJS}: ${_link}
  297 .endif
  298 .endfor
  299 
  300 ${_ILINKS}:
  301         @case ${.TARGET} in \
  302         machine) \
  303                 path=${S}/${MACHINE}/include ;; \
  304         *) \
  305                 path=${S}/${.TARGET}/include ;; \
  306         esac ; \
  307         ${ECHO} ${.TARGET} "->" $$path ; \
  308         ln -fhs $$path ${.TARGET}
  309 
  310 # .depend needs include links so we remove them only together.
  311 kernel-cleandepend: .PHONY
  312         rm -f ${DEPENDFILES} ${_ILINKS}
  313 
  314 kernel-tags:
  315         @ls .depend.* > /dev/null 2>&1 || \
  316             { echo "you must make all first"; exit 1; }
  317         sh $S/conf/systags.sh
  318 
  319 kernel-install: .PHONY
  320         @if [ ! -f ${KERNEL_KO} ] ; then \
  321                 echo "You must build a kernel first." ; \
  322                 exit 1 ; \
  323         fi
  324 .if exists(${DESTDIR}${KODIR})
  325         -thiskernel=`sysctl -n kern.bootfile` ; \
  326         if [ ! "`dirname "$$thiskernel"`" -ef ${DESTDIR}${KODIR} ] ; then \
  327                 chflags -R noschg ${DESTDIR}${KODIR} ; \
  328                 rm -rf ${DESTDIR}${KODIR} ; \
  329                 rm -rf ${DESTDIR}${KERN_DEBUGDIR}${KODIR} ; \
  330         else \
  331                 if [ -d ${DESTDIR}${KODIR}.old ] ; then \
  332                         chflags -R noschg ${DESTDIR}${KODIR}.old ; \
  333                         rm -rf ${DESTDIR}${KODIR}.old ; \
  334                 fi ; \
  335                 mv ${DESTDIR}${KODIR} ${DESTDIR}${KODIR}.old ; \
  336                 if [ -n "${KERN_DEBUGDIR}" -a \
  337                      -d ${DESTDIR}${KERN_DEBUGDIR}${KODIR} ]; then \
  338                         rm -rf ${DESTDIR}${KERN_DEBUGDIR}${KODIR}.old ; \
  339                         mv ${DESTDIR}${KERN_DEBUGDIR}${KODIR} ${DESTDIR}${KERN_DEBUGDIR}${KODIR}.old ; \
  340                 fi ; \
  341                 sysctl kern.bootfile=${DESTDIR}${KODIR}.old/"`basename "$$thiskernel"`" ; \
  342         fi
  343 .endif
  344         mkdir -p ${DESTDIR}${KODIR}
  345         ${INSTALL} -p -m 555 -o ${KMODOWN} -g ${KMODGRP} ${KERNEL_KO} ${DESTDIR}${KODIR}/
  346 .if defined(DEBUG) && !defined(INSTALL_NODEBUG) && ${MK_KERNEL_SYMBOLS} != "no"
  347         mkdir -p ${DESTDIR}${KERN_DEBUGDIR}${KODIR}
  348         ${INSTALL} -p -m 555 -o ${KMODOWN} -g ${KMODGRP} ${KERNEL_KO}.debug ${DESTDIR}${KERN_DEBUGDIR}${KODIR}/
  349 .endif
  350 .if defined(KERNEL_EXTRA_INSTALL)
  351         ${INSTALL} -p -m 555 -o ${KMODOWN} -g ${KMODGRP} ${KERNEL_EXTRA_INSTALL} ${DESTDIR}${KODIR}/
  352 .endif
  353 
  354 
  355 
  356 kernel-reinstall:
  357         @-chflags -R noschg ${DESTDIR}${KODIR}
  358         ${INSTALL} -p -m 555 -o ${KMODOWN} -g ${KMODGRP} ${KERNEL_KO} ${DESTDIR}${KODIR}/
  359 .if defined(DEBUG) && !defined(INSTALL_NODEBUG) && ${MK_KERNEL_SYMBOLS} != "no"
  360         ${INSTALL} -p -m 555 -o ${KMODOWN} -g ${KMODGRP} ${KERNEL_KO}.debug ${DESTDIR}${KERN_DEBUGDIR}${KODIR}/
  361 .endif
  362 
  363 config.o env.o hints.o vers.o vnode_if.o:
  364         ${NORMAL_C}
  365         ${NORMAL_CTFCONVERT}
  366 
  367 config.ln env.ln hints.ln vers.ln vnode_if.ln:
  368         ${NORMAL_LINT}
  369 
  370 .if ${MK_REPRODUCIBLE_BUILD} != "no"
  371 REPRO_FLAG="-r"
  372 .endif
  373 vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP}
  374         MAKE=${MAKE} sh $S/conf/newvers.sh ${REPRO_FLAG} ${KERN_IDENT}
  375 
  376 vnode_if.c: $S/tools/vnode_if.awk $S/kern/vnode_if.src
  377         ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -c
  378 
  379 vnode_if.h vnode_if_newproto.h vnode_if_typedef.h: $S/tools/vnode_if.awk \
  380     $S/kern/vnode_if.src
  381 vnode_if.h: vnode_if_newproto.h vnode_if_typedef.h
  382         ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -h
  383 vnode_if_newproto.h:
  384         ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -p
  385 vnode_if_typedef.h:
  386         ${AWK} -f $S/tools/vnode_if.awk $S/kern/vnode_if.src -q
  387 
  388 .if ${MFS_IMAGE:Uno} != "no"
  389 .if empty(MD_ROOT_SIZE_CONFIGURED)
  390 # Generate an object file from the file system image to embed in the kernel
  391 # via linking. Make sure the contents are in the mfs section and rename the
  392 # start/end/size variables to __start_mfs, __stop_mfs, and mfs_size,
  393 # respectively.
  394 embedfs_${MFS_IMAGE:T:R}.o: ${MFS_IMAGE}
  395         ${OBJCOPY} --input-target binary \
  396             --output-target ${EMBEDFS_FORMAT.${MACHINE_ARCH}} \
  397             --binary-architecture ${EMBEDFS_ARCH.${MACHINE_ARCH}} \
  398             ${MFS_IMAGE} ${.TARGET}
  399         ${OBJCOPY} \
  400             --rename-section .data=mfs,contents,alloc,load,readonly,data \
  401             --redefine-sym \
  402                 _binary_${MFS_IMAGE:C,[^[:alnum:]],_,g}_size=__mfs_root_size \
  403             --redefine-sym \
  404                 _binary_${MFS_IMAGE:C,[^[:alnum:]],_,g}_start=mfs_root \
  405             --redefine-sym \
  406                 _binary_${MFS_IMAGE:C,[^[:alnum:]],_,g}_end=mfs_root_end \
  407             ${.TARGET}
  408 .endif
  409 .endif
  410 
  411 # XXX strictly, everything depends on Makefile because changes to ${PROF}
  412 # only appear there, but we don't handle that.
  413 
  414 .include "kern.mk"

Cache object: 48e066b59c96d016af5d6800a07e65fa


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.