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