kmod.mk revision 144330
1# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2# $FreeBSD: head/sys/conf/kmod.mk 144330 2005-03-30 12:03:40Z sos $ 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# DESTDIR The tree where the module gets installed. [not set] 40# 41# +++ targets +++ 42# 43# install: 44# install the kernel module; if the Makefile 45# does not itself define the target install, the targets 46# beforeinstall and afterinstall may also be used to cause 47# actions immediately before and after the install target 48# is executed. 49# 50# load: 51# Load a module. 52# 53# unload: 54# Unload a module. 55# 56 57AWK?= awk 58KMODLOAD?= /sbin/kldload 59KMODUNLOAD?= /sbin/kldunload 60OBJCOPY?= objcopy 61 62.if defined(KMODDEPS) 63.error "Do not use KMODDEPS on 5.0+; use MODULE_VERSION/MODULE_DEPEND" 64.endif 65 66.include <bsd.init.mk> 67 68.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 69 70.if ${CC} == "icc" 71CFLAGS:= ${CFLAGS:C/(-x[^M^K^W]+)[MKW]+|-x[MKW]+/\1/} 72.else 73. if !empty(CFLAGS:M-O[23s]) && empty(CFLAGS:M-fno-strict-aliasing) 74CFLAGS+= -fno-strict-aliasing 75. endif 76WERROR?= -Werror 77.endif 78CFLAGS+= ${WERROR} 79CFLAGS+= -D_KERNEL 80CFLAGS+= -DKLD_MODULE 81 82# Don't use any standard or source-relative include directories. 83# Since -nostdinc will annull any previous -I paths, we repeat all 84# such paths after -nostdinc. It doesn't seem to be possible to 85# add to the front of `make' variable. 86_ICFLAGS:= ${CFLAGS:M-I*} 87.if ${CC} == "icc" 88NOSTDINC= -X 89.else 90NOSTDINC= -nostdinc 91.endif 92CFLAGS+= ${NOSTDINC} -I- ${INCLMAGIC} ${_ICFLAGS} 93.if defined(KERNBUILDDIR) 94CFLAGS+= -include ${KERNBUILDDIR}/opt_global.h 95.endif 96 97# Add -I paths for system headers. Individual module makefiles don't 98# need any -I paths for this. Similar defaults for .PATH can't be 99# set because there are no standard paths for non-headers. 100CFLAGS+= -I. -I@ 101 102# Add -I path for altq headers as they are included via net/if_var.h 103# for example. 104CFLAGS+= -I@/contrib/altq 105 106# Add a -I path to standard headers like <stddef.h>. Use a relative 107# path to src/include if possible. If the @ symlink hasn't been built 108# yet, then we can't tell if the relative path exists. Add both the 109# potential relative path and an absolute path in that case. 110.if exists(@) 111.if exists(@/../include) 112CFLAGS+= -I@/../include 113.else 114CFLAGS+= -I${DESTDIR}/usr/include 115.endif 116.else # !@ 117CFLAGS+= -I@/../include -I${DESTDIR}/usr/include 118.endif # @ 119 120.if ${CC} != "icc" 121CFLAGS+= -finline-limit=${INLINE_LIMIT} 122.endif 123 124# Disallow common variables, and if we end up with commons from 125# somewhere unexpected, allocate storage for them in the module itself. 126.if ${CC} != "icc" 127CFLAGS+= -fno-common 128.endif 129LDFLAGS+= -d -warn-common 130 131CFLAGS+= ${DEBUG_FLAGS} 132.if ${MACHINE_ARCH} == amd64 133CFLAGS+= -fno-omit-frame-pointer 134.endif 135 136.if ${MACHINE_ARCH} == "powerpc" 137CFLAGS+= -mlongcall -fno-omit-frame-pointer 138.endif 139 140OBJS+= ${SRCS:N*.h:R:S/$/.o/g} 141 142.if !defined(PROG) 143PROG= ${KMOD}.ko 144.endif 145 146.if !defined(DEBUG_FLAGS) 147FULLPROG= ${PROG} 148.else 149FULLPROG= ${PROG}.debug 150${PROG}: ${FULLPROG} 151 ${OBJCOPY} --strip-debug ${FULLPROG} ${PROG} 152.endif 153 154.if ${MACHINE_ARCH} != amd64 155${FULLPROG}: ${KMOD}.kld 156 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld 157.if !defined(DEBUG_FLAGS) 158 ${OBJCOPY} --strip-debug ${.TARGET} 159.endif 160.endif 161 162EXPORT_SYMS?= NO 163.if ${EXPORT_SYMS} != YES 164CLEANFILES+= export_syms 165.endif 166 167.if ${MACHINE_ARCH} != amd64 168${KMOD}.kld: ${OBJS} 169.else 170${FULLPROG}: ${OBJS} 171.endif 172 ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS} 173.if defined(EXPORT_SYMS) 174.if ${EXPORT_SYMS} != YES 175.if ${EXPORT_SYMS} == NO 176 touch export_syms 177.elif !exists(${.CURDIR}/${EXPORT_SYMS}) 178 echo ${EXPORT_SYMS} > export_syms 179.else 180 grep -v '^#' < ${EXPORT_SYMS} > export_syms 181.endif 182 awk -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \ 183 export_syms | xargs -J% ${OBJCOPY} % ${.TARGET} 184.endif 185.endif 186.if !defined(DEBUG_FLAGS) && ${MACHINE_ARCH} == amd64 187 ${OBJCOPY} --strip-debug ${.TARGET} 188.endif 189 190_ILINKS=@ machine 191 192all: objwarn ${PROG} 193 194beforedepend: ${_ILINKS} 195 196# Ensure that the links exist without depending on it when it exists which 197# causes all the modules to be rebuilt when the directory pointed to changes. 198.for _link in ${_ILINKS} 199.if !exists(${.OBJDIR}/${_link}) 200${OBJS}: ${_link} 201.endif 202.endfor 203 204# Search for kernel source tree in standard places. 205.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys 206.if !defined(SYSDIR) && exists(${_dir}/kern/) 207SYSDIR= ${_dir} 208.endif 209.endfor 210.if !defined(SYSDIR) || !exists(${SYSDIR}/kern/) 211.error "can't find kernel source tree" 212.endif 213 214${_ILINKS}: 215 @case ${.TARGET} in \ 216 machine) \ 217 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \ 218 @) \ 219 path=${SYSDIR} ;; \ 220 esac ; \ 221 path=`(cd $$path && /bin/pwd)` ; \ 222 ${ECHO} ${.TARGET} "->" $$path ; \ 223 ln -s $$path ${.TARGET} 224 225CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} 226 227.if defined(DEBUG_FLAGS) 228CLEANFILES+= ${FULLPROG} 229.endif 230 231.if !target(install) 232 233_INSTALLFLAGS:= ${INSTALLFLAGS} 234.for ie in ${INSTALLFLAGS_EDIT} 235_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 236.endfor 237 238.if !target(install.debug) && defined(DEBUG_FLAGS) 239install.debug: 240 cd ${.CURDIR}; ${MAKE} -DINSTALL_DEBUG install 241.endif 242 243.if !target(realinstall) 244realinstall: _kmodinstall 245.ORDER: beforeinstall _kmodinstall 246_kmodinstall: 247.if defined(DEBUG_FLAGS) && defined(INSTALL_DEBUG) 248 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 249 ${_INSTALLFLAGS} ${FULLPROG} ${DESTDIR}${KMODDIR} 250.else 251 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 252 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 253 254.include <bsd.links.mk> 255 256.if !defined(NO_XREF) 257afterinstall: _kldxref 258.ORDER: realinstall _kldxref 259.ORDER: _installlinks _kldxref 260_kldxref: 261 @if type kldxref >/dev/null 2>&1; then \ 262 ${ECHO} kldxref ${DESTDIR}${KMODDIR}; \ 263 kldxref ${DESTDIR}${KMODDIR}; \ 264 fi 265.endif 266.endif 267.endif !target(realinstall) 268 269.endif !target(install) 270 271.if !target(load) 272load: ${PROG} 273 ${KMODLOAD} -v ${.OBJDIR}/${PROG} 274.endif 275 276.if !target(unload) 277unload: 278 ${KMODUNLOAD} -v ${PROG} 279.endif 280 281.if defined(KERNBUILDDIR) 282.PATH: ${KERNBUILDDIR} 283CFLAGS+= -I${KERNBUILDDIR} 284.for _src in ${SRCS:Mopt_*.h} 285CLEANFILES+= ${_src} 286.if !target(${_src}) 287${_src}: 288 ln -s ${KERNBUILDDIR}/${_src} ${.TARGET} 289.endif 290.endfor 291.else 292.for _src in ${SRCS:Mopt_*.h} 293CLEANFILES+= ${_src} 294.if !target(${_src}) 295${_src}: 296 touch ${.TARGET} 297.endif 298.endfor 299.endif 300 301MFILES?= dev/acpica/acpi_if.m dev/ata/ata_if.m dev/eisa/eisa_if.m \ 302 dev/iicbus/iicbb_if.m dev/iicbus/iicbus_if.m \ 303 dev/mii/miibus_if.m dev/ofw/ofw_bus_if.m \ 304 dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \ 305 dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \ 306 dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ 307 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m dev/uart/uart_if.m \ 308 dev/usb/usb_if.m isa/isa_if.m \ 309 kern/bus_if.m kern/cpufreq_if.m kern/device_if.m \ 310 libkern/iconv_converter_if.m opencrypto/crypto_if.m \ 311 pc98/pc98/canbus_if.m pci/agp_if.m 312 313.for _srcsrc in ${MFILES} 314.for _ext in c h 315.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}} 316CLEANFILES+= ${_src} 317.if !target(${_src}) 318.if !exists(@) 319${_src}: @ 320.else 321${_src}: @/tools/makeobjops.awk @/${_srcsrc} 322.endif 323 ${AWK} -f @/tools/makeobjops.awk @/${_srcsrc} -${_ext} 324.endif 325.endfor # _src 326.endfor # _ext 327.endfor # _srcsrc 328 329.if ${SRCS:Mvnode_if.c} != "" 330CLEANFILES+= vnode_if.c 331.if !exists(@) 332vnode_if.c: @ 333.else 334vnode_if.c: @/tools/vnode_if.awk @/kern/vnode_if.src 335.endif 336 ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -c 337.endif 338 339.if ${SRCS:Mvnode_if.h} != "" 340CLEANFILES+= vnode_if.h vnode_if_newproto.h vnode_if_typedef.h 341.if !exists(@) 342vnode_if.h vnode_if_newproto.h vnode_if_typedef.h: @ 343.else 344vnode_if.h vnode_if_newproto.h vnode_if_typedef.h: @/tools/vnode_if.awk \ 345 @/kern/vnode_if.src 346.endif 347vnode_if.h: vnode_if_newproto.h vnode_if_typedef.h 348 ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -h 349vnode_if_newproto.h: 350 ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -p 351vnode_if_typedef.h: 352 ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -q 353.endif 354 355.for _i in mii pccard 356.if ${SRCS:M${_i}devs.h} != "" 357CLEANFILES+= ${_i}devs.h 358.if !exists(@) 359${_i}devs.h: @ 360.else 361${_i}devs.h: @/tools/${_i}devs2h.awk @/dev/${_i}/${_i}devs 362.endif 363 ${AWK} -f @/tools/${_i}devs2h.awk @/dev/${_i}/${_i}devs 364.endif 365.endfor # _i 366 367.if ${SRCS:Musbdevs.h} != "" 368CLEANFILES+= usbdevs.h 369.if !exists(@) 370usbdevs.h: @ 371.else 372usbdevs.h: @/tools/usbdevs2h.awk @/dev/usb/usbdevs 373.endif 374 ${AWK} -f @/tools/usbdevs2h.awk @/dev/usb/usbdevs -h 375.endif 376 377.if ${SRCS:Musbdevs_data.h} != "" 378CLEANFILES+= usbdevs_data.h 379.if !exists(@) 380usbdevs_data.h: @ 381.else 382usbdevs_data.h: @/tools/usbdevs2h.awk @/dev/usb/usbdevs 383.endif 384 ${AWK} -f @/tools/usbdevs2h.awk @/dev/usb/usbdevs -d 385.endif 386 387.if ${SRCS:Macpi_quirks.h} != "" 388CLEANFILES+= acpi_quirks.h 389.if !exists(@) 390acpi_quirks.h: @ 391.else 392acpi_quirks.h: @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks 393.endif 394 ${AWK} -f @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks 395.endif 396 397lint: ${SRCS} 398 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC:M*.c} 399 400.include <bsd.dep.mk> 401 402.if !exists(${.OBJDIR}/${DEPENDFILE}) 403${OBJS}: ${SRCS:M*.h} 404.endif 405 406.include <bsd.obj.mk> 407.include "kern.mk" 408