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# 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 ${CFLAGS:M-O[23s]} != "" 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/eisa/eisa_if.m dev/iicbus/iicbb_if.m \ 302 dev/iicbus/iicbus_if.m dev/mii/miibus_if.m dev/ofw/ofw_bus_if.m \ 303 dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \ 304 dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \ 305 dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ 306 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m dev/uart/uart_if.m \ 307 dev/usb/usb_if.m isa/isa_if.m \ 308 kern/bus_if.m kern/cpufreq_if.m kern/device_if.m \ 309 libkern/iconv_converter_if.m opencrypto/crypto_if.m \ 310 pc98/pc98/canbus_if.m pci/agp_if.m 311 312.for _srcsrc in ${MFILES} 313.for _ext in c h 314.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}} 315CLEANFILES+= ${_src} 316.if !target(${_src}) 317.if !exists(@) 318${_src}: @ 319.else 320${_src}: @/tools/makeobjops.awk @/${_srcsrc} 321.endif 322 ${AWK} -f @/tools/makeobjops.awk @/${_srcsrc} -${_ext} 323.endif 324.endfor # _src 325.endfor # _ext 326.endfor # _srcsrc 327 328.if ${SRCS:Mvnode_if.c} != "" 329CLEANFILES+= vnode_if.c 330.if !exists(@) 331vnode_if.c: @ 332.else 333vnode_if.c: @/tools/vnode_if.awk @/kern/vnode_if.src 334.endif 335 ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -c 336.endif 337 338.if ${SRCS:Mvnode_if.h} != "" 339CLEANFILES+= vnode_if.h vnode_if_newproto.h vnode_if_typedef.h 340.if !exists(@) 341vnode_if.h vnode_if_newproto.h vnode_if_typedef.h: @ 342.else 343vnode_if.h vnode_if_newproto.h vnode_if_typedef.h: @/tools/vnode_if.awk \ 344 @/kern/vnode_if.src 345.endif 346vnode_if.h: vnode_if_newproto.h vnode_if_typedef.h 347 ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -h 348vnode_if_newproto.h: 349 ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -p 350vnode_if_typedef.h: 351 ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -q 352.endif 353 354.for _i in mii pccard 355.if ${SRCS:M${_i}devs.h} != "" 356CLEANFILES+= ${_i}devs.h 357.if !exists(@) 358${_i}devs.h: @ 359.else 360${_i}devs.h: @/tools/${_i}devs2h.awk @/dev/${_i}/${_i}devs 361.endif 362 ${AWK} -f @/tools/${_i}devs2h.awk @/dev/${_i}/${_i}devs 363.endif 364.endfor # _i 365 366.if ${SRCS:Musbdevs.h} != "" 367CLEANFILES+= usbdevs.h 368.if !exists(@) 369usbdevs.h: @ 370.else 371usbdevs.h: @/tools/usbdevs2h.awk @/dev/usb/usbdevs 372.endif 373 ${AWK} -f @/tools/usbdevs2h.awk @/dev/usb/usbdevs -h 374.endif 375 376.if ${SRCS:Musbdevs_data.h} != "" 377CLEANFILES+= usbdevs_data.h 378.if !exists(@) 379usbdevs_data.h: @ 380.else 381usbdevs_data.h: @/tools/usbdevs2h.awk @/dev/usb/usbdevs 382.endif 383 ${AWK} -f @/tools/usbdevs2h.awk @/dev/usb/usbdevs -d 384.endif 385 386.if ${SRCS:Macpi_quirks.h} != "" 387CLEANFILES+= acpi_quirks.h 388.if !exists(@) 389acpi_quirks.h: @ 390.else 391acpi_quirks.h: @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks 392.endif 393 ${AWK} -f @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks 394.endif 395 396lint: ${SRCS} 397 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC:M*.c} 398 399.include <bsd.dep.mk> 400 401.if !exists(${.OBJDIR}/${DEPENDFILE}) 402${OBJS}: ${SRCS:M*.h} 403.endif 404 405.include <bsd.obj.mk> 406.include "kern.mk" 407