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
9 # CLEANFILES Additional files to remove for the clean and cleandir targets.
11 # KMOD The name of the kernel module to build.
13 # KMODDIR Base path for kernel modules (see kld(4)).
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 # PROG The name of the kernel module to build.
27 # If not supplied, ${KMOD}.o is used.
29 # SRCS List of source files
31 # DESTKERNDIR Change the tree where the kernel and the modules get
32 # installed. [/boot] ${DESTDIR} changes the root of the tree
33 # pointed to by ${DESTKERNDIR}.
35 # MFILES Optionally a list of interfaces used by the module.
36 # This file contains a default list of interfaces.
38 # FIRMWS List of firmware images in format filename:shortname:version
41 # Set to the name of the license the user has to agree on in
42 # order to use this firmware. See /usr/share/doc/legal
47 # install the kernel module and its manual pages; if the Makefile
48 # does not itself define the target install, the targets
49 # beforeinstall and afterinstall may also be used to cause
50 # actions immediately before and after the install target
59 # bsd.obj.mk: clean, cleandir and obj
60 # bsd.dep.mk: cleandepend, depend and tags
64 KMODLOAD?= /sbin/kldload
65 KMODUNLOAD?= /sbin/kldunload
67 # KERNEL is needed when running make install directly from
71 KMODDIR?= ${DESTKERNDIR}
76 .include <bsd.init.mk>
78 .SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
80 .if !defined(NO_WERROR) && (${CCVER} == "gcc44" || ${CCVER} == "gcc47")
84 CFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS} ${WERROR}
87 # Don't use any standard include directories.
88 # Since -nostdinc will annull any previous -I paths, we repeat all
89 # such paths after -nostdinc. It doesn't seem to be possible to
90 # add to the front of `make' variable.
92 # Don't use -I- anymore, source-relative includes are desireable.
93 _ICFLAGS:= ${CFLAGS:M-I*}
94 CFLAGS+= -nostdinc ${_ICFLAGS}
96 # Add -I paths for system headers. Individual KLD makefiles don't
97 # need any -I paths for this. Similar defaults for .PATH can't be
98 # set because there are no standard paths for non-headers.
100 # NOTE! Traditional architecture paths such as <i386/i386/blah.h>
101 # must run through the "machine_base" softlink using
102 # <machine_base/i386/blah.h>. An explicit cross-architecture path must
103 # operate relative to /usr/src/sys using e.g. <arch/i386/i386/blah.h>
107 # Add -I paths for headers in the kernel build directory
109 .if defined(BUILDING_WITH_KERNEL)
110 CFLAGS+= -I${BUILDING_WITH_KERNEL}
111 _MACHINE_FWD= ${BUILDING_WITH_KERNEL}
113 .if defined(MAKEOBJDIRPREFIX)
114 _MACHINE_FWD= ${MAKEOBJDIRPREFIX}/${SYSDIR}/forwarder_${MACHINE_ARCH}
116 _MACHINE_FWD= ${.OBJDIR}/forwarder_${MACHINE_ARCH}
117 CLEANDIRS+= ${_MACHINE_FWD}
120 CFLAGS+= -I${_MACHINE_FWD}/include
121 .include "kern.fwd.mk"
123 # Add a -I path to standard headers like <stddef.h>. Use a relative
124 # path to src/include if possible. If the @ symlink hasn't been built
125 # yet, then we can't tell if the relative path exists. Add both the
126 # potential relative path and an absolute path in that case.
128 .if exists(@/../include)
129 CFLAGS+= -I@/../include
131 CFLAGS+= -I${DESTDIR}/usr/include
134 CFLAGS+= -I@/../include -I${DESTDIR}/usr/include
137 .if defined(BUILDING_WITH_KERNEL) && \
138 exists(${BUILDING_WITH_KERNEL}/opt_global.h)
139 CFLAGS+= -include ${BUILDING_WITH_KERNEL}/opt_global.h
142 CFLAGS+= ${DEBUG_FLAGS}
143 .if ${MACHINE_ARCH} == x86_64
144 CFLAGS+= -fno-omit-frame-pointer
147 .include <bsd.patch.mk>
154 ${KMOD:S/$/.c/}: @/tools/fw_stub.awk
156 ${AWK} -f @/tools/fw_stub.awk ${FIRMWS} -m${KMOD} -c${KMOD:S/$/.c/g} \
157 ${FIRMWARE_LICENSE:C/.+/-l/}${FIRMWARE_LICENSE}
159 SRCS+= ${KMOD:S/$/.c/}
160 CLEANFILES+= ${KMOD:S/$/.c/}
162 .for _firmw in ${FIRMWS}
163 ${_firmw:C/\:.*$/.fwo/}: ${_firmw:C/\:.*$//}
164 @${ECHO} ${_firmw:C/\:.*$//} ${.ALLSRC:M*${_firmw:C/\:.*$//}}
165 @if [ -e ${_firmw:C/\:.*$//} ]; then \
166 ${LD} -b binary --no-warn-mismatch ${LDFLAGS} \
167 -r -d -o ${.TARGET} ${_firmw:C/\:.*$//}; \
169 ln -s ${.ALLSRC:M*${_firmw:C/\:.*$//}} ${_firmw:C/\:.*$//}; \
170 ${LD} -b binary --no-warn-mismatch ${LDFLAGS} \
171 -r -d -o ${.TARGET} ${_firmw:C/\:.*$//}; \
172 rm ${_firmw:C/\:.*$//}; \
175 OBJS+= ${_firmw:C/\:.*$/.fwo/}
179 OBJS+= ${SRCS:N*.h:N*.patch:R:S/$/.o/g}
185 .if ${MACHINE_ARCH} != x86_64
187 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld
190 .if ${MACHINE_ARCH} != x86_64
192 ${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS}
195 ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS}
198 # links to platform and cpu architecture include files. If we are
199 # building with a kernel these already exist in the kernel build dir.
200 # '@' is a link to the system source.
201 .if defined(BUILDING_WITH_KERNEL)
204 _ILINKS=@ machine_base machine cpu_base cpu
211 all: objwarn fwheaders ${PROG}
213 beforedepend: fwheaders
214 fwheaders: ${_ILINKS} ${FORWARD_HEADERS_COOKIE}
215 # Ensure that the links exist without depending on it when it exists which
216 # causes all the modules to be rebuilt when the directory pointed to changes.
217 .for _link in ${_ILINKS}
218 .if !exists(${.OBJDIR}/${_link})
223 # Search for kernel source tree in standard places.
224 .for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. ${.CURDIR}/../../../.. /sys /usr/src/sys
225 .if !defined(SYSDIR) && exists(${_dir}/kern/)
229 .if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
230 .error "can't find kernel source tree"
234 # path=`(cd $$path && /bin/pwd)` ;
237 @case ${.TARGET} in \
239 path=${SYSDIR}/platform/${MACHINE_PLATFORM}/include ;; \
241 path=${SYSDIR}/platform/${MACHINE_PLATFORM} ;; \
243 path=${SYSDIR}/cpu/${MACHINE_ARCH}/include ;; \
245 path=${SYSDIR}/cpu/${MACHINE_ARCH} ;; \
249 path=${.CURDIR}/${MACHINE_ARCH} ;; \
251 ${ECHO} ${.TARGET} "->" $$path ; \
252 ${LN} -s $$path ${.TARGET}
254 CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
258 _INSTALLFLAGS:= ${INSTALLFLAGS}
259 .for ie in ${INSTALLFLAGS_EDIT}
260 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
263 .if !target(realinstall)
264 realinstall: _kmodinstall
265 .ORDER: beforeinstall _kmodinstall
267 .if defined(INSTALLSTRIPPEDMODULES)
268 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
269 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
270 ${OBJCOPY} --strip-debug ${DESTDIR}${KMODDIR}/${PROG}
272 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
273 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
275 .endif # !target(realinstall)
277 .include <bsd.links.mk>
279 .endif # !target(install)
283 ${KMODLOAD} -v ./${KMOD}.ko
288 ${KMODUNLOAD} -v ${KMOD}
291 .for _src in ${SRCS:Mopt_*.h} ${SRCS:Muse_*.h}
294 .if defined(BUILDING_WITH_KERNEL) && exists(${BUILDING_WITH_KERNEL}/${_src})
295 ${_src}: ${BUILDING_WITH_KERNEL}/${_src}
296 # we do not have to copy these files any more, the kernel build
297 # directory is included in the path now.
298 # cp ${BUILDING_WITH_KERNEL}/${_src} ${.TARGET}
302 .endif # BUILDING_WITH_KERNEL
306 MFILES?= kern/bus_if.m kern/device_if.m bus/iicbus/iicbb_if.m \
307 bus/iicbus/iicbus_if.m bus/isa/isa_if.m dev/netif/mii_layer/miibus_if.m \
308 bus/pccard/card_if.m bus/pccard/power_if.m bus/pci/pci_if.m \
310 bus/ppbus/ppbus_if.m bus/smbus/smbus_if.m \
311 dev/acpica/acpi_if.m dev/acpica/acpi_wmi_if.m dev/disk/nata/ata_if.m \
312 dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
313 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \
314 libiconv/iconv_converter_if.m dev/agp/agp_if.m opencrypto/cryptodev_if.m \
315 bus/mmc/mmcbus_if.m bus/mmc/mmcbr_if.m \
316 dev/virtual/virtio/virtio/virtio_bus_if.m \
317 dev/virtual/virtio/virtio/virtio_if.m
319 .if !defined(WANT_OLDUSB)
320 MFILES+=bus/u4b/usb_if.m
322 MFILES+=bus/usb/usb_if.m
325 .for _srcsrc in ${MFILES}
327 .for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
332 ${_src}: @/tools/makeobjops.awk @/${_srcsrc}
335 .if defined(BUILDING_WITH_KERNEL) && \
336 exists(${BUILDING_WITH_KERNEL}/${_src})
338 awk -f @/tools/makeobjops.awk -- -${_ext} @/${_srcsrc}
346 #.if ${SRCS:Mvnode_if.${_ext}} != ""
347 #CLEANFILES+= vnode_if.${_ext}
350 #vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src
352 # awk -f @/tools/vnode_if.awk -- -${_ext} @/kern/vnode_if.src
356 .if !empty(SRCS:Mmiidevs.h)
357 CLEANFILES+= miidevs.h
361 miidevs.h: @/tools/miidevs2h.awk @/dev/netif/mii_layer/miidevs
363 ${AWK} -f @/tools/miidevs2h.awk @/dev/netif/mii_layer/miidevs
366 .if !empty(SRCS:Mpccarddevs.h)
367 CLEANFILES+= pccarddevs.h
371 pccarddevs.h: @/tools/pccarddevs2h.awk @/bus/pccard/pccarddevs
373 ${AWK} -f @/tools/pccarddevs2h.awk @/bus/pccard/pccarddevs
376 .if !empty(SRCS:Mpcidevs.h)
377 CLEANFILES+= pcidevs.h
381 pcidevs.h: @/tools/pcidevs2h.awk @/bus/pci/pcidevs
383 ${AWK} -f @/tools/pcidevs2h.awk @/bus/pci/pcidevs
386 .if !empty(SRCS:Musbdevs.h)
387 CLEANFILES+= usbdevs.h
391 usbdevs.h: @/tools/usbdevs2h.awk @/bus/u4b/usbdevs
393 ${AWK} -f @/tools/usbdevs2h.awk @/bus/u4b/usbdevs -h
396 .if !empty(SRCS:Musbdevs_data.h)
397 CLEANFILES+= usbdevs_data.h
401 usbdevs_data.h: @/tools/usbdevs2h.awk @/bus/u4b/usbdevs
403 ${AWK} -f @/tools/usbdevs2h.awk @/bus/u4b/usbdevs -d
406 .if !empty(SRCS:Macpi_quirks.h)
407 CLEANFILES+= acpi_quirks.h
411 acpi_quirks.h: @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks
413 ${AWK} -f @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks
416 .if !empty(SRCS:Massym.s)
417 CLEANFILES+= assym.s genassym.o
419 .if defined(BUILDING_WITH_KERNEL)
420 genassym.o: opt_global.h
425 assym.s: @/kern/genassym.sh
427 sh @/kern/genassym.sh genassym.o > ${.TARGET}
429 genassym.o: @/platform/${MACHINE_PLATFORM}/${MACHINE_ARCH}/genassym.c
431 genassym.o: @ ${SRCS:Mopt_*.h}
432 ${CC} -c ${CFLAGS:N-fno-common:N-mcmodel=small} ${WERROR} \
433 @/platform/${MACHINE_PLATFORM}/${MACHINE_ARCH}/genassym.c
438 .include <bsd.dep.mk>
440 .if !exists(${DEPENDFILE})
441 ${OBJS}: ${SRCS:M*.h}
444 .include <bsd.obj.mk>
445 .include "bsd.kern.mk"
447 # Behaves like MODULE_OVERRIDE
448 .if defined(KLD_DEPS)
451 .for _mdep in ${KLD_DEPS}
452 cd ${SYSDIR}/${_mdep} && make all
454 depend: _kdeps_depend
456 .for _mdep in ${KLD_DEPS}
457 cd ${SYSDIR}/${_mdep} && make depend
459 install: _kdeps_install
461 .for _mdep in ${KLD_DEPS}
462 cd ${SYSDIR}/${_mdep} && make install
466 .for _mdep in ${KLD_DEPS}
467 cd ${SYSDIR}/${_mdep} && make clean