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