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

Cache object: 98e8aeeabc0dad227c1c5a6b76ca097f


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