telnet - Apply FreeBSD-SA-19:12.telnet.asc to telnet
[dragonfly.git] / sys / conf / kmod.mk
blob86db82a584bc95c515355e62825ebc6d1085f0a1
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
5 # drivers (KLD's).
8 # +++ variables +++
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)).
14 # [${DESTKERNDIR}]
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
40 # FIRMWARE_LICENSE
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
44 # +++ targets +++
46 # install:
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
51 # is executed.
53 # load:
54 # Load KLD.
56 # unload:
57 # Unload KLD.
59 # bsd.obj.mk: clean, cleandir and obj
60 # bsd.dep.mk: cleandepend, depend and tags
63 OBJCOPY?= objcopy
64 KMODLOAD?= /sbin/kldload
65 KMODUNLOAD?= /sbin/kldunload
67 # KERNEL is needed when running make install directly from
68 # the obj directory.
69 KERNEL?= kernel
71 KMODDIR?= ${DESTKERNDIR}
72 KMODOWN?= ${BINOWN}
73 KMODGRP?= ${BINGRP}
74 KMODMODE?= ${BINMODE}
76 .include <bsd.init.mk>
78 .SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
80 .if !defined(NO_WERROR) && (${CCVER} == "gcc47" || ${CCVER} == "gcc80")
81 WERROR=-Werror
82 .endif
84 COPTFLAGS?=-O2 -pipe
86 # useful for debugging
87 #.warning "KMOD-PREFILTER ${CFLAGS}"
89 WORLD_CCOPTLEVEL= # XXX prevent world opt level affecting kernel modules
90 CFLAGS= ${COPTFLAGS} ${KCFLAGS} ${COPTS} -D_KERNEL
91 CFLAGS+= ${CWARNFLAGS} ${WERROR}
92 CFLAGS+= -DKLD_MODULE
94 # Don't use any standard include directories.
95 # Since -nostdinc will annull any previous -I paths, we repeat all
96 # such paths after -nostdinc. It doesn't seem to be possible to
97 # add to the front of `make' variable.
99 # Don't use -I- anymore, source-relative includes are desireable.
100 _ICFLAGS:= ${CFLAGS:M-I*}
101 CFLAGS+= -nostdinc ${_ICFLAGS}
103 # Add -I paths for system headers. Individual KLD makefiles don't
104 # need any -I paths for this. Similar defaults for .PATH can't be
105 # set because there are no standard paths for non-headers.
107 # NOTE! Traditional platform paths such as <platform/pc64/blah.h>
108 # must run through the "machine_base" softlink using
109 # <machine_base/blah.h>. An explicit cross-platform path must
110 # operate relative to /usr/src/sys using e.g. <platform/pc64/isa/blah.h>
112 CFLAGS+= -I. -I@
114 # Add -I paths for headers in the kernel build directory
116 .if defined(BUILDING_WITH_KERNEL)
117 CFLAGS+= -I${BUILDING_WITH_KERNEL}
118 _MACHINE_FWD= ${BUILDING_WITH_KERNEL}
119 .else
120 .if defined(MAKEOBJDIRPREFIX)
121 _MACHINE_FWD= ${MAKEOBJDIRPREFIX}/${SYSDIR}/forwarder_${MACHINE_ARCH}
122 .else
123 _MACHINE_FWD= ${.OBJDIR}/forwarder_${MACHINE_ARCH}
124 CLEANDIRS+= ${_MACHINE_FWD}
125 .endif
126 .endif
127 CFLAGS+= -I${_MACHINE_FWD}/include
129 # For <openssl/headerfile>
131 CFLAGS+=-I@/../crypto/libressl/include
133 .include "kern.fwd.mk"
135 # Add a -I path to standard headers like <stddef.h>. Use a relative
136 # path to src/include if possible. If the @ symlink hasn't been built
137 # yet, then we can't tell if the relative path exists. Add both the
138 # potential relative path and an absolute path in that case.
139 .if exists(@)
140 .if exists(@/../include)
141 CFLAGS+= -I@/../include
142 .else
143 CFLAGS+= -I${DESTDIR}/usr/include
144 .endif
145 .else # !@
146 CFLAGS+= -I@/../include -I${DESTDIR}/usr/include
147 .endif # @
149 .if defined(BUILDING_WITH_KERNEL) && \
150 exists(${BUILDING_WITH_KERNEL}/opt_global.h)
151 CFLAGS+= -DHAVE_KERNEL_OPTION_HEADERS -include ${BUILDING_WITH_KERNEL}/opt_global.h
152 .endif
154 CFLAGS+= ${DEBUG_FLAGS}
155 .if ${MACHINE_ARCH} == "x86_64"
156 CFLAGS+= -fno-omit-frame-pointer
157 .endif
159 .include <bsd.patch.mk>
161 .if defined(FIRMWS)
162 AWK=/usr/bin/awk
163 .if !exists(@)
164 ${KMOD:S/$/.c/}: @
165 .else
166 ${KMOD:S/$/.c/}: @/tools/fw_stub.awk
167 .endif
168 ${AWK} -f @/tools/fw_stub.awk ${FIRMWS} -m${KMOD} -c${KMOD:S/$/.c/g} \
169 ${FIRMWARE_LICENSE:C/.+/-l/}${FIRMWARE_LICENSE}
171 SRCS+= ${KMOD:S/$/.c/}
172 CLEANFILES+= ${KMOD:S/$/.c/}
174 .for _firmw in ${FIRMWS}
175 ${_firmw:C/\:.*$/.fwo/}: ${_firmw:C/\:.*$//}
176 @${ECHO} ${_firmw:C/\:.*$//} ${.ALLSRC:M*${_firmw:C/\:.*$//}}
177 @if [ -e ${_firmw:C/\:.*$//} ]; then \
178 ${LD} -b binary --no-warn-mismatch ${LDFLAGS} \
179 -r -d -o ${.TARGET} ${_firmw:C/\:.*$//}; \
180 else \
181 ln -s ${.ALLSRC:M*${_firmw:C/\:.*$//}} ${_firmw:C/\:.*$//}; \
182 ${LD} -b binary --no-warn-mismatch ${LDFLAGS} \
183 -r -d -o ${.TARGET} ${_firmw:C/\:.*$//}; \
184 rm ${_firmw:C/\:.*$//}; \
187 OBJS+= ${_firmw:C/\:.*$/.fwo/}
188 .endfor
189 .endif
191 OBJS+= ${SRCS:N*.h:N*.patch:R:S/$/.o/g}
193 .if !defined(PROG)
194 PROG= ${KMOD}.ko
195 .endif
197 # In case of LTO provide all standard CFLAGS!
198 .if ${CFLAGS:M-flto}
199 ELDFLAGS+= ${CFLAGS}
200 .endif
202 .if ${MACHINE_ARCH} != x86_64
203 ${PROG}: ${KMOD}.kld
204 ${CC} ${ELDFLAGS} -nostdlib -Wl,--hash-style=sysv \
205 -Wl,-Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld
206 .endif
208 .if ${MACHINE_ARCH} != x86_64
209 ${KMOD}.kld: ${OBJS}
210 ${CC} ${ELDFLAGS} -nostdlib -Wl,--hash-style=sysv \
211 ${LDFLAGS} -r -o ${.TARGET} ${OBJS}
212 .else
213 ${PROG}: ${OBJS}
214 ${CC} ${ELDFLAGS} -nostdlib -Wl,--hash-style=sysv \
215 ${LDFLAGS} -r -Wl,-d -o ${.TARGET} ${OBJS}
216 .endif
218 # links to platform and cpu architecture include files. If we are
219 # building with a kernel these already exist in the kernel build dir.
220 # '@' is a link to the system source.
221 .if defined(BUILDING_WITH_KERNEL)
222 _ILINKS=@
223 .else
224 _ILINKS=@ machine_base machine cpu_base cpu
225 .endif
227 .if defined(ARCH)
228 _ILINKS+=${ARCH}
229 .endif
231 all: objwarn fwheaders ${PROG}
233 beforedepend: fwheaders
234 fwheaders: ${_ILINKS} ${FORWARD_HEADERS_COOKIE}
235 # Ensure that the links exist without depending on it when it exists which
236 # causes all the modules to be rebuilt when the directory pointed to changes.
237 .for _link in ${_ILINKS}
238 .if !exists(${.OBJDIR}/${_link})
239 ${OBJS}: ${_link}
240 .endif
241 .endfor
243 # Search for kernel source tree in standard places.
244 .for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. ${.CURDIR}/../../../.. /sys /usr/src/sys
245 .if !defined(SYSDIR) && exists(${_dir}/kern/)
246 SYSDIR= ${_dir}
247 .endif
248 .endfor
249 .if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
250 .error "can't find kernel source tree"
251 .endif
252 S= ${SYSDIR}
254 # path=`(cd $$path && /bin/pwd)` ;
256 ${_ILINKS}:
257 @case ${.TARGET} in \
258 machine) \
259 path=${SYSDIR}/platform/${MACHINE_PLATFORM}/include ;; \
260 machine_base) \
261 path=${SYSDIR}/platform/${MACHINE_PLATFORM} ;; \
262 cpu) \
263 path=${SYSDIR}/cpu/${MACHINE_ARCH}/include ;; \
264 cpu_base) \
265 path=${SYSDIR}/cpu/${MACHINE_ARCH} ;; \
266 @) \
267 path=${SYSDIR} ;; \
268 arch_*) \
269 path=${.CURDIR}/${MACHINE_ARCH} ;; \
270 esac ; \
271 ${ECHO} ${.TARGET} "->" $$path ; \
272 ${LN} -s $$path ${.TARGET}
274 CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
276 .if !target(install)
278 _INSTALLFLAGS:= ${INSTALLFLAGS}
279 .for ie in ${INSTALLFLAGS_EDIT}
280 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
281 .endfor
283 .if !target(realinstall)
284 realinstall: _kmodinstall
285 .ORDER: beforeinstall _kmodinstall
286 _kmodinstall:
287 .if defined(INSTALLSTRIPPEDMODULES)
288 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
289 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
290 ${OBJCOPY} --strip-debug ${DESTDIR}${KMODDIR}/${PROG}
291 .else
292 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
293 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
294 .endif
295 .endif # !target(realinstall)
297 .include <bsd.links.mk>
299 .endif # !target(install)
301 .if !target(load)
302 load: ${PROG}
303 ${KMODLOAD} -v ./${KMOD}.ko
304 .endif
306 .if !target(unload)
307 unload:
308 ${KMODUNLOAD} -v ${KMOD}
309 .endif
311 .for _src in ${SRCS:Mopt_*.h} ${SRCS:Muse_*.h}
312 CLEANFILES+= ${_src}
313 .if !target(${_src})
314 .if defined(BUILDING_WITH_KERNEL) && exists(${BUILDING_WITH_KERNEL}/${_src})
315 ${_src}: ${BUILDING_WITH_KERNEL}/${_src}
316 # we do not have to copy these files any more, the kernel build
317 # directory is included in the path now.
318 # cp ${BUILDING_WITH_KERNEL}/${_src} ${.TARGET}
319 .else
320 ${_src}:
321 touch ${.TARGET}
322 .endif # BUILDING_WITH_KERNEL
323 .endif
324 .endfor
326 MFILES?= kern/bus_if.m kern/device_if.m bus/iicbus/iicbb_if.m \
327 bus/iicbus/iicbus_if.m bus/isa/isa_if.m dev/netif/mii_layer/miibus_if.m \
328 bus/pccard/card_if.m bus/pccard/power_if.m bus/pci/pci_if.m \
329 bus/pci/pcib_if.m \
330 bus/ppbus/ppbus_if.m bus/smbus/smbus_if.m bus/u4b/usb_if.m \
331 dev/acpica/acpi_if.m dev/acpica/acpi_wmi_if.m dev/disk/nata/ata_if.m \
332 dev/disk/sdhci/sdhci_if.m \
333 dev/sound/pci/hda/hdac_if.m \
334 dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
335 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \
336 dev/sound/midi/mpu_if.m dev/sound/midi/mpufoi_if.m \
337 dev/sound/midi/synth_if.m \
338 libiconv/iconv_converter_if.m dev/agp/agp_if.m opencrypto/cryptodev_if.m \
339 bus/mmc/mmcbus_if.m bus/mmc/mmcbr_if.m \
340 dev/virtual/virtio/virtio/virtio_bus_if.m \
341 dev/misc/coremctl/coremctl_if.m kern/cpu_if.m \
342 bus/gpio/gpio_if.m
344 .for _srcsrc in ${MFILES}
345 .for _ext in c h
346 .for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
347 CLEANFILES+= ${_src}
348 .if !target(${_src})
349 ${_src}: @
350 .if exists(@)
351 ${_src}: @/tools/makeobjops.awk @/${_srcsrc}
352 .endif
354 .if defined(BUILDING_WITH_KERNEL) && \
355 exists(${BUILDING_WITH_KERNEL}/${_src})
356 .else
357 awk -f @/tools/makeobjops.awk -- -${_ext} @/${_srcsrc}
358 .endif
359 .endif
360 .endfor # _src
361 .endfor # _ext
362 .endfor # _srcsrc
364 #.for _ext in c h
365 #.if ${SRCS:Mvnode_if.${_ext}} != ""
366 #CLEANFILES+= vnode_if.${_ext}
367 #vnode_if.${_ext}: @
368 #.if exists(@)
369 #vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src
370 #.endif
371 # awk -f @/tools/vnode_if.awk -- -${_ext} @/kern/vnode_if.src
372 #.endif
373 #.endfor
375 .if !empty(SRCS:Mmiidevs.h)
376 CLEANFILES+= miidevs.h
377 .if !exists(@)
378 miidevs.h: @
379 .else
380 miidevs.h: @/tools/miidevs2h.awk @/dev/netif/mii_layer/miidevs
381 .endif
382 ${AWK} -f @/tools/miidevs2h.awk @/dev/netif/mii_layer/miidevs
383 .endif
385 .if !empty(SRCS:Mpccarddevs.h)
386 CLEANFILES+= pccarddevs.h
387 .if !exists(@)
388 pccarddevs.h: @
389 .else
390 pccarddevs.h: @/tools/pccarddevs2h.awk @/bus/pccard/pccarddevs
391 .endif
392 ${AWK} -f @/tools/pccarddevs2h.awk @/bus/pccard/pccarddevs
393 .endif
395 .if !empty(SRCS:Mpcidevs.h)
396 CLEANFILES+= pcidevs.h
397 .if !exists(@)
398 pcidevs.h: @
399 .else
400 pcidevs.h: @/tools/pcidevs2h.awk @/bus/pci/pcidevs
401 .endif
402 ${AWK} -f @/tools/pcidevs2h.awk @/bus/pci/pcidevs
403 .endif
405 .if !empty(SRCS:Musbdevs.h)
406 CLEANFILES+= usbdevs.h
407 .if !exists(@)
408 usbdevs.h: @
409 .else
410 usbdevs.h: @/tools/usbdevs2h.awk @/bus/u4b/usbdevs
411 .endif
412 ${AWK} -f @/tools/usbdevs2h.awk @/bus/u4b/usbdevs -h
413 .endif
415 .if !empty(SRCS:Musbdevs_data.h)
416 CLEANFILES+= usbdevs_data.h
417 .if !exists(@)
418 usbdevs_data.h: @
419 .else
420 usbdevs_data.h: @/tools/usbdevs2h.awk @/bus/u4b/usbdevs
421 .endif
422 ${AWK} -f @/tools/usbdevs2h.awk @/bus/u4b/usbdevs -d
423 .endif
425 .if !empty(SRCS:Macpi_quirks.h)
426 CLEANFILES+= acpi_quirks.h
427 .if !exists(@)
428 acpi_quirks.h: @
429 .else
430 acpi_quirks.h: @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks
431 .endif
432 ${AWK} -f @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks
433 .endif
435 .if !empty(SRCS:Massym.s)
436 CLEANFILES+= assym.s genassym.o
437 assym.s: genassym.o
438 .if defined(BUILDING_WITH_KERNEL)
439 genassym.o: opt_global.h
440 .endif
441 .if !exists(@)
442 assym.s: @
443 .else
444 assym.s: @/kern/genassym.sh
445 .endif
446 sh @/kern/genassym.sh genassym.o > ${.TARGET}
447 .if exists(@)
448 genassym.o: @/platform/${MACHINE_PLATFORM}/${MACHINE_ARCH}/genassym.c
449 .endif
450 genassym.o: @ ${SRCS:Mopt_*.h}
451 ${CC} -c ${CFLAGS:N-fno-common:N-flto:N-mcmodel=small} ${WERROR} \
452 @/platform/${MACHINE_PLATFORM}/${MACHINE_ARCH}/genassym.c
453 .endif
455 regress:
457 .include <bsd.dep.mk>
459 .if !exists(${DEPENDFILE})
460 ${OBJS}: ${SRCS:M*.h}
461 .endif
463 .include <bsd.obj.mk>
464 .include "bsd.kern.mk"
466 # Behaves like MODULE_OVERRIDE
467 .if defined(KLD_DEPS)
468 all: _kdeps_all
469 _kdeps_all: @
470 .for _mdep in ${KLD_DEPS}
471 cd ${SYSDIR}/${_mdep} && make all
472 .endfor
473 depend: _kdeps_depend
474 _kdeps_depend: @
475 .for _mdep in ${KLD_DEPS}
476 cd ${SYSDIR}/${_mdep} && make depend
477 .endfor
478 install: _kdeps_install
479 _kdeps_install: @
480 .for _mdep in ${KLD_DEPS}
481 cd ${SYSDIR}/${_mdep} && make install
482 .endfor
483 clean: _kdeps_clean
484 _kdeps_clean: @
485 .for _mdep in ${KLD_DEPS}
486 cd ${SYSDIR}/${_mdep} && make clean
487 .endfor
488 .endif