1# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2# $FreeBSD: src/sys/conf/kmod.mk,v 1.82.2.15 2003/02/10 13:11:50 nyan Exp $ 3# $DragonFly: src/sys/conf/kmod.mk,v 1.21 2005/06/27 11:03:43 corecode Exp $ 4# 5# The include file <bsd.kmod.mk> handles installing Kernel Loadable Device 6# drivers (KLD's). 7# 8# 9# +++ variables +++ 10# 11# CLEANFILES Additional files to remove for the clean and cleandir targets. 12# 13# KMOD The name of the kernel module to build. 14# 15# KMODDIR Base path for kernel modules (see kld(4)). [/modules] 16# 17# KMODOWN KLD owner. [${BINOWN}] 18# 19# KMODGRP KLD group. [${BINGRP}] 20# 21# KMODMODE KLD mode. [${BINMODE}] 22# 23# KMODLOAD Command to load a kernel module [/sbin/kldload] 24# 25# KMODUNLOAD Command to unload a kernel module [/sbin/kldunload] 26# 27# NOMAN KLD does not have a manual page if set. 28# 29# PROG The name of the kernel module to build. 30# If not supplied, ${KMOD}.o is used. 31# 32# SRCS List of source files 33# 34# KMODDEPS List of modules which this one is dependant on 35# 36# DESTDIR Change the tree where the module gets installed. [not set] 37# 38# MFILES Optionally a list of interfaces used by the module. 39# This file contains a default list of interfaces. 40# 41# +++ targets +++ 42# 43# install: 44# install the kernel module and its manual pages; 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# bsd.man.mk: maninstall 59# 60 61OBJCOPY?= objcopy 62KMODLOAD?= /sbin/kldload 63KMODUNLOAD?= /sbin/kldunload 64 65.include <bsd.init.mk> 66 67.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 68 69CFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS} 70CFLAGS+= -DKLD_MODULE 71 72# Don't use any standard include directories. 73# Since -nostdinc will annull any previous -I paths, we repeat all 74# such paths after -nostdinc. It doesn't seem to be possible to 75# add to the front of `make' variable. 76# 77# Don't use -I- anymore, source-relative includes are desireable. 78_ICFLAGS:= ${CFLAGS:M-I*} 79CFLAGS+= -nostdinc ${_ICFLAGS} 80 81# Add -I paths for system headers. Individual KLD makefiles don't 82# need any -I paths for this. Similar defaults for .PATH can't be 83# set because there are no standard paths for non-headers. 84CFLAGS+= -I. -I@ 85 86# Add a -I path to standard headers like <stddef.h>. Use a relative 87# path to src/include if possible. If the @ symlink hasn't been built 88# yet, then we can't tell if the relative path exists. Add both the 89# potential relative path and an absolute path in that case. 90.if exists(@) 91.if exists(@/../include) 92CFLAGS+= -I@/../include 93.else 94CFLAGS+= -I${DESTDIR}/usr/include 95.endif 96.else # !@ 97CFLAGS+= -I@/../include -I${DESTDIR}/usr/include 98.endif # @ 99 100.if defined(BUILDING_WITH_KERNEL) && \ 101 exists(${BUILDING_WITH_KERNEL}/opt_global.h) 102CFLAGS+= -include ${BUILDING_WITH_KERNEL}/opt_global.h 103.endif 104 105CFLAGS+= ${DEBUG_FLAGS} 106 107OBJS+= ${SRCS:N*.h:N*.patch:R:S/$/.o/g} 108.for _PATCH in ${SRCS:T:N*.h.patch:M*.patch} 109.for _OBJ in ${_PATCH:R:R:S/$/.o/} 110OBJS:= ${OBJS:N${_OBJ}} ${_OBJ} 111.endfor 112.endfor 113 114.if !defined(PROG) 115PROG= ${KMOD}.ko 116.endif 117 118${PROG}: ${KMOD}.kld ${KMODDEPS} 119 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld ${KMODDEPS} 120 121.if defined(KMODDEPS) 122.for dep in ${KMODDEPS} 123CLEANFILES+= ${dep} __${dep}_hack_dep.c 124 125${dep}: 126 touch __${dep}_hack_dep.c 127 ${CC} -shared ${CFLAGS} -o ${dep} __${dep}_hack_dep.c 128.endfor 129.endif 130 131${KMOD}.kld: ${OBJS} 132 ${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS} 133 134.if !defined(NOMAN) 135.include <bsd.man.mk> 136.endif 137 138_ILINKS=@ machine 139.if defined(ARCH) 140_ILINKS+=${ARCH} 141.endif 142 143all: objwarn ${PROG} 144.if !defined(NOMAN) 145all: _manpages 146.endif 147 148beforedepend: ${_ILINKS} 149# Ensure that the links exist without depending on it when it exists which 150# causes all the modules to be rebuilt when the directory pointed to changes. 151.for _link in ${_ILINKS} 152.if !exists(${.OBJDIR}/${_link}) 153${OBJS}: ${_link} 154.endif 155.endfor 156 157# Search for kernel source tree in standard places. 158.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. ${.CURDIR}/../../../.. /sys /usr/src/sys 159.if !defined(SYSDIR) && exists(${_dir}/kern/) 160SYSDIR= ${_dir} 161.endif 162.endfor 163.if !defined(SYSDIR) || !exists(${SYSDIR}/kern) 164.error "can't find kernel source tree" 165.endif 166 167# path=`(cd $$path && /bin/pwd)` ; 168 169${_ILINKS}: 170 @case ${.TARGET} in \ 171 machine) \ 172 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \ 173 @) \ 174 path=${SYSDIR} ;; \ 175 arch_*) \ 176 path=${.CURDIR}/${MACHINE_ARCH} ;; \ 177 esac ; \ 178 ${ECHO} ${.TARGET} "->" $$path ; \ 179 ln -s $$path ${.TARGET} 180 181CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o 182 183.if !target(install) 184 185_INSTALLFLAGS:= ${INSTALLFLAGS} 186.for ie in ${INSTALLFLAGS_EDIT} 187_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 188.endfor 189 190.if !target(realinstall) 191realinstall: _kmodinstall 192.ORDER: beforeinstall _kmodinstall 193_kmodinstall: 194.if defined(INSTALLSTRIPPEDMODULES) 195 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 196 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 197 ${OBJCOPY} --strip-debug ${DESTDIR}${KMODDIR}/${PROG} 198.else 199 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 200 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 201.endif 202.endif # !target(realinstall) 203 204.include <bsd.links.mk> 205 206.if !defined(NOMAN) 207realinstall: _maninstall 208.ORDER: beforeinstall _maninstall 209.endif 210 211.endif # !target(install) 212 213.if !target(load) 214load: ${PROG} 215 ${KMODLOAD} -v ./${KMOD}.ko 216.endif 217 218.if !target(unload) 219unload: 220 ${KMODUNLOAD} -v ${KMOD} 221.endif 222 223.for _src in ${SRCS:Mopt_*.h} ${SRCS:Muse_*.h} 224CLEANFILES+= ${_src} 225.if !target(${_src}) 226.if defined(BUILDING_WITH_KERNEL) && exists(${BUILDING_WITH_KERNEL}/${_src}) 227${_src}: ${BUILDING_WITH_KERNEL}/${_src} 228 cp ${BUILDING_WITH_KERNEL}/${_src} ${.TARGET} 229.else 230${_src}: 231 touch ${.TARGET} 232.endif # BUILDING_WITH_KERNEL 233.endif 234.endfor 235 236MFILES?= kern/bus_if.m kern/device_if.m bus/iicbus/iicbb_if.m \ 237 bus/iicbus/iicbus_if.m bus/isa/isa_if.m dev/netif/mii_layer/miibus_if.m \ 238 bus/pccard/card_if.m bus/pccard/power_if.m bus/pci/pci_if.m \ 239 bus/pci/pcib_if.m \ 240 bus/ppbus/ppbus_if.m bus/smbus/smbus_if.m bus/usb/usb_if.m \ 241 dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ 242 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \ 243 libiconv/iconv_converter_if.m dev/agp/agp_if.m opencrypto/crypto_if.m 244 245.for _srcsrc in ${MFILES} 246.for _ext in c h 247.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}} 248CLEANFILES+= ${_src} 249.if !target(${_src}) 250${_src}: @ 251.if exists(@) 252${_src}: @/tools/makeobjops.awk @/${_srcsrc} 253.endif 254 awk -f @/tools/makeobjops.awk -- -${_ext} @/${_srcsrc} 255.endif 256.endfor # _src 257.endfor # _ext 258.endfor # _srcsrc 259 260#.for _ext in c h 261#.if ${SRCS:Mvnode_if.${_ext}} != "" 262#CLEANFILES+= vnode_if.${_ext} 263#vnode_if.${_ext}: @ 264#.if exists(@) 265#vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src 266#.endif 267# awk -f @/tools/vnode_if.awk -- -${_ext} @/kern/vnode_if.src 268#.endif 269#.endfor 270 271regress: 272 273.include <bsd.dep.mk> 274 275.if !exists(${DEPENDFILE}) 276${OBJS}: ${SRCS:M*.h} 277.endif 278 279.include <bsd.obj.mk> 280.include "bsd.kern.mk" 281 282# Behaves like MODULE_OVERRIDE 283.if defined(KLD_DEPS) 284all: _kdeps_all 285_kdeps_all: @ 286.for _mdep in ${KLD_DEPS} 287 cd ${SYSDIR}/${_mdep} && make all 288.endfor 289depend: _kdeps_depend 290_kdeps_depend: @ 291.for _mdep in ${KLD_DEPS} 292 cd ${SYSDIR}/${_mdep} && make depend 293.endfor 294install: _kdeps_install 295_kdeps_install: @ 296.for _mdep in ${KLD_DEPS} 297 cd ${SYSDIR}/${_mdep} && make install 298.endfor 299clean: _kdeps_clean 300_kdeps_clean: @ 301.for _mdep in ${KLD_DEPS} 302 cd ${SYSDIR}/${_mdep} && make clean 303.endfor 304.endif 305