kmod.mk revision 133653
155682Smarkm# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2178825Sdfr# $FreeBSD: head/sys/conf/kmod.mk 133653 2004-08-13 14:30:26Z ru $ 355682Smarkm# 455682Smarkm# The include file <bsd.kmod.mk> handles installing Kernel Loadable Device 555682Smarkm# drivers (KLD's). 655682Smarkm# 755682Smarkm# 855682Smarkm# +++ variables +++ 955682Smarkm# 1055682Smarkm# CLEANFILES Additional files to remove for the clean and cleandir targets. 1155682Smarkm# 1255682Smarkm# KMOD The name of the kernel module to build. 1355682Smarkm# 1455682Smarkm# KMODDIR Base path for kernel modules (see kld(4)). [/boot/kernel] 1555682Smarkm# 1655682Smarkm# KMODOWN KLD owner. [${BINOWN}] 1755682Smarkm# 1855682Smarkm# KMODGRP KLD group. [${BINGRP}] 1955682Smarkm# 2055682Smarkm# KMODMODE KLD mode. [${BINMODE}] 2155682Smarkm# 2255682Smarkm# KMODLOAD Command to load a kernel module [/sbin/kldload] 2355682Smarkm# 2455682Smarkm# KMODUNLOAD Command to unload a kernel module [/sbin/kldunload] 2555682Smarkm# 2655682Smarkm# PROG The name of the kernel module to build. 2755682Smarkm# If not supplied, ${KMOD}.o is used. 2855682Smarkm# 2955682Smarkm# SRCS List of source files 3055682Smarkm# 3155682Smarkm# DESTDIR Change the tree where the module gets installed. [not set] 3255682Smarkm# 3355682Smarkm# MFILES Optionally a list of interfaces used by the module. 3455682Smarkm# This file contains a default list of interfaces. 3555682Smarkm# 36178825Sdfr# EXPORT_SYMS A list of symbols that should be exported from the module, 3755682Smarkm# or the name of a file containing a list of symbols, or YES 3890926Snectar# to export all symbols. If not defined, no symbols are 3990926Snectar# exported. 4090926Snectar# 4190926Snectar# +++ targets +++ 4290926Snectar# 4390926Snectar# install: 4490926Snectar# install the kernel module; if the Makefile 4590926Snectar# does not itself define the target install, the targets 4690926Snectar# beforeinstall and afterinstall may also be used to cause 4790926Snectar# actions immediately before and after the install target 4890926Snectar# is executed. 4990926Snectar# 5090926Snectar# load: 5190926Snectar# Load KLD. 5290926Snectar# 5390926Snectar# unload: 5490926Snectar# Unload KLD. 5590926Snectar# 5655682Smarkm# bsd.obj.mk: clean, cleandir and obj 5755682Smarkm# bsd.dep.mk: cleandepend, depend and tags 5855682Smarkm# 5955682Smarkm 6055682SmarkmAWK?= awk 6155682SmarkmKMODLOAD?= /sbin/kldload 6255682SmarkmKMODUNLOAD?= /sbin/kldunload 63178825SdfrOBJCOPY?= objcopy 6455682Smarkm 65178825Sdfr.if defined(KMODDEPS) 66178825Sdfr.error "Do not use KMODDEPS on 5.0+, use MODULE_VERSION/MODULE_DEPEND" 6755682Smarkm.endif 6890926Snectar 6990926Snectar.include <bsd.init.mk> 70178825Sdfr 7190926Snectar.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 7290926Snectar 7390926Snectar.if ${CC} == "icc" 7490926SnectarCFLAGS:= ${CFLAGS:C/(-x[^M^K^W]+)[MKW]+|-x[MKW]+/\1/} 7590926Snectar.endif 7690926SnectarCFLAGS+= -D_KERNEL 7790926SnectarCFLAGS+= -DKLD_MODULE 7890926Snectar 7990926Snectar# Don't use any standard or source-relative include directories. 80178825Sdfr# Since -nostdinc will annull any previous -I paths, we repeat all 81178825Sdfr# such paths after -nostdinc. It doesn't seem to be possible to 82178825Sdfr# add to the front of `make' variable. 8390926Snectar_ICFLAGS:= ${CFLAGS:M-I*} 8472445Sassar.if ${CC} == "icc" 8572445SassarNOSTDINC= -X 8672445Sassar.else 8755682SmarkmNOSTDINC= -nostdinc 88178825Sdfr.endif 89178825SdfrCFLAGS+= ${NOSTDINC} -I- ${INCLMAGIC} ${_ICFLAGS} 90178825Sdfr.if defined(KERNBUILDDIR) 9155682SmarkmCFLAGS+= -include ${KERNBUILDDIR}/opt_global.h 92178825Sdfr.endif 9355682Smarkm 9455682Smarkm# Add -I paths for system headers. Individual KLD makefiles don't 9555682Smarkm# need any -I paths for this. Similar defaults for .PATH can't be 9655682Smarkm# set because there are no standard paths for non-headers. 9755682SmarkmCFLAGS+= -I. -I@ 98178825Sdfr 99178825Sdfr# Add -I path for altq headers as they are included via net/if_var.h 100178825Sdfr# for example. 101178825SdfrCFLAGS+= -I@/contrib/altq 102178825Sdfr 103178825Sdfr# Add a -I path to standard headers like <stddef.h>. Use a relative 10455682Smarkm# path to src/include if possible. If the @ symlink hasn't been built 10555682Smarkm# yet, then we can't tell if the relative path exists. Add both the 106178825Sdfr# potential relative path and an absolute path in that case. 10755682Smarkm.if exists(@) 10855682Smarkm.if exists(@/../include) 10955682SmarkmCFLAGS+= -I@/../include 11055682Smarkm.else 11155682SmarkmCFLAGS+= -I${DESTDIR}/usr/include 112178825Sdfr.endif 11355682Smarkm.else # !@ 11455682SmarkmCFLAGS+= -I@/../include -I${DESTDIR}/usr/include 11555682Smarkm.endif # @ 11655682Smarkm 11755682Smarkm.if ${CC} != "icc" 11855682SmarkmCFLAGS+= -finline-limit=${INLINE_LIMIT} 11955682Smarkm.endif 12055682Smarkm 12155682Smarkm# Disallow common variables, and if we end up with commons from 12255682Smarkm# somewhere unexpected, allocate storage for them in the module itself. 12355682Smarkm.if ${CC} != "icc" 12455682SmarkmCFLAGS+= -fno-common 125178825Sdfr.endif 12655682SmarkmLDFLAGS+= -d -warn-common 12755682Smarkm 12855682SmarkmCFLAGS+= ${DEBUG_FLAGS} 129 130OBJS+= ${SRCS:N*.h:R:S/$/.o/g} 131 132.if !defined(PROG) 133PROG= ${KMOD}.ko 134.endif 135 136.if !defined(DEBUG_FLAGS) 137FULLPROG= ${PROG} 138.else 139FULLPROG= ${PROG}.debug 140${PROG}: ${FULLPROG} 141 ${OBJCOPY} --strip-debug ${FULLPROG} ${PROG} 142.endif 143 144.if ${MACHINE_ARCH} != amd64 145${FULLPROG}: ${KMOD}.kld 146 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld 147.if !defined(DEBUG_FLAGS) 148 ${OBJCOPY} --strip-debug ${.TARGET} 149.endif 150.endif 151 152EXPORT_SYMS?= NO 153.if ${EXPORT_SYMS} != YES 154CLEANFILES+= ${.OBJDIR}/export_syms 155.endif 156 157.if ${MACHINE_ARCH} != amd64 158${KMOD}.kld: ${OBJS} 159.else 160${FULLPROG}: ${OBJS} 161.endif 162 ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS} 163.if defined(EXPORT_SYMS) 164.if ${EXPORT_SYMS} != YES 165.if ${EXPORT_SYMS} == NO 166 touch ${.OBJDIR}/export_syms 167.elif !exists(${.CURDIR}/${EXPORT_SYMS}) 168 echo ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 169.else 170 grep -v '^#' < ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 171.endif 172 awk -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \ 173 ${.OBJDIR}/export_syms | \ 174 xargs -J% ${OBJCOPY} % ${.TARGET} 175.endif 176.endif 177.if !defined(DEBUG_FLAGS) && ${MACHINE_ARCH} == amd64 178 ${OBJCOPY} --strip-debug ${.TARGET} 179.endif 180 181_ILINKS=@ machine 182 183all: objwarn ${PROG} 184 185beforedepend: ${_ILINKS} 186 @rm -f .depend 187 188# Ensure that the links exist without depending on it when it exists which 189# causes all the modules to be rebuilt when the directory pointed to changes. 190.for _link in ${_ILINKS} 191.if !exists(${.OBJDIR}/${_link}) 192${OBJS}: ${_link} 193.endif 194.endfor 195 196# Search for kernel source tree in standard places. 197.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys 198.if !defined(SYSDIR) && exists(${_dir}/kern/) 199SYSDIR= ${_dir} 200.endif 201.endfor 202.if !defined(SYSDIR) || !exists(${SYSDIR}/kern/) 203.error "can't find kernel source tree" 204.endif 205 206${_ILINKS}: 207 @case ${.TARGET} in \ 208 machine) \ 209 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \ 210 @) \ 211 path=${SYSDIR} ;; \ 212 esac ; \ 213 path=`(cd $$path && /bin/pwd)` ; \ 214 ${ECHO} ${.TARGET} "->" $$path ; \ 215 ln -s $$path ${.TARGET} 216 217CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o 218 219.if defined(DEBUG_FLAGS) 220CLEANFILES+= ${FULLPROG} 221.endif 222 223.if !target(install) 224 225_INSTALLFLAGS:= ${INSTALLFLAGS} 226.for ie in ${INSTALLFLAGS_EDIT} 227_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 228.endfor 229 230.if defined(DEBUG_FLAGS) 231install.debug: 232 cd ${.CURDIR}; ${MAKE} -DINSTALL_DEBUG install 233.endif 234 235.if !target(realinstall) 236realinstall: _kmodinstall 237.ORDER: beforeinstall _kmodinstall 238_kmodinstall: 239.if defined(DEBUG_FLAGS) && defined(INSTALL_DEBUG) 240 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 241 ${_INSTALLFLAGS} ${FULLPROG} ${DESTDIR}${KMODDIR} 242.else 243 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 244 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 245 246.include <bsd.links.mk> 247 248.if !defined(NO_XREF) 249afterinstall: _kldxref 250.ORDER: realinstall _kldxref 251.ORDER: _installlinks _kldxref 252_kldxref: 253 @if type kldxref >/dev/null 2>&1; then \ 254 ${ECHO} kldxref ${DESTDIR}${KMODDIR}; \ 255 kldxref ${DESTDIR}${KMODDIR}; \ 256 fi 257.endif 258.endif 259.endif !target(realinstall) 260 261.endif !target(install) 262 263.if !target(load) 264load: ${PROG} 265 ${KMODLOAD} -v ${.OBJDIR}/${KMOD}.ko 266.endif 267 268.if !target(unload) 269unload: 270 ${KMODUNLOAD} -v ${KMOD} 271.endif 272 273.if defined(KERNBUILDDIR) 274.PATH: ${KERNBUILDDIR} 275CFLAGS += -I${KERNBUILDDIR} 276.for _src in ${SRCS:Mopt_*.h} 277CLEANFILES+= ${_src} 278.if !target(${_src}) 279${_src}: 280 ln -s ${KERNBUILDDIR}/${_src} ${.TARGET} 281.endif 282.endfor 283.else 284.for _src in ${SRCS:Mopt_*.h} 285CLEANFILES+= ${_src} 286.if !target(${_src}) 287${_src}: 288 touch ${.TARGET} 289.endif 290.endfor 291.endif 292 293MFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \ 294 dev/iicbus/iicbus_if.m isa/isa_if.m \ 295 libkern/iconv_converter_if.m \ 296 dev/acpica/acpi_if.m dev/eisa/eisa_if.m dev/mii/miibus_if.m \ 297 dev/ofw/ofw_bus_if.m \ 298 dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \ 299 dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \ 300 dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ 301 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m pci/agp_if.m \ 302 opencrypto/crypto_if.m pc98/pc98/canbus_if.m dev/uart/uart_if.m 303 304.for _srcsrc in ${MFILES} 305.for _ext in c h 306.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}} 307CLEANFILES+= ${_src} 308.if !target(${_src}) 309.if !exists(@) 310${_src}: @ 311.endif 312.if exists(@) 313${_src}: @/tools/makeobjops.awk @/${_srcsrc} 314.endif 315 ${AWK} -f @/tools/makeobjops.awk @/${_srcsrc} -${_ext} 316.endif 317.endfor # _src 318.endfor # _ext 319.endfor # _srcsrc 320 321.for _ext in c h 322.if ${SRCS:Mvnode_if.${_ext}} != "" 323CLEANFILES+= vnode_if.${_ext} 324.if !exists(@) 325vnode_if.${_ext}: @ 326.endif 327.if exists(@) 328vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src 329.endif 330 ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -${_ext} 331.endif 332.endfor 333 334.for _i in mii pccard usb 335.if ${SRCS:M${_i}devs.h} != "" 336CLEANFILES+= ${_i}devs.h 337.if !exists(@) 338${_i}devs.h: @ 339.endif 340.if exists(@) 341${_i}devs.h: @/tools/${_i}devs2h.awk @/dev/${_i}/${_i}devs 342.endif 343 ${AWK} -f @/tools/${_i}devs2h.awk @/dev/${_i}/${_i}devs 344.endif 345.endfor # _i 346 347.if ${SRCS:Macpi_quirks.h} != "" 348CLEANFILES+= acpi_quirks.h 349.if !exists(@) 350acpi_quirks.h: @ 351.endif 352.if exists(@) 353acpi_quirks.h: @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks 354.endif 355 ${AWK} -f @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks 356.endif 357 358regress: 359 360lint: ${SRCS} 361 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC:M*.c} 362 363.include <bsd.dep.mk> 364 365.if !exists(${.OBJDIR}/${DEPENDFILE}) 366${OBJS}: ${SRCS:M*.h} 367.endif 368 369.include <bsd.obj.mk> 370.include "kern.mk" 371