kmod.mk revision 126890
1# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2# $FreeBSD: head/sys/conf/kmod.mk 126890 2004-03-12 21:36:12Z trhodes $ 3# 4# The include file <bsd.kmod.mk> handles installing Kernel Loadable Device 5# drivers (KLD's). 6# 7# 8# +++ variables +++ 9# 10# CLEANFILES Additional files to remove for the clean and cleandir targets. 11# 12# KMOD The name of the kernel module to build. 13# 14# KMODDIR Base path for kernel modules (see kld(4)). [/boot/kernel] 15# 16# KMODOWN KLD owner. [${BINOWN}] 17# 18# KMODGRP KLD group. [${BINGRP}] 19# 20# KMODMODE KLD mode. [${BINMODE}] 21# 22# KMODLOAD Command to load a kernel module [/sbin/kldload] 23# 24# KMODUNLOAD Command to unload a kernel module [/sbin/kldunload] 25# 26# PROG The name of the kernel module to build. 27# If not supplied, ${KMOD}.o is used. 28# 29# SRCS List of source files 30# 31# DESTDIR Change the tree where the module gets installed. [not set] 32# 33# MFILES Optionally a list of interfaces used by the module. 34# This file contains a default list of interfaces. 35# 36# EXPORT_SYMS A list of symbols that should be exported from the module, 37# or the name of a file containing a list of symbols, or YES 38# to export all symbols. If not defined, no symbols are 39# exported. 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 KLD. 52# 53# unload: 54# Unload KLD. 55# 56# bsd.obj.mk: clean, cleandir and obj 57# bsd.dep.mk: cleandepend, depend and tags 58# 59 60AWK?= awk 61KMODLOAD?= /sbin/kldload 62KMODUNLOAD?= /sbin/kldunload 63OBJCOPY?= objcopy 64 65.if defined(KMODDEPS) 66.error "Do not use KMODDEPS on 5.0+, use MODULE_VERSION/MODULE_DEPEND" 67.endif 68 69.include <bsd.init.mk> 70 71.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 72 73.if ${CC} == "icc" 74_ICC_CFLAGS:= ${CFLAGS:C/(-x[^M^K^W]+)[MKW]+|-x[MKW]+/\1/} 75CFLAGS= ${_ICC_CFLAGS} 76.endif 77CFLAGS+= ${COPTS} -D_KERNEL 78CFLAGS+= -DKLD_MODULE 79 80# Don't use any standard or source-relative include directories. 81# Since -nostdinc will annull any previous -I paths, we repeat all 82# such paths after -nostdinc. It doesn't seem to be possible to 83# add to the front of `make' variable. 84_ICFLAGS:= ${CFLAGS:M-I*} 85.if ${CC} == "icc" 86NOSTDINC= -X 87.else 88NOSTDINC= -nostdinc 89.endif 90CFLAGS+= ${NOSTDINC} -I- ${INCLMAGIC} ${_ICFLAGS} 91.if defined(KERNBUILDDIR) 92CFLAGS+= -include ${KERNBUILDDIR}/opt_global.h 93.endif 94 95# Add -I paths for system headers. Individual KLD makefiles don't 96# need any -I paths for this. Similar defaults for .PATH can't be 97# set because there are no standard paths for non-headers. 98CFLAGS+= -I. -I@ 99 100# Add a -I path to standard headers like <stddef.h>. Use a relative 101# path to src/include if possible. If the @ symlink hasn't been built 102# yet, then we can't tell if the relative path exists. Add both the 103# potential relative path and an absolute path in that case. 104.if exists(@) 105.if exists(@/../include) 106CFLAGS+= -I@/../include 107.else 108CFLAGS+= -I${DESTDIR}/usr/include 109.endif 110.else # !@ 111CFLAGS+= -I@/../include -I${DESTDIR}/usr/include 112.endif # @ 113 114.if ${CC} != "icc" 115CFLAGS+= -finline-limit=${INLINE_LIMIT} 116.endif 117 118# Disallow common variables, and if we end up with commons from 119# somewhere unexpected, allocate storage for them in the module itself. 120.if ${CC} != "icc" 121CFLAGS+= -fno-common 122.endif 123LDFLAGS+= -d -warn-common 124 125CFLAGS+= ${DEBUG_FLAGS} 126 127OBJS+= ${SRCS:N*.h:R:S/$/.o/g} 128 129.if !defined(PROG) 130PROG= ${KMOD}.ko 131.endif 132 133.if !defined(DEBUG_FLAGS) 134FULLPROG= ${PROG} 135.else 136FULLPROG= ${PROG}.debug 137${PROG}: ${FULLPROG} 138 ${OBJCOPY} --strip-debug ${FULLPROG} ${PROG} 139.endif 140 141${FULLPROG}: ${KMOD}.kld 142 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld 143.if !defined(DEBUG_FLAGS) 144 ${OBJCOPY} --strip-debug ${.TARGET} 145.endif 146 147EXPORT_SYMS?= NO 148.if ${EXPORT_SYMS} != YES 149CLEANFILES+= ${.OBJDIR}/export_syms 150.endif 151 152${KMOD}.kld: ${OBJS} 153 ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS} 154.if defined(EXPORT_SYMS) 155.if ${EXPORT_SYMS} != YES 156.if ${EXPORT_SYMS} == NO 157 touch ${.OBJDIR}/export_syms 158.elif !exists(${.CURDIR}/${EXPORT_SYMS}) 159 echo ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 160.else 161 grep -v '^#' < ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 162.endif 163 awk -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \ 164 ${.OBJDIR}/export_syms | \ 165 xargs -J% ${OBJCOPY} % ${.TARGET} 166.endif 167.endif 168 169_ILINKS=@ machine 170 171all: objwarn ${PROG} 172 173beforedepend: ${_ILINKS} 174 @rm -f .depend 175 176# Ensure that the links exist without depending on it when it exists which 177# causes all the modules to be rebuilt when the directory pointed to changes. 178.for _link in ${_ILINKS} 179.if !exists(${.OBJDIR}/${_link}) 180${OBJS}: ${_link} 181.endif 182.endfor 183 184# Search for kernel source tree in standard places. 185.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys 186.if !defined(SYSDIR) && exists(${_dir}/kern/) 187SYSDIR= ${_dir} 188.endif 189.endfor 190.if !defined(SYSDIR) || !exists(${SYSDIR}/kern/) 191.error "can't find kernel source tree" 192.endif 193 194${_ILINKS}: 195 @case ${.TARGET} in \ 196 machine) \ 197 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \ 198 @) \ 199 path=${SYSDIR} ;; \ 200 esac ; \ 201 path=`(cd $$path && /bin/pwd)` ; \ 202 ${ECHO} ${.TARGET} "->" $$path ; \ 203 ln -s $$path ${.TARGET} 204 205CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o 206 207.if defined(DEBUG_FLAGS) 208CLEANFILES+= ${FULLPROG} 209.endif 210 211.if !target(install) 212 213_INSTALLFLAGS:= ${INSTALLFLAGS} 214.for ie in ${INSTALLFLAGS_EDIT} 215_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 216.endfor 217 218.if defined(DEBUG_FLAGS) 219install.debug: 220 cd ${.CURDIR}; ${MAKE} -DINSTALL_DEBUG install 221.endif 222 223.if !target(realinstall) 224realinstall: _kmodinstall 225.ORDER: beforeinstall _kmodinstall 226_kmodinstall: 227.if defined(DEBUG_FLAGS) && defined(INSTALL_DEBUG) 228 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 229 ${_INSTALLFLAGS} ${FULLPROG} ${DESTDIR}${KMODDIR} 230.else 231 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 232 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 233 234.include <bsd.links.mk> 235 236.if !defined(NO_XREF) 237afterinstall: _kldxref 238.ORDER: realinstall _kldxref 239.ORDER: _installlinks _kldxref 240_kldxref: 241 @if type kldxref >/dev/null 2>&1; then \ 242 ${ECHO} kldxref ${DESTDIR}${KMODDIR}; \ 243 kldxref ${DESTDIR}${KMODDIR}; \ 244 fi 245.endif 246.endif 247.endif !target(realinstall) 248 249.endif !target(install) 250 251.if !target(load) 252load: ${PROG} 253 ${KMODLOAD} -v ${.OBJDIR}/${KMOD}.ko 254.endif 255 256.if !target(unload) 257unload: 258 ${KMODUNLOAD} -v ${KMOD} 259.endif 260 261.if defined(KERNBUILDDIR) 262.PATH: ${KERNBUILDDIR} 263CFLAGS += -I${KERNBUILDDIR} 264.for _src in ${SRCS:Mopt_*.h} 265CLEANFILES+= ${_src} 266.if !target(${_src}) 267${_src}: 268 ln -s ${KERNBUILDDIR}/${_src} ${.TARGET} 269.endif 270.endfor 271.else 272.for _src in ${SRCS:Mopt_*.h} 273CLEANFILES+= ${_src} 274.if !target(${_src}) 275${_src}: 276 touch ${.TARGET} 277.endif 278.endfor 279.endif 280 281MFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \ 282 dev/iicbus/iicbus_if.m isa/isa_if.m \ 283 libkern/iconv_converter_if.m \ 284 dev/mii/miibus_if.m \ 285 dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \ 286 dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \ 287 dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ 288 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m pci/agp_if.m \ 289 opencrypto/crypto_if.m pc98/pc98/canbus_if.m dev/uart/uart_if.m 290 291.for _srcsrc in ${MFILES} 292.for _ext in c h 293.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}} 294CLEANFILES+= ${_src} 295.if !target(${_src}) 296.if !exists(@) 297${_src}: @ 298.endif 299.if exists(@) 300${_src}: @/tools/makeobjops.awk @/${_srcsrc} 301.endif 302 ${AWK} -f @/tools/makeobjops.awk @/${_srcsrc} -${_ext} 303.endif 304.endfor # _src 305.endfor # _ext 306.endfor # _srcsrc 307 308.for _ext in c h 309.if ${SRCS:Mvnode_if.${_ext}} != "" 310CLEANFILES+= vnode_if.${_ext} 311.if !exists(@) 312vnode_if.${_ext}: @ 313.endif 314.if exists(@) 315vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src 316.endif 317 ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -${_ext} 318.endif 319.endfor 320 321.if ${SRCS:Mmiidevs.h} != "" 322CLEANFILES+= miidevs.h 323.if !exists(@) 324miidevs.h: @ 325.endif 326.if exists(@) 327miidevs.h: @/tools/devlist2h.awk @/dev/mii/miidevs 328.endif 329 ${AWK} -f @/tools/devlist2h.awk @/dev/mii/miidevs 330.endif 331 332regress: 333 334lint: ${SRCS} 335 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC:M*.c} 336 337.include <bsd.dep.mk> 338 339.if !exists(${.OBJDIR}/${DEPENDFILE}) 340${OBJS}: ${SRCS:M*.h} 341.endif 342 343.include <bsd.obj.mk> 344.include "kern.mk" 345