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.1/sys/conf/kmod.mk 265169 2014-05-01 03:18:11Z markj $
    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 .if ${MACHINE_CPUARCH} == powerpc
  129 CFLAGS+=        -mlongcall -fno-omit-frame-pointer
  130 .endif
  131 
  132 .if ${MACHINE_CPUARCH} == mips
  133 CFLAGS+=        -G0 -fno-pic -mno-abicalls -mlong-calls
  134 .endif
  135 
  136 .if defined(DEBUG) || defined(DEBUG_FLAGS)
  137 CTFFLAGS+=      -g
  138 .endif
  139 
  140 .if defined(FIRMWS)
  141 .if !exists(@)
  142 ${KMOD:S/$/.c/}: @
  143 .else
  144 ${KMOD:S/$/.c/}: @/tools/fw_stub.awk
  145 .endif
  146         ${AWK} -f @/tools/fw_stub.awk ${FIRMWS} -m${KMOD} -c${KMOD:S/$/.c/g} \
  147             ${FIRMWARE_LICENSE:C/.+/-l/}${FIRMWARE_LICENSE}
  148 
  149 SRCS+=  ${KMOD:S/$/.c/}
  150 CLEANFILES+=    ${KMOD:S/$/.c/}
  151 
  152 .for _firmw in ${FIRMWS}
  153 ${_firmw:C/\:.*$/.fwo/}:        ${_firmw:C/\:.*$//}
  154         @${ECHO} ${_firmw:C/\:.*$//} ${.ALLSRC:M*${_firmw:C/\:.*$//}}
  155         @if [ -e ${_firmw:C/\:.*$//} ]; then                    \
  156                 ${LD} -b binary --no-warn-mismatch ${LDFLAGS}   \
  157                     -r -d -o ${.TARGET} ${_firmw:C/\:.*$//};    \
  158         else                                                    \
  159                 ln -s ${.ALLSRC:M*${_firmw:C/\:.*$//}} ${_firmw:C/\:.*$//}; \
  160                 ${LD} -b binary --no-warn-mismatch ${LDFLAGS}   \
  161                     -r -d -o ${.TARGET} ${_firmw:C/\:.*$//};    \
  162                 rm ${_firmw:C/\:.*$//};                         \
  163         fi
  164 
  165 OBJS+=  ${_firmw:C/\:.*$/.fwo/}
  166 .endfor
  167 .endif
  168 
  169 OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
  170 
  171 .if !defined(PROG)
  172 PROG=   ${KMOD}.ko
  173 .endif
  174 
  175 .if !defined(DEBUG_FLAGS)
  176 FULLPROG=       ${PROG}
  177 .else
  178 FULLPROG=       ${PROG}.debug
  179 ${PROG}: ${FULLPROG} ${PROG}.symbols
  180         ${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROG}.symbols\
  181             ${FULLPROG} ${.TARGET}
  182 ${PROG}.symbols: ${FULLPROG}
  183         ${OBJCOPY} --only-keep-debug ${FULLPROG} ${.TARGET}
  184 .endif
  185 
  186 .if ${__KLD_SHARED} == yes
  187 ${FULLPROG}: ${KMOD}.kld
  188         ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld
  189 .if !defined(DEBUG_FLAGS)
  190         ${OBJCOPY} --strip-debug ${.TARGET}
  191 .endif
  192 .endif
  193 
  194 EXPORT_SYMS?=   NO
  195 .if ${EXPORT_SYMS} != YES
  196 CLEANFILES+=    export_syms
  197 .endif
  198 
  199 .if ${__KLD_SHARED} == yes
  200 ${KMOD}.kld: ${OBJS}
  201 .else
  202 ${FULLPROG}: ${OBJS}
  203 .endif
  204         ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS}
  205 .if defined(MK_CTF) && ${MK_CTF} != "no"
  206         ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
  207 .endif
  208 .if defined(EXPORT_SYMS)
  209 .if ${EXPORT_SYMS} != YES
  210 .if ${EXPORT_SYMS} == NO
  211         :> export_syms
  212 .elif !exists(${.CURDIR}/${EXPORT_SYMS})
  213         echo ${EXPORT_SYMS} > export_syms
  214 .else
  215         grep -v '^#' < ${EXPORT_SYMS} > export_syms
  216 .endif
  217         awk -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \
  218             export_syms | xargs -J% ${OBJCOPY} % ${.TARGET}
  219 .endif
  220 .endif
  221 .if !defined(DEBUG_FLAGS) && ${__KLD_SHARED} == no
  222         ${OBJCOPY} --strip-debug ${.TARGET}
  223 .endif
  224 
  225 _ILINKS=@ machine
  226 .if ${MACHINE} != ${MACHINE_CPUARCH}
  227 _ILINKS+=${MACHINE_CPUARCH}
  228 .endif
  229 .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
  230 _ILINKS+=x86
  231 .endif
  232 
  233 all: objwarn ${PROG}
  234 
  235 beforedepend: ${_ILINKS}
  236 
  237 # Ensure that the links exist without depending on it when it exists which
  238 # causes all the modules to be rebuilt when the directory pointed to changes.
  239 .for _link in ${_ILINKS}
  240 .if !exists(${.OBJDIR}/${_link})
  241 ${OBJS}: ${.OBJDIR}/${_link}
  242 .endif
  243 .endfor
  244 
  245 # Search for kernel source tree in standard places.
  246 .for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys
  247 .if !defined(SYSDIR) && exists(${_dir}/kern/)
  248 SYSDIR= ${_dir}
  249 .endif
  250 .endfor
  251 .if !defined(SYSDIR) || !exists(${SYSDIR}/kern/)
  252 .error "can't find kernel source tree"
  253 .endif
  254 
  255 .for _link in ${_ILINKS}
  256 .PHONY: ${_link}
  257 ${_link}: ${.OBJDIR}/${_link}
  258 
  259 ${.OBJDIR}/${_link}:
  260         @case ${.TARGET:T} in \
  261         machine) \
  262                 path=${SYSDIR}/${MACHINE}/include ;; \
  263         @) \
  264                 path=${SYSDIR} ;; \
  265         *) \
  266                 path=${SYSDIR}/${.TARGET:T}/include ;; \
  267         esac ; \
  268         path=`(cd $$path && /bin/pwd)` ; \
  269         ${ECHO} ${.TARGET:T} "->" $$path ; \
  270         ln -sf $$path ${.TARGET:T}
  271 .endfor
  272 
  273 CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS}
  274 
  275 .if defined(DEBUG_FLAGS)
  276 CLEANFILES+= ${FULLPROG} ${PROG}.symbols
  277 .endif
  278 
  279 .if !target(install)
  280 
  281 _INSTALLFLAGS:= ${INSTALLFLAGS}
  282 .for ie in ${INSTALLFLAGS_EDIT}
  283 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
  284 .endfor
  285 
  286 .if !target(realinstall)
  287 realinstall: _kmodinstall
  288 .ORDER: beforeinstall _kmodinstall
  289 _kmodinstall:
  290         ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
  291             ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
  292 .if defined(DEBUG_FLAGS) && !defined(INSTALL_NODEBUG) && ${MK_KERNEL_SYMBOLS} != "no"
  293         ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
  294             ${_INSTALLFLAGS} ${PROG}.symbols ${DESTDIR}${KMODDIR}
  295 .endif
  296 
  297 .include <bsd.links.mk>
  298 
  299 .if !defined(NO_XREF)
  300 afterinstall: _kldxref
  301 .ORDER: realinstall _kldxref
  302 .ORDER: _installlinks _kldxref
  303 _kldxref:
  304         @if type kldxref >/dev/null 2>&1; then \
  305                 ${ECHO} kldxref ${DESTDIR}${KMODDIR}; \
  306                 kldxref ${DESTDIR}${KMODDIR}; \
  307         fi
  308 .endif
  309 .endif # !target(realinstall)
  310 
  311 .endif # !target(install)
  312 
  313 .if !target(load)
  314 load: ${PROG}
  315         ${KMODLOAD} -v ${.OBJDIR}/${PROG}
  316 .endif
  317 
  318 .if !target(unload)
  319 unload:
  320         ${KMODUNLOAD} -v ${PROG}
  321 .endif
  322 
  323 .if defined(KERNBUILDDIR)
  324 .PATH: ${KERNBUILDDIR}
  325 CFLAGS+=        -I${KERNBUILDDIR}
  326 .for _src in ${SRCS:Mopt_*.h}
  327 CLEANFILES+=    ${_src}
  328 .if !target(${_src})
  329 ${_src}:
  330         ln -sf ${KERNBUILDDIR}/${_src} ${.TARGET}
  331 .endif
  332 .endfor
  333 .else
  334 .for _src in ${SRCS:Mopt_*.h}
  335 CLEANFILES+=    ${_src}
  336 .if !target(${_src})
  337 ${_src}:
  338         :> ${.TARGET}
  339 .endif
  340 .endfor
  341 .endif
  342 
  343 # Respect configuration-specific C flags.
  344 CFLAGS+=        ${CONF_CFLAGS}
  345 
  346 MFILES?= dev/acpica/acpi_if.m dev/acpi_support/acpi_wmi_if.m \
  347         dev/agp/agp_if.m dev/ata/ata_if.m dev/eisa/eisa_if.m \
  348         dev/fb/fb_if.m dev/gpio/gpio_if.m dev/gpio/gpiobus_if.m \
  349         dev/iicbus/iicbb_if.m dev/iicbus/iicbus_if.m \
  350         dev/mmc/mmcbr_if.m dev/mmc/mmcbus_if.m \
  351         dev/mii/miibus_if.m dev/mvs/mvs_if.m dev/ofw/ofw_bus_if.m \
  352         dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \
  353         dev/pci/pcib_if.m dev/ppbus/ppbus_if.m \
  354         dev/sdhci/sdhci_if.m dev/smbus/smbus_if.m dev/spibus/spibus_if.m \
  355         dev/sound/pci/hda/hdac_if.m \
  356         dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
  357         dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \
  358         dev/sound/midi/mpu_if.m dev/sound/midi/mpufoi_if.m \
  359         dev/sound/midi/synth_if.m dev/usb/usb_if.m isa/isa_if.m \
  360         kern/bus_if.m kern/clock_if.m \
  361         kern/cpufreq_if.m kern/device_if.m kern/serdev_if.m \
  362         libkern/iconv_converter_if.m opencrypto/cryptodev_if.m \
  363         pc98/pc98/canbus_if.m dev/etherswitch/mdio_if.m
  364 
  365 .for _srcsrc in ${MFILES}
  366 .for _ext in c h
  367 .for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
  368 CLEANFILES+=    ${_src}
  369 .if !target(${_src})
  370 .if !exists(@)
  371 ${_src}: @
  372 .else
  373 ${_src}: @/tools/makeobjops.awk @/${_srcsrc}
  374 .endif
  375         ${AWK} -f @/tools/makeobjops.awk @/${_srcsrc} -${_ext}
  376 .endif
  377 .endfor # _src
  378 .endfor # _ext
  379 .endfor # _srcsrc
  380 
  381 .if !empty(SRCS:Mvnode_if.c)
  382 CLEANFILES+=    vnode_if.c
  383 .if !exists(@)
  384 vnode_if.c: @
  385 .else
  386 vnode_if.c: @/tools/vnode_if.awk @/kern/vnode_if.src
  387 .endif
  388         ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -c
  389 .endif
  390 
  391 .if !empty(SRCS:Mvnode_if.h)
  392 CLEANFILES+=    vnode_if.h vnode_if_newproto.h vnode_if_typedef.h
  393 .if !exists(@)
  394 vnode_if.h vnode_if_newproto.h vnode_if_typedef.h: @
  395 .else
  396 vnode_if.h vnode_if_newproto.h vnode_if_typedef.h: @/tools/vnode_if.awk \
  397     @/kern/vnode_if.src
  398 .endif
  399 vnode_if.h: vnode_if_newproto.h vnode_if_typedef.h
  400         ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -h
  401 vnode_if_newproto.h:
  402         ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -p
  403 vnode_if_typedef.h:
  404         ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -q
  405 .endif
  406 
  407 .for _i in mii pccard
  408 .if !empty(SRCS:M${_i}devs.h)
  409 CLEANFILES+=    ${_i}devs.h
  410 .if !exists(@)
  411 ${_i}devs.h: @
  412 .else
  413 ${_i}devs.h: @/tools/${_i}devs2h.awk @/dev/${_i}/${_i}devs
  414 .endif
  415         ${AWK} -f @/tools/${_i}devs2h.awk @/dev/${_i}/${_i}devs
  416 .endif
  417 .endfor # _i
  418 
  419 .if !empty(SRCS:Musbdevs.h)
  420 CLEANFILES+=    usbdevs.h
  421 .if !exists(@)
  422 usbdevs.h: @
  423 .else
  424 usbdevs.h: @/tools/usbdevs2h.awk @/dev/usb/usbdevs
  425 .endif
  426         ${AWK} -f @/tools/usbdevs2h.awk @/dev/usb/usbdevs -h
  427 .endif
  428 
  429 .if !empty(SRCS:Musbdevs_data.h)
  430 CLEANFILES+=    usbdevs_data.h
  431 .if !exists(@)
  432 usbdevs_data.h: @
  433 .else
  434 usbdevs_data.h: @/tools/usbdevs2h.awk @/dev/usb/usbdevs
  435 .endif
  436         ${AWK} -f @/tools/usbdevs2h.awk @/dev/usb/usbdevs -d
  437 .endif
  438 
  439 .if !empty(SRCS:Macpi_quirks.h)
  440 CLEANFILES+=    acpi_quirks.h
  441 .if !exists(@)
  442 acpi_quirks.h: @
  443 .else
  444 acpi_quirks.h: @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks
  445 .endif
  446         ${AWK} -f @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks
  447 .endif
  448 
  449 .if !empty(SRCS:Massym.s)
  450 CLEANFILES+=    assym.s genassym.o
  451 assym.s: genassym.o
  452 .if defined(KERNBUILDDIR)
  453 genassym.o: opt_global.h
  454 .endif
  455 .if !exists(@)
  456 assym.s: @
  457 .else
  458 assym.s: @/kern/genassym.sh
  459 .endif
  460         sh @/kern/genassym.sh genassym.o > ${.TARGET}
  461 .if exists(@)
  462 genassym.o: @/${MACHINE_CPUARCH}/${MACHINE_CPUARCH}/genassym.c
  463 .endif
  464 genassym.o: @ machine ${SRCS:Mopt_*.h}
  465         ${CC} -c ${CFLAGS:N-fno-common} \
  466             @/${MACHINE_CPUARCH}/${MACHINE_CPUARCH}/genassym.c
  467 .endif
  468 
  469 lint: ${SRCS}
  470         ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC:M*.c}
  471 
  472 .if defined(KERNBUILDDIR)
  473 ${OBJS}: opt_global.h
  474 .endif
  475 
  476 .include <bsd.dep.mk>
  477 
  478 cleandepend: cleanilinks
  479 # .depend needs include links so we remove them only together.
  480 cleanilinks:
  481         rm -f ${_ILINKS}
  482 
  483 .if !exists(${.OBJDIR}/${DEPENDFILE})
  484 ${OBJS}: ${SRCS:M*.h}
  485 .endif
  486 
  487 .include <bsd.obj.mk>
  488 .include "kern.mk"

Cache object: 59570fe45989e762a2e44d1d4d0dbc92


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