kmod.mk revision 122894
1139825Simp# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 277957Sbenno# $FreeBSD: head/sys/conf/kmod.mk 122894 2003-11-19 05:08:27Z imp $ 377957Sbenno# 477957Sbenno# The include file <bsd.kmod.mk> handles installing Kernel Loadable Device 577957Sbenno# drivers (KLD's). 677957Sbenno# 777957Sbenno# 877957Sbenno# +++ variables +++ 977957Sbenno# 1077957Sbenno# CLEANFILES Additional files to remove for the clean and cleandir targets. 1177957Sbenno# 1277957Sbenno# KMOD The name of the kernel module to build. 1377957Sbenno# 1477957Sbenno# KMODDIR Base path for kernel modules (see kld(4)). [/boot/kernel] 1577957Sbenno# 1677957Sbenno# KMODOWN KLD owner. [${BINOWN}] 1777957Sbenno# 1877957Sbenno# KMODGRP KLD group. [${BINGRP}] 1977957Sbenno# 2077957Sbenno# KMODMODE KLD mode. [${BINMODE}] 2177957Sbenno# 2277957Sbenno# KMODLOAD Command to load a kernel module [/sbin/kldload] 2377957Sbenno# 2477957Sbenno# KMODUNLOAD Command to unload a kernel module [/sbin/kldunload] 2577957Sbenno# 2677957Sbenno# PROG The name of the kernel module to build. 2777957Sbenno# If not supplied, ${KMOD}.o is used. 2877957Sbenno# 2977957Sbenno# SRCS List of source files 3077957Sbenno# 31139825Simp# DESTDIR Change the tree where the module gets installed. [not set] 3277957Sbenno# 3377957Sbenno# MFILES Optionally a list of interfaces used by the module. 3477957Sbenno# This file contains a default list of interfaces. 3577957Sbenno# 3677957Sbenno# EXPORT_SYMS A list of symbols that should be exported from the module, 3777957Sbenno# or the name of a file containing a list of symbols, or YES 3877957Sbenno# to export all symbols. If not defined, no symbols are 3977957Sbenno# exported. 4077957Sbenno# 4177957Sbenno# +++ targets +++ 4277957Sbenno# 4377957Sbenno# install: 4477957Sbenno# install the kernel module; if the Makefile 4577957Sbenno# does not itself define the target install, the targets 4677957Sbenno# beforeinstall and afterinstall may also be used to cause 4777957Sbenno# actions immediately before and after the install target 4877957Sbenno# is executed. 4977957Sbenno# 5077957Sbenno# load: 5177957Sbenno# Load KLD. 5277957Sbenno# 5377957Sbenno# unload: 5477957Sbenno# Unload KLD. 5577957Sbenno# 5677957Sbenno# bsd.obj.mk: clean, cleandir and obj 57113038Sobrien# bsd.dep.mk: cleandepend, depend and tags 58113038Sobrien# 5977957Sbenno 6077957SbennoAWK?= awk 61132681SgrehanKMODLOAD?= /sbin/kldload 62118239SpeterKMODUNLOAD?= /sbin/kldunload 63239666SrpauloOBJCOPY?= objcopy 6477957Sbenno 6577957Sbenno.if defined(KMODDEPS) 66141378Snjl.error "Do not use KMODDEPS on 5.0+, use MODULE_VERSION/MODULE_DEPEND" 6777957Sbenno.endif 68141249Snjl 69141249Snjl.include <bsd.init.mk> 70141249Snjl 71141378Snjl.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 72141237Snjl 73141249SnjlCFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS} 74141378SnjlCFLAGS+= -DKLD_MODULE 75141378Snjl 76132073Sgrehan# Don't use any standard or source-relative include directories. 77141378Snjl# Since -nostdinc will annull any previous -I paths, we repeat all 78141378Snjl# such paths after -nostdinc. It doesn't seem to be possible to 79141378Snjl# add to the front of `make' variable. 8085201Smp_ICFLAGS:= ${CFLAGS:M-I*} 8177957SbennoCFLAGS+= -nostdinc -I- ${INCLMAGIC} ${_ICFLAGS} 8277957Sbenno.if defined(KERNBUILDDIR) 8377957SbennoCFLAGS+= -include ${KERNBUILDDIR}/opt_global.h 84141378Snjl.endif 85141378Snjl 86141378Snjl# Add -I paths for system headers. Individual KLD makefiles don't 87248084Sattilio# need any -I paths for this. Similar defaults for .PATH can't be 88141378Snjl# set because there are no standard paths for non-headers. 89209613SjhbCFLAGS+= -I. -I@ 9077957Sbenno 91141378Snjl# Add a -I path to standard headers like <stddef.h>. Use a relative 92141378Snjl# path to src/include if possible. If the @ symlink hasn't been built 93141378Snjl# yet, then we can't tell if the relative path exists. Add both the 9477957Sbenno# potential relative path and an absolute path in that case. 95141378Snjl.if exists(@) 96141378Snjl.if exists(@/../include) 97141378SnjlCFLAGS+= -I@/../include 9877957Sbenno.else 99141378SnjlCFLAGS+= -I${DESTDIR}/usr/include 10077957Sbenno.endif 101141378Snjl.else # !@ 10277957SbennoCFLAGS+= -I@/../include -I${DESTDIR}/usr/include 10377957Sbenno.endif # @ 10477957Sbenno 10577957SbennoCFLAGS+= -finline-limit=${INLINE_LIMIT} 10677957Sbenno 107141378Snjl# Disallow common variables, and if we end up with commons from 108188860Snwhitehorn# somewhere unexpected, allocate storage for them in the module itself. 109209975SnwhitehornCFLAGS+= -fno-common 11077957SbennoLDFLAGS+= -d -warn-common 111209975Snwhitehorn 112125687SgrehanCFLAGS+= ${DEBUG_FLAGS} 113141378Snjl 114141378SnjlOBJS+= ${SRCS:N*.h:R:S/$/.o/g} 115176919Smarcel 116176742Sraj.if !defined(PROG) 11777957SbennoPROG= ${KMOD}.ko 11899729Sbenno.endif 119152179Sgrehan 120138129Sdas.if !defined(DEBUG) 12177957SbennoFULLPROG= ${PROG} 122141378Snjl.else 123190953SnwhitehornFULLPROG= ${PROG}.debug 124141378Snjl${PROG}: ${FULLPROG} 12577957Sbenno ${OBJCOPY} --strip-debug ${FULLPROG} ${PROG} 126259235Sandreast.endif 12777957Sbenno 128132073Sgrehan${FULLPROG}: ${KMOD}.kld 129132073Sgrehan ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld 130141378Snjl 131141378SnjlEXPORT_SYMS?= NO 132132681Sgrehan.if ${EXPORT_SYMS} != YES 133132681SgrehanCLEANFILES+= ${.OBJDIR}/export_syms 134132681Sgrehan.endif 135132681Sgrehan 13677957Sbenno${KMOD}.kld: ${OBJS} 137209975Snwhitehorn ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS} 138222620Snwhitehorn.if defined(EXPORT_SYMS) 139209975Snwhitehorn.if ${EXPORT_SYMS} != YES 140209975Snwhitehorn.if ${EXPORT_SYMS} == NO 141183319Snwhitehorn touch ${.OBJDIR}/export_syms 142209975Snwhitehorn.elif !exists(${.CURDIR}/${EXPORT_SYMS}) 143190681Snwhitehorn echo ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 14477957Sbenno.else 145262675Sjhibbits grep -v '^#' < ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 146262675Sjhibbits.endif 147178628Smarcel awk -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \ 148178628Smarcel ${.OBJDIR}/export_syms | \ 149176222Smarcel xargs -J% ${OBJCOPY} % ${.TARGET} 15077957Sbenno.endif 15177957Sbenno.endif 15277957Sbenno 15377957Sbenno_ILINKS=@ machine 154183319Snwhitehorn 155183319Snwhitehornall: objwarn ${PROG} 156183319Snwhitehorn 157103600Sgrehanbeforedepend: ${_ILINKS} 158103600Sgrehan @rm -f .depend 159103600Sgrehan 160209975Snwhitehorn# Ensure that the links exist without depending on it when it exists which 16177957Sbenno# causes all the modules to be rebuilt when the directory pointed to changes. 162102600Speter.for _link in ${_ILINKS} 163142882Sgrehan.if !exists(${.OBJDIR}/${_link}) 16477957Sbenno${OBJS}: ${_link} 165209975Snwhitehorn.endif 16677957Sbenno.endfor 167209975Snwhitehorn 16877957Sbenno# Search for kernel source tree in standard places. 16982939Speter.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys 17077957Sbenno.if !defined(SYSDIR) && exists(${_dir}/kern) 17177957SbennoSYSDIR= ${_dir} 17277957Sbenno.endif 17377957Sbenno.endfor 17477957Sbenno.if !defined(SYSDIR) || !exists(${SYSDIR}/kern) 17577957Sbenno.error "can't find kernel source tree" 176173584Sgrehan.endif 177173584Sgrehan 178173584Sgrehan${_ILINKS}: 179173584Sgrehan @case ${.TARGET} in \ 180173584Sgrehan machine) \ 18177957Sbenno path=${SYSDIR}/${MACHINE_ARCH}/include ;; \ 18277957Sbenno @) \ 183110387Sbenno path=${SYSDIR} ;; \ 18477957Sbenno esac ; \ 18577957Sbenno path=`(cd $$path && /bin/pwd)` ; \ 18677957Sbenno ${ECHO} ${.TARGET} "->" $$path ; \ 18777957Sbenno ln -s $$path ${.TARGET} 188143201Sgrehan 189143201SgrehanCLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o 190143201Sgrehan 19177957Sbenno.if defined(DEBUG) 192204128SnwhitehornCLEANFILES+= ${FULLPROG} 193204128Snwhitehorn.endif 194204128Snwhitehorn 195204128Snwhitehorn.if !target(install) 196204128Snwhitehorn 19777957Sbenno_INSTALLFLAGS:= ${INSTALLFLAGS} 19877957Sbenno.for ie in ${INSTALLFLAGS_EDIT} 19977957Sbenno_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 20077957Sbenno.endfor 20177957Sbenno 20277957Sbenno.if defined(DEBUG) 20377957Sbennoinstall.debug: 20477957Sbenno cd ${.CURDIR}; ${MAKE} -DINSTALL_DEBUG install 205209975Snwhitehorn.endif 206209975Snwhitehorn 20777957Sbenno.if !target(realinstall) 208209975Snwhitehornrealinstall: _kmodinstall 209220818Sandreast.ORDER: beforeinstall _kmodinstall 210209975Snwhitehorn.if defined(DEBUG) && defined(INSTALL_DEBUG) 211209975Snwhitehorn_kmodinstall: 212209975Snwhitehorn ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 21377957Sbenno ${_INSTALLFLAGS} ${FULLPROG} ${DESTDIR}${KMODDIR} 21477957Sbenno.else 21577957Sbenno_kmodinstall: 21677957Sbenno ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 21777957Sbenno ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 21882939Speter 21977957Sbenno.include <bsd.links.mk> 220170170Sattilio 221170170Sattilio.if !defined(NO_XREF) 22277957Sbennoafterinstall: _kldxref 22377957Sbenno.ORDER: realinstall _kldxref 22477957Sbenno.ORDER: _installlinks _kldxref 22577957Sbenno_kldxref: 22677957Sbenno @if type kldxref >/dev/null 2>&1; then \ 22777957Sbenno ${ECHO} kldxref ${DESTDIR}${KMODDIR}; \ 22877957Sbenno kldxref ${DESTDIR}${KMODDIR}; \ 22977957Sbenno fi 23077957Sbenno.endif 23177957Sbenno.endif 232209975Snwhitehorn.endif !target(realinstall) 233209975Snwhitehorn 234190681Snwhitehorn.endif !target(install) 235190681Snwhitehorn 236190681Snwhitehorn.if !target(load) 237209975Snwhitehornload: ${PROG} 238209975Snwhitehorn ${KMODLOAD} -v ${.OBJDIR}/${KMOD}.ko 239209975Snwhitehorn.endif 240178628Smarcel 241209975Snwhitehorn.if !target(unload) 242230123Snwhitehornunload: 24377957Sbenno ${KMODUNLOAD} -v ${KMOD} 24477957Sbenno.endif 24577957Sbenno 24699664Sbenno.if defined(KERNBUILDDIR) 247132073Sgrehan.PATH: ${KERNBUILDDIR} 248215107SnwhitehornCFLAGS += -I${KERNBUILDDIR} 249215107Snwhitehorn.for _src in ${SRCS:Mopt_*.h} 250215107SnwhitehornCLEANFILES+= ${_src} 251259235Sandreast.if !target(${_src}) 25277957Sbenno${_src}: 253209975Snwhitehorn ln -s ${KERNBUILDDIR}/${_src} ${.TARGET} 254209975Snwhitehorn.endif 255209975Snwhitehorn.endfor 25677957Sbenno.else 25790643Sbenno.for _src in ${SRCS:Mopt_*.h} 258190681SnwhitehornCLEANFILES+= ${_src} 259190681Snwhitehorn.if !target(${_src}) 26099729Sbenno${_src}: 261142756Sgrehan touch ${.TARGET} 262239682Srpaulo.endif 263239682Srpaulo.endfor 264239682Srpaulo.endif 265239682Srpaulo 266190953SnwhitehornMFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \ 267212597Sgrehan dev/iicbus/iicbus_if.m isa/isa_if.m \ 268209975Snwhitehorn libkern/iconv_converter_if.m \ 269199886Snwhitehorn dev/mii/miibus_if.m \ 270209975Snwhitehorn dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \ 27190643Sbenno dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \ 27299729Sbenno dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ 273190681Snwhitehorn dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m pci/agp_if.m \ 274212597Sgrehan opencrypto/crypto_if.m pc98/pc98/canbus_if.m dev/uart/uart_if.m 27599729Sbenno 276259235Sandreast.for _srcsrc in ${MFILES} 277259235Sandreast.for _ext in c h 278259235Sandreast.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}} 279239666SrpauloCLEANFILES+= ${_src} 28090643Sbenno.if !target(${_src}) 281239480Sadrian.if !exists(@) 282239480Sadrian${_src}: @ 283239480Sadrian.endif 284239480Sadrian.if exists(@) 285239480Sadrian${_src}: @/tools/makeobjops.awk @/${_srcsrc} 286239480Sadrian.endif 287239666Srpaulo ${AWK} -f @/tools/makeobjops.awk @/${_srcsrc} -${_ext} 288239480Sadrian.endif 289239480Sadrian.endfor # _src 29099729Sbenno.endfor # _ext 29199729Sbenno.endfor # _srcsrc 29299729Sbenno 29399729Sbenno.for _ext in c h 29499729Sbenno.if ${SRCS:Mvnode_if.${_ext}} != "" 29599729SbennoCLEANFILES+= vnode_if.${_ext} 296114374Speter.if !exists(@) 29799729Sbennovnode_if.${_ext}: @ 29899729Sbenno.endif 29999729Sbenno.if exists(@) 300222615Snwhitehornvnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src 301222615Snwhitehorn.endif 302132681Sgrehan ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -${_ext} 303132681Sgrehan.endif 304132681Sgrehan.endfor 305132681Sgrehan 30699729Sbenno.if ${SRCS:Mmiidevs.h} != "" 30799729SbennoCLEANFILES+= miidevs.h 30899729Sbenno.if !exists(@) 30999729Sbennomiidevs.h: @ 310126474Sgrehan.endif 311126474Sgrehan.if exists(@) 312126474Sgrehanmiidevs.h: @/tools/devlist2h.awk @/dev/mii/miidevs 313126474Sgrehan.endif 314126474Sgrehan ${AWK} -f @/tools/devlist2h.awk @/dev/mii/miidevs 315126474Sgrehan.endif 316126474Sgrehan 317173361Skibregress: 318126474Sgrehan 319126474Sgrehanlint: ${SRCS} 320126474Sgrehan ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC:M*.c} 321126474Sgrehan 322126474Sgrehan.include <bsd.dep.mk> 323178628Smarcel 324126474Sgrehan.if !exists(${.OBJDIR}/${DEPENDFILE}) 325227628Snwhitehorn${OBJS}: ${SRCS:M*.h} 326227628Snwhitehorn.endif 327227628Snwhitehorn 328227628Snwhitehorn.include <bsd.obj.mk> 329227628Snwhitehorn.include "kern.mk" 330227628Snwhitehorn