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/kmod.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 #       From: @(#)bsd.prog.mk   5.26 (Berkeley) 6/25/91
    2 # $FreeBSD: releng/10.2/sys/conf/kmod.mk 278678 2015-02-13 15:41:28Z ian $
    3 #
    4 # The include file <bsd.kmod.mk> handles building and installing loadable
    5 # kernel modules.
    6 #
    7 #
    8 # +++ variables +++
    9 #
   10 # CLEANFILES    Additional files to remove for the clean and cleandir targets.
   11 #
   12 # EXPORT_SYMS   A list of symbols that should be exported from the module,
   13 #               or the name of a file containing a list of symbols, or YES
   14 #               to export all symbols.  If not defined, no symbols are
   15 #               exported.
   16 #
   17 # KMOD          The name of the kernel module to build.
   18 #
   19 # KMODDIR       Base path for kernel modules (see kld(4)). [/boot/kernel]
   20 #
   21 # KMODOWN       Module file owner. [${BINOWN}]
   22 #
   23 # KMODGRP       Module file group. [${BINGRP}]
   24 #
   25 # KMODMODE      Module file mode. [${BINMODE}]
   26 #
   27 # KMODLOAD      Command to load a kernel module [/sbin/kldload]
   28 #
   29 # KMODUNLOAD    Command to unload a kernel module [/sbin/kldunload]
   30 #
   31 # MFILES        Optionally a list of interfaces used by the module.
   32 #               This file contains a default list of interfaces.
   33 #
   34 # PROG          The name of the kernel module to build.
   35 #               If not supplied, ${KMOD}.ko is used.
   36 #
   37 # SRCS          List of source files.
   38 #
   39 # FIRMWS        List of firmware images in format filename:shortname:version
   40 #
   41 # FIRMWARE_LICENSE
   42 #               Set to the name of the license the user has to agree on in
   43 #               order to use this firmware. See /usr/share/doc/legal
   44 #
   45 # DESTDIR       The tree where the module gets installed. [not set]
   46 #
   47 # +++ targets +++
   48 #
   49 #       install:
   50 #               install the kernel module; if the Makefile
   51 #               does not itself define the target install, the targets
   52 #               beforeinstall and afterinstall may also be used to cause
   53 #               actions immediately before and after the install target
   54 #               is executed.
   55 #
   56 #       load:
   57 #               Load a module.
   58 #
   59 #       unload:
   60 #               Unload a module.
   61 #
   62 
   63 # backwards compat option for older systems.
   64 MACHINE_CPUARCH?=${MACHINE_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb)?/arm/:C/powerpc64/powerpc/}
   65 
   66 AWK?=           awk
   67 KMODLOAD?=      /sbin/kldload
   68 KMODUNLOAD?=    /sbin/kldunload
   69 OBJCOPY?=       objcopy
   70 
   71 .if defined(KMODDEPS)
   72 .error "Do not use KMODDEPS on 5.0+; use MODULE_VERSION/MODULE_DEPEND"
   73 .endif
   74 
   75 .include <bsd.init.mk>
   76 .include <bsd.compiler.mk>
   77 
   78 .SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
   79 
   80 # amd64 and mips use direct linking for kmod, all others use shared binaries
   81 .if ${MACHINE_CPUARCH} != amd64 && ${MACHINE_CPUARCH} != mips
   82 __KLD_SHARED=yes
   83 .else
   84 __KLD_SHARED=no
   85 .endif
   86 
   87 .if !empty(CFLAGS:M-O[23s]) && empty(CFLAGS:M-fno-strict-aliasing)
   88 CFLAGS+=        -fno-strict-aliasing
   89 .endif
   90 WERROR?=        -Werror
   91 CFLAGS+=        ${WERROR}
   92 CFLAGS+=        -D_KERNEL
   93 CFLAGS+=        -DKLD_MODULE
   94 
   95 # Don't use any standard or source-relative include directories.
   96 CSTD=           c99
   97 NOSTDINC=       -nostdinc
   98 CFLAGS:=        ${CFLAGS:N-I*} ${NOSTDINC} ${INCLMAGIC} ${CFLAGS:M-I*}
   99 .if defined(KERNBUILDDIR)
  100 CFLAGS+=        -DHAVE_KERNEL_OPTION_HEADERS -include ${KERNBUILDDIR}/opt_global.h
  101 .endif
  102 
  103 # Add -I paths for system headers.  Individual module makefiles don't
  104 # need any -I paths for this.  Similar defaults for .PATH can't be
  105 # set because there are no standard paths for non-headers.
  106 CFLAGS+=        -I. -I@
  107 
  108 # Add -I path for altq headers as they are included via net/if_var.h
  109 # for example.
  110 CFLAGS+=        -I@/contrib/altq
  111 
  112 .if ${COMPILER_TYPE} != "clang"
  113 CFLAGS+=        -finline-limit=${INLINE_LIMIT}
  114 CFLAGS+= --param inline-unit-growth=100
  115 CFLAGS+= --param large-function-growth=1000
  116 .endif
  117 
  118 # Disallow common variables, and if we end up with commons from
  119 # somewhere unexpected, allocate storage for them in the module itself.
  120 CFLAGS+=        -fno-common
  121 LDFLAGS+=       -d -warn-common
  122 
  123 CFLAGS+=        ${DEBUG_FLAGS}
  124 .if ${MACHINE_CPUARCH} == amd64
  125 CFLAGS+=        -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer
  126 .endif
  127 
  128 # Temporary workaround for PR 196407, which contains the fascinating details.
  129 # Don't allow clang to use fpu instructions or registers in kernel modules.
  130 .if ${MACHINE_CPUARCH} == arm
  131 CFLAGS.clang+=  -mllvm -arm-use-movt=0
  132 CFLAGS.clang+=  -mfpu=none
  133 .endif
  134 
  135 .if ${MACHINE_CPUARCH} == powerpc
  136 CFLAGS+=        -mlongcall -fno-omit-frame-pointer
  137 .endif
  138 
  139 .if ${MACHINE_CPUARCH} == mips
  140 CFLAGS+=        -G0 -fno-pic -mno-abicalls -mlong-calls
  141 .endif
  142 
  143 .if defined(DEBUG) || defined(DEBUG_FLAGS)
  144 CTFFLAGS+=      -g
  145 .endif
  146 
  147 .if defined(FIRMWS)
  148 .if !exists(@)
  149 ${KMOD:S/$/.c/}: @
  150 .else
  151 ${KMOD:S/$/.c/}: @/tools/fw_stub.awk
  152 .endif
  153         ${AWK} -f @/tools/fw_stub.awk ${FIRMWS} -m${KMOD} -c${KMOD:S/$/.c/g} \
  154             ${FIRMWARE_LICENSE:C/.+/-l/}${FIRMWARE_LICENSE}
  155 
  156 SRCS+=  ${KMOD:S/$/.c/}
  157 CLEANFILES+=    ${KMOD:S/$/.c/}
  158 
  159 .for _firmw in ${FIRMWS}
  160 ${_firmw:C/\:.*$/.fwo/}:        ${_firmw:C/\:.*$//}
  161         @${ECHO} ${_firmw:C/\:.*$//} ${.ALLSRC:M*${_firmw:C/\:.*$//}}
  162         @if [ -e ${_firmw:C/\:.*$//} ]; then                    \
  163                 ${LD} -b binary --no-warn-mismatch ${LDFLAGS}   \
  164                     -r -d -o ${.TARGET} ${_firmw:C/\:.*$//};    \
  165         else                                                    \
  166                 ln -s ${.ALLSRC:M*${_firmw:C/\:.*$//}} ${_firmw:C/\:.*$//}; \
  167                 ${LD} -b binary --no-warn-mismatch ${LDFLAGS}   \
  168                     -r -d -o ${.TARGET} ${_firmw:C/\:.*$//};    \
  169                 rm ${_firmw:C/\:.*$//};                         \
  170         fi
  171 
  172 OBJS+=  ${_firmw:C/\:.*$/.fwo/}
  173 .endfor
  174 .endif
  175 
  176 OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
  177 
  178 .if !defined(PROG)
  179 PROG=   ${KMOD}.ko
  180 .endif
  181 
  182 .if !defined(DEBUG_FLAGS)
  183 FULLPROG=       ${PROG}
  184 .else
  185 FULLPROG=       ${PROG}.debug
  186 ${PROG}: ${FULLPROG} ${PROG}.symbols
  187         ${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROG}.symbols\
  188             ${FULLPROG} ${.TARGET}
  189 ${PROG}.symbols: ${FULLPROG}
  190         ${OBJCOPY} --only-keep-debug ${FULLPROG} ${.TARGET}
  191 .endif
  192 
  193 .if ${__KLD_SHARED} == yes
  194 ${FULLPROG}: ${KMOD}.kld
  195         ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld
  196 .if !defined(DEBUG_FLAGS)
  197         ${OBJCOPY} --strip-debug ${.TARGET}
  198 .endif
  199 .endif
  200 
  201 EXPORT_SYMS?=   NO
  202 .if ${EXPORT_SYMS} != YES
  203 CLEANFILES+=    export_syms
  204 .endif
  205 
  206 .if ${__KLD_SHARED} == yes
  207 ${KMOD}.kld: ${OBJS}
  208 .else
  209 ${FULLPROG}: ${OBJS}
  210 .endif
  211         ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS}
  212 .if defined(MK_CTF) && ${MK_CTF} != "no"
  213         ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
  214 .endif
  215 .if defined(EXPORT_SYMS)
  216 .if ${EXPORT_SYMS} != YES
  217 .if ${EXPORT_SYMS} == NO
  218         :> export_syms
  219 .elif !exists(${.CURDIR}/${EXPORT_SYMS})
  220         echo ${EXPORT_SYMS} > export_syms
  221 .else
  222         grep -v '^#' < ${EXPORT_SYMS} > export_syms
  223 .endif
  224         awk -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \
  225             export_syms | xargs -J% ${OBJCOPY} % ${.TARGET}
  226 .endif
  227 .endif
  228 .if !defined(DEBUG_FLAGS) && ${__KLD_SHARED} == no
  229         ${OBJCOPY} --strip-debug ${.TARGET}
  230 .endif
  231 
  232 _ILINKS=@ machine
  233 .if ${MACHINE} != ${MACHINE_CPUARCH}
  234 _ILINKS+=${MACHINE_CPUARCH}
  235 .endif
  236 .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
  237 _ILINKS+=x86
  238 .endif
  239 
  240 all: objwarn ${PROG}
  241 
  242 beforedepend: ${_ILINKS}
  243 
  244 # Ensure that the links exist without depending on it when it exists which
  245 # causes all the modules to be rebuilt when the directory pointed to changes.
  246 .for _link in ${_ILINKS}
  247 .if !exists(${.OBJDIR}/${_link})
  248 ${OBJS}: ${.OBJDIR}/${_link}
  249 .endif
  250 .endfor
  251 
  252 # Search for kernel source tree in standard places.
  253 .for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys
  254 .if !defined(SYSDIR) && exists(${_dir}/kern/)
  255 SYSDIR= ${_dir}
  256 .endif
  257 .endfor
  258 .if !defined(SYSDIR) || !exists(${SYSDIR}/kern/)
  259 .error "can't find kernel source tree"
  260 .endif
  261 
  262 .for _link in ${_ILINKS}
  263 .PHONY: ${_link}
  264 ${_link}: ${.OBJDIR}/${_link}
  265 
  266 ${.OBJDIR}/${_link}:
  267         @case ${.TARGET:T} in \
  268         machine) \
  269                 path=${SYSDIR}/${MACHINE}/include ;; \
  270         @) \
  271                 path=${SYSDIR} ;; \
  272         *) \
  273                 path=${SYSDIR}/${.TARGET:T}/include ;; \
  274         esac ; \
  275         path=`(cd $$path && /bin/pwd)` ; \
  276         ${ECHO} ${.TARGET:T} "->" $$path ; \
  277         ln -sf $$path ${.TARGET:T}
  278 .endfor
  279 
  280 CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS}
  281 
  282 .if defined(DEBUG_FLAGS)
  283 CLEANFILES+= ${FULLPROG} ${PROG}.symbols
  284 .endif
  285 
  286 .if !target(install)
  287 
  288 _INSTALLFLAGS:= ${INSTALLFLAGS}
  289 .for ie in ${INSTALLFLAGS_EDIT}
  290 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
  291 .endfor
  292 
  293 .if !target(realinstall)
  294 realinstall: _kmodinstall
  295 .ORDER: beforeinstall _kmodinstall
  296 _kmodinstall:
  297         ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
  298             ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
  299 .if defined(DEBUG_FLAGS) && !defined(INSTALL_NODEBUG) && ${MK_KERNEL_SYMBOLS} != "no"
  300         ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
  301             ${_INSTALLFLAGS} ${PROG}.symbols ${DESTDIR}${KMODDIR}
  302 .endif
  303 
  304 .include <bsd.links.mk>
  305 
  306 .if !defined(NO_XREF)
  307 afterinstall: _kldxref
  308 .ORDER: realinstall _kldxref
  309 .ORDER: _installlinks _kldxref
  310 _kldxref:
  311         @if type kldxref >/dev/null 2>&1; then \
  312                 ${ECHO} kldxref ${DESTDIR}${KMODDIR}; \
  313                 kldxref ${DESTDIR}${KMODDIR}; \
  314         fi
  315 .endif
  316 .endif # !target(realinstall)
  317 
  318 .endif # !target(install)
  319 
  320 .if !target(load)
  321 load: ${PROG}
  322         ${KMODLOAD} -v ${.OBJDIR}/${PROG}
  323 .endif
  324 
  325 .if !target(unload)
  326 unload:
  327         ${KMODUNLOAD} -v ${PROG}
  328 .endif
  329 
  330 .if defined(KERNBUILDDIR)
  331 .PATH: ${KERNBUILDDIR}
  332 CFLAGS+=        -I${KERNBUILDDIR}
  333 .for _src in ${SRCS:Mopt_*.h}
  334 CLEANFILES+=    ${_src}
  335 .if !target(${_src})
  336 ${_src}:
  337         ln -sf ${KERNBUILDDIR}/${_src} ${.TARGET}
  338 .endif
  339 .endfor
  340 .else
  341 .for _src in ${SRCS:Mopt_*.h}
  342 CLEANFILES+=    ${_src}
  343 .if !target(${_src})
  344 ${_src}:
  345         :> ${.TARGET}
  346 .endif
  347 .endfor
  348 .endif
  349 
  350 # Respect configuration-specific C flags.
  351 CFLAGS+=        ${CONF_CFLAGS}
  352 
  353 MFILES?= dev/acpica/acpi_if.m dev/acpi_support/acpi_wmi_if.m \
  354         dev/agp/agp_if.m dev/ata/ata_if.m dev/eisa/eisa_if.m \
  355         dev/fb/fb_if.m dev/gpio/gpio_if.m dev/gpio/gpiobus_if.m \
  356         dev/iicbus/iicbb_if.m dev/iicbus/iicbus_if.m \
  357         dev/mmc/mmcbr_if.m dev/mmc/mmcbus_if.m \
  358         dev/mii/miibus_if.m dev/mvs/mvs_if.m dev/ofw/ofw_bus_if.m \
  359         dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \
  360         dev/pci/pcib_if.m dev/ppbus/ppbus_if.m \
  361         dev/sdhci/sdhci_if.m dev/smbus/smbus_if.m dev/spibus/spibus_if.m \
  362         dev/sound/pci/hda/hdac_if.m \
  363         dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
  364         dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \
  365         dev/sound/midi/mpu_if.m dev/sound/midi/mpufoi_if.m \
  366         dev/sound/midi/synth_if.m dev/usb/usb_if.m isa/isa_if.m \
  367         kern/bus_if.m kern/clock_if.m \
  368         kern/cpufreq_if.m kern/device_if.m kern/serdev_if.m \
  369         libkern/iconv_converter_if.m opencrypto/cryptodev_if.m \
  370         pc98/pc98/canbus_if.m dev/etherswitch/mdio_if.m
  371 
  372 .for _srcsrc in ${MFILES}
  373 .for _ext in c h
  374 .for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
  375 CLEANFILES+=    ${_src}
  376 .if !target(${_src})
  377 .if !exists(@)
  378 ${_src}: @
  379 .else
  380 ${_src}: @/tools/makeobjops.awk @/${_srcsrc}
  381 .endif
  382         ${AWK} -f @/tools/makeobjops.awk @/${_srcsrc} -${_ext}
  383 .endif
  384 .endfor # _src
  385 .endfor # _ext
  386 .endfor # _srcsrc
  387 
  388 .if !empty(SRCS:Mvnode_if.c)
  389 CLEANFILES+=    vnode_if.c
  390 .if !exists(@)
  391 vnode_if.c: @
  392 .else
  393 vnode_if.c: @/tools/vnode_if.awk @/kern/vnode_if.src
  394 .endif
  395         ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -c
  396 .endif
  397 
  398 .if !empty(SRCS:Mvnode_if.h)
  399 CLEANFILES+=    vnode_if.h vnode_if_newproto.h vnode_if_typedef.h
  400 .if !exists(@)
  401 vnode_if.h vnode_if_newproto.h vnode_if_typedef.h: @
  402 .else
  403 vnode_if.h vnode_if_newproto.h vnode_if_typedef.h: @/tools/vnode_if.awk \
  404     @/kern/vnode_if.src
  405 .endif
  406 vnode_if.h: vnode_if_newproto.h vnode_if_typedef.h
  407         ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -h
  408 vnode_if_newproto.h:
  409         ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -p
  410 vnode_if_typedef.h:
  411         ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -q
  412 .endif
  413 
  414 .for _i in mii pccard
  415 .if !empty(SRCS:M${_i}devs.h)
  416 CLEANFILES+=    ${_i}devs.h
  417 .if !exists(@)
  418 ${_i}devs.h: @
  419 .else
  420 ${_i}devs.h: @/tools/${_i}devs2h.awk @/dev/${_i}/${_i}devs
  421 .endif
  422         ${AWK} -f @/tools/${_i}devs2h.awk @/dev/${_i}/${_i}devs
  423 .endif
  424 .endfor # _i
  425 
  426 .if !empty(SRCS:Musbdevs.h)
  427 CLEANFILES+=    usbdevs.h
  428 .if !exists(@)
  429 usbdevs.h: @
  430 .else
  431 usbdevs.h: @/tools/usbdevs2h.awk @/dev/usb/usbdevs
  432 .endif
  433         ${AWK} -f @/tools/usbdevs2h.awk @/dev/usb/usbdevs -h
  434 .endif
  435 
  436 .if !empty(SRCS:Musbdevs_data.h)
  437 CLEANFILES+=    usbdevs_data.h
  438 .if !exists(@)
  439 usbdevs_data.h: @
  440 .else
  441 usbdevs_data.h: @/tools/usbdevs2h.awk @/dev/usb/usbdevs
  442 .endif
  443         ${AWK} -f @/tools/usbdevs2h.awk @/dev/usb/usbdevs -d
  444 .endif
  445 
  446 .if !empty(SRCS:Macpi_quirks.h)
  447 CLEANFILES+=    acpi_quirks.h
  448 .if !exists(@)
  449 acpi_quirks.h: @
  450 .else
  451 acpi_quirks.h: @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks
  452 .endif
  453         ${AWK} -f @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks
  454 .endif
  455 
  456 .if !empty(SRCS:Massym.s)
  457 CLEANFILES+=    assym.s genassym.o
  458 assym.s: genassym.o
  459 .if defined(KERNBUILDDIR)
  460 genassym.o: opt_global.h
  461 .endif
  462 .if !exists(@)
  463 assym.s: @
  464 .else
  465 assym.s: @/kern/genassym.sh
  466 .endif
  467         sh @/kern/genassym.sh genassym.o > ${.TARGET}
  468 .if exists(@)
  469 genassym.o: @/${MACHINE_CPUARCH}/${MACHINE_CPUARCH}/genassym.c
  470 .endif
  471 genassym.o: @ machine ${SRCS:Mopt_*.h}
  472         ${CC} -c ${CFLAGS:N-fno-common} \
  473             @/${MACHINE_CPUARCH}/${MACHINE_CPUARCH}/genassym.c
  474 .endif
  475 
  476 lint: ${SRCS}
  477         ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC:M*.c}
  478 
  479 .if defined(KERNBUILDDIR)
  480 ${OBJS}: opt_global.h
  481 .endif
  482 
  483 .include <bsd.dep.mk>
  484 
  485 cleandepend: cleanilinks
  486 # .depend needs include links so we remove them only together.
  487 cleanilinks:
  488         rm -f ${_ILINKS}
  489 
  490 .if !exists(${.OBJDIR}/${DEPENDFILE})
  491 ${OBJS}: ${SRCS:M*.h}
  492 .endif
  493 
  494 .include <bsd.obj.mk>
  495 .include "kern.mk"

Cache object: b1ae137be4caa201d8a773c0eaa5d26c


[ 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.