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

Cache object: 8871a607d50a1e862ad8bf82a44fe240


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