xref: /freebsd/sys/conf/kmod.mk (revision 1dd50172b0d868e007f4172c778c231e13d2629c)
1639a2e50SGarrett Wollman#	From: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
27f3dea24SPeter Wemm# $FreeBSD$
353996fadSWolfram Schneider#
41f089616SRuslan Ermilov# The include file <bsd.kmod.mk> handles building and installing loadable
51f089616SRuslan Ermilov# kernel modules.
653996fadSWolfram Schneider#
753996fadSWolfram Schneider#
853996fadSWolfram Schneider# +++ variables +++
953996fadSWolfram Schneider#
1053996fadSWolfram Schneider# CLEANFILES	Additional files to remove for the clean and cleandir targets.
1153996fadSWolfram Schneider#
121f089616SRuslan Ermilov# EXPORT_SYMS	A list of symbols that should be exported from the module,
131f089616SRuslan Ermilov#		or the name of a file containing a list of symbols, or YES
141f089616SRuslan Ermilov#		to export all symbols.  If not defined, no symbols are
151f089616SRuslan Ermilov#		exported.
161f089616SRuslan Ermilov#
17fe3cac87SNick Hibma# KMOD		The name of the kernel module to build.
1853996fadSWolfram Schneider#
193bdfa9e5SDavid E. O'Brien# KMODDIR	Base path for kernel modules (see kld(4)). [/boot/kernel]
2053996fadSWolfram Schneider#
211f089616SRuslan Ermilov# KMODOWN	Module file owner. [${BINOWN}]
2253996fadSWolfram Schneider#
231f089616SRuslan Ermilov# KMODGRP	Module file group. [${BINGRP}]
2453996fadSWolfram Schneider#
251f089616SRuslan Ermilov# KMODMODE	Module file mode. [${BINMODE}]
2653996fadSWolfram Schneider#
27fe3cac87SNick Hibma# KMODLOAD	Command to load a kernel module [/sbin/kldload]
287bc830bbSWolfram Schneider#
29fe3cac87SNick Hibma# KMODUNLOAD	Command to unload a kernel module [/sbin/kldunload]
307bc830bbSWolfram Schneider#
3193bffaf2SDag-Erling Smørgrav# KMODISLOADED	Command to check whether a kernel module is
3293bffaf2SDag-Erling Smørgrav#		loaded [/sbin/kldstat -q -n]
3393bffaf2SDag-Erling Smørgrav#
341f089616SRuslan Ermilov# PROG		The name of the kernel module to build.
351f089616SRuslan Ermilov#		If not supplied, ${KMOD}.ko is used.
361f089616SRuslan Ermilov#
371f089616SRuslan Ermilov# SRCS		List of source files.
381f089616SRuslan Ermilov#
396aec1278SMax Laier# FIRMWS	List of firmware images in format filename:shortname:version
406aec1278SMax Laier#
4141e80f2aSFlorent Thoumie# FIRMWARE_LICENSE
427bd6fde3SFlorent Thoumie#		Set to the name of the license the user has to agree on in
437bd6fde3SFlorent Thoumie#		order to use this firmware. See /usr/share/doc/legal
447bd6fde3SFlorent Thoumie#
451f089616SRuslan Ermilov# DESTDIR	The tree where the module gets installed. [not set]
460b3178a4SMike Smith#
4753996fadSWolfram Schneider# +++ targets +++
4853996fadSWolfram Schneider#
4953996fadSWolfram Schneider# 	install:
5017d6c636SRuslan Ermilov#               install the kernel module; if the Makefile
5153996fadSWolfram Schneider#               does not itself define the target install, the targets
5253996fadSWolfram Schneider#               beforeinstall and afterinstall may also be used to cause
5353996fadSWolfram Schneider#               actions immediately before and after the install target
5453996fadSWolfram Schneider#		is executed.
5553996fadSWolfram Schneider#
5653996fadSWolfram Schneider# 	load:
571f089616SRuslan Ermilov#		Load a module.
5853996fadSWolfram Schneider#
5953996fadSWolfram Schneider# 	unload:
601f089616SRuslan Ermilov#		Unload a module.
6153996fadSWolfram Schneider#
6293bffaf2SDag-Erling Smørgrav#	reload:
6393bffaf2SDag-Erling Smørgrav#		Unload if loaded, then load.
6493bffaf2SDag-Erling Smørgrav#
65639a2e50SGarrett Wollman
66b7bbb709SDavid E. O'BrienAWK?=		awk
67fe3cac87SNick HibmaKMODLOAD?=	/sbin/kldload
68fe3cac87SNick HibmaKMODUNLOAD?=	/sbin/kldunload
6993bffaf2SDag-Erling SmørgravKMODISLOADED?=	/sbin/kldstat -q -n
70f6611608SSheldon HearnOBJCOPY?=	objcopy
717bc830bbSWolfram Schneider
720ac2fc87SRuslan Ermilov.include <bsd.init.mk>
73b0a8d404SWarner Losh# Grab all the options for a kernel build. For backwards compat, we need to
74b0a8d404SWarner Losh# do this after bsd.own.mk.
75b0a8d404SWarner Losh.include "kern.opts.mk"
769215d178SBrooks Davis.include <bsd.compiler.mk>
7735c4406dSWarner Losh.include "config.mk"
78639a2e50SGarrett Wollman
795d4447e0SBryan Drewery# Search for kernel source tree in standard places.
805d4447e0SBryan Drewery.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys
815d4447e0SBryan Drewery.if !defined(SYSDIR) && exists(${_dir}/kern/)
825d4447e0SBryan DrewerySYSDIR=	${_dir:tA}
835d4447e0SBryan Drewery.endif
845d4447e0SBryan Drewery.endfor
855d4447e0SBryan Drewery.if !defined(SYSDIR) || !exists(${SYSDIR}/kern/)
865d4447e0SBryan Drewery.error "can't find kernel source tree"
875d4447e0SBryan Drewery.endif
885d4447e0SBryan Drewery
8912f05b84SWarner Losh.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S .m
90639a2e50SGarrett Wollman
913a0d123eSWarner Losh# amd64 and mips use direct linking for kmod, all others use shared binaries
923a0d123eSWarner Losh.if ${MACHINE_CPUARCH} != amd64 && ${MACHINE_CPUARCH} != mips
933a0d123eSWarner Losh__KLD_SHARED=yes
943a0d123eSWarner Losh.else
953a0d123eSWarner Losh__KLD_SHARED=no
963a0d123eSWarner Losh.endif
973a0d123eSWarner Losh
98f165cb7cSRuslan Ermilov.if !empty(CFLAGS:M-O[23s]) && empty(CFLAGS:M-fno-strict-aliasing)
99db0cd7e1SDavid E. O'BrienCFLAGS+=	-fno-strict-aliasing
100db0cd7e1SDavid E. O'Brien.endif
1015d3b2922SRuslan ErmilovWERROR?=	-Werror
102daaea395SWarner LoshCFLAGS+=	${WERROR}
10348aea4daSRuslan ErmilovCFLAGS+=	-D_KERNEL
1048fe644b2SMike SmithCFLAGS+=	-DKLD_MODULE
1054a2d2630SBruce Evans
106021886ffSBruce Evans# Don't use any standard or source-relative include directories.
10706d6e4fcSTom RhodesNOSTDINC=	-nostdinc
108da3bcc92SAlexander KabaevCFLAGS:=	${CFLAGS:N-I*} ${NOSTDINC} ${INCLMAGIC} ${CFLAGS:M-I*}
1098fa793d0SBrian Feldman.if defined(KERNBUILDDIR)
1100c063641SGleb SmirnoffCFLAGS+=	-DHAVE_KERNEL_OPTION_HEADERS -include ${KERNBUILDDIR}/opt_global.h
1118fa793d0SBrian Feldman.endif
112021886ffSBruce Evans
1131f089616SRuslan Ermilov# Add -I paths for system headers.  Individual module makefiles don't
114021886ffSBruce Evans# need any -I paths for this.  Similar defaults for .PATH can't be
115021886ffSBruce Evans# set because there are no standard paths for non-headers.
116528013d5SWarner LoshCFLAGS+=	-I. -I${SYSDIR}
1174a2d2630SBruce Evans
11822ba0b2fSWarner LoshCFLAGS.gcc+=	-finline-limit=${INLINE_LIMIT}
119cc4a90c4SGleb SmirnoffCFLAGS.gcc+=	-fms-extensions
12022ba0b2fSWarner LoshCFLAGS.gcc+= --param inline-unit-growth=100
12122ba0b2fSWarner LoshCFLAGS.gcc+= --param large-function-growth=1000
1222a51529fSPeter Wemm
1230b3178a4SMike Smith# Disallow common variables, and if we end up with commons from
1240b3178a4SMike Smith# somewhere unexpected, allocate storage for them in the module itself.
1250b3178a4SMike SmithCFLAGS+=	-fno-common
1260b3178a4SMike SmithLDFLAGS+=	-d -warn-common
1270b3178a4SMike Smith
1289e4be63dSBruce EvansCFLAGS+=	${DEBUG_FLAGS}
1293a0d123eSWarner Losh.if ${MACHINE_CPUARCH} == amd64
1302565edc4SAndriy GaponCFLAGS+=	-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer
13183c457dcSIan Dowse.endif
1329e4be63dSBruce Evans
1338dbd4f30SRuslan Bukin.if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "riscv"
1348598392cSKonstantin BelousovCFLAGS+=	-fPIC
1358598392cSKonstantin Belousov.endif
1368598392cSKonstantin Belousov
137b54c389fSIan Lepore# Temporary workaround for PR 196407, which contains the fascinating details.
138c6f7b900SIan Lepore# Don't allow clang to use fpu instructions or registers in kernel modules.
139b54c389fSIan Lepore.if ${MACHINE_CPUARCH} == arm
14067e3484fSDimitry Andric.if ${COMPILER_VERSION} < 30800
141b54c389fSIan LeporeCFLAGS.clang+=	-mllvm -arm-use-movt=0
14267e3484fSDimitry Andric.else
14367e3484fSDimitry AndricCFLAGS.clang+=	-mno-movt
14467e3484fSDimitry Andric.endif
145c6f7b900SIan LeporeCFLAGS.clang+=	-mfpu=none
1461b23f9b9SAndrew TurnerCFLAGS+=	-funwind-tables
147b54c389fSIan Lepore.endif
148b54c389fSIan Lepore
1493a0d123eSWarner Losh.if ${MACHINE_CPUARCH} == powerpc
15055a5dcc8SPeter GrehanCFLAGS+=	-mlongcall -fno-omit-frame-pointer
151fded756eSPeter Grehan.endif
152fded756eSPeter Grehan
1533a0d123eSWarner Losh.if ${MACHINE_CPUARCH} == mips
1546f3c6327SNeel NatuCFLAGS+=	-G0 -fno-pic -mno-abicalls -mlong-calls
1556f3c6327SNeel Natu.endif
1566f3c6327SNeel Natu
15769745d38SAlexander Leidinger.if defined(DEBUG) || defined(DEBUG_FLAGS)
15869745d38SAlexander LeidingerCTFFLAGS+=	-g
15969745d38SAlexander Leidinger.endif
16069745d38SAlexander Leidinger
1616aec1278SMax Laier.if defined(FIRMWS)
1625852ae2dSBryan Drewery${KMOD:S/$/.c/}: ${SYSDIR}/tools/fw_stub.awk
163528013d5SWarner Losh	${AWK} -f ${SYSDIR}/tools/fw_stub.awk ${FIRMWS} -m${KMOD} -c${KMOD:S/$/.c/g} \
1647bd6fde3SFlorent Thoumie	    ${FIRMWARE_LICENSE:C/.+/-l/}${FIRMWARE_LICENSE}
1656aec1278SMax Laier
1666aec1278SMax LaierSRCS+=	${KMOD:S/$/.c/}
1676aec1278SMax LaierCLEANFILES+=	${KMOD:S/$/.c/}
1686aec1278SMax Laier
1696aec1278SMax Laier.for _firmw in ${FIRMWS}
1705852ae2dSBryan Drewery${_firmw:C/\:.*$/.fwo/:T}:	${_firmw:C/\:.*$//}
1716aec1278SMax Laier	@${ECHO} ${_firmw:C/\:.*$//} ${.ALLSRC:M*${_firmw:C/\:.*$//}}
172009b3d3dSMax Laier	@if [ -e ${_firmw:C/\:.*$//} ]; then			\
1735b6dc2efSSimon J. Gerraty		${LD} -b binary --no-warn-mismatch ${_LDFLAGS}	\
174*1dd50172SEd Maste		    -m ${LD_EMULATION} -r -d			\
175*1dd50172SEd Maste		    -o ${.TARGET} ${_firmw:C/\:.*$//};		\
176ff8e7669SMax Laier	else							\
177ff8e7669SMax Laier		ln -s ${.ALLSRC:M*${_firmw:C/\:.*$//}} ${_firmw:C/\:.*$//}; \
1785b6dc2efSSimon J. Gerraty		${LD} -b binary --no-warn-mismatch ${_LDFLAGS}	\
179*1dd50172SEd Maste		    -m ${LD_EMULATION} -r -d			\
180*1dd50172SEd Maste		    -o ${.TARGET} ${_firmw:C/\:.*$//};		\
181ff8e7669SMax Laier		rm ${_firmw:C/\:.*$//};				\
182ff8e7669SMax Laier	fi
1836aec1278SMax Laier
184d9eed6f4SJohn BaldwinOBJS+=	${_firmw:C/\:.*$/.fwo/:T}
1856aec1278SMax Laier.endfor
1866aec1278SMax Laier.endif
1876aec1278SMax Laier
18835c4406dSWarner Losh# Conditionally include SRCS based on kernel config options.
18935c4406dSWarner Losh.for _o in ${KERN_OPTS}
19035c4406dSWarner LoshSRCS+=${SRCS.${_o}}
19135c4406dSWarner Losh.endfor
19235c4406dSWarner Losh
193639a2e50SGarrett WollmanOBJS+=	${SRCS:N*.h:R:S/$/.o/g}
194639a2e50SGarrett Wollman
195639a2e50SGarrett Wollman.if !defined(PROG)
19690f60fc9SMike SmithPROG=	${KMOD}.ko
19790f60fc9SMike Smith.endif
198639a2e50SGarrett Wollman
199817b59bfSRuslan Ermilov.if !defined(DEBUG_FLAGS)
200f6611608SSheldon HearnFULLPROG=	${PROG}
201f6611608SSheldon Hearn.else
20205117b57SEd MasteFULLPROG=	${PROG}.full
2035852ae2dSBryan Drewery${PROG}: ${FULLPROG} ${PROG}.debug
20405117b57SEd Maste	${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROG}.debug \
20598b45a8fSRuslan Ermilov	    ${FULLPROG} ${.TARGET}
2065852ae2dSBryan Drewery${PROG}.debug: ${FULLPROG}
20798b45a8fSRuslan Ermilov	${OBJCOPY} --only-keep-debug ${FULLPROG} ${.TARGET}
208f6611608SSheldon Hearn.endif
209f6611608SSheldon Hearn
2103a0d123eSWarner Losh.if ${__KLD_SHARED} == yes
2115852ae2dSBryan Drewery${FULLPROG}: ${KMOD}.kld
2128598392cSKonstantin Belousov.if ${MACHINE_CPUARCH} != "aarch64"
2135b6dc2efSSimon J. Gerraty	${LD} -Bshareable ${_LDFLAGS} -o ${.TARGET} ${KMOD}.kld
2148598392cSKonstantin Belousov.else
2158598392cSKonstantin Belousov#XXXKIB Relocatable linking in aarch64 ld from binutils 2.25.1 does
2168598392cSKonstantin Belousov#       not work.  The linker corrupts the references to the external
2178598392cSKonstantin Belousov#       symbols which are defined by other object in the linking set
2188598392cSKonstantin Belousov#       and should therefore loose the GOT entry.  The problem seems
2198598392cSKonstantin Belousov#       to be fixed in the binutils-gdb git HEAD as of 2015-10-04.  Hack
2208598392cSKonstantin Belousov#       below allows to get partially functioning modules for now.
2218598392cSKonstantin Belousov	${LD} -Bshareable ${_LDFLAGS} -o ${.TARGET} ${OBJS}
2228598392cSKonstantin Belousov.endif
223817b59bfSRuslan Ermilov.if !defined(DEBUG_FLAGS)
224817b59bfSRuslan Ermilov	${OBJCOPY} --strip-debug ${.TARGET}
2254c293d35SRuslan Ermilov.endif
2264d6bcc83SPeter Wemm.endif
22709be11baSPeter Wemm
22893f03548SMike SmithEXPORT_SYMS?=	NO
22993f03548SMike Smith.if ${EXPORT_SYMS} != YES
2301f089616SRuslan ErmilovCLEANFILES+=	export_syms
2310b3178a4SMike Smith.endif
2320b3178a4SMike Smith
2333a0d123eSWarner Losh.if ${__KLD_SHARED} == yes
2345852ae2dSBryan Drewery${KMOD}.kld: ${OBJS}
2354d6bcc83SPeter Wemm.else
2365852ae2dSBryan Drewery${FULLPROG}: ${OBJS}
2374d6bcc83SPeter Wemm.endif
2385b6dc2efSSimon J. Gerraty	${LD} ${_LDFLAGS} -r -d -o ${.TARGET} ${OBJS}
239724afafaSWarner Losh.if ${MK_CTF} != "no"
240cd49c2e8SMax Khon	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
241cd49c2e8SMax Khon.endif
2420b3178a4SMike Smith.if defined(EXPORT_SYMS)
24393f03548SMike Smith.if ${EXPORT_SYMS} != YES
2440b3178a4SMike Smith.if ${EXPORT_SYMS} == NO
2458b3ae668SDag-Erling Smørgrav	:> export_syms
2460b3178a4SMike Smith.elif !exists(${.CURDIR}/${EXPORT_SYMS})
2471f089616SRuslan Ermilov	echo ${EXPORT_SYMS} > export_syms
2480b3178a4SMike Smith.else
2491f089616SRuslan Ermilov	grep -v '^#' < ${EXPORT_SYMS} > export_syms
2500b3178a4SMike Smith.endif
25111f1d284SMark Johnston	${AWK} -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \
2521f089616SRuslan Ermilov	    export_syms | xargs -J% ${OBJCOPY} % ${.TARGET}
25393f03548SMike Smith.endif
2540b3178a4SMike Smith.endif
2553a0d123eSWarner Losh.if !defined(DEBUG_FLAGS) && ${__KLD_SHARED} == no
2564d6bcc83SPeter Wemm	${OBJCOPY} --strip-debug ${.TARGET}
2574d6bcc83SPeter Wemm.endif
2580b3178a4SMike Smith
259528013d5SWarner Losh_ILINKS=machine
2608598392cSKonstantin Belousov.if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64"
261915b4b09SNathan Whitehorn_ILINKS+=${MACHINE_CPUARCH}
262df3a103dSWarner Losh.endif
263544de89dSJohn Baldwin.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
264544de89dSJohn Baldwin_ILINKS+=x86
265544de89dSJohn Baldwin.endif
26631a01497SSean BrunoCLEANFILES+=${_ILINKS}
267639a2e50SGarrett Wollman
2681bd4272fSBryan Dreweryall: ${PROG}
2694a2d2630SBruce Evans
270db00e6c5SDavid E. O'Brienbeforedepend: ${_ILINKS}
27168d96923SBryan Drewerybeforebuild: ${_ILINKS}
272985f41afSWarner Losh
273f3cc9575SWarner Losh# Ensure that the links exist without depending on it when it exists which
274f3cc9575SWarner Losh# causes all the modules to be rebuilt when the directory pointed to changes.
275f3cc9575SWarner Losh.for _link in ${_ILINKS}
276f3cc9575SWarner Losh.if !exists(${.OBJDIR}/${_link})
2778cf80600SSimon J. Gerraty${OBJS}: ${_link}
278f3cc9575SWarner Losh.endif
279f3cc9575SWarner Losh.endfor
2804a2d2630SBruce Evans
2817750ad47SMarcel Moolenaar.NOPATH: ${_ILINKS}
2823c4368b2SMark Johnston
2834a2d2630SBruce Evans${_ILINKS}:
2849a8631b3SWarner Losh	@case ${.TARGET} in \
285df3a103dSWarner Losh	machine) \
286df3a103dSWarner Losh		path=${SYSDIR}/${MACHINE}/include ;; \
287544de89dSJohn Baldwin	*) \
2883c4368b2SMark Johnston		path=${SYSDIR}/${.TARGET:T}/include ;; \
28908a04a89SPeter Wemm	esac ; \
29008a04a89SPeter Wemm	path=`(cd $$path && /bin/pwd)` ; \
2913c4368b2SMark Johnston	${ECHO} ${.TARGET:T} "->" $$path ; \
292292c5292SBryan Drewery	ln -fhs $$path ${.TARGET:T}
2934a2d2630SBruce Evans
29474465532SRuslan ErmilovCLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS}
295361186e5SMaxime Henrion
296817b59bfSRuslan Ermilov.if defined(DEBUG_FLAGS)
29705117b57SEd MasteCLEANFILES+= ${FULLPROG} ${PROG}.debug
298361186e5SMaxime Henrion.endif
299639a2e50SGarrett Wollman
300639a2e50SGarrett Wollman.if !target(install)
301639a2e50SGarrett Wollman
302ea87b3cbSDavid E. O'Brien_INSTALLFLAGS:=	${INSTALLFLAGS}
303e902c1bbSTim Vanderhoek.for ie in ${INSTALLFLAGS_EDIT}
304e902c1bbSTim Vanderhoek_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
305e902c1bbSTim Vanderhoek.endfor
306e902c1bbSTim Vanderhoek
3072b06260dSRuslan Ermilov.if !target(realinstall)
30805117b57SEd MasteKERN_DEBUGDIR?=	${DEBUGDIR}
3092b06260dSRuslan Ermilovrealinstall: _kmodinstall
3102b06260dSRuslan Ermilov.ORDER: beforeinstall _kmodinstall
31149773547SBryan Drewery_kmodinstall: .PHONY
3121c6eb1b2SBaptiste Daroussin	${INSTALL} -T release -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
3130ed70e42SBryan Drewery	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}/
314cd95660fSDavid E. O'Brien.if defined(DEBUG_FLAGS) && !defined(INSTALL_NODEBUG) && ${MK_KERNEL_SYMBOLS} != "no"
3151c6eb1b2SBaptiste Daroussin	${INSTALL} -T debug -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
3160ed70e42SBryan Drewery	    ${_INSTALLFLAGS} ${PROG}.debug ${DESTDIR}${KERN_DEBUGDIR}${KMODDIR}/
317d24864f7SRuslan Ermilov.endif
3182b06260dSRuslan Ermilov
3192b06260dSRuslan Ermilov.include <bsd.links.mk>
3202b06260dSRuslan Ermilov
3214875819cSJake Burkholder.if !defined(NO_XREF)
3222b06260dSRuslan Ermilovafterinstall: _kldxref
3232b06260dSRuslan Ermilov.ORDER: realinstall _kldxref
3242b06260dSRuslan Ermilov.ORDER: _installlinks _kldxref
32549773547SBryan Drewery_kldxref: .PHONY
326be1d673dSRuslan Ermilov	@if type kldxref >/dev/null 2>&1; then \
327be1d673dSRuslan Ermilov		${ECHO} kldxref ${DESTDIR}${KMODDIR}; \
328be1d673dSRuslan Ermilov		kldxref ${DESTDIR}${KMODDIR}; \
329be1d673dSRuslan Ermilov	fi
330505222d3SPeter Wemm.endif
33122a8b405SMaxime Henrion.endif # !target(realinstall)
332639a2e50SGarrett Wollman
33322a8b405SMaxime Henrion.endif # !target(install)
334639a2e50SGarrett Wollman
335639a2e50SGarrett Wollman.if !target(load)
33649773547SBryan Dreweryload: ${PROG} .PHONY
3371f089616SRuslan Ermilov	${KMODLOAD} -v ${.OBJDIR}/${PROG}
338639a2e50SGarrett Wollman.endif
339639a2e50SGarrett Wollman
340639a2e50SGarrett Wollman.if !target(unload)
34149773547SBryan Dreweryunload: .PHONY
34293bffaf2SDag-Erling Smørgrav	if ${KMODISLOADED} ${PROG} ; then ${KMODUNLOAD} -v ${PROG} ; fi
34393bffaf2SDag-Erling Smørgrav.endif
34493bffaf2SDag-Erling Smørgrav
34593bffaf2SDag-Erling Smørgrav.if !target(reload)
34649773547SBryan Dreweryreload: unload load .PHONY
34708a04a89SPeter Wemm.endif
3481aa57be3SGarrett Wollman
3496b1bb559SWarner Losh.if defined(KERNBUILDDIR)
3506b1bb559SWarner Losh.PATH: ${KERNBUILDDIR}
3516b1bb559SWarner LoshCFLAGS+=	-I${KERNBUILDDIR}
3526b1bb559SWarner Losh.for _src in ${SRCS:Mopt_*.h}
3536b1bb559SWarner LoshCLEANFILES+=	${_src}
3546b1bb559SWarner Losh.if !target(${_src})
3556b1bb559SWarner Losh${_src}:
35640244cc2SDavid E. O'Brien	ln -sf ${KERNBUILDDIR}/${_src} ${.TARGET}
3576b1bb559SWarner Losh.endif
3586b1bb559SWarner Losh.endfor
3596b1bb559SWarner Losh.else
3604fea6704SBruce Evans.for _src in ${SRCS:Mopt_*.h}
3614fea6704SBruce EvansCLEANFILES+=	${_src}
3624fea6704SBruce Evans.if !target(${_src})
3634fea6704SBruce Evans${_src}:
3648b3ae668SDag-Erling Smørgrav	:> ${.TARGET}
3654fea6704SBruce Evans.endif
3664fea6704SBruce Evans.endfor
3676b1bb559SWarner Losh.endif
3684fea6704SBruce Evans
3693fd1e05bSAlexander Leidinger# Respect configuration-specific C flags.
37062769330SAlexander LeidingerCFLAGS+=	${CONF_CFLAGS}
37162769330SAlexander Leidinger
372a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Mvnode_if.c)
37378b2c868SBrian FeldmanCLEANFILES+=	vnode_if.c
374528013d5SWarner Loshvnode_if.c: ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src
375528013d5SWarner Losh	${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -c
3764fea6704SBruce Evans.endif
37778b2c868SBrian Feldman
378a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Mvnode_if.h)
3799f73f0e8SRuslan ErmilovCLEANFILES+=	vnode_if.h vnode_if_newproto.h vnode_if_typedef.h
380528013d5SWarner Loshvnode_if.h vnode_if_newproto.h vnode_if_typedef.h: ${SYSDIR}/tools/vnode_if.awk \
381528013d5SWarner Losh    ${SYSDIR}/kern/vnode_if.src
3829f73f0e8SRuslan Ermilovvnode_if.h: vnode_if_newproto.h vnode_if_typedef.h
383528013d5SWarner Losh	${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -h
3849f73f0e8SRuslan Ermilovvnode_if_newproto.h:
385528013d5SWarner Losh	${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -p
3869f73f0e8SRuslan Ermilovvnode_if_typedef.h:
387528013d5SWarner Losh	${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -q
38878b2c868SBrian Feldman.endif
3891aa57be3SGarrett Wollman
39012f05b84SWarner Losh# Build _if.[ch] from _if.m, and clean them when we're done.
391ec4047adSBryan Drewery# __MPATH defined in config.mk
3922cd2ff0eSJohn Baldwin_MFILES=${__MPATH:T:O}
3932cd2ff0eSJohn Baldwin_MPATH=${__MPATH:H:O:u}
39412f05b84SWarner Losh.PATH.m: ${_MPATH}
395160c44feSWarner Losh.for _i in ${SRCS:M*_if.[ch]}
3962cd2ff0eSJohn Baldwin_MATCH=M${_i:R:S/$/.m/}
3972cd2ff0eSJohn Baldwin_MATCHES=${_MFILES:${_MATCH}}
3982cd2ff0eSJohn Baldwin.if !empty(_MATCHES)
3992cd2ff0eSJohn BaldwinCLEANFILES+=	${_i}
4002cd2ff0eSJohn Baldwin.endif
401160c44feSWarner Losh.endfor # _i
4025852ae2dSBryan Drewery.m.c:	${SYSDIR}/tools/makeobjops.awk
40312f05b84SWarner Losh	${AWK} -f ${SYSDIR}/tools/makeobjops.awk ${.IMPSRC} -c
40412f05b84SWarner Losh
4055852ae2dSBryan Drewery.m.h:	${SYSDIR}/tools/makeobjops.awk
40612f05b84SWarner Losh	${AWK} -f ${SYSDIR}/tools/makeobjops.awk ${.IMPSRC} -h
40712f05b84SWarner Losh
4084e91eaf2SWarner Losh.for _i in mii pccard
409a7d30e5fSDavid E. O'Brien.if !empty(SRCS:M${_i}devs.h)
410dba6dd17SWarner LoshCLEANFILES+=	${_i}devs.h
4115852ae2dSBryan Drewery${_i}devs.h: ${SYSDIR}/tools/${_i}devs2h.awk ${SYSDIR}/dev/${_i}/${_i}devs
412528013d5SWarner Losh	${AWK} -f ${SYSDIR}/tools/${_i}devs2h.awk ${SYSDIR}/dev/${_i}/${_i}devs
4132d3ce713SDavid E. O'Brien.endif
414dba6dd17SWarner Losh.endfor # _i
4152d3ce713SDavid E. O'Brien
416e83ce340SAdrian Chadd.if !empty(SRCS:Mbhnd_nvram_map.h)
417e83ce340SAdrian ChaddCLEANFILES+=	bhnd_nvram_map.h
418e83ce340SAdrian Chaddbhnd_nvram_map.h: ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.awk \
419e83ce340SAdrian Chadd    ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.sh \
4205852ae2dSBryan Drewery    ${SYSDIR}/dev/bhnd/nvram/nvram_map
4215852ae2dSBryan Drewerybhnd_nvram_map.h:
42216fba18fSDimitry Andric	sh ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.sh \
423e83ce340SAdrian Chadd	    ${SYSDIR}/dev/bhnd/nvram/nvram_map -h
424e83ce340SAdrian Chadd.endif
425e83ce340SAdrian Chadd
426e83ce340SAdrian Chadd.if !empty(SRCS:Mbhnd_nvram_map_data.h)
427e83ce340SAdrian ChaddCLEANFILES+=	bhnd_nvram_map_data.h
428e83ce340SAdrian Chaddbhnd_nvram_map_data.h: ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.awk \
429e83ce340SAdrian Chadd    ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.sh \
4305852ae2dSBryan Drewery    ${SYSDIR}/dev/bhnd/nvram/nvram_map
4315852ae2dSBryan Drewerybhnd_nvram_map_data.h:
43216fba18fSDimitry Andric	sh ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.sh \
433e83ce340SAdrian Chadd	    ${SYSDIR}/dev/bhnd/nvram/nvram_map -d
434e83ce340SAdrian Chadd.endif
435e83ce340SAdrian Chadd
436a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Musbdevs.h)
4374e91eaf2SWarner LoshCLEANFILES+=	usbdevs.h
4385852ae2dSBryan Dreweryusbdevs.h: ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs
439528013d5SWarner Losh	${AWK} -f ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs -h
4404e91eaf2SWarner Losh.endif
4414e91eaf2SWarner Losh
442a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Musbdevs_data.h)
4434e91eaf2SWarner LoshCLEANFILES+=	usbdevs_data.h
4445852ae2dSBryan Dreweryusbdevs_data.h: ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs
445528013d5SWarner Losh	${AWK} -f ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs -d
4464e91eaf2SWarner Losh.endif
4474e91eaf2SWarner Losh
448a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Macpi_quirks.h)
449684c1c1dSNate LawsonCLEANFILES+=	acpi_quirks.h
4505852ae2dSBryan Dreweryacpi_quirks.h: ${SYSDIR}/tools/acpi_quirks2h.awk ${SYSDIR}/dev/acpica/acpi_quirks
451528013d5SWarner Losh	${AWK} -f ${SYSDIR}/tools/acpi_quirks2h.awk ${SYSDIR}/dev/acpica/acpi_quirks
452684c1c1dSNate Lawson.endif
453684c1c1dSNate Lawson
454a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Massym.s)
455705d63cdSIan DowseCLEANFILES+=	assym.s genassym.o
456705d63cdSIan Dowseassym.s: genassym.o
45788314df8SJohn Baldwin.if defined(KERNBUILDDIR)
45888314df8SJohn Baldwingenassym.o: opt_global.h
45988314df8SJohn Baldwin.endif
4605852ae2dSBryan Dreweryassym.s: ${SYSDIR}/kern/genassym.sh
461528013d5SWarner Losh	sh ${SYSDIR}/kern/genassym.sh genassym.o > ${.TARGET}
4627dd824c3SEd Mastegenassym.o: ${SYSDIR}/${MACHINE}/${MACHINE}/genassym.c
4635852ae2dSBryan Drewerygenassym.o: ${SRCS:Mopt_*.h}
464705d63cdSIan Dowse	${CC} -c ${CFLAGS:N-fno-common} \
4657dd824c3SEd Maste	    ${SYSDIR}/${MACHINE}/${MACHINE}/genassym.c
466705d63cdSIan Dowse.endif
467705d63cdSIan Dowse
468766f7d6eSMark Murraylint: ${SRCS}
469bbb467cdSRuslan Ermilov	${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC:M*.c}
470766f7d6eSMark Murray
47188314df8SJohn Baldwin.if defined(KERNBUILDDIR)
47288314df8SJohn Baldwin${OBJS}: opt_global.h
47388314df8SJohn Baldwin.endif
47488314df8SJohn Baldwin
475de1a3bd9SBryan DreweryCLEANDEPENDFILES+=	${_ILINKS}
47674465532SRuslan Ermilov# .depend needs include links so we remove them only together.
47774465532SRuslan Ermilovcleanilinks:
47874465532SRuslan Ermilov	rm -f ${_ILINKS}
47974465532SRuslan Ermilov
480d7beff08SBryan DreweryOBJS_DEPEND_GUESS+= ${SRCS:M*.h}
48188fe1f7aSBryan Drewery
48288fe1f7aSBryan Drewery.include <bsd.dep.mk>
483aae63957SBryan Drewery.include <bsd.clang-analyze.mk>
484afba897fSBruce Evans.include <bsd.obj.mk>
485ddc474a8SRuslan Ermilov.include "kern.mk"
486