test 5
[dragonfly.git] / sys / conf / kmod.mk
... / ...
CommitLineData
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.27 2006/10/23 21:50:31 dillon 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.
84#
85# NOTE! Traditional architecture paths such as <i386/i386/blah.h>
86# must run through the "arch" softlink using <arch/i386/blah.h>. An
87# explicit cross-architecture path must operate relative to /usr/src/sys
88# using e.g. <arch/i386/i386/blah.h>
89#
90CFLAGS+= -I. -I@
91
92# Add a -I path to standard headers like <stddef.h>. Use a relative
93# path to src/include if possible. If the @ symlink hasn't been built
94# yet, then we can't tell if the relative path exists. Add both the
95# potential relative path and an absolute path in that case.
96.if exists(@)
97.if exists(@/../include)
98CFLAGS+= -I@/../include
99.else
100CFLAGS+= -I${DESTDIR}/usr/include
101.endif
102.else # !@
103CFLAGS+= -I@/../include -I${DESTDIR}/usr/include
104.endif # @
105
106.if defined(BUILDING_WITH_KERNEL) && \
107 exists(${BUILDING_WITH_KERNEL}/opt_global.h)
108CFLAGS+= -include ${BUILDING_WITH_KERNEL}/opt_global.h
109.endif
110
111CFLAGS+= ${DEBUG_FLAGS}
112
113.include <bsd.patch.mk>
114
115OBJS+= ${SRCS:N*.h:N*.patch:R:S/$/.o/g}
116
117.if !defined(PROG)
118PROG= ${KMOD}.ko
119.endif
120
121${PROG}: ${KMOD}.kld ${KMODDEPS}
122 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld ${KMODDEPS}
123
124.if defined(KMODDEPS)
125.for dep in ${KMODDEPS}
126CLEANFILES+= ${dep} __${dep}_hack_dep.c
127
128${dep}:
129 touch __${dep}_hack_dep.c
130 ${CC} -shared ${CFLAGS} -o ${dep} __${dep}_hack_dep.c
131.endfor
132.endif
133
134${KMOD}.kld: ${OBJS}
135 ${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS}
136
137.if !defined(NOMAN)
138.include <bsd.man.mk>
139.endif
140
141_ILINKS=@ arch machine
142.if defined(ARCH)
143_ILINKS+=${ARCH}
144.endif
145
146all: objwarn ${PROG}
147.if !defined(NOMAN)
148all: _manpages
149.endif
150
151beforedepend: ${_ILINKS}
152# Ensure that the links exist without depending on it when it exists which
153# causes all the modules to be rebuilt when the directory pointed to changes.
154.for _link in ${_ILINKS}
155.if !exists(${.OBJDIR}/${_link})
156${OBJS}: ${_link}
157.endif
158.endfor
159
160# Search for kernel source tree in standard places.
161.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. ${.CURDIR}/../../../.. /sys /usr/src/sys
162.if !defined(SYSDIR) && exists(${_dir}/kern/)
163SYSDIR= ${_dir}
164.endif
165.endfor
166.if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
167.error "can't find kernel source tree"
168.endif
169S= ${SYSDIR}
170
171# path=`(cd $$path && /bin/pwd)` ;
172
173${_ILINKS}:
174 @case ${.TARGET} in \
175 arch) \
176 path=${SYSDIR}/arch/${MACHINE_ARCH} ;; \
177 machine) \
178 path=${SYSDIR}/arch/${MACHINE_ARCH}/include ;; \
179 @) \
180 path=${SYSDIR} ;; \
181 arch_*) \
182 path=${.CURDIR}/${MACHINE_ARCH} ;; \
183 esac ; \
184 ${ECHO} ${.TARGET} "->" $$path ; \
185 ${LN} -s $$path ${.TARGET}
186
187CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
188
189.if !target(install)
190
191_INSTALLFLAGS:= ${INSTALLFLAGS}
192.for ie in ${INSTALLFLAGS_EDIT}
193_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
194.endfor
195
196.if !target(realinstall)
197realinstall: _kmodinstall
198.ORDER: beforeinstall _kmodinstall
199_kmodinstall:
200.if defined(INSTALLSTRIPPEDMODULES)
201 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
202 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
203 ${OBJCOPY} --strip-debug ${DESTDIR}${KMODDIR}/${PROG}
204.else
205 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
206 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
207.endif
208.endif # !target(realinstall)
209
210.include <bsd.links.mk>
211
212.if !defined(NOMAN)
213realinstall: _maninstall
214.ORDER: beforeinstall _maninstall
215.endif
216
217.endif # !target(install)
218
219.if !target(load)
220load: ${PROG}
221 ${KMODLOAD} -v ./${KMOD}.ko
222.endif
223
224.if !target(unload)
225unload:
226 ${KMODUNLOAD} -v ${KMOD}
227.endif
228
229.for _src in ${SRCS:Mopt_*.h} ${SRCS:Muse_*.h}
230CLEANFILES+= ${_src}
231.if !target(${_src})
232.if defined(BUILDING_WITH_KERNEL) && exists(${BUILDING_WITH_KERNEL}/${_src})
233${_src}: ${BUILDING_WITH_KERNEL}/${_src}
234 cp ${BUILDING_WITH_KERNEL}/${_src} ${.TARGET}
235.else
236${_src}:
237 touch ${.TARGET}
238.endif # BUILDING_WITH_KERNEL
239.endif
240.endfor
241
242MFILES?= kern/bus_if.m kern/device_if.m bus/iicbus/iicbb_if.m \
243 bus/iicbus/iicbus_if.m bus/isa/isa_if.m dev/netif/mii_layer/miibus_if.m \
244 bus/pccard/card_if.m bus/pccard/power_if.m bus/pci/pci_if.m \
245 bus/pci/pcib_if.m \
246 bus/ppbus/ppbus_if.m bus/smbus/smbus_if.m bus/usb/usb_if.m \
247 dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
248 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \
249 libiconv/iconv_converter_if.m dev/agp/agp_if.m opencrypto/crypto_if.m
250
251.for _srcsrc in ${MFILES}
252.for _ext in c h
253.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
254CLEANFILES+= ${_src}
255.if !target(${_src})
256${_src}: @
257.if exists(@)
258${_src}: @/tools/makeobjops.awk @/${_srcsrc}
259.endif
260 awk -f @/tools/makeobjops.awk -- -${_ext} @/${_srcsrc}
261.endif
262.endfor # _src
263.endfor # _ext
264.endfor # _srcsrc
265
266#.for _ext in c h
267#.if ${SRCS:Mvnode_if.${_ext}} != ""
268#CLEANFILES+= vnode_if.${_ext}
269#vnode_if.${_ext}: @
270#.if exists(@)
271#vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src
272#.endif
273# awk -f @/tools/vnode_if.awk -- -${_ext} @/kern/vnode_if.src
274#.endif
275#.endfor
276
277regress:
278
279.include <bsd.dep.mk>
280
281.if !exists(${DEPENDFILE})
282${OBJS}: ${SRCS:M*.h}
283.endif
284
285.include <bsd.obj.mk>
286.include "bsd.kern.mk"
287
288# Behaves like MODULE_OVERRIDE
289.if defined(KLD_DEPS)
290all: _kdeps_all
291_kdeps_all: @
292.for _mdep in ${KLD_DEPS}
293 cd ${SYSDIR}/${_mdep} && make all
294.endfor
295depend: _kdeps_depend
296_kdeps_depend: @
297.for _mdep in ${KLD_DEPS}
298 cd ${SYSDIR}/${_mdep} && make depend
299.endfor
300install: _kdeps_install
301_kdeps_install: @
302.for _mdep in ${KLD_DEPS}
303 cd ${SYSDIR}/${_mdep} && make install
304.endfor
305clean: _kdeps_clean
306_kdeps_clean: @
307.for _mdep in ${KLD_DEPS}
308 cd ${SYSDIR}/${_mdep} && make clean
309.endfor
310.endif