xref: /freebsd/sys/conf/kmod.mk (revision 0ed70e428de8bd1f6cad836356b86c32c7fabd2e)
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#
311f089616SRuslan Ermilov# PROG		The name of the kernel module to build.
321f089616SRuslan Ermilov#		If not supplied, ${KMOD}.ko is used.
331f089616SRuslan Ermilov#
341f089616SRuslan Ermilov# SRCS		List of source files.
351f089616SRuslan Ermilov#
366aec1278SMax Laier# FIRMWS	List of firmware images in format filename:shortname:version
376aec1278SMax Laier#
3841e80f2aSFlorent Thoumie# FIRMWARE_LICENSE
397bd6fde3SFlorent Thoumie#		Set to the name of the license the user has to agree on in
407bd6fde3SFlorent Thoumie#		order to use this firmware. See /usr/share/doc/legal
417bd6fde3SFlorent Thoumie#
421f089616SRuslan Ermilov# DESTDIR	The tree where the module gets installed. [not set]
430b3178a4SMike Smith#
4453996fadSWolfram Schneider# +++ targets +++
4553996fadSWolfram Schneider#
4653996fadSWolfram Schneider# 	install:
4717d6c636SRuslan Ermilov#               install the kernel module; if the Makefile
4853996fadSWolfram Schneider#               does not itself define the target install, the targets
4953996fadSWolfram Schneider#               beforeinstall and afterinstall may also be used to cause
5053996fadSWolfram Schneider#               actions immediately before and after the install target
5153996fadSWolfram Schneider#		is executed.
5253996fadSWolfram Schneider#
5353996fadSWolfram Schneider# 	load:
541f089616SRuslan Ermilov#		Load a module.
5553996fadSWolfram Schneider#
5653996fadSWolfram Schneider# 	unload:
571f089616SRuslan Ermilov#		Unload a module.
5853996fadSWolfram Schneider#
59639a2e50SGarrett Wollman
60b7bbb709SDavid E. O'BrienAWK?=		awk
61fe3cac87SNick HibmaKMODLOAD?=	/sbin/kldload
62fe3cac87SNick HibmaKMODUNLOAD?=	/sbin/kldunload
63f6611608SSheldon HearnOBJCOPY?=	objcopy
647bc830bbSWolfram Schneider
650ac2fc87SRuslan Ermilov.include <bsd.init.mk>
66b0a8d404SWarner Losh# Grab all the options for a kernel build. For backwards compat, we need to
67b0a8d404SWarner Losh# do this after bsd.own.mk.
68b0a8d404SWarner Losh.include "kern.opts.mk"
699215d178SBrooks Davis.include <bsd.compiler.mk>
7035c4406dSWarner Losh.include "config.mk"
71639a2e50SGarrett Wollman
7212f05b84SWarner Losh.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S .m
73639a2e50SGarrett Wollman
743a0d123eSWarner Losh# amd64 and mips use direct linking for kmod, all others use shared binaries
753a0d123eSWarner Losh.if ${MACHINE_CPUARCH} != amd64 && ${MACHINE_CPUARCH} != mips
763a0d123eSWarner Losh__KLD_SHARED=yes
773a0d123eSWarner Losh.else
783a0d123eSWarner Losh__KLD_SHARED=no
793a0d123eSWarner Losh.endif
803a0d123eSWarner Losh
81f165cb7cSRuslan Ermilov.if !empty(CFLAGS:M-O[23s]) && empty(CFLAGS:M-fno-strict-aliasing)
82db0cd7e1SDavid E. O'BrienCFLAGS+=	-fno-strict-aliasing
83db0cd7e1SDavid E. O'Brien.endif
845d3b2922SRuslan ErmilovWERROR?=	-Werror
85daaea395SWarner LoshCFLAGS+=	${WERROR}
8648aea4daSRuslan ErmilovCFLAGS+=	-D_KERNEL
878fe644b2SMike SmithCFLAGS+=	-DKLD_MODULE
884a2d2630SBruce Evans
89021886ffSBruce Evans# Don't use any standard or source-relative include directories.
9006d6e4fcSTom RhodesNOSTDINC=	-nostdinc
91da3bcc92SAlexander KabaevCFLAGS:=	${CFLAGS:N-I*} ${NOSTDINC} ${INCLMAGIC} ${CFLAGS:M-I*}
928fa793d0SBrian Feldman.if defined(KERNBUILDDIR)
930c063641SGleb SmirnoffCFLAGS+=	-DHAVE_KERNEL_OPTION_HEADERS -include ${KERNBUILDDIR}/opt_global.h
948fa793d0SBrian Feldman.endif
95021886ffSBruce Evans
961f089616SRuslan Ermilov# Add -I paths for system headers.  Individual module makefiles don't
97021886ffSBruce Evans# need any -I paths for this.  Similar defaults for .PATH can't be
98021886ffSBruce Evans# set because there are no standard paths for non-headers.
99528013d5SWarner LoshCFLAGS+=	-I. -I${SYSDIR}
1004a2d2630SBruce Evans
10122ba0b2fSWarner LoshCFLAGS.gcc+=	-finline-limit=${INLINE_LIMIT}
102cc4a90c4SGleb SmirnoffCFLAGS.gcc+=	-fms-extensions
10322ba0b2fSWarner LoshCFLAGS.gcc+= --param inline-unit-growth=100
10422ba0b2fSWarner LoshCFLAGS.gcc+= --param large-function-growth=1000
1052a51529fSPeter Wemm
1060b3178a4SMike Smith# Disallow common variables, and if we end up with commons from
1070b3178a4SMike Smith# somewhere unexpected, allocate storage for them in the module itself.
1080b3178a4SMike SmithCFLAGS+=	-fno-common
1090b3178a4SMike SmithLDFLAGS+=	-d -warn-common
1100b3178a4SMike Smith
1119e4be63dSBruce EvansCFLAGS+=	${DEBUG_FLAGS}
1123a0d123eSWarner Losh.if ${MACHINE_CPUARCH} == amd64
1132565edc4SAndriy GaponCFLAGS+=	-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer
11483c457dcSIan Dowse.endif
1159e4be63dSBruce Evans
1168598392cSKonstantin Belousov.if ${MACHINE_CPUARCH} == "aarch64"
1178598392cSKonstantin BelousovCFLAGS+=	-fPIC
1188598392cSKonstantin Belousov.endif
1198598392cSKonstantin Belousov
120b54c389fSIan Lepore# Temporary workaround for PR 196407, which contains the fascinating details.
121c6f7b900SIan Lepore# Don't allow clang to use fpu instructions or registers in kernel modules.
122b54c389fSIan Lepore.if ${MACHINE_CPUARCH} == arm
123b54c389fSIan LeporeCFLAGS.clang+=	-mllvm -arm-use-movt=0
124c6f7b900SIan LeporeCFLAGS.clang+=	-mfpu=none
1251b23f9b9SAndrew TurnerCFLAGS+=	-funwind-tables
126b54c389fSIan Lepore.endif
127b54c389fSIan Lepore
1283a0d123eSWarner Losh.if ${MACHINE_CPUARCH} == powerpc
12955a5dcc8SPeter GrehanCFLAGS+=	-mlongcall -fno-omit-frame-pointer
130fded756eSPeter Grehan.endif
131fded756eSPeter Grehan
1323a0d123eSWarner Losh.if ${MACHINE_CPUARCH} == mips
1336f3c6327SNeel NatuCFLAGS+=	-G0 -fno-pic -mno-abicalls -mlong-calls
1346f3c6327SNeel Natu.endif
1356f3c6327SNeel Natu
13669745d38SAlexander Leidinger.if defined(DEBUG) || defined(DEBUG_FLAGS)
13769745d38SAlexander LeidingerCTFFLAGS+=	-g
13869745d38SAlexander Leidinger.endif
13969745d38SAlexander Leidinger
1406aec1278SMax Laier.if defined(FIRMWS)
141528013d5SWarner Losh${KMOD:S/$/.c/}: ${SYSDIR}/tools/fw_stub.awk
142528013d5SWarner Losh	${AWK} -f ${SYSDIR}/tools/fw_stub.awk ${FIRMWS} -m${KMOD} -c${KMOD:S/$/.c/g} \
1437bd6fde3SFlorent Thoumie	    ${FIRMWARE_LICENSE:C/.+/-l/}${FIRMWARE_LICENSE}
1446aec1278SMax Laier
1456aec1278SMax LaierSRCS+=	${KMOD:S/$/.c/}
1466aec1278SMax LaierCLEANFILES+=	${KMOD:S/$/.c/}
1476aec1278SMax Laier
1486aec1278SMax Laier.for _firmw in ${FIRMWS}
1496aec1278SMax Laier${_firmw:C/\:.*$/.fwo/}:	${_firmw:C/\:.*$//}
1506aec1278SMax Laier	@${ECHO} ${_firmw:C/\:.*$//} ${.ALLSRC:M*${_firmw:C/\:.*$//}}
151009b3d3dSMax Laier	@if [ -e ${_firmw:C/\:.*$//} ]; then			\
1525b6dc2efSSimon J. Gerraty		${LD} -b binary --no-warn-mismatch ${_LDFLAGS}	\
153ba6a2bb3SMarcel Moolenaar		    -r -d -o ${.TARGET}	${_firmw:C/\:.*$//};	\
154ff8e7669SMax Laier	else							\
155ff8e7669SMax Laier		ln -s ${.ALLSRC:M*${_firmw:C/\:.*$//}} ${_firmw:C/\:.*$//}; \
1565b6dc2efSSimon J. Gerraty		${LD} -b binary --no-warn-mismatch ${_LDFLAGS}	\
157ba6a2bb3SMarcel Moolenaar		    -r -d -o ${.TARGET}	${_firmw:C/\:.*$//};	\
158ff8e7669SMax Laier		rm ${_firmw:C/\:.*$//};				\
159ff8e7669SMax Laier	fi
1606aec1278SMax Laier
1616aec1278SMax LaierOBJS+=	${_firmw:C/\:.*$/.fwo/}
1626aec1278SMax Laier.endfor
1636aec1278SMax Laier.endif
1646aec1278SMax Laier
16535c4406dSWarner Losh# Conditionally include SRCS based on kernel config options.
16635c4406dSWarner Losh.for _o in ${KERN_OPTS}
16735c4406dSWarner LoshSRCS+=${SRCS.${_o}}
16835c4406dSWarner Losh.endfor
16935c4406dSWarner Losh
170639a2e50SGarrett WollmanOBJS+=	${SRCS:N*.h:R:S/$/.o/g}
171639a2e50SGarrett Wollman
172639a2e50SGarrett Wollman.if !defined(PROG)
17390f60fc9SMike SmithPROG=	${KMOD}.ko
17490f60fc9SMike Smith.endif
175639a2e50SGarrett Wollman
176817b59bfSRuslan Ermilov.if !defined(DEBUG_FLAGS)
177f6611608SSheldon HearnFULLPROG=	${PROG}
178f6611608SSheldon Hearn.else
17905117b57SEd MasteFULLPROG=	${PROG}.full
18005117b57SEd Maste${PROG}: ${FULLPROG} ${PROG}.debug
18105117b57SEd Maste	${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROG}.debug \
18298b45a8fSRuslan Ermilov	    ${FULLPROG} ${.TARGET}
18305117b57SEd Maste${PROG}.debug: ${FULLPROG}
18498b45a8fSRuslan Ermilov	${OBJCOPY} --only-keep-debug ${FULLPROG} ${.TARGET}
185f6611608SSheldon Hearn.endif
186f6611608SSheldon Hearn
1873a0d123eSWarner Losh.if ${__KLD_SHARED} == yes
188f6611608SSheldon Hearn${FULLPROG}: ${KMOD}.kld
1898598392cSKonstantin Belousov.if ${MACHINE_CPUARCH} != "aarch64"
1905b6dc2efSSimon J. Gerraty	${LD} -Bshareable ${_LDFLAGS} -o ${.TARGET} ${KMOD}.kld
1918598392cSKonstantin Belousov.else
1928598392cSKonstantin Belousov#XXXKIB Relocatable linking in aarch64 ld from binutils 2.25.1 does
1938598392cSKonstantin Belousov#       not work.  The linker corrupts the references to the external
1948598392cSKonstantin Belousov#       symbols which are defined by other object in the linking set
1958598392cSKonstantin Belousov#       and should therefore loose the GOT entry.  The problem seems
1968598392cSKonstantin Belousov#       to be fixed in the binutils-gdb git HEAD as of 2015-10-04.  Hack
1978598392cSKonstantin Belousov#       below allows to get partially functioning modules for now.
1988598392cSKonstantin Belousov	${LD} -Bshareable ${_LDFLAGS} -o ${.TARGET} ${OBJS}
1998598392cSKonstantin Belousov.endif
200817b59bfSRuslan Ermilov.if !defined(DEBUG_FLAGS)
201817b59bfSRuslan Ermilov	${OBJCOPY} --strip-debug ${.TARGET}
2024c293d35SRuslan Ermilov.endif
2034d6bcc83SPeter Wemm.endif
20409be11baSPeter Wemm
20593f03548SMike SmithEXPORT_SYMS?=	NO
20693f03548SMike Smith.if ${EXPORT_SYMS} != YES
2071f089616SRuslan ErmilovCLEANFILES+=	export_syms
2080b3178a4SMike Smith.endif
2090b3178a4SMike Smith
2103a0d123eSWarner Losh.if ${__KLD_SHARED} == yes
21109be11baSPeter Wemm${KMOD}.kld: ${OBJS}
2124d6bcc83SPeter Wemm.else
2134d6bcc83SPeter Wemm${FULLPROG}: ${OBJS}
2144d6bcc83SPeter Wemm.endif
2155b6dc2efSSimon J. Gerraty	${LD} ${_LDFLAGS} -r -d -o ${.TARGET} ${OBJS}
216724afafaSWarner Losh.if ${MK_CTF} != "no"
217cd49c2e8SMax Khon	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
218cd49c2e8SMax Khon.endif
2190b3178a4SMike Smith.if defined(EXPORT_SYMS)
22093f03548SMike Smith.if ${EXPORT_SYMS} != YES
2210b3178a4SMike Smith.if ${EXPORT_SYMS} == NO
2228b3ae668SDag-Erling Smørgrav	:> export_syms
2230b3178a4SMike Smith.elif !exists(${.CURDIR}/${EXPORT_SYMS})
2241f089616SRuslan Ermilov	echo ${EXPORT_SYMS} > export_syms
2250b3178a4SMike Smith.else
2261f089616SRuslan Ermilov	grep -v '^#' < ${EXPORT_SYMS} > export_syms
2270b3178a4SMike Smith.endif
2280b3178a4SMike Smith	awk -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \
2291f089616SRuslan Ermilov	    export_syms | xargs -J% ${OBJCOPY} % ${.TARGET}
23093f03548SMike Smith.endif
2310b3178a4SMike Smith.endif
2323a0d123eSWarner Losh.if !defined(DEBUG_FLAGS) && ${__KLD_SHARED} == no
2334d6bcc83SPeter Wemm	${OBJCOPY} --strip-debug ${.TARGET}
2344d6bcc83SPeter Wemm.endif
2350b3178a4SMike Smith
236528013d5SWarner Losh_ILINKS=machine
2378598392cSKonstantin Belousov.if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64"
238915b4b09SNathan Whitehorn_ILINKS+=${MACHINE_CPUARCH}
239df3a103dSWarner Losh.endif
240544de89dSJohn Baldwin.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
241544de89dSJohn Baldwin_ILINKS+=x86
242544de89dSJohn Baldwin.endif
24331a01497SSean BrunoCLEANFILES+=${_ILINKS}
244639a2e50SGarrett Wollman
245b25a566dSRuslan Ermilovall: objwarn ${PROG}
2464a2d2630SBruce Evans
247db00e6c5SDavid E. O'Brienbeforedepend: ${_ILINKS}
248985f41afSWarner Losh
249f3cc9575SWarner Losh# Ensure that the links exist without depending on it when it exists which
250f3cc9575SWarner Losh# causes all the modules to be rebuilt when the directory pointed to changes.
251f3cc9575SWarner Losh.for _link in ${_ILINKS}
252f3cc9575SWarner Losh.if !exists(${.OBJDIR}/${_link})
2538cf80600SSimon J. Gerraty${OBJS}: ${_link}
254f3cc9575SWarner Losh.endif
255f3cc9575SWarner Losh.endfor
2564a2d2630SBruce Evans
2579a8631b3SWarner Losh# Search for kernel source tree in standard places.
2589a8631b3SWarner Losh.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys
259776f50b9SRuslan Ermilov.if !defined(SYSDIR) && exists(${_dir}/kern/)
2609a8631b3SWarner LoshSYSDIR=	${_dir}
2619a8631b3SWarner Losh.endif
2629a8631b3SWarner Losh.endfor
263776f50b9SRuslan Ermilov.if !defined(SYSDIR) || !exists(${SYSDIR}/kern/)
2649a8631b3SWarner Losh.error "can't find kernel source tree"
2659a8631b3SWarner Losh.endif
2669a8631b3SWarner Losh
2677750ad47SMarcel Moolenaar.NOPATH: ${_ILINKS}
2683c4368b2SMark Johnston
2694a2d2630SBruce Evans${_ILINKS}:
2709a8631b3SWarner Losh	@case ${.TARGET} in \
271df3a103dSWarner Losh	machine) \
272df3a103dSWarner Losh		path=${SYSDIR}/${MACHINE}/include ;; \
273544de89dSJohn Baldwin	*) \
2743c4368b2SMark Johnston		path=${SYSDIR}/${.TARGET:T}/include ;; \
27508a04a89SPeter Wemm	esac ; \
27608a04a89SPeter Wemm	path=`(cd $$path && /bin/pwd)` ; \
2773c4368b2SMark Johnston	${ECHO} ${.TARGET:T} "->" $$path ; \
2783c4368b2SMark Johnston	ln -sf $$path ${.TARGET:T}
2794a2d2630SBruce Evans
28074465532SRuslan ErmilovCLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS}
281361186e5SMaxime Henrion
282817b59bfSRuslan Ermilov.if defined(DEBUG_FLAGS)
28305117b57SEd MasteCLEANFILES+= ${FULLPROG} ${PROG}.debug
284361186e5SMaxime Henrion.endif
285639a2e50SGarrett Wollman
286639a2e50SGarrett Wollman.if !target(install)
287639a2e50SGarrett Wollman
288ea87b3cbSDavid E. O'Brien_INSTALLFLAGS:=	${INSTALLFLAGS}
289e902c1bbSTim Vanderhoek.for ie in ${INSTALLFLAGS_EDIT}
290e902c1bbSTim Vanderhoek_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
291e902c1bbSTim Vanderhoek.endfor
292e902c1bbSTim Vanderhoek
2932b06260dSRuslan Ermilov.if !target(realinstall)
29405117b57SEd MasteKERN_DEBUGDIR?=	${DEBUGDIR}
2952b06260dSRuslan Ermilovrealinstall: _kmodinstall
2962b06260dSRuslan Ermilov.ORDER: beforeinstall _kmodinstall
2972b06260dSRuslan Ermilov_kmodinstall:
298d2893b16SRuslan Ermilov	${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
299*0ed70e42SBryan Drewery	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}/
300cd95660fSDavid E. O'Brien.if defined(DEBUG_FLAGS) && !defined(INSTALL_NODEBUG) && ${MK_KERNEL_SYMBOLS} != "no"
30198b45a8fSRuslan Ermilov	${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
302*0ed70e42SBryan Drewery	    ${_INSTALLFLAGS} ${PROG}.debug ${DESTDIR}${KERN_DEBUGDIR}${KMODDIR}/
303d24864f7SRuslan Ermilov.endif
3042b06260dSRuslan Ermilov
3052b06260dSRuslan Ermilov.include <bsd.links.mk>
3062b06260dSRuslan Ermilov
3074875819cSJake Burkholder.if !defined(NO_XREF)
3082b06260dSRuslan Ermilovafterinstall: _kldxref
3092b06260dSRuslan Ermilov.ORDER: realinstall _kldxref
3102b06260dSRuslan Ermilov.ORDER: _installlinks _kldxref
3112b06260dSRuslan Ermilov_kldxref:
312be1d673dSRuslan Ermilov	@if type kldxref >/dev/null 2>&1; then \
313be1d673dSRuslan Ermilov		${ECHO} kldxref ${DESTDIR}${KMODDIR}; \
314be1d673dSRuslan Ermilov		kldxref ${DESTDIR}${KMODDIR}; \
315be1d673dSRuslan Ermilov	fi
316505222d3SPeter Wemm.endif
31722a8b405SMaxime Henrion.endif # !target(realinstall)
318639a2e50SGarrett Wollman
31922a8b405SMaxime Henrion.endif # !target(install)
320639a2e50SGarrett Wollman
321639a2e50SGarrett Wollman.if !target(load)
3229a8631b3SWarner Loshload: ${PROG}
3231f089616SRuslan Ermilov	${KMODLOAD} -v ${.OBJDIR}/${PROG}
324639a2e50SGarrett Wollman.endif
325639a2e50SGarrett Wollman
326639a2e50SGarrett Wollman.if !target(unload)
327fe3cac87SNick Hibmaunload:
3281f089616SRuslan Ermilov	${KMODUNLOAD} -v ${PROG}
32908a04a89SPeter Wemm.endif
3301aa57be3SGarrett Wollman
3316b1bb559SWarner Losh.if defined(KERNBUILDDIR)
3326b1bb559SWarner Losh.PATH: ${KERNBUILDDIR}
3336b1bb559SWarner LoshCFLAGS+=	-I${KERNBUILDDIR}
3346b1bb559SWarner Losh.for _src in ${SRCS:Mopt_*.h}
3356b1bb559SWarner LoshCLEANFILES+=	${_src}
3366b1bb559SWarner Losh.if !target(${_src})
3376b1bb559SWarner Losh${_src}:
33840244cc2SDavid E. O'Brien	ln -sf ${KERNBUILDDIR}/${_src} ${.TARGET}
3396b1bb559SWarner Losh.endif
3406b1bb559SWarner Losh.endfor
3416b1bb559SWarner Losh.else
3424fea6704SBruce Evans.for _src in ${SRCS:Mopt_*.h}
3434fea6704SBruce EvansCLEANFILES+=	${_src}
3444fea6704SBruce Evans.if !target(${_src})
3454fea6704SBruce Evans${_src}:
3468b3ae668SDag-Erling Smørgrav	:> ${.TARGET}
3474fea6704SBruce Evans.endif
3484fea6704SBruce Evans.endfor
3496b1bb559SWarner Losh.endif
3504fea6704SBruce Evans
3513fd1e05bSAlexander Leidinger# Respect configuration-specific C flags.
35262769330SAlexander LeidingerCFLAGS+=	${CONF_CFLAGS}
35362769330SAlexander Leidinger
354a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Mvnode_if.c)
35578b2c868SBrian FeldmanCLEANFILES+=	vnode_if.c
356528013d5SWarner Loshvnode_if.c: ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src
357528013d5SWarner Losh	${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -c
3584fea6704SBruce Evans.endif
35978b2c868SBrian Feldman
360a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Mvnode_if.h)
3619f73f0e8SRuslan ErmilovCLEANFILES+=	vnode_if.h vnode_if_newproto.h vnode_if_typedef.h
362528013d5SWarner Loshvnode_if.h vnode_if_newproto.h vnode_if_typedef.h: ${SYSDIR}/tools/vnode_if.awk \
363528013d5SWarner Losh    ${SYSDIR}/kern/vnode_if.src
3649f73f0e8SRuslan Ermilovvnode_if.h: vnode_if_newproto.h vnode_if_typedef.h
365528013d5SWarner Losh	${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -h
3669f73f0e8SRuslan Ermilovvnode_if_newproto.h:
367528013d5SWarner Losh	${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -p
3689f73f0e8SRuslan Ermilovvnode_if_typedef.h:
369528013d5SWarner Losh	${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -q
37078b2c868SBrian Feldman.endif
3711aa57be3SGarrett Wollman
37212f05b84SWarner Losh# Build _if.[ch] from _if.m, and clean them when we're done.
3738cad626fSWarner Losh.if !defined(_MPATH)
37412f05b84SWarner Losh__MPATH!=find ${SYSDIR:tA}/ -name \*_if.m
37512f05b84SWarner Losh_MPATH=${__MPATH:H:O:u}
3768cad626fSWarner Losh.endif
37712f05b84SWarner Losh.PATH.m: ${_MPATH}
378160c44feSWarner Losh.for _i in ${SRCS:M*_if.[ch]}
379fd449cdfSWarner Losh#removes too much, comment out until it's more constrained.
380fd449cdfSWarner Losh#CLEANFILES+=	${_i}
381160c44feSWarner Losh.endfor # _i
38212f05b84SWarner Losh.m.c:	${SYSDIR}/tools/makeobjops.awk
38312f05b84SWarner Losh	${AWK} -f ${SYSDIR}/tools/makeobjops.awk ${.IMPSRC} -c
38412f05b84SWarner Losh
38512f05b84SWarner Losh.m.h:	${SYSDIR}/tools/makeobjops.awk
38612f05b84SWarner Losh	${AWK} -f ${SYSDIR}/tools/makeobjops.awk ${.IMPSRC} -h
38712f05b84SWarner Losh
3884e91eaf2SWarner Losh.for _i in mii pccard
389a7d30e5fSDavid E. O'Brien.if !empty(SRCS:M${_i}devs.h)
390dba6dd17SWarner LoshCLEANFILES+=	${_i}devs.h
391528013d5SWarner Losh${_i}devs.h: ${SYSDIR}/tools/${_i}devs2h.awk ${SYSDIR}/dev/${_i}/${_i}devs
392528013d5SWarner Losh	${AWK} -f ${SYSDIR}/tools/${_i}devs2h.awk ${SYSDIR}/dev/${_i}/${_i}devs
3932d3ce713SDavid E. O'Brien.endif
394dba6dd17SWarner Losh.endfor # _i
3952d3ce713SDavid E. O'Brien
396a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Musbdevs.h)
3974e91eaf2SWarner LoshCLEANFILES+=	usbdevs.h
398528013d5SWarner Loshusbdevs.h: ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs
399528013d5SWarner Losh	${AWK} -f ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs -h
4004e91eaf2SWarner Losh.endif
4014e91eaf2SWarner Losh
402a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Musbdevs_data.h)
4034e91eaf2SWarner LoshCLEANFILES+=	usbdevs_data.h
404528013d5SWarner Loshusbdevs_data.h: ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs
405528013d5SWarner Losh	${AWK} -f ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs -d
4064e91eaf2SWarner Losh.endif
4074e91eaf2SWarner Losh
408a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Macpi_quirks.h)
409684c1c1dSNate LawsonCLEANFILES+=	acpi_quirks.h
410528013d5SWarner Loshacpi_quirks.h: ${SYSDIR}/tools/acpi_quirks2h.awk ${SYSDIR}/dev/acpica/acpi_quirks
411528013d5SWarner Losh	${AWK} -f ${SYSDIR}/tools/acpi_quirks2h.awk ${SYSDIR}/dev/acpica/acpi_quirks
412684c1c1dSNate Lawson.endif
413684c1c1dSNate Lawson
414a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Massym.s)
415705d63cdSIan DowseCLEANFILES+=	assym.s genassym.o
416705d63cdSIan Dowseassym.s: genassym.o
41788314df8SJohn Baldwin.if defined(KERNBUILDDIR)
41888314df8SJohn Baldwingenassym.o: opt_global.h
41988314df8SJohn Baldwin.endif
420528013d5SWarner Loshassym.s: ${SYSDIR}/kern/genassym.sh
421528013d5SWarner Losh	sh ${SYSDIR}/kern/genassym.sh genassym.o > ${.TARGET}
4227dd824c3SEd Mastegenassym.o: ${SYSDIR}/${MACHINE}/${MACHINE}/genassym.c
4230c0fde95SWarner Loshgenassym.o: ${SRCS:Mopt_*.h}
424705d63cdSIan Dowse	${CC} -c ${CFLAGS:N-fno-common} \
4257dd824c3SEd Maste	    ${SYSDIR}/${MACHINE}/${MACHINE}/genassym.c
426705d63cdSIan Dowse.endif
427705d63cdSIan Dowse
428766f7d6eSMark Murraylint: ${SRCS}
429bbb467cdSRuslan Ermilov	${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC:M*.c}
430766f7d6eSMark Murray
43188314df8SJohn Baldwin.if defined(KERNBUILDDIR)
43288314df8SJohn Baldwin${OBJS}: opt_global.h
43388314df8SJohn Baldwin.endif
43488314df8SJohn Baldwin
43568e00b92SJordan K. Hubbard.include <bsd.dep.mk>
43647da63c3SBruce Evans
43774465532SRuslan Ermilovcleandepend: cleanilinks
43874465532SRuslan Ermilov# .depend needs include links so we remove them only together.
43974465532SRuslan Ermilovcleanilinks:
44074465532SRuslan Ermilov	rm -f ${_ILINKS}
44174465532SRuslan Ermilov
442f2bffe0fSRuslan Ermilov.if !exists(${.OBJDIR}/${DEPENDFILE})
443589d9341SBruce Evans${OBJS}: ${SRCS:M*.h}
44447da63c3SBruce Evans.endif
44547da63c3SBruce Evans
446afba897fSBruce Evans.include <bsd.obj.mk>
447ddc474a8SRuslan Ermilov.include "kern.mk"
448