Add the kernel support function allocsysid().
[dragonfly/vkernel-mp.git] / sys / conf / kmod.mk
blob1fba862abaaf196cf5521e3c77af59516a112d8c
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.32 2007/01/19 08:23:42 dillon Exp $
5 # The include file <bsd.kmod.mk> handles installing Kernel Loadable Device
6 # drivers (KLD's).
9 # +++ variables +++
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.
41 # +++ targets +++
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.
50 # load:
51 # Load KLD.
53 # unload:
54 # Unload KLD.
56 # bsd.obj.mk: clean, cleandir and obj
57 # bsd.dep.mk: cleandepend, depend and tags
58 # bsd.man.mk: maninstall
61 OBJCOPY?= objcopy
62 KMODLOAD?= /sbin/kldload
63 KMODUNLOAD?= /sbin/kldunload
65 .include <bsd.init.mk>
67 .SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
69 CFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS}
70 CFLAGS+= -DKLD_MODULE
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.
77 # Don't use -I- anymore, source-relative includes are desireable.
78 _ICFLAGS:= ${CFLAGS:M-I*}
79 CFLAGS+= -nostdinc ${_ICFLAGS}
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.
85 # NOTE! Traditional architecture paths such as <i386/i386/blah.h>
86 # must run through the "machine_base" softlink using
87 # <machine_base/i386/blah.h>. An explicit cross-architecture path must
88 # operate relative to /usr/src/sys using e.g. <arch/i386/i386/blah.h>
90 CFLAGS+= -I. -I@
92 # Add -I paths for headers in the kernel build directory
94 .if defined(BUILDING_WITH_KERNEL)
95 CFLAGS+= -I${BUILDING_WITH_KERNEL}
96 _MACHINE_FWD= ${BUILDING_WITH_KERNEL}
97 .else
98 .if defined(MAKEOBJDIRPREFIX)
99 _MACHINE_FWD= ${MAKEOBJDIRPREFIX}/${SYSDIR}/forwarder_${MACHINE_ARCH}
100 .else
101 _MACHINE_FWD= ${.OBJDIR}/forwarder_${MACHINE_ARCH}
102 CLEANDIRS+= ${_MACHINE_FWD}
103 .endif
104 .endif
105 CFLAGS+= -I${_MACHINE_FWD}/include
106 .include "kern.fwd.mk"
108 # Add a -I path to standard headers like <stddef.h>. Use a relative
109 # path to src/include if possible. If the @ symlink hasn't been built
110 # yet, then we can't tell if the relative path exists. Add both the
111 # potential relative path and an absolute path in that case.
112 .if exists(@)
113 .if exists(@/../include)
114 CFLAGS+= -I@/../include
115 .else
116 CFLAGS+= -I${DESTDIR}/usr/include
117 .endif
118 .else # !@
119 CFLAGS+= -I@/../include -I${DESTDIR}/usr/include
120 .endif # @
122 .if defined(BUILDING_WITH_KERNEL) && \
123 exists(${BUILDING_WITH_KERNEL}/opt_global.h)
124 CFLAGS+= -include ${BUILDING_WITH_KERNEL}/opt_global.h
125 .endif
127 CFLAGS+= ${DEBUG_FLAGS}
129 .include <bsd.patch.mk>
131 OBJS+= ${SRCS:N*.h:N*.patch:R:S/$/.o/g}
133 .if !defined(PROG)
134 PROG= ${KMOD}.ko
135 .endif
137 ${PROG}: ${KMOD}.kld ${KMODDEPS}
138 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld ${KMODDEPS}
140 .if defined(KMODDEPS)
141 .for dep in ${KMODDEPS}
142 CLEANFILES+= ${dep} __${dep}_hack_dep.c
144 ${dep}:
145 touch __${dep}_hack_dep.c
146 ${CC} -shared ${CFLAGS} -o ${dep} __${dep}_hack_dep.c
147 .endfor
148 .endif
150 ${KMOD}.kld: ${OBJS}
151 ${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS}
153 .if !defined(NOMAN)
154 .include <bsd.man.mk>
155 .endif
157 # links to platform and cpu architecture include files. If we are
158 # building with a kernel these already exist in the kernel build dir.
159 # '@' is a link to the system source.
160 .if defined(BUILDING_WITH_KERNEL)
161 _ILINKS=@
162 .else
163 _ILINKS=@ machine_base machine cpu_base cpu
164 .endif
166 .if defined(ARCH)
167 _ILINKS+=${ARCH}
168 .endif
170 all: objwarn ${PROG}
171 .if !defined(NOMAN)
172 all: _manpages
173 .endif
175 beforedepend: ${_ILINKS} ${FORWARD_HEADERS_COOKIE}
176 # Ensure that the links exist without depending on it when it exists which
177 # causes all the modules to be rebuilt when the directory pointed to changes.
178 .for _link in ${_ILINKS}
179 .if !exists(${.OBJDIR}/${_link})
180 ${OBJS}: ${_link}
181 .endif
182 .endfor
184 # Search for kernel source tree in standard places.
185 .for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. ${.CURDIR}/../../../.. /sys /usr/src/sys
186 .if !defined(SYSDIR) && exists(${_dir}/kern/)
187 SYSDIR= ${_dir}
188 .endif
189 .endfor
190 .if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
191 .error "can't find kernel source tree"
192 .endif
193 S= ${SYSDIR}
195 # path=`(cd $$path && /bin/pwd)` ;
197 ${_ILINKS}:
198 @case ${.TARGET} in \
199 machine) \
200 path=${SYSDIR}/platform/${MACHINE_PLATFORM}/include ;; \
201 machine_base) \
202 path=${SYSDIR}/platform/${MACHINE_PLATFORM} ;; \
203 cpu) \
204 path=${SYSDIR}/cpu/${MACHINE_ARCH}/include ;; \
205 cpu_base) \
206 path=${SYSDIR}/cpu/${MACHINE_ARCH} ;; \
207 @) \
208 path=${SYSDIR} ;; \
209 arch_*) \
210 path=${.CURDIR}/${MACHINE_ARCH} ;; \
211 esac ; \
212 ${ECHO} ${.TARGET} "->" $$path ; \
213 ${LN} -s $$path ${.TARGET}
215 CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
217 .if !target(install)
219 _INSTALLFLAGS:= ${INSTALLFLAGS}
220 .for ie in ${INSTALLFLAGS_EDIT}
221 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
222 .endfor
224 .if !target(realinstall)
225 realinstall: _kmodinstall
226 .ORDER: beforeinstall _kmodinstall
227 _kmodinstall:
228 .if defined(INSTALLSTRIPPEDMODULES)
229 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
230 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
231 ${OBJCOPY} --strip-debug ${DESTDIR}${KMODDIR}/${PROG}
232 .else
233 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
234 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
235 .endif
236 .endif # !target(realinstall)
238 .include <bsd.links.mk>
240 .if !defined(NOMAN)
241 realinstall: _maninstall
242 .ORDER: beforeinstall _maninstall
243 .endif
245 .endif # !target(install)
247 .if !target(load)
248 load: ${PROG}
249 ${KMODLOAD} -v ./${KMOD}.ko
250 .endif
252 .if !target(unload)
253 unload:
254 ${KMODUNLOAD} -v ${KMOD}
255 .endif
257 .for _src in ${SRCS:Mopt_*.h} ${SRCS:Muse_*.h}
258 CLEANFILES+= ${_src}
259 .if !target(${_src})
260 .if defined(BUILDING_WITH_KERNEL) && exists(${BUILDING_WITH_KERNEL}/${_src})
261 ${_src}: ${BUILDING_WITH_KERNEL}/${_src}
262 # we do not have to copy these files any more, the kernel build
263 # directory is included in the path now.
264 # cp ${BUILDING_WITH_KERNEL}/${_src} ${.TARGET}
265 .else
266 ${_src}:
267 touch ${.TARGET}
268 .endif # BUILDING_WITH_KERNEL
269 .endif
270 .endfor
272 MFILES?= kern/bus_if.m kern/device_if.m bus/iicbus/iicbb_if.m \
273 bus/iicbus/iicbus_if.m bus/isa/isa_if.m dev/netif/mii_layer/miibus_if.m \
274 bus/pccard/card_if.m bus/pccard/power_if.m bus/pci/pci_if.m \
275 bus/pci/pcib_if.m \
276 bus/ppbus/ppbus_if.m bus/smbus/smbus_if.m bus/usb/usb_if.m \
277 dev/disk/nata/ata_if.m \
278 dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
279 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \
280 libiconv/iconv_converter_if.m dev/agp/agp_if.m opencrypto/crypto_if.m
282 .for _srcsrc in ${MFILES}
283 .for _ext in c h
284 .for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
285 CLEANFILES+= ${_src}
286 .if !target(${_src})
287 ${_src}: @
288 .if exists(@)
289 ${_src}: @/tools/makeobjops.awk @/${_srcsrc}
290 .endif
292 .if defined(BUILDING_WITH_KERNEL) && \
293 exists(${BUILDING_WITH_KERNEL}/${_src})
294 .else
295 awk -f @/tools/makeobjops.awk -- -${_ext} @/${_srcsrc}
296 .endif
297 .endif
298 .endfor # _src
299 .endfor # _ext
300 .endfor # _srcsrc
302 #.for _ext in c h
303 #.if ${SRCS:Mvnode_if.${_ext}} != ""
304 #CLEANFILES+= vnode_if.${_ext}
305 #vnode_if.${_ext}: @
306 #.if exists(@)
307 #vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src
308 #.endif
309 # awk -f @/tools/vnode_if.awk -- -${_ext} @/kern/vnode_if.src
310 #.endif
311 #.endfor
313 regress:
315 .include <bsd.dep.mk>
317 .if !exists(${DEPENDFILE})
318 ${OBJS}: ${SRCS:M*.h}
319 .endif
321 .include <bsd.obj.mk>
322 .include "bsd.kern.mk"
324 # Behaves like MODULE_OVERRIDE
325 .if defined(KLD_DEPS)
326 all: _kdeps_all
327 _kdeps_all: @
328 .for _mdep in ${KLD_DEPS}
329 cd ${SYSDIR}/${_mdep} && make all
330 .endfor
331 depend: _kdeps_depend
332 _kdeps_depend: @
333 .for _mdep in ${KLD_DEPS}
334 cd ${SYSDIR}/${_mdep} && make depend
335 .endfor
336 install: _kdeps_install
337 _kdeps_install: @
338 .for _mdep in ${KLD_DEPS}
339 cd ${SYSDIR}/${_mdep} && make install
340 .endfor
341 clean: _kdeps_clean
342 _kdeps_clean: @
343 .for _mdep in ${KLD_DEPS}
344 cd ${SYSDIR}/${_mdep} && make clean
345 .endfor
346 .endif