Sync ACPICA with Intel's version 20161222.
[dragonfly.git] / sys / conf / kmod.mk
blob0761c87d04a75ed6b361b0799895d259becdad1d
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} == "gcc50")
81 WERROR=-Werror
82 .endif
84 WORLD_CCOPTLEVEL= # XXX prevent world opt level affecting kernel modules
85 CFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS} ${WERROR}
86 CFLAGS+= -DKLD_MODULE
88 # Don't use any standard include directories.
89 # Since -nostdinc will annull any previous -I paths, we repeat all
90 # such paths after -nostdinc. It doesn't seem to be possible to
91 # add to the front of `make' variable.
93 # Don't use -I- anymore, source-relative includes are desireable.
94 _ICFLAGS:= ${CFLAGS:M-I*}
95 CFLAGS+= -nostdinc ${_ICFLAGS}
97 # Add -I paths for system headers. Individual KLD makefiles don't
98 # need any -I paths for this. Similar defaults for .PATH can't be
99 # set because there are no standard paths for non-headers.
101 # NOTE! Traditional architecture paths such as <i386/i386/blah.h>
102 # must run through the "machine_base" softlink using
103 # <machine_base/i386/blah.h>. An explicit cross-architecture path must
104 # operate relative to /usr/src/sys using e.g. <arch/i386/i386/blah.h>
106 CFLAGS+= -I. -I@
108 # Add -I paths for headers in the kernel build directory
110 .if defined(BUILDING_WITH_KERNEL)
111 CFLAGS+= -I${BUILDING_WITH_KERNEL}
112 _MACHINE_FWD= ${BUILDING_WITH_KERNEL}
113 .else
114 .if defined(MAKEOBJDIRPREFIX)
115 _MACHINE_FWD= ${MAKEOBJDIRPREFIX}/${SYSDIR}/forwarder_${MACHINE_ARCH}
116 .else
117 _MACHINE_FWD= ${.OBJDIR}/forwarder_${MACHINE_ARCH}
118 CLEANDIRS+= ${_MACHINE_FWD}
119 .endif
120 .endif
121 CFLAGS+= -I${_MACHINE_FWD}/include
123 # For <openssl/headerfile>
125 CFLAGS+=-I@/../crypto/libressl/include
127 .include "kern.fwd.mk"
129 # Add a -I path to standard headers like <stddef.h>. Use a relative
130 # path to src/include if possible. If the @ symlink hasn't been built
131 # yet, then we can't tell if the relative path exists. Add both the
132 # potential relative path and an absolute path in that case.
133 .if exists(@)
134 .if exists(@/../include)
135 CFLAGS+= -I@/../include
136 .else
137 CFLAGS+= -I${DESTDIR}/usr/include
138 .endif
139 .else # !@
140 CFLAGS+= -I@/../include -I${DESTDIR}/usr/include
141 .endif # @
143 .if defined(BUILDING_WITH_KERNEL) && \
144 exists(${BUILDING_WITH_KERNEL}/opt_global.h)
145 CFLAGS+= -DHAVE_KERNEL_OPTION_HEADERS -include ${BUILDING_WITH_KERNEL}/opt_global.h
146 .endif
148 CFLAGS+= ${DEBUG_FLAGS}
149 .if ${MACHINE_ARCH} == "x86_64"
150 CFLAGS+= -fno-omit-frame-pointer
151 .endif
153 .include <bsd.patch.mk>
155 .if defined(FIRMWS)
156 AWK=/usr/bin/awk
157 .if !exists(@)
158 ${KMOD:S/$/.c/}: @
159 .else
160 ${KMOD:S/$/.c/}: @/tools/fw_stub.awk
161 .endif
162 ${AWK} -f @/tools/fw_stub.awk ${FIRMWS} -m${KMOD} -c${KMOD:S/$/.c/g} \
163 ${FIRMWARE_LICENSE:C/.+/-l/}${FIRMWARE_LICENSE}
165 SRCS+= ${KMOD:S/$/.c/}
166 CLEANFILES+= ${KMOD:S/$/.c/}
168 .for _firmw in ${FIRMWS}
169 ${_firmw:C/\:.*$/.fwo/}: ${_firmw:C/\:.*$//}
170 @${ECHO} ${_firmw:C/\:.*$//} ${.ALLSRC:M*${_firmw:C/\:.*$//}}
171 @if [ -e ${_firmw:C/\:.*$//} ]; then \
172 ${LD} -b binary --no-warn-mismatch ${LDFLAGS} \
173 -r -d -o ${.TARGET} ${_firmw:C/\:.*$//}; \
174 else \
175 ln -s ${.ALLSRC:M*${_firmw:C/\:.*$//}} ${_firmw:C/\:.*$//}; \
176 ${LD} -b binary --no-warn-mismatch ${LDFLAGS} \
177 -r -d -o ${.TARGET} ${_firmw:C/\:.*$//}; \
178 rm ${_firmw:C/\:.*$//}; \
181 OBJS+= ${_firmw:C/\:.*$/.fwo/}
182 .endfor
183 .endif
185 OBJS+= ${SRCS:N*.h:N*.patch:R:S/$/.o/g}
187 .if !defined(PROG)
188 PROG= ${KMOD}.ko
189 .endif
191 .if ${MACHINE_ARCH} != x86_64
192 ${PROG}: ${KMOD}.kld
193 ${CC} -nostdlib -Wl,--hash-style=sysv \
194 -Wl,-Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld
195 .endif
197 .if ${MACHINE_ARCH} != x86_64
198 ${KMOD}.kld: ${OBJS}
199 ${CC} -nostdlib -Wl,--hash-style=sysv \
200 ${LDFLAGS} -r -o ${.TARGET} ${OBJS}
201 .else
202 ${PROG}: ${OBJS}
203 ${CC} -nostdlib -Wl,--hash-style=sysv \
204 ${LDFLAGS} -r -Wl,-d -o ${.TARGET} ${OBJS}
205 .endif
207 # links to platform and cpu architecture include files. If we are
208 # building with a kernel these already exist in the kernel build dir.
209 # '@' is a link to the system source.
210 .if defined(BUILDING_WITH_KERNEL)
211 _ILINKS=@
212 .else
213 _ILINKS=@ machine_base machine cpu_base cpu
214 .endif
216 .if defined(ARCH)
217 _ILINKS+=${ARCH}
218 .endif
220 all: objwarn fwheaders ${PROG}
222 beforedepend: fwheaders
223 fwheaders: ${_ILINKS} ${FORWARD_HEADERS_COOKIE}
224 # Ensure that the links exist without depending on it when it exists which
225 # causes all the modules to be rebuilt when the directory pointed to changes.
226 .for _link in ${_ILINKS}
227 .if !exists(${.OBJDIR}/${_link})
228 ${OBJS}: ${_link}
229 .endif
230 .endfor
232 # Search for kernel source tree in standard places.
233 .for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. ${.CURDIR}/../../../.. /sys /usr/src/sys
234 .if !defined(SYSDIR) && exists(${_dir}/kern/)
235 SYSDIR= ${_dir}
236 .endif
237 .endfor
238 .if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
239 .error "can't find kernel source tree"
240 .endif
241 S= ${SYSDIR}
243 # path=`(cd $$path && /bin/pwd)` ;
245 ${_ILINKS}:
246 @case ${.TARGET} in \
247 machine) \
248 path=${SYSDIR}/platform/${MACHINE_PLATFORM}/include ;; \
249 machine_base) \
250 path=${SYSDIR}/platform/${MACHINE_PLATFORM} ;; \
251 cpu) \
252 path=${SYSDIR}/cpu/${MACHINE_ARCH}/include ;; \
253 cpu_base) \
254 path=${SYSDIR}/cpu/${MACHINE_ARCH} ;; \
255 @) \
256 path=${SYSDIR} ;; \
257 arch_*) \
258 path=${.CURDIR}/${MACHINE_ARCH} ;; \
259 esac ; \
260 ${ECHO} ${.TARGET} "->" $$path ; \
261 ${LN} -s $$path ${.TARGET}
263 CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
265 .if !target(install)
267 _INSTALLFLAGS:= ${INSTALLFLAGS}
268 .for ie in ${INSTALLFLAGS_EDIT}
269 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
270 .endfor
272 .if !target(realinstall)
273 realinstall: _kmodinstall
274 .ORDER: beforeinstall _kmodinstall
275 _kmodinstall:
276 .if defined(INSTALLSTRIPPEDMODULES)
277 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
278 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
279 ${OBJCOPY} --strip-debug ${DESTDIR}${KMODDIR}/${PROG}
280 .else
281 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
282 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
283 .endif
284 .endif # !target(realinstall)
286 .include <bsd.links.mk>
288 .endif # !target(install)
290 .if !target(load)
291 load: ${PROG}
292 ${KMODLOAD} -v ./${KMOD}.ko
293 .endif
295 .if !target(unload)
296 unload:
297 ${KMODUNLOAD} -v ${KMOD}
298 .endif
300 .for _src in ${SRCS:Mopt_*.h} ${SRCS:Muse_*.h}
301 CLEANFILES+= ${_src}
302 .if !target(${_src})
303 .if defined(BUILDING_WITH_KERNEL) && exists(${BUILDING_WITH_KERNEL}/${_src})
304 ${_src}: ${BUILDING_WITH_KERNEL}/${_src}
305 # we do not have to copy these files any more, the kernel build
306 # directory is included in the path now.
307 # cp ${BUILDING_WITH_KERNEL}/${_src} ${.TARGET}
308 .else
309 ${_src}:
310 touch ${.TARGET}
311 .endif # BUILDING_WITH_KERNEL
312 .endif
313 .endfor
315 MFILES?= kern/bus_if.m kern/device_if.m bus/iicbus/iicbb_if.m \
316 bus/iicbus/iicbus_if.m bus/isa/isa_if.m dev/netif/mii_layer/miibus_if.m \
317 bus/pccard/card_if.m bus/pccard/power_if.m bus/pci/pci_if.m \
318 bus/pci/pcib_if.m \
319 bus/ppbus/ppbus_if.m bus/smbus/smbus_if.m bus/u4b/usb_if.m \
320 dev/acpica/acpi_if.m dev/acpica/acpi_wmi_if.m dev/disk/nata/ata_if.m \
321 dev/disk/sdhci/sdhci_if.m \
322 dev/sound/pci/hda/hdac_if.m \
323 dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
324 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \
325 dev/sound/midi/mpu_if.m dev/sound/midi/mpufoi_if.m \
326 dev/sound/midi/synth_if.m \
327 libiconv/iconv_converter_if.m dev/agp/agp_if.m opencrypto/cryptodev_if.m \
328 bus/mmc/mmcbus_if.m bus/mmc/mmcbr_if.m \
329 dev/virtual/virtio/virtio/virtio_bus_if.m \
330 dev/virtual/virtio/virtio/virtio_if.m \
331 dev/misc/coremctl/coremctl_if.m kern/cpu_if.m \
332 bus/gpio/gpio_if.m
334 .for _srcsrc in ${MFILES}
335 .for _ext in c h
336 .for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
337 CLEANFILES+= ${_src}
338 .if !target(${_src})
339 ${_src}: @
340 .if exists(@)
341 ${_src}: @/tools/makeobjops.awk @/${_srcsrc}
342 .endif
344 .if defined(BUILDING_WITH_KERNEL) && \
345 exists(${BUILDING_WITH_KERNEL}/${_src})
346 .else
347 awk -f @/tools/makeobjops.awk -- -${_ext} @/${_srcsrc}
348 .endif
349 .endif
350 .endfor # _src
351 .endfor # _ext
352 .endfor # _srcsrc
354 #.for _ext in c h
355 #.if ${SRCS:Mvnode_if.${_ext}} != ""
356 #CLEANFILES+= vnode_if.${_ext}
357 #vnode_if.${_ext}: @
358 #.if exists(@)
359 #vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src
360 #.endif
361 # awk -f @/tools/vnode_if.awk -- -${_ext} @/kern/vnode_if.src
362 #.endif
363 #.endfor
365 .if !empty(SRCS:Mmiidevs.h)
366 CLEANFILES+= miidevs.h
367 .if !exists(@)
368 miidevs.h: @
369 .else
370 miidevs.h: @/tools/miidevs2h.awk @/dev/netif/mii_layer/miidevs
371 .endif
372 ${AWK} -f @/tools/miidevs2h.awk @/dev/netif/mii_layer/miidevs
373 .endif
375 .if !empty(SRCS:Mpccarddevs.h)
376 CLEANFILES+= pccarddevs.h
377 .if !exists(@)
378 pccarddevs.h: @
379 .else
380 pccarddevs.h: @/tools/pccarddevs2h.awk @/bus/pccard/pccarddevs
381 .endif
382 ${AWK} -f @/tools/pccarddevs2h.awk @/bus/pccard/pccarddevs
383 .endif
385 .if !empty(SRCS:Mpcidevs.h)
386 CLEANFILES+= pcidevs.h
387 .if !exists(@)
388 pcidevs.h: @
389 .else
390 pcidevs.h: @/tools/pcidevs2h.awk @/bus/pci/pcidevs
391 .endif
392 ${AWK} -f @/tools/pcidevs2h.awk @/bus/pci/pcidevs
393 .endif
395 .if !empty(SRCS:Musbdevs.h)
396 CLEANFILES+= usbdevs.h
397 .if !exists(@)
398 usbdevs.h: @
399 .else
400 usbdevs.h: @/tools/usbdevs2h.awk @/bus/u4b/usbdevs
401 .endif
402 ${AWK} -f @/tools/usbdevs2h.awk @/bus/u4b/usbdevs -h
403 .endif
405 .if !empty(SRCS:Musbdevs_data.h)
406 CLEANFILES+= usbdevs_data.h
407 .if !exists(@)
408 usbdevs_data.h: @
409 .else
410 usbdevs_data.h: @/tools/usbdevs2h.awk @/bus/u4b/usbdevs
411 .endif
412 ${AWK} -f @/tools/usbdevs2h.awk @/bus/u4b/usbdevs -d
413 .endif
415 .if !empty(SRCS:Macpi_quirks.h)
416 CLEANFILES+= acpi_quirks.h
417 .if !exists(@)
418 acpi_quirks.h: @
419 .else
420 acpi_quirks.h: @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks
421 .endif
422 ${AWK} -f @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks
423 .endif
425 .if !empty(SRCS:Massym.s)
426 CLEANFILES+= assym.s genassym.o
427 assym.s: genassym.o
428 .if defined(BUILDING_WITH_KERNEL)
429 genassym.o: opt_global.h
430 .endif
431 .if !exists(@)
432 assym.s: @
433 .else
434 assym.s: @/kern/genassym.sh
435 .endif
436 sh @/kern/genassym.sh genassym.o > ${.TARGET}
437 .if exists(@)
438 genassym.o: @/platform/${MACHINE_PLATFORM}/${MACHINE_ARCH}/genassym.c
439 .endif
440 genassym.o: @ ${SRCS:Mopt_*.h}
441 ${CC} -c ${CFLAGS:N-fno-common:N-flto:N-mcmodel=small} ${WERROR} \
442 @/platform/${MACHINE_PLATFORM}/${MACHINE_ARCH}/genassym.c
443 .endif
445 regress:
447 .include <bsd.dep.mk>
449 .if !exists(${DEPENDFILE})
450 ${OBJS}: ${SRCS:M*.h}
451 .endif
453 .include <bsd.obj.mk>
454 .include "bsd.kern.mk"
456 # Behaves like MODULE_OVERRIDE
457 .if defined(KLD_DEPS)
458 all: _kdeps_all
459 _kdeps_all: @
460 .for _mdep in ${KLD_DEPS}
461 cd ${SYSDIR}/${_mdep} && make all
462 .endfor
463 depend: _kdeps_depend
464 _kdeps_depend: @
465 .for _mdep in ${KLD_DEPS}
466 cd ${SYSDIR}/${_mdep} && make depend
467 .endfor
468 install: _kdeps_install
469 _kdeps_install: @
470 .for _mdep in ${KLD_DEPS}
471 cd ${SYSDIR}/${_mdep} && make install
472 .endfor
473 clean: _kdeps_clean
474 _kdeps_clean: @
475 .for _mdep in ${KLD_DEPS}
476 cd ${SYSDIR}/${_mdep} && make clean
477 .endfor
478 .endif