kmod.mk revision 125770
1# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2# $FreeBSD: head/sys/conf/kmod.mk 125770 2004-02-13 09:39:45Z ru $ 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 73CFLAGS+= ${COPTS} -D_KERNEL 74CFLAGS+= -DKLD_MODULE 75 76# Don't use any standard or source-relative include directories. 77# Since -nostdinc will annull any previous -I paths, we repeat all 78# such paths after -nostdinc. It doesn't seem to be possible to 79# add to the front of `make' variable. 80_ICFLAGS:= ${CFLAGS:M-I*} 81CFLAGS+= -nostdinc -I- ${INCLMAGIC} ${_ICFLAGS} 82.if defined(KERNBUILDDIR) 83CFLAGS+= -include ${KERNBUILDDIR}/opt_global.h 84.endif 85 86# Add -I paths for system headers. Individual KLD makefiles don't 87# need any -I paths for this. Similar defaults for .PATH can't be 88# set because there are no standard paths for non-headers. 89CFLAGS+= -I. -I@ 90 91# Add a -I path to standard headers like <stddef.h>. Use a relative 92# path to src/include if possible. If the @ symlink hasn't been built 93# yet, then we can't tell if the relative path exists. Add both the 94# potential relative path and an absolute path in that case. 95.if exists(@) 96.if exists(@/../include) 97CFLAGS+= -I@/../include 98.else 99CFLAGS+= -I${DESTDIR}/usr/include 100.endif 101.else # !@ 102CFLAGS+= -I@/../include -I${DESTDIR}/usr/include 103.endif # @ 104 105CFLAGS+= -finline-limit=${INLINE_LIMIT} 106 107# Disallow common variables, and if we end up with commons from 108# somewhere unexpected, allocate storage for them in the module itself. 109CFLAGS+= -fno-common 110LDFLAGS+= -d -warn-common 111 112CFLAGS+= ${DEBUG_FLAGS} 113 114OBJS+= ${SRCS:N*.h:R:S/$/.o/g} 115 116.if !defined(PROG) 117PROG= ${KMOD}.ko 118.endif 119 120.if !defined(DEBUG) 121FULLPROG= ${PROG} 122.else 123FULLPROG= ${PROG}.debug 124${PROG}: ${FULLPROG} 125 ${OBJCOPY} --strip-debug ${FULLPROG} ${PROG} 126.endif 127 128${FULLPROG}: ${KMOD}.kld 129 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld 130.if !defined(DEBUG) 131 ${OBJCOPY} --strip-debug ${FULLPROG} 132.endif 133 134EXPORT_SYMS?= NO 135.if ${EXPORT_SYMS} != YES 136CLEANFILES+= ${.OBJDIR}/export_syms 137.endif 138 139${KMOD}.kld: ${OBJS} 140 ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS} 141.if defined(EXPORT_SYMS) 142.if ${EXPORT_SYMS} != YES 143.if ${EXPORT_SYMS} == NO 144 touch ${.OBJDIR}/export_syms 145.elif !exists(${.CURDIR}/${EXPORT_SYMS}) 146 echo ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 147.else 148 grep -v '^#' < ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 149.endif 150 awk -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \ 151 ${.OBJDIR}/export_syms | \ 152 xargs -J% ${OBJCOPY} % ${.TARGET} 153.endif 154.endif 155 156_ILINKS=@ machine 157 158all: objwarn ${PROG} 159 160beforedepend: ${_ILINKS} 161 @rm -f .depend 162 163# Ensure that the links exist without depending on it when it exists which 164# causes all the modules to be rebuilt when the directory pointed to changes. 165.for _link in ${_ILINKS} 166.if !exists(${.OBJDIR}/${_link}) 167${OBJS}: ${_link} 168.endif 169.endfor 170 171# Search for kernel source tree in standard places. 172.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys 173.if !defined(SYSDIR) && exists(${_dir}/kern) 174SYSDIR= ${_dir} 175.endif 176.endfor 177.if !defined(SYSDIR) || !exists(${SYSDIR}/kern) 178.error "can't find kernel source tree" 179.endif 180 181${_ILINKS}: 182 @case ${.TARGET} in \ 183 machine) \ 184 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \ 185 @) \ 186 path=${SYSDIR} ;; \ 187 esac ; \ 188 path=`(cd $$path && /bin/pwd)` ; \ 189 ${ECHO} ${.TARGET} "->" $$path ; \ 190 ln -s $$path ${.TARGET} 191 192CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o 193 194.if defined(DEBUG) 195CLEANFILES+= ${FULLPROG} 196.endif 197 198.if !target(install) 199 200_INSTALLFLAGS:= ${INSTALLFLAGS} 201.for ie in ${INSTALLFLAGS_EDIT} 202_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 203.endfor 204 205.if defined(DEBUG) 206install.debug: 207 cd ${.CURDIR}; ${MAKE} -DINSTALL_DEBUG install 208.endif 209 210.if !target(realinstall) 211realinstall: _kmodinstall 212.ORDER: beforeinstall _kmodinstall 213.if defined(DEBUG) && defined(INSTALL_DEBUG) 214_kmodinstall: 215 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 216 ${_INSTALLFLAGS} ${FULLPROG} ${DESTDIR}${KMODDIR} 217.else 218_kmodinstall: 219 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 220 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 221 222.include <bsd.links.mk> 223 224.if !defined(NO_XREF) 225afterinstall: _kldxref 226.ORDER: realinstall _kldxref 227.ORDER: _installlinks _kldxref 228_kldxref: 229 @if type kldxref >/dev/null 2>&1; then \ 230 ${ECHO} kldxref ${DESTDIR}${KMODDIR}; \ 231 kldxref ${DESTDIR}${KMODDIR}; \ 232 fi 233.endif 234.endif 235.endif !target(realinstall) 236 237.endif !target(install) 238 239.if !target(load) 240load: ${PROG} 241 ${KMODLOAD} -v ${.OBJDIR}/${KMOD}.ko 242.endif 243 244.if !target(unload) 245unload: 246 ${KMODUNLOAD} -v ${KMOD} 247.endif 248 249.if defined(KERNBUILDDIR) 250.PATH: ${KERNBUILDDIR} 251CFLAGS += -I${KERNBUILDDIR} 252.for _src in ${SRCS:Mopt_*.h} 253CLEANFILES+= ${_src} 254.if !target(${_src}) 255${_src}: 256 ln -s ${KERNBUILDDIR}/${_src} ${.TARGET} 257.endif 258.endfor 259.else 260.for _src in ${SRCS:Mopt_*.h} 261CLEANFILES+= ${_src} 262.if !target(${_src}) 263${_src}: 264 touch ${.TARGET} 265.endif 266.endfor 267.endif 268 269MFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \ 270 dev/iicbus/iicbus_if.m isa/isa_if.m \ 271 libkern/iconv_converter_if.m \ 272 dev/mii/miibus_if.m \ 273 dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \ 274 dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \ 275 dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ 276 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m pci/agp_if.m \ 277 opencrypto/crypto_if.m pc98/pc98/canbus_if.m dev/uart/uart_if.m 278 279.for _srcsrc in ${MFILES} 280.for _ext in c h 281.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}} 282CLEANFILES+= ${_src} 283.if !target(${_src}) 284.if !exists(@) 285${_src}: @ 286.endif 287.if exists(@) 288${_src}: @/tools/makeobjops.awk @/${_srcsrc} 289.endif 290 ${AWK} -f @/tools/makeobjops.awk @/${_srcsrc} -${_ext} 291.endif 292.endfor # _src 293.endfor # _ext 294.endfor # _srcsrc 295 296.for _ext in c h 297.if ${SRCS:Mvnode_if.${_ext}} != "" 298CLEANFILES+= vnode_if.${_ext} 299.if !exists(@) 300vnode_if.${_ext}: @ 301.endif 302.if exists(@) 303vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src 304.endif 305 ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -${_ext} 306.endif 307.endfor 308 309.if ${SRCS:Mmiidevs.h} != "" 310CLEANFILES+= miidevs.h 311.if !exists(@) 312miidevs.h: @ 313.endif 314.if exists(@) 315miidevs.h: @/tools/devlist2h.awk @/dev/mii/miidevs 316.endif 317 ${AWK} -f @/tools/devlist2h.awk @/dev/mii/miidevs 318.endif 319 320regress: 321 322lint: ${SRCS} 323 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC:M*.c} 324 325.include <bsd.dep.mk> 326 327.if !exists(${.OBJDIR}/${DEPENDFILE}) 328${OBJS}: ${SRCS:M*.h} 329.endif 330 331.include <bsd.obj.mk> 332.include "kern.mk" 333