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.14 2004/04/12 12:46:42 eirikn Exp $
5 # The include file <bsd.kmod.mk> handles installing Kernel Loadable Device
11 # CLEANFILES Additional files to remove for the clean and cleandir targets.
13 # KMOD The name of the kernel module to build.
15 # KMODDIR Base path for kernel modules (see kld(4)). [/modules]
17 # KMODOWN KLD owner. [${BINOWN}]
19 # KMODGRP KLD group. [${BINGRP}]
21 # KMODMODE KLD mode. [${BINMODE}]
23 # KMODLOAD Command to load a kernel module [/sbin/kldload]
25 # KMODUNLOAD Command to unload a kernel module [/sbin/kldunload]
27 # NOMAN KLD does not have a manual page if set.
29 # PROG The name of the kernel module to build.
30 # If not supplied, ${KMOD}.o is used.
32 # SRCS List of source files
34 # KMODDEPS List of modules which this one is dependant on
36 # DESTDIR Change the tree where the module gets installed. [not set]
38 # MFILES Optionally a list of interfaces used by the module.
39 # This file contains a default list of interfaces.
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
56 # bsd.obj.mk: clean, cleandir and obj
57 # bsd.dep.mk: cleandepend, depend and tags
58 # bsd.man.mk: maninstall
61 KMODLOAD?= /sbin/kldload
62 KMODUNLOAD?= /sbin/kldunload
64 .include <bsd.init.mk>
66 .SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
68 CFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS}
71 # Don't use any standard include directories.
72 # Since -nostdinc will annull any previous -I paths, we repeat all
73 # such paths after -nostdinc. It doesn't seem to be possible to
74 # add to the front of `make' variable.
76 # Don't use -I- anymore, source-relative includes are desireable.
77 _ICFLAGS:= ${CFLAGS:M-I*}
78 CFLAGS+= -nostdinc ${_ICFLAGS}
80 # Add -I paths for system headers. Individual KLD makefiles don't
81 # need any -I paths for this. Similar defaults for .PATH can't be
82 # set because there are no standard paths for non-headers.
85 # Add a -I path to standard headers like <stddef.h>. Use a relative
86 # path to src/include if possible. If the @ symlink hasn't been built
87 # yet, then we can't tell if the relative path exists. Add both the
88 # potential relative path and an absolute path in that case.
90 .if exists(@/../include)
91 CFLAGS+= -I@/../include
93 CFLAGS+= -I${DESTDIR}/usr/include
96 CFLAGS+= -I@/../include -I${DESTDIR}/usr/include
99 CFLAGS+= ${DEBUG_FLAGS}
101 OBJS+= ${SRCS:N*.h:R:S/$/.o/g}
107 ${PROG}: ${KMOD}.kld ${KMODDEPS}
108 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld ${KMODDEPS}
110 .if defined(KMODDEPS)
111 .for dep in ${KMODDEPS}
112 CLEANFILES+= ${dep} __${dep}_hack_dep.c
115 touch __${dep}_hack_dep.c
116 ${CC} -shared ${CFLAGS} -o ${dep} __${dep}_hack_dep.c
121 ${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS}
124 .include <bsd.man.mk>
137 beforedepend: ${_ILINKS}
138 # Ensure that the links exist without depending on it when it exists which
139 # causes all the modules to be rebuilt when the directory pointed to changes.
140 .for _link in ${_ILINKS}
141 .if !exists(${.OBJDIR}/${_link})
146 # Search for kernel source tree in standard places.
147 .for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. ${.CURDIR}/../../../.. /sys /usr/src/sys
148 .if !defined(SYSDIR) && exists(${_dir}/kern/)
152 .if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
153 .error "can't find kernel source tree"
156 # path=`(cd $$path && /bin/pwd)` ;
159 @case ${.TARGET} in \
161 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \
165 path=${.CURDIR}/${MACHINE_ARCH} ;; \
167 ${ECHO} ${.TARGET} "->" $$path ; \
168 ln -s $$path ${.TARGET}
170 CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
174 _INSTALLFLAGS:= ${INSTALLFLAGS}
175 .for ie in ${INSTALLFLAGS_EDIT}
176 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
179 .if !target(realinstall)
180 realinstall: _kmodinstall
181 .ORDER: beforeinstall _kmodinstall
183 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
184 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
185 .endif !target(realinstall)
187 .include <bsd.links.mk>
190 realinstall: _maninstall
191 .ORDER: beforeinstall _maninstall
194 .endif !target(install)
198 ${KMODLOAD} -v ./${KMOD}.ko
203 ${KMODUNLOAD} -v ${KMOD}
206 .for _src in ${SRCS:Mopt_*.h}
214 MFILES?= kern/bus_if.m kern/device_if.m bus/iicbus/iicbb_if.m \
215 bus/iicbus/iicbus_if.m bus/isa/isa_if.m dev/netif/mii_layer/miibus_if.m \
216 bus/pccard/card_if.m bus/pccard/power_if.m bus/pci/pci_if.m \
218 bus/ppbus/ppbus_if.m bus/smbus/smbus_if.m bus/usb/usb_if.m \
219 dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
220 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \
221 libiconv/iconv_converter_if.m dev/agp/agp_if.m opencrypto/crypto_if.m \
222 bus/canbus/canbus_if.m
224 .for _srcsrc in ${MFILES}
226 .for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
231 ${_src}: @/tools/makeobjops.awk @/${_srcsrc}
233 awk -f @/tools/makeobjops.awk -- -${_ext} @/${_srcsrc}
240 .if ${SRCS:Mvnode_if.${_ext}} != ""
241 CLEANFILES+= vnode_if.${_ext}
244 vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src
246 awk -f @/tools/vnode_if.awk -- -${_ext} @/kern/vnode_if.src
252 .include <bsd.dep.mk>
254 .if !exists(${DEPENDFILE})
255 ${OBJS}: ${SRCS:M*.h}
258 .include <bsd.obj.mk>
259 .include "bsd.kern.mk"
261 # Behaves like MODULE_OVERRIDE
262 .if defined(KLD_DEPS)
265 .for _mdep in ${KLD_DEPS}
266 cd ${SYSDIR}/${_mdep} && make all
268 depend: _kdeps_depend
270 .for _mdep in ${KLD_DEPS}
271 cd ${SYSDIR}/${_mdep} && make depend
273 install: _kdeps_install
275 .for _mdep in ${KLD_DEPS}
276 cd ${SYSDIR}/${_mdep} && make install
280 .for _mdep in ${KLD_DEPS}
281 cd ${SYSDIR}/${_mdep} && make clean