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 $
4 # The include file <bsd.kmod.mk> handles installing Kernel Loadable Device
10 # CLEANFILES Additional files to remove for the clean and cleandir targets.
12 # KMOD The name of the kernel module to build.
14 # KMODDIR Base path for kernel modules (see kld(4)). [/modules]
16 # KMODOWN KLD owner. [${BINOWN}]
18 # KMODGRP KLD group. [${BINGRP}]
20 # KMODMODE KLD mode. [${BINMODE}]
22 # KMODLOAD Command to load a kernel module [/sbin/kldload]
24 # KMODUNLOAD Command to unload a kernel module [/sbin/kldunload]
26 # NOMAN KLD does not have a manual page if set.
28 # PROG The name of the kernel module to build.
29 # If not supplied, ${KMOD}.o is used.
31 # SRCS List of source files
33 # KMODDEPS List of modules which this one is dependant on
35 # DESTDIR Change the tree where the module gets installed. [not set]
37 # MFILES Optionally a list of interfaces used by the module.
38 # This file contains a default list of interfaces.
43 # install the kernel module and its manual pages; if the Makefile
44 # does not itself define the target install, the targets
45 # beforeinstall and afterinstall may also be used to cause
46 # actions immediately before and after the install target
55 # bsd.obj.mk: clean, cleandir and obj
56 # bsd.dep.mk: cleandepend, depend and tags
57 # bsd.man.mk: maninstall
60 KMODLOAD?= /sbin/kldload
61 KMODUNLOAD?= /sbin/kldunload
63 .include <bsd.init.mk>
65 .SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
67 CFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS}
70 # Don't use any standard or source-relative include directories.
71 # Since -nostdinc will annull any previous -I paths, we repeat all
72 # such paths after -nostdinc. It doesn't seem to be possible to
73 # add to the front of `make' variable.
74 _ICFLAGS:= ${CFLAGS:M-I*}
75 CFLAGS+= -nostdinc -I- ${_ICFLAGS}
77 # Add -I paths for system headers. Individual KLD makefiles don't
78 # need any -I paths for this. Similar defaults for .PATH can't be
79 # set because there are no standard paths for non-headers.
82 # Add a -I path to standard headers like <stddef.h>. Use a relative
83 # path to src/include if possible. If the @ symlink hasn't been built
84 # yet, then we can't tell if the relative path exists. Add both the
85 # potential relative path and an absolute path in that case.
87 .if exists(@/../include)
88 CFLAGS+= -I@/../include
90 CFLAGS+= -I${DESTDIR}/usr/include
93 CFLAGS+= -I@/../include -I${DESTDIR}/usr/include
96 CFLAGS+= ${DEBUG_FLAGS}
98 .if ${OBJFORMAT} == elf
99 CLEANFILES+= setdef0.c setdef1.c setdefs.h
100 CLEANFILES+= setdef0.o setdef1.o
103 OBJS+= ${SRCS:N*.h:R:S/$/.o/g}
109 ${PROG}: ${KMOD}.kld ${KMODDEPS}
110 .if ${OBJFORMAT} == elf
111 gensetdefs ${KMOD}.kld
112 ${CC} ${CFLAGS} -c setdef0.c
113 ${CC} ${CFLAGS} -c setdef1.c
114 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} setdef0.o ${KMOD}.kld setdef1.o ${KMODDEPS}
116 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld ${KMODDEPS}
119 .if defined(KMODDEPS)
120 .for dep in ${KMODDEPS}
121 CLEANFILES+= ${dep} __${dep}_hack_dep.c
124 touch __${dep}_hack_dep.c
125 ${CC} -shared ${CFLAGS} -o ${dep} __${dep}_hack_dep.c
130 ${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS}
133 .include <bsd.man.mk>
143 beforedepend: ${_ILINKS}
144 # Ensure that the links exist without depending on it when it exists which
145 # causes all the modules to be rebuilt when the directory pointed to changes.
146 .for _link in ${_ILINKS}
147 .if !exists(${.OBJDIR}/${_link})
152 # Search for kernel source tree in standard places.
153 .for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys
154 .if !defined(SYSDIR) && exists(${_dir}/kern/)
158 .if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
159 .error "can't find kernel source tree"
163 @case ${.TARGET} in \
165 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \
169 path=`(cd $$path && /bin/pwd)` ; \
170 ${ECHO} ${.TARGET} "->" $$path ; \
171 ln -s $$path ${.TARGET}
173 CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
177 _INSTALLFLAGS:= ${INSTALLFLAGS}
178 .for ie in ${INSTALLFLAGS_EDIT}
179 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
182 .if !target(realinstall)
183 realinstall: _kmodinstall
184 .ORDER: beforeinstall _kmodinstall
186 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
187 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
188 .endif !target(realinstall)
190 .include <bsd.links.mk>
193 realinstall: _maninstall
194 .ORDER: beforeinstall _maninstall
197 .endif !target(install)
201 ${KMODLOAD} -v ./${KMOD}.ko
206 ${KMODUNLOAD} -v ${KMOD}
209 .for _src in ${SRCS:Mopt_*.h}
217 MFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \
218 dev/iicbus/iicbus_if.m isa/isa_if.m dev/mii/miibus_if.m \
219 dev/pccard/card_if.m dev/pccard/power_if.m pci/pci_if.m \
220 dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m dev/usb/usb_if.m \
221 dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
222 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \
223 libkern/iconv_converter_if.m pci/agp_if.m opencrypto/crypto_if.m \
224 pc98/pc98/canbus_if.m
226 .for _srcsrc in ${MFILES}
228 .for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
233 ${_src}: @/kern/makeops.pl @/${_srcsrc}
235 perl @/kern/makeops.pl -${_ext} @/${_srcsrc}
242 .if ${SRCS:Mvnode_if.${_ext}} != ""
243 CLEANFILES+= vnode_if.${_ext}
246 vnode_if.${_ext}: @/kern/vnode_if.pl @/kern/vnode_if.src
248 perl @/kern/vnode_if.pl -${_ext} @/kern/vnode_if.src
254 .include <bsd.dep.mk>
256 .if !exists(${DEPENDFILE})
257 ${OBJS}: ${SRCS:M*.h}
260 .include <bsd.obj.mk>
261 .include <bsd.kern.mk>