FreeBSD/Linux Kernel Cross Reference
sys/conf/kmod.mk
1 # From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91
2 # $FreeBSD: releng/5.3/sys/conf/kmod.mk 136588 2004-10-16 08:43:07Z cvs2svn $
3 #
4 # The include file <bsd.kmod.mk> handles installing Kernel Loadable Device
5 # drivers (KLD's).
6 #
7 #
8 # +++ variables +++
9 #
10 # CLEANFILES Additional files to remove for the clean and cleandir targets.
11 #
12 # KMOD The name of the kernel module to build.
13 #
14 # KMODDIR Base path for kernel modules (see kld(4)). [/boot/kernel]
15 #
16 # KMODOWN KLD owner. [${BINOWN}]
17 #
18 # KMODGRP KLD group. [${BINGRP}]
19 #
20 # KMODMODE KLD mode. [${BINMODE}]
21 #
22 # KMODLOAD Command to load a kernel module [/sbin/kldload]
23 #
24 # KMODUNLOAD Command to unload a kernel module [/sbin/kldunload]
25 #
26 # PROG The name of the kernel module to build.
27 # If not supplied, ${KMOD}.o is used.
28 #
29 # SRCS List of source files
30 #
31 # DESTDIR Change the tree where the module gets installed. [not set]
32 #
33 # MFILES Optionally a list of interfaces used by the module.
34 # This file contains a default list of interfaces.
35 #
36 # EXPORT_SYMS A list of symbols that should be exported from the module,
37 # or the name of a file containing a list of symbols, or YES
38 # to export all symbols. If not defined, no symbols are
39 # exported.
40 #
41 # +++ targets +++
42 #
43 # install:
44 # install the kernel module; 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 #
59
60 AWK?= awk
61 KMODLOAD?= /sbin/kldload
62 KMODUNLOAD?= /sbin/kldunload
63 OBJCOPY?= objcopy
64
65 .if defined(KMODDEPS)
66 .error "Do not use KMODDEPS on 5.0+, use MODULE_VERSION/MODULE_DEPEND"
67 .endif
68
69 .include <bsd.init.mk>
70
71 .SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
72
73 .if ${CC} == "icc"
74 CFLAGS:= ${CFLAGS:C/(-x[^M^K^W]+)[MKW]+|-x[MKW]+/\1/}
75 .endif
76 CFLAGS+= -D_KERNEL
77 CFLAGS+= -DKLD_MODULE
78
79 # Don't use any standard or source-relative include directories.
80 # Since -nostdinc will annull any previous -I paths, we repeat all
81 # such paths after -nostdinc. It doesn't seem to be possible to
82 # add to the front of `make' variable.
83 _ICFLAGS:= ${CFLAGS:M-I*}
84 .if ${CC} == "icc"
85 NOSTDINC= -X
86 .else
87 NOSTDINC= -nostdinc
88 .endif
89 CFLAGS+= ${NOSTDINC} -I- ${INCLMAGIC} ${_ICFLAGS}
90 .if defined(KERNBUILDDIR)
91 CFLAGS+= -include ${KERNBUILDDIR}/opt_global.h
92 .endif
93
94 # Add -I paths for system headers. Individual KLD makefiles don't
95 # need any -I paths for this. Similar defaults for .PATH can't be
96 # set because there are no standard paths for non-headers.
97 CFLAGS+= -I. -I@
98
99 # Add -I path for altq headers as they are included via net/if_var.h
100 # for example.
101 CFLAGS+= -I@/contrib/altq
102
103 # Add a -I path to standard headers like <stddef.h>. Use a relative
104 # path to src/include if possible. If the @ symlink hasn't been built
105 # yet, then we can't tell if the relative path exists. Add both the
106 # potential relative path and an absolute path in that case.
107 .if exists(@)
108 .if exists(@/../include)
109 CFLAGS+= -I@/../include
110 .else
111 CFLAGS+= -I${DESTDIR}/usr/include
112 .endif
113 .else # !@
114 CFLAGS+= -I@/../include -I${DESTDIR}/usr/include
115 .endif # @
116
117 .if ${CC} != "icc"
118 CFLAGS+= -finline-limit=${INLINE_LIMIT}
119 .endif
120
121 # Disallow common variables, and if we end up with commons from
122 # somewhere unexpected, allocate storage for them in the module itself.
123 .if ${CC} != "icc"
124 CFLAGS+= -fno-common
125 .endif
126 LDFLAGS+= -d -warn-common
127
128 CFLAGS+= ${DEBUG_FLAGS}
129
130 OBJS+= ${SRCS:N*.h:R:S/$/.o/g}
131
132 .if !defined(PROG)
133 PROG= ${KMOD}.ko
134 .endif
135
136 .if !defined(DEBUG_FLAGS)
137 FULLPROG= ${PROG}
138 .else
139 FULLPROG= ${PROG}.debug
140 ${PROG}: ${FULLPROG}
141 ${OBJCOPY} --strip-debug ${FULLPROG} ${PROG}
142 .endif
143
144 .if ${MACHINE_ARCH} != amd64
145 ${FULLPROG}: ${KMOD}.kld
146 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld
147 .if !defined(DEBUG_FLAGS)
148 ${OBJCOPY} --strip-debug ${.TARGET}
149 .endif
150 .endif
151
152 EXPORT_SYMS?= NO
153 .if ${EXPORT_SYMS} != YES
154 CLEANFILES+= ${.OBJDIR}/export_syms
155 .endif
156
157 .if ${MACHINE_ARCH} != amd64
158 ${KMOD}.kld: ${OBJS}
159 .else
160 ${FULLPROG}: ${OBJS}
161 .endif
162 ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS}
163 .if defined(EXPORT_SYMS)
164 .if ${EXPORT_SYMS} != YES
165 .if ${EXPORT_SYMS} == NO
166 touch ${.OBJDIR}/export_syms
167 .elif !exists(${.CURDIR}/${EXPORT_SYMS})
168 echo ${EXPORT_SYMS} > ${.OBJDIR}/export_syms
169 .else
170 grep -v '^#' < ${EXPORT_SYMS} > ${.OBJDIR}/export_syms
171 .endif
172 awk -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \
173 ${.OBJDIR}/export_syms | \
174 xargs -J% ${OBJCOPY} % ${.TARGET}
175 .endif
176 .endif
177 .if !defined(DEBUG_FLAGS) && ${MACHINE_ARCH} == amd64
178 ${OBJCOPY} --strip-debug ${.TARGET}
179 .endif
180
181 _ILINKS=@ machine
182
183 all: objwarn ${PROG}
184
185 beforedepend: ${_ILINKS}
186 @rm -f .depend
187
188 # Ensure that the links exist without depending on it when it exists which
189 # causes all the modules to be rebuilt when the directory pointed to changes.
190 .for _link in ${_ILINKS}
191 .if !exists(${.OBJDIR}/${_link})
192 ${OBJS}: ${_link}
193 .endif
194 .endfor
195
196 # Search for kernel source tree in standard places.
197 .for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys
198 .if !defined(SYSDIR) && exists(${_dir}/kern/)
199 SYSDIR= ${_dir}
200 .endif
201 .endfor
202 .if !defined(SYSDIR) || !exists(${SYSDIR}/kern/)
203 .error "can't find kernel source tree"
204 .endif
205
206 ${_ILINKS}:
207 @case ${.TARGET} in \
208 machine) \
209 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \
210 @) \
211 path=${SYSDIR} ;; \
212 esac ; \
213 path=`(cd $$path && /bin/pwd)` ; \
214 ${ECHO} ${.TARGET} "->" $$path ; \
215 ln -s $$path ${.TARGET}
216
217 CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
218
219 .if defined(DEBUG_FLAGS)
220 CLEANFILES+= ${FULLPROG}
221 .endif
222
223 .if !target(install)
224
225 _INSTALLFLAGS:= ${INSTALLFLAGS}
226 .for ie in ${INSTALLFLAGS_EDIT}
227 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
228 .endfor
229
230 .if defined(DEBUG_FLAGS)
231 install.debug:
232 cd ${.CURDIR}; ${MAKE} -DINSTALL_DEBUG install
233 .endif
234
235 .if !target(realinstall)
236 realinstall: _kmodinstall
237 .ORDER: beforeinstall _kmodinstall
238 _kmodinstall:
239 .if defined(DEBUG_FLAGS) && defined(INSTALL_DEBUG)
240 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
241 ${_INSTALLFLAGS} ${FULLPROG} ${DESTDIR}${KMODDIR}
242 .else
243 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
244 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
245
246 .include <bsd.links.mk>
247
248 .if !defined(NO_XREF)
249 afterinstall: _kldxref
250 .ORDER: realinstall _kldxref
251 .ORDER: _installlinks _kldxref
252 _kldxref:
253 @if type kldxref >/dev/null 2>&1; then \
254 ${ECHO} kldxref ${DESTDIR}${KMODDIR}; \
255 kldxref ${DESTDIR}${KMODDIR}; \
256 fi
257 .endif
258 .endif
259 .endif !target(realinstall)
260
261 .endif !target(install)
262
263 .if !target(load)
264 load: ${PROG}
265 ${KMODLOAD} -v ${.OBJDIR}/${KMOD}.ko
266 .endif
267
268 .if !target(unload)
269 unload:
270 ${KMODUNLOAD} -v ${KMOD}
271 .endif
272
273 .if defined(KERNBUILDDIR)
274 .PATH: ${KERNBUILDDIR}
275 CFLAGS += -I${KERNBUILDDIR}
276 .for _src in ${SRCS:Mopt_*.h}
277 CLEANFILES+= ${_src}
278 .if !target(${_src})
279 ${_src}:
280 ln -s ${KERNBUILDDIR}/${_src} ${.TARGET}
281 .endif
282 .endfor
283 .else
284 .for _src in ${SRCS:Mopt_*.h}
285 CLEANFILES+= ${_src}
286 .if !target(${_src})
287 ${_src}:
288 touch ${.TARGET}
289 .endif
290 .endfor
291 .endif
292
293 MFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \
294 dev/iicbus/iicbus_if.m isa/isa_if.m \
295 libkern/iconv_converter_if.m \
296 dev/acpica/acpi_if.m dev/eisa/eisa_if.m dev/mii/miibus_if.m \
297 dev/ofw/ofw_bus_if.m \
298 dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \
299 dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \
300 dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
301 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m pci/agp_if.m \
302 opencrypto/crypto_if.m pc98/pc98/canbus_if.m dev/uart/uart_if.m \
303 sparc64/pci/ofw_pci_if.m
304
305 .for _srcsrc in ${MFILES}
306 .for _ext in c h
307 .for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
308 CLEANFILES+= ${_src}
309 .if !target(${_src})
310 .if !exists(@)
311 ${_src}: @
312 .endif
313 .if exists(@)
314 ${_src}: @/tools/makeobjops.awk @/${_srcsrc}
315 .endif
316 ${AWK} -f @/tools/makeobjops.awk @/${_srcsrc} -${_ext}
317 .endif
318 .endfor # _src
319 .endfor # _ext
320 .endfor # _srcsrc
321
322 .for _ext in c h
323 .if ${SRCS:Mvnode_if.${_ext}} != ""
324 CLEANFILES+= vnode_if.${_ext}
325 .if !exists(@)
326 vnode_if.${_ext}: @
327 .endif
328 .if exists(@)
329 vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src
330 .endif
331 ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -${_ext}
332 .endif
333 .endfor
334
335 .for _i in mii pccard usb
336 .if ${SRCS:M${_i}devs.h} != ""
337 CLEANFILES+= ${_i}devs.h
338 .if !exists(@)
339 ${_i}devs.h: @
340 .endif
341 .if exists(@)
342 ${_i}devs.h: @/tools/${_i}devs2h.awk @/dev/${_i}/${_i}devs
343 .endif
344 ${AWK} -f @/tools/${_i}devs2h.awk @/dev/${_i}/${_i}devs
345 .endif
346 .endfor # _i
347
348 .if ${SRCS:Macpi_quirks.h} != ""
349 CLEANFILES+= acpi_quirks.h
350 .if !exists(@)
351 acpi_quirks.h: @
352 .endif
353 .if exists(@)
354 acpi_quirks.h: @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks
355 .endif
356 ${AWK} -f @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks
357 .endif
358
359 regress:
360
361 lint: ${SRCS}
362 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC:M*.c}
363
364 .include <bsd.dep.mk>
365
366 .if !exists(${.OBJDIR}/${DEPENDFILE})
367 ${OBJS}: ${SRCS:M*.h}
368 .endif
369
370 .include <bsd.obj.mk>
371 .include "kern.mk"
Cache object: 98f14b5aedda4a1f0533d03325870192
|