xref: /freebsd/sys/conf/kmod.mk (revision aca928a50a42f00f344df934005b09dbcb4e2f77)
1# The include file <bsd.kmod.mk> handles building and installing loadable
2# kernel modules.
3#
4#
5# +++ variables +++
6#
7# CLEANFILES	Additional files to remove for the clean and cleandir targets.
8#
9# EXPORT_SYMS	A list of symbols that should be exported from the module,
10#		or the name of a file containing a list of symbols, or YES
11#		to export all symbols.  If not defined, no symbols are
12#		exported.
13#
14# KMOD		The name of the kernel module to build.
15#
16# KMODDIR	Base path for kernel modules (see kld(4)). [/boot/kernel]
17#
18# KMODOWN	Module file owner. [${BINOWN}]
19#
20# KMODGRP	Module file group. [${BINGRP}]
21#
22# KMODMODE	Module file mode. [${BINMODE}]
23#
24# KMODLOAD	Command to load a kernel module [/sbin/kldload]
25#
26# KMODUNLOAD	Command to unload a kernel module [/sbin/kldunload]
27#
28# KMODISLOADED	Command to check whether a kernel module is
29#		loaded [/sbin/kldstat -q -n]
30#
31# PROG		The name of the kernel module to build.
32#		If not supplied, ${KMOD}.ko is used.
33#
34# SRCS		List of source files.
35#
36# FIRMWS	List of firmware images in format filename:shortname:version
37#
38# FIRMWARE_LICENSE
39#		Set to the name of the license the user has to agree on in
40#		order to use this firmware. See /usr/share/doc/legal
41#
42# DESTDIR	The tree where the module gets installed. [not set]
43#
44# KERNBUILDDIR	Set to the location of the kernel build directory where
45#		the opt_*.h files, .o's and kernel winds up.
46#
47# BLOB_OBJS	Prebuilt binary blobs .o's from the src tree to be linked into
48#		the module. These are precious and not removed in make clean.
49#
50# +++ targets +++
51#
52# 	install:
53#               install the kernel module; if the Makefile
54#               does not itself define the target install, the targets
55#               beforeinstall and afterinstall may also be used to cause
56#               actions immediately before and after the install target
57#		is executed.
58#
59# 	load:
60#		Load a module.
61#
62# 	unload:
63#		Unload a module.
64#
65#	reload:
66#		Unload if loaded, then load.
67#
68
69AWK?=		awk
70KMODLOAD?=	/sbin/kldload
71KMODUNLOAD?=	/sbin/kldunload
72KMODISLOADED?=	/sbin/kldstat -q -n
73OBJCOPY?=	objcopy
74XARGS?=		xargs
75XARGS_J?=	-J
76
77.include "kmod.opts.mk"
78.include <bsd.sysdir.mk>
79
80.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S .m
81
82# amd64 uses direct linking for kmod, all others use shared binaries
83.if ${MACHINE_CPUARCH} != amd64
84__KLD_SHARED=yes
85.else
86__KLD_SHARED=no
87.endif
88
89.if !empty(CFLAGS:M-O[23s]) && empty(CFLAGS:M-fno-strict-aliasing)
90CFLAGS+=	-fno-strict-aliasing
91.endif
92WERROR?=	-Werror
93
94LINUXKPI_GENSRCS+= \
95	backlight_if.h \
96	bus_if.h \
97	device_if.h \
98	iicbus_if.h \
99	iicbb_if.h \
100	lkpi_iic_if.c \
101	lkpi_iic_if.h \
102	pci_if.h \
103	pci_iov_if.h \
104	pcib_if.h \
105	vnode_if.h \
106	usb_if.h \
107	opt_usb.h \
108	opt_stack.h
109
110LINUXKPI_INCLUDES+= \
111	-I${SYSDIR}/compat/linuxkpi/common/include \
112	-I${SYSDIR}/compat/linuxkpi/dummy/include
113
114CFLAGS+=	${WERROR}
115CFLAGS+=	-D_KERNEL
116CFLAGS+=	-DKLD_MODULE
117.if defined(MODULE_TIED)
118CFLAGS+=	-DKLD_TIED
119.endif
120
121# Don't use any standard or source-relative include directories.
122NOSTDINC=	-nostdinc
123CFLAGS:=	${CFLAGS:N-I*} ${NOSTDINC} ${INCLMAGIC} ${CFLAGS:M-I*}
124.if defined(KERNBUILDDIR)
125CFLAGS+=	-DHAVE_KERNEL_OPTION_HEADERS -include ${KERNBUILDDIR}/opt_global.h
126.else
127SRCS+=		opt_global.h
128CFLAGS+=	-include ${.OBJDIR}/opt_global.h
129.endif
130
131# Add -I paths for system headers.  Individual module makefiles don't
132# need any -I paths for this.  Similar defaults for .PATH can't be
133# set because there are no standard paths for non-headers.
134CFLAGS+=	-I. -I${SYSDIR} -I${SYSDIR}/contrib/ck/include
135
136CFLAGS.gcc+=	-finline-limit=${INLINE_LIMIT}
137CFLAGS.gcc+=	-fms-extensions
138CFLAGS.gcc+= --param inline-unit-growth=100
139CFLAGS.gcc+= --param large-function-growth=1000
140
141# Disallow common variables, and if we end up with commons from
142# somewhere unexpected, allocate storage for them in the module itself.
143#
144# -fno-common is the default for src builds, but this should be left in place
145# until at least we catch up to GCC10/LLVM11 or otherwise enable -fno-common
146# in <bsd.sys.mk> instead.  For now, we will have duplicate -fno-common in
147# CFLAGS for in-tree module builds as they will also pick it up from
148# share/mk/src.sys.mk, but the following is important for out-of-tree modules
149# (e.g. ports).
150CFLAGS+=	-fno-common
151.if ${LINKER_TYPE} != "lld" || ${LINKER_VERSION} < 140000
152# lld >= 14 warns that -d is deprecated, and will be removed.
153LDFLAGS+=	-d
154.endif
155LDFLAGS+=	-warn-common
156
157.if defined(LINKER_FEATURES) && ${LINKER_FEATURES:Mbuild-id}
158LDFLAGS+=	--build-id=sha1
159.endif
160
161CFLAGS+=	${DEBUG_FLAGS}
162.if ${MACHINE_CPUARCH} == aarch64 || ${MACHINE_CPUARCH} == amd64 || \
163    ${MACHINE_CPUARCH} == riscv
164CFLAGS+=	-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer
165.endif
166
167.if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "riscv" || \
168    ${MACHINE_CPUARCH} == "powerpc" || ${MACHINE_CPUARCH} == "i386"
169CFLAGS+=	-fPIC
170.endif
171
172.if ${MACHINE_CPUARCH} == "aarch64"
173# https://bugs.freebsd.org/264094
174# lld >= 14 and recent GNU ld can relax adrp+add and adrp+ldr instructions,
175# which breaks VNET.
176LDFLAGS+=	--no-relax
177.endif
178
179# Temporary workaround for PR 196407, which contains the fascinating details.
180# Don't allow clang to use fpu instructions or registers in kernel modules.
181.if ${MACHINE_CPUARCH} == arm
182CFLAGS.clang+=	-mno-movt
183CFLAGS.clang+=	-mfpu=none
184CFLAGS+=	-funwind-tables
185.endif
186
187.if ${MACHINE_CPUARCH} == powerpc
188CFLAGS+=	-mlongcall -fno-omit-frame-pointer
189.if ${LINKER_TYPE} == "lld"
190# TOC optimization in LLD (9.0) currently breaks kernel modules, so disable it
191LDFLAGS+=	--no-toc-optimize
192.endif
193.endif
194
195.if defined(DEBUG) || defined(DEBUG_FLAGS)
196CTFFLAGS+=	-g
197.endif
198
199.if defined(FIRMWS)
200${KMOD:S/$/.c/}: ${SYSDIR}/tools/fw_stub.awk
201	${AWK} -f ${SYSDIR}/tools/fw_stub.awk ${FIRMWS} -m${KMOD} -c${KMOD:S/$/.c/g} \
202	    ${FIRMWARE_LICENSE:C/.+/-l/}${FIRMWARE_LICENSE}
203
204SRCS+=	${KMOD:S/$/.c/}
205CLEANFILES+=	${KMOD:S/$/.c/}
206
207.for _firmw in ${FIRMWS}
208${_firmw:C/\:.*$/.fwo/:T}:	${_firmw:C/\:.*$//} ${SYSDIR}/kern/firmw.S
209	@${ECHO} ${_firmw:C/\:.*$//} ${.ALLSRC:M*${_firmw:C/\:.*$//}}
210	${CC:N${CCACHE_BIN}} -c -x assembler-with-cpp -DLOCORE 	\
211	    ${CFLAGS} ${WERROR} 				\
212	    -DFIRMW_FILE=\""${.ALLSRC:M*${_firmw:C/\:.*$//}}"\"	\
213	    -DFIRMW_SYMBOL="${_firmw:C/\:.*$//:C/[-.\/@]/_/g}"	\
214	    ${SYSDIR}/kern/firmw.S -o ${.TARGET}
215
216OBJS+=	${_firmw:C/\:.*$/.fwo/:T}
217.endfor
218.endif
219
220# Conditionally include SRCS based on kernel config options.
221.for _o in ${KERN_OPTS}
222SRCS+=${SRCS.${_o}}
223.endfor
224
225OBJS+=	${SRCS:N*.h:R:S/$/.o/g}
226
227.if !defined(PROG)
228PROG=	${KMOD}.ko
229.endif
230
231.if !defined(DEBUG_FLAGS) || ${MK_SPLIT_KERNEL_DEBUG} == "no"
232FULLPROG=	${PROG}
233.else
234FULLPROG=	${PROG}.full
235${PROG}: ${FULLPROG} ${PROG}.debug
236	${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROG}.debug \
237	    ${FULLPROG} ${.TARGET}
238${PROG}.debug: ${FULLPROG}
239	${OBJCOPY} --only-keep-debug ${FULLPROG} ${.TARGET}
240.endif
241
242.if ${__KLD_SHARED} == yes
243${FULLPROG}: ${KMOD}.kld
244	${LD} -m ${LD_EMULATION} -Bshareable -znotext -znorelro ${_LDFLAGS} \
245	    -o ${.TARGET} ${KMOD}.kld
246.if !defined(DEBUG_FLAGS)
247	${OBJCOPY} --strip-debug ${.TARGET}
248.endif
249.endif
250
251EXPORT_SYMS?=	NO
252.if ${EXPORT_SYMS} != YES
253CLEANFILES+=	export_syms
254.endif
255
256.if exists(${SYSDIR}/conf/ldscript.kmod.${MACHINE})
257LDSCRIPT_FLAGS?= -T ${SYSDIR}/conf/ldscript.kmod.${MACHINE}
258.endif
259
260.if ${__KLD_SHARED} == yes
261${KMOD}.kld: ${OBJS} ${BLOB_OBJS}
262.else
263${FULLPROG}: ${OBJS} ${BLOB_OBJS}
264.endif
265	${LD} -m ${LD_EMULATION} ${_LDFLAGS} ${LDSCRIPT_FLAGS} -r \
266	    -o ${.TARGET} ${OBJS} ${BLOB_OBJS}
267.if ${MK_CTF} != "no"
268	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} ${BLOB_OBJS}
269.endif
270.if defined(EXPORT_SYMS)
271.if ${EXPORT_SYMS} != YES
272.if ${EXPORT_SYMS} == NO
273	:> export_syms
274.elif !exists(${.CURDIR}/${EXPORT_SYMS})
275	printf '%s' "${EXPORT_SYMS:@s@$s${.newline}@}" > export_syms
276.else
277	grep -v '^#' < ${EXPORT_SYMS} > export_syms
278.endif
279	${AWK} -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \
280	    export_syms | ${XARGS} ${XARGS_J} % ${OBJCOPY} % ${.TARGET}
281.endif
282.endif # defined(EXPORT_SYMS)
283.if defined(PREFIX_SYMS)
284	${AWK} -v prefix=${PREFIX_SYMS} -f ${SYSDIR}/conf/kmod_syms_prefix.awk \
285	    ${.TARGET} /dev/null | ${XARGS} ${XARGS_J} % ${OBJCOPY} % ${.TARGET}
286.endif
287.if !defined(DEBUG_FLAGS) && ${__KLD_SHARED} == no
288	${OBJCOPY} --strip-debug ${.TARGET}
289.endif
290
291_ILINKS=machine
292.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
293_ILINKS+=x86
294.endif
295.if ${MACHINE_CPUARCH} == "amd64"
296_ILINKS+=i386
297.endif
298CLEANFILES+=${_ILINKS}
299
300all: ${PROG}
301
302beforedepend: ${_ILINKS}
303beforebuild: ${_ILINKS}
304
305# Ensure that the links exist without depending on it when it exists which
306# causes all the modules to be rebuilt when the directory pointed to changes.
307# Ensure that debug info references the path in the source tree.
308.for _link in ${_ILINKS}
309.if !exists(${.OBJDIR}/${_link})
310OBJS_DEPEND_GUESS+=	${_link}
311.endif
312.if ${_link} == "machine"
313CFLAGS+= -fdebug-prefix-map=./machine=${SYSDIR}/${MACHINE}/include
314.else
315CFLAGS+= -fdebug-prefix-map=./${_link}=${SYSDIR}/${_link}/include
316.endif
317.endfor
318
319.NOPATH: ${_ILINKS}
320
321${_ILINKS}:
322	@case ${.TARGET} in \
323	machine) \
324		path=${SYSDIR}/${MACHINE}/include ;; \
325	*) \
326		path=${SYSDIR}/${.TARGET:T}/include ;; \
327	esac ; \
328	path=`realpath $$path`; \
329	${ECHO} ${.TARGET:T} "->" $$path ; \
330	ln -fns $$path ${.TARGET:T}
331
332CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS}
333
334.if defined(DEBUG_FLAGS) && ${MK_SPLIT_KERNEL_DEBUG} != "no"
335CLEANFILES+= ${FULLPROG} ${PROG}.debug
336.endif
337
338.if !target(install)
339
340_INSTALLFLAGS:=	${INSTALLFLAGS}
341.for ie in ${INSTALLFLAGS_EDIT}
342_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
343.endfor
344
345.if !target(realinstall)
346KERN_DEBUGDIR?=	${DEBUGDIR}
347realinstall: _kmodinstall
348.ORDER: beforeinstall _kmodinstall
349_kmodinstall: .PHONY
350	${INSTALL} -T release -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
351	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}/
352.if defined(DEBUG_FLAGS) && !defined(INSTALL_NODEBUG) && ${MK_KERNEL_SYMBOLS} != "no"
353	${INSTALL} -T dbg -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
354	    ${_INSTALLFLAGS} ${PROG}.debug ${DESTDIR}${KERN_DEBUGDIR}${KMODDIR}/
355.endif
356
357.include <bsd.links.mk>
358
359.if !defined(NO_XREF)
360afterinstall: _kldxref
361.ORDER: realinstall _kldxref
362.ORDER: _installlinks _kldxref
363_kldxref: .PHONY
364	${KLDXREF_CMD} ${DESTDIR}${KMODDIR}
365.if defined(NO_ROOT) && defined(METALOG)
366	echo ".${DISTBASE}${KMODDIR}/linker.hints type=file mode=0644 uname=root gname=wheel" | \
367	    cat -l >> ${METALOG}
368.endif
369.endif
370.endif # !target(realinstall)
371
372.endif # !target(install)
373
374.if !target(load)
375load: ${PROG} .PHONY
376	${KMODLOAD} -v ${.OBJDIR}/${PROG}
377.endif
378
379.if !target(unload)
380unload: .PHONY
381	if ${KMODISLOADED} ${PROG} ; then ${KMODUNLOAD} -v ${PROG} ; fi
382.endif
383
384.if !target(reload)
385reload: unload load .PHONY
386.endif
387
388.if defined(KERNBUILDDIR)
389.PATH: ${KERNBUILDDIR}
390CFLAGS+=	-I${KERNBUILDDIR}
391.for _src in ${SRCS:Mopt_*.h}
392CLEANFILES+=	${_src}
393.if !target(${_src})
394${_src}:
395	ln -sf ${KERNBUILDDIR}/${_src} ${.TARGET}
396.endif
397.endfor
398.else
399.for _src in ${SRCS:Mopt_*.h}
400CLEANFILES+=	${_src}
401.if !target(${_src})
402${_src}:
403	:> ${.TARGET}
404.endif
405.endfor
406.endif
407
408# Add the sanitizer C flags
409CFLAGS+=	${SAN_CFLAGS}
410
411# Add the gcov flags
412CFLAGS+=	${GCOV_CFLAGS}
413
414# Respect configuration-specific C flags.
415CFLAGS+=	${ARCH_FLAGS} ${CONF_CFLAGS}
416
417.if !empty(SRCS:Mvnode_if.c)
418CLEANFILES+=	vnode_if.c
419vnode_if.c: ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src
420	${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -c
421.endif
422
423.if !empty(SRCS:Mvnode_if.h)
424CLEANFILES+=	vnode_if.h vnode_if_newproto.h vnode_if_typedef.h
425vnode_if.h vnode_if_newproto.h vnode_if_typedef.h: ${SYSDIR}/tools/vnode_if.awk \
426    ${SYSDIR}/kern/vnode_if.src
427vnode_if.h: vnode_if_newproto.h vnode_if_typedef.h
428	${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -h
429vnode_if_newproto.h:
430	${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -p
431vnode_if_typedef.h:
432	${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -q
433.endif
434
435# Build _if.[ch] from _if.m, and clean them when we're done.
436# __MPATH defined in config.mk
437_MFILES=${__MPATH:T:O}
438_MPATH=${__MPATH:H:O:u}
439.PATH.m: ${_MPATH}
440.for _i in ${SRCS:M*_if.[ch]}
441_MATCH=M${_i:R:S/$/.m/}
442_MATCHES=${_MFILES:${_MATCH}}
443.if !empty(_MATCHES)
444CLEANFILES+=	${_i}
445.endif
446.endfor # _i
447.m.c:	${SYSDIR}/tools/makeobjops.awk
448	${AWK} -f ${SYSDIR}/tools/makeobjops.awk ${.IMPSRC} -c
449
450.m.h:	${SYSDIR}/tools/makeobjops.awk
451	${AWK} -f ${SYSDIR}/tools/makeobjops.awk ${.IMPSRC} -h
452
453.for _i in mii pccard
454.if !empty(SRCS:M${_i}devs.h)
455CLEANFILES+=	${_i}devs.h
456${_i}devs.h: ${SYSDIR}/tools/${_i}devs2h.awk ${SYSDIR}/dev/${_i}/${_i}devs
457	${AWK} -f ${SYSDIR}/tools/${_i}devs2h.awk ${SYSDIR}/dev/${_i}/${_i}devs
458.endif
459.endfor # _i
460
461.if !empty(SRCS:Mbhnd_nvram_map.h)
462CLEANFILES+=	bhnd_nvram_map.h
463bhnd_nvram_map.h: ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.awk \
464    ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.sh \
465    ${SYSDIR}/dev/bhnd/nvram/nvram_map
466bhnd_nvram_map.h:
467	sh ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.sh \
468	    ${SYSDIR}/dev/bhnd/nvram/nvram_map -h
469.endif
470
471.if !empty(SRCS:Mbhnd_nvram_map_data.h)
472CLEANFILES+=	bhnd_nvram_map_data.h
473bhnd_nvram_map_data.h: ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.awk \
474    ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.sh \
475    ${SYSDIR}/dev/bhnd/nvram/nvram_map
476bhnd_nvram_map_data.h:
477	sh ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.sh \
478	    ${SYSDIR}/dev/bhnd/nvram/nvram_map -d
479.endif
480
481.if !empty(SRCS:Musbdevs.h)
482CLEANFILES+=	usbdevs.h
483usbdevs.h: ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs
484	${AWK} -f ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs -h
485.endif
486
487.if !empty(SRCS:Musbdevs_data.h)
488CLEANFILES+=	usbdevs_data.h
489usbdevs_data.h: ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs
490	${AWK} -f ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs -d
491.endif
492
493.if !empty(SRCS:Msdiodevs.h)
494CLEANFILES+=	sdiodevs.h
495sdiodevs.h: ${SYSDIR}/tools/sdiodevs2h.awk ${SYSDIR}/dev/sdio/sdiodevs
496	${AWK} -f ${SYSDIR}/tools/sdiodevs2h.awk ${SYSDIR}/dev/sdio/sdiodevs -h
497.endif
498
499.if !empty(SRCS:Msdiodevs_data.h)
500CLEANFILES+=	sdiodevs_data.h
501sdiodevs_data.h: ${SYSDIR}/tools/sdiodevs2h.awk ${SYSDIR}/dev/sdio/sdiodevs
502	${AWK} -f ${SYSDIR}/tools/sdiodevs2h.awk ${SYSDIR}/dev/sdio/sdiodevs -d
503.endif
504
505.if !empty(SRCS:Macpi_quirks.h)
506CLEANFILES+=	acpi_quirks.h
507acpi_quirks.h: ${SYSDIR}/tools/acpi_quirks2h.awk ${SYSDIR}/dev/acpica/acpi_quirks
508	${AWK} -f ${SYSDIR}/tools/acpi_quirks2h.awk ${SYSDIR}/dev/acpica/acpi_quirks
509.endif
510
511.if !empty(SRCS:Massym.inc) || !empty(DPSRCS:Massym.inc)
512CLEANFILES+=	assym.inc genassym.o
513DEPENDOBJS+=	genassym.o
514DPSRCS+=	offset.inc
515.endif
516.if defined(MODULE_TIED)
517DPSRCS+=	offset.inc
518.endif
519.if !empty(SRCS:Moffset.inc) || !empty(DPSRCS:Moffset.inc)
520CLEANFILES+=	offset.inc genoffset.o
521DEPENDOBJS+=	genoffset.o
522.endif
523assym.inc: genassym.o
524offset.inc: genoffset.o
525assym.inc: ${SYSDIR}/kern/genassym.sh
526	sh ${SYSDIR}/kern/genassym.sh genassym.o > ${.TARGET}
527genassym.o: ${SYSDIR}/${MACHINE}/${MACHINE}/genassym.c offset.inc
528genassym.o: ${SRCS:Mopt_*.h}
529	${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} -fcommon \
530	    ${SYSDIR}/${MACHINE}/${MACHINE}/genassym.c
531offset.inc: ${SYSDIR}/kern/genoffset.sh genoffset.o
532	sh ${SYSDIR}/kern/genoffset.sh genoffset.o > ${.TARGET}
533genoffset.o: ${SYSDIR}/kern/genoffset.c
534genoffset.o: ${SRCS:Mopt_*.h}
535	${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} -fcommon \
536	    ${SYSDIR}/kern/genoffset.c
537
538CLEANDEPENDFILES+=	${_ILINKS}
539# .depend needs include links so we remove them only together.
540cleanilinks:
541	rm -f ${_ILINKS}
542
543OBJS_DEPEND_GUESS+= ${SRCS:M*.h}
544.if defined(KERNBUILDDIR)
545OBJS_DEPEND_GUESS+= opt_global.h
546.endif
547
548ZINCDIR=${SYSDIR}/contrib/openzfs/include
549OPENZFS_CFLAGS=     \
550	-D_SYS_VMEM_H_  \
551	-D__KERNEL__ \
552	-nostdinc \
553	-DSMP \
554	-I${ZINCDIR}  \
555	-I${ZINCDIR}/os/freebsd \
556	-I${ZINCDIR}/os/freebsd/spl \
557	-I${ZINCDIR}/os/freebsd/zfs \
558	-I${SYSDIR}/cddl/compat/opensolaris \
559	-I${SYSDIR}/cddl/contrib/opensolaris/uts/common \
560	-include ${ZINCDIR}/os/freebsd/spl/sys/ccompile.h
561
562.include <bsd.dep.mk>
563.include <bsd.clang-analyze.mk>
564.include <bsd.obj.mk>
565.include "kern.mk"
566