kmod.mk revision 95880
175584Sru# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2151497Sru# $FreeBSD: head/sys/conf/kmod.mk 95880 2002-05-01 19:24:26Z imp $ 375584Sru# 4104862Sru# The include file <bsd.kmod.mk> handles installing Kernel Loadable Device 5104862Sru# drivers (KLD's). 6104862Sru# 7104862Sru# 8104862Sru# +++ variables +++ 9104862Sru# 10104862Sru# CLEANFILES Additional files to remove for the clean and cleandir targets. 11104862Sru# 12104862Sru# DISTRIBUTION Name of distribution. [bin] 13104862Sru# 14104862Sru# KMOD The name of the kernel module to build. 15104862Sru# 16104862Sru# KMODDIR Base path for kernel modules (see kld(4)). [/boot/kernel] 17104862Sru# 18104862Sru# KMODOWN KLD owner. [${BINOWN}] 19151497Sru# 20104862Sru# KMODGRP KLD group. [${BINGRP}] 21151497Sru# 22151497Sru# KMODMODE KLD mode. [${BINMODE}] 23104862Sru# 24151497Sru# LINKS The list of KLD links; should be full pathnames, the 25104862Sru# linked-to file coming first, followed by the linked 26104862Sru# file. The files are hard-linked. For example, to link 27104862Sru# /modules/master and /modules/meister, use: 28151497Sru# 29104862Sru# LINKS= /modules/master /modules/meister 30151497Sru# 31104862Sru# KMODLOAD Command to load a kernel module [/sbin/kldload] 32104862Sru# 33104862Sru# KMODUNLOAD Command to unload a kernel module [/sbin/kldunload] 34104862Sru# 35104862Sru# PROG The name of the kernel module to build. 36104862Sru# If not supplied, ${KMOD}.o is used. 37104862Sru# 38151497Sru# SRCS List of source files 39151497Sru# 40104862Sru# SUBDIR A list of subdirectories that should be built as well. 41151497Sru# Each of the targets will execute the same target in the 42104862Sru# subdirectories. 43104862Sru# 44151497Sru# SYMLINKS Same as LINKS, except it creates symlinks and the 45104862Sru# linked-to pathname may be relative. 46104862Sru# 47151497Sru# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk) 48151497Sru# 49151497Sru# MFILES Optionally a list of interfaces used by the module. 50104862Sru# This file contains a default list of interfaces. 5175584Sru# 5275584Sru# EXPORT_SYMS A list of symbols that should be exported from the module, 53114402Sru# or the name of a file containing a list of symbols, or YES 54114402Sru# to export all symbols. If not defined, no symbols are 55114402Sru# exported. 56114402Sru# 57114402Sru# +++ targets +++ 58114402Sru# 59114402Sru# distribute: 60114402Sru# This is a variant of install, which will 61114402Sru# put the stuff into the right "distribution". 62114402Sru# 63114402Sru# install: 64114402Sru# install the kernel module; if the Makefile 65114402Sru# does not itself define the target install, the targets 66151497Sru# beforeinstall and afterinstall may also be used to cause 67114402Sru# actions immediately before and after the install target 68151497Sru# is executed. 69114402Sru# 70114402Sru# load: 71114402Sru# Load KLD. 72114402Sru# 73114402Sru# unload: 74151497Sru# Unload KLD. 75114402Sru# 76114402Sru# bsd.obj.mk: clean, cleandir and obj 77114402Sru# bsd.dep.mk: cleandepend, depend and tags 78114402Sru# 79114402Sru 80114402SruAWK?= awk 81114402SruKMODLOAD?= /sbin/kldload 82151497SruKMODUNLOAD?= /sbin/kldunload 83114402SruOBJCOPY?= objcopy 84114402Sru 85114402Sru.if defined(KMODDEPS) 86151497Sru.error "Do not use KMODDEPS on 5.0+, use MODULE_VERSION/MODULE_DEPEND" 87114402Sru.endif 88114402Sru 89151497Sru.include <bsd.init.mk> 90151497Sru 91151497Sru.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 92114402Sru 9375584SruCFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS} 9475584SruCFLAGS+= -DKLD_MODULE 9575584Sru 9675584Sru# Don't use any standard or source-relative include directories. 9775584Sru# Since -nostdinc will annull any previous -I paths, we repeat all 9875584Sru# such paths after -nostdinc. It doesn't seem to be possible to 9975584Sru# add to the front of `make' variable. 10075584Sru_ICFLAGS:= ${CFLAGS:M-I*} 101151497SruCFLAGS+= -nostdinc -I- ${INCLMAGIC} ${_ICFLAGS} 10275584Sru 103151497Sru# Add -I paths for system headers. Individual KLD makefiles don't 104151497Sru# need any -I paths for this. Similar defaults for .PATH can't be 105114402Sru# set because there are no standard paths for non-headers. 10675584SruCFLAGS+= -I. -I@ -I@/dev 107114402Sru 108104862Sru# Add a -I path to standard headers like <stddef.h>. Use a relative 109104862Sru# path to src/include if possible. If the @ symlink hasn't been built 11075584Sru# yet, then we can't tell if the relative path exists. Add both the 111114402Sru# potential relative path and an absolute path in that case. 11275584Sru.if exists(@) 113104862Sru.if exists(@/../include) 114104862SruCFLAGS+= -I@/../include 11575584Sru.else 116114402SruCFLAGS+= -I${DESTDIR}/usr/include 117114402Sru.endif 118104862Sru.else # !@ 119104862SruCFLAGS+= -I@/../include -I${DESTDIR}/usr/include 120104862Sru.endif # @ 12175584Sru 122104862Sru# Disallow common variables, and if we end up with commons from 123104862Sru# somewhere unexpected, allocate storage for them in the module itself. 124104862SruCFLAGS+= -fno-common 125104862SruLDFLAGS+= -d -warn-common 126104862Sru 127CFLAGS+= ${DEBUG_FLAGS} 128 129.if ${OBJFORMAT} == elf 130CLEANFILES+= setdef0.c setdef1.c setdefs.h 131CLEANFILES+= setdef0.o setdef1.o 132.endif 133 134OBJS+= ${SRCS:N*.h:R:S/$/.o/g} 135 136.if !defined(PROG) 137PROG= ${KMOD}.ko 138.endif 139 140.if !defined(DEBUG) 141FULLPROG= ${PROG} 142.else 143FULLPROG= ${PROG}.debug 144${PROG}: ${FULLPROG} 145 ${OBJCOPY} --strip-debug ${FULLPROG} ${PROG} 146.endif 147 148${FULLPROG}: ${KMOD}.kld 149 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld 150 151EXPORT_SYMS?= NO 152.if ${EXPORT_SYMS} != YES 153CLEANFILES+= ${.OBJDIR}/export_syms 154.endif 155 156${KMOD}.kld: ${OBJS} 157 ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS} 158.if defined(EXPORT_SYMS) 159.if ${EXPORT_SYMS} != YES 160.if ${EXPORT_SYMS} == NO 161 touch ${.OBJDIR}/export_syms 162.elif !exists(${.CURDIR}/${EXPORT_SYMS}) 163 echo ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 164.else 165 grep -v '^#' < ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 166.endif 167 awk -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \ 168 ${.OBJDIR}/export_syms | \ 169 xargs -J% ${OBJCOPY} % ${.TARGET} 170.endif 171.endif 172 173.if !exists(/usr/sbin/kldxref) 174NO_XREF=yes 175.endif 176 177_ILINKS=@ machine 178 179all: objwarn ${PROG} 180 181beforedepend: ${_ILINKS} 182 @rm -f .depend 183 184# Ensure that the links exist without depending on it when it exists which 185# causes all the modules to be rebuilt when the directory pointed to changes. 186.for _link in ${_ILINKS} 187.if !exists(${.OBJDIR}/${_link}) 188${OBJS}: ${_link} 189.endif 190.endfor 191 192# Search for kernel source tree in standard places. 193.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys 194.if !defined(SYSDIR) && exists(${_dir}/kern/) 195SYSDIR= ${_dir} 196.endif 197.endfor 198.if !defined(SYSDIR) || !exists(${SYSDIR}/kern) 199.error "can't find kernel source tree" 200.endif 201 202${_ILINKS}: 203 @case ${.TARGET} in \ 204 machine) \ 205 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \ 206 @) \ 207 path=${SYSDIR} ;; \ 208 esac ; \ 209 path=`(cd $$path && /bin/pwd)` ; \ 210 ${ECHO} ${.TARGET} "->" $$path ; \ 211 ln -s $$path ${.TARGET} 212 213CLEANFILES+= ${PROG} ${FULLPROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o 214 215.if !target(install) 216.if !target(beforeinstall) 217beforeinstall: 218.endif 219.if !target(afterinstall) 220afterinstall: 221.endif 222 223_INSTALLFLAGS:= ${INSTALLFLAGS} 224.for ie in ${INSTALLFLAGS_EDIT} 225_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 226.endfor 227 228.if defined(DEBUG) 229install.debug: 230 cd ${.CURDIR}; ${MAKE} -DINSTALL_DEBUG install 231.endif 232 233realinstall: 234.if defined(DEBUG) && defined(INSTALL_DEBUG) 235 ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 236 ${_INSTALLFLAGS} ${FULLPROG} ${DESTDIR}${KMODDIR}/ 237.else 238 ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 239 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}/ 240.if defined(LINKS) && !empty(LINKS) 241 @set ${LINKS}; \ 242 while test $$# -ge 2; do \ 243 l=${DESTDIR}$$1; \ 244 shift; \ 245 t=${DESTDIR}$$1; \ 246 shift; \ 247 ${ECHO} $$t -\> $$l; \ 248 ln -f $$l $$t; \ 249 done; true 250.endif 251.if defined(SYMLINKS) && !empty(SYMLINKS) 252 @set ${SYMLINKS}; \ 253 while test $$# -ge 2; do \ 254 l=$$1; \ 255 shift; \ 256 t=${DESTDIR}$$1; \ 257 shift; \ 258 ${ECHO} $$t -\> $$l; \ 259 ln -fs $$l $$t; \ 260 done; true 261.endif 262.if !defined(NO_XREF) 263 -kldxref ${DESTDIR}${KMODDIR} 264.endif 265.endif 266 267install: afterinstall 268afterinstall: realinstall 269realinstall: beforeinstall 270.endif 271 272DISTRIBUTION?= bin 273.if !target(distribute) 274distribute: 275.for dist in ${DISTRIBUTION} 276 cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 277.endfor 278.endif 279 280.if !target(load) 281load: ${PROG} 282 ${KMODLOAD} -v ${.CURDIR}/${KMOD}.ko 283.endif 284 285.if !target(unload) 286unload: 287 ${KMODUNLOAD} -v ${KMOD} 288.endif 289 290.for _src in ${SRCS:Mopt_*.h} 291CLEANFILES+= ${_src} 292.if !target(${_src}) 293${_src}: 294 touch ${.TARGET} 295.endif 296.endfor 297 298MFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \ 299 dev/iicbus/iicbus_if.m isa/isa_if.m \ 300 libkern/iconv_converter_if.m \ 301 dev/mii/miibus_if.m \ 302 dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \ 303 dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \ 304 dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ 305 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m pci/agp_if.m 306 307.for _srcsrc in ${MFILES} 308.for _ext in c h 309.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}} 310CLEANFILES+= ${_src} 311.if !target(${_src}) 312.if !exists(@) 313${_src}: @ 314.endif 315.if exists(@) 316${_src}: @/tools/makeobjops.awk @/${_srcsrc} 317.endif 318 ${AWK} -f @/tools/makeobjops.awk @/${_srcsrc} -${_ext} 319.endif 320.endfor # _src 321.endfor # _ext 322.endfor # _srcsrc 323 324.for _ext in c h 325.if ${SRCS:Mvnode_if.${_ext}} != "" 326CLEANFILES+= vnode_if.${_ext} 327.if !exists(@) 328vnode_if.${_ext}: @ 329.endif 330.if exists(@) 331vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src 332.endif 333 ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -${_ext} 334.endif 335.endfor 336 337regress: 338 339lint: ${SRCS} 340 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC:M*.c} 341 342.include <bsd.dep.mk> 343 344.if !exists(${DEPENDFILE}) 345${OBJS}: ${SRCS:M*.h} 346.endif 347 348.include <bsd.obj.mk> 349.include <bsd.kern.mk> 350