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