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# 47e8dca53aSWarner Losh# KERNBUILDDIR Set to the location of the kernel build directory where 48489b536fSWarner Losh# the opt_*.h files, .o's and kernel winds up. 49489b536fSWarner Losh# 50e8dca53aSWarner Losh# BLOB_OBJS Prebuilt binary blobs .o's from the src tree to be linked into 51e8dca53aSWarner Losh# the module. These are precious and not removed in make clean. 52e8dca53aSWarner Losh# 5353996fadSWolfram Schneider# +++ targets +++ 5453996fadSWolfram Schneider# 5553996fadSWolfram Schneider# install: 5617d6c636SRuslan Ermilov# install the kernel module; if the Makefile 5753996fadSWolfram Schneider# does not itself define the target install, the targets 5853996fadSWolfram Schneider# beforeinstall and afterinstall may also be used to cause 5953996fadSWolfram Schneider# actions immediately before and after the install target 6053996fadSWolfram Schneider# is executed. 6153996fadSWolfram Schneider# 6253996fadSWolfram Schneider# load: 631f089616SRuslan Ermilov# Load a module. 6453996fadSWolfram Schneider# 6553996fadSWolfram Schneider# unload: 661f089616SRuslan Ermilov# Unload a module. 6753996fadSWolfram Schneider# 6893bffaf2SDag-Erling Smørgrav# reload: 6993bffaf2SDag-Erling Smørgrav# Unload if loaded, then load. 7093bffaf2SDag-Erling Smørgrav# 71639a2e50SGarrett Wollman 72b7bbb709SDavid E. O'BrienAWK?= awk 73fe3cac87SNick HibmaKMODLOAD?= /sbin/kldload 74fe3cac87SNick HibmaKMODUNLOAD?= /sbin/kldunload 7593bffaf2SDag-Erling SmørgravKMODISLOADED?= /sbin/kldstat -q -n 76f6611608SSheldon HearnOBJCOPY?= objcopy 777bc830bbSWolfram Schneider 789ab286b7SJohn Baldwin.include "kmod.opts.mk" 793cc5d6a4SWarner Losh.include <bsd.sysdir.mk> 805d4447e0SBryan Drewery 8112f05b84SWarner Losh.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S .m 82639a2e50SGarrett Wollman 83c09981f1SWarner Losh# amd64 uses direct linking for kmod, all others use shared binaries 84c09981f1SWarner Losh.if ${MACHINE_CPUARCH} != amd64 853a0d123eSWarner Losh__KLD_SHARED=yes 863a0d123eSWarner Losh.else 873a0d123eSWarner Losh__KLD_SHARED=no 883a0d123eSWarner Losh.endif 893a0d123eSWarner Losh 90f165cb7cSRuslan Ermilov.if !empty(CFLAGS:M-O[23s]) && empty(CFLAGS:M-fno-strict-aliasing) 91db0cd7e1SDavid E. O'BrienCFLAGS+= -fno-strict-aliasing 92db0cd7e1SDavid E. O'Brien.endif 935d3b2922SRuslan ErmilovWERROR?= -Werror 9417c12f64SWarner Losh 9515fe2513SKonstantin BelousovLINUXKPI_GENSRCS+= \ 962b68c973SEmmanuel Vadot backlight_if.h \ 9715fe2513SKonstantin Belousov bus_if.h \ 9815fe2513SKonstantin Belousov device_if.h \ 991961a14aSEmmanuel Vadot iicbus_if.h \ 1001961a14aSEmmanuel Vadot iicbb_if.h \ 1011961a14aSEmmanuel Vadot lkpi_iic_if.c \ 1021961a14aSEmmanuel Vadot lkpi_iic_if.h \ 10315fe2513SKonstantin Belousov pci_if.h \ 10415fe2513SKonstantin Belousov pci_iov_if.h \ 105de27805fSKonstantin Belousov pcib_if.h \ 10615fe2513SKonstantin Belousov vnode_if.h \ 10715fe2513SKonstantin Belousov usb_if.h \ 10815fe2513SKonstantin Belousov opt_usb.h \ 10915fe2513SKonstantin Belousov opt_stack.h 11015fe2513SKonstantin Belousov 111514fb387SBjoern A. ZeebLINUXKPI_INCLUDES+= \ 112*f8bad561SBjoern A. Zeeb -I${SYSDIR}/compat/linuxkpi/common/include \ 113*f8bad561SBjoern A. Zeeb -I${SYSDIR}/compat/linuxkpi/dummy/include 114514fb387SBjoern A. Zeeb 115daaea395SWarner LoshCFLAGS+= ${WERROR} 11648aea4daSRuslan ErmilovCFLAGS+= -D_KERNEL 1178fe644b2SMike SmithCFLAGS+= -DKLD_MODULE 118f4b36404SMatt Macy.if defined(MODULE_TIED) 119f4b36404SMatt MacyCFLAGS+= -DKLD_TIED 120f4b36404SMatt Macy.endif 1214a2d2630SBruce Evans 122021886ffSBruce Evans# Don't use any standard or source-relative include directories. 12306d6e4fcSTom RhodesNOSTDINC= -nostdinc 124da3bcc92SAlexander KabaevCFLAGS:= ${CFLAGS:N-I*} ${NOSTDINC} ${INCLMAGIC} ${CFLAGS:M-I*} 1258fa793d0SBrian Feldman.if defined(KERNBUILDDIR) 1260c063641SGleb SmirnoffCFLAGS+= -DHAVE_KERNEL_OPTION_HEADERS -include ${KERNBUILDDIR}/opt_global.h 1270c4c5948SKyle Evans.else 1280c4c5948SKyle EvansSRCS+= opt_global.h 1290c4c5948SKyle EvansCFLAGS+= -include ${.OBJDIR}/opt_global.h 1308fa793d0SBrian Feldman.endif 131021886ffSBruce Evans 1321f089616SRuslan Ermilov# Add -I paths for system headers. Individual module makefiles don't 133021886ffSBruce Evans# need any -I paths for this. Similar defaults for .PATH can't be 134021886ffSBruce Evans# set because there are no standard paths for non-headers. 1357bf272a6SMatt MacyCFLAGS+= -I. -I${SYSDIR} -I${SYSDIR}/contrib/ck/include 1364a2d2630SBruce Evans 13722ba0b2fSWarner LoshCFLAGS.gcc+= -finline-limit=${INLINE_LIMIT} 138cc4a90c4SGleb SmirnoffCFLAGS.gcc+= -fms-extensions 13922ba0b2fSWarner LoshCFLAGS.gcc+= --param inline-unit-growth=100 14022ba0b2fSWarner LoshCFLAGS.gcc+= --param large-function-growth=1000 1412a51529fSPeter Wemm 1420b3178a4SMike Smith# Disallow common variables, and if we end up with commons from 1430b3178a4SMike Smith# somewhere unexpected, allocate storage for them in the module itself. 1448eb1a0ceSKyle Evans# 1458eb1a0ceSKyle Evans# -fno-common is the default for src builds, but this should be left in place 1468eb1a0ceSKyle Evans# until at least we catch up to GCC10/LLVM11 or otherwise enable -fno-common 1478eb1a0ceSKyle Evans# in <bsd.sys.mk> instead. For now, we will have duplicate -fno-common in 1488eb1a0ceSKyle Evans# CFLAGS for in-tree module builds as they will also pick it up from 1498eb1a0ceSKyle Evans# share/mk/src.sys.mk, but the following is important for out-of-tree modules 1508eb1a0ceSKyle Evans# (e.g. ports). 1510b3178a4SMike SmithCFLAGS+= -fno-common 1520817c8dcSDimitry Andric.if ${LINKER_TYPE} != "lld" || ${LINKER_VERSION} < 140000 1530817c8dcSDimitry Andric# lld >= 14 warns that -d is deprecated, and will be removed. 1540817c8dcSDimitry AndricLDFLAGS+= -d 1550817c8dcSDimitry Andric.endif 1560817c8dcSDimitry AndricLDFLAGS+= -warn-common 1570b3178a4SMike Smith 158738cf81bSBryan Drewery.if defined(LINKER_FEATURES) && ${LINKER_FEATURES:Mbuild-id} 159b5155bc9SMark JohnstonLDFLAGS+= --build-id=sha1 16053e0bebaSEd Maste.endif 16153e0bebaSEd Maste 1629e4be63dSBruce EvansCFLAGS+= ${DEBUG_FLAGS} 163594389d1SAndrew Turner.if ${MACHINE_CPUARCH} == aarch64 || ${MACHINE_CPUARCH} == amd64 1642565edc4SAndriy GaponCFLAGS+= -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer 16583c457dcSIan Dowse.endif 1669e4be63dSBruce Evans 167b1f8da38SBrandon Bergren.if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "riscv" || \ 168b1f8da38SBrandon Bergren ${MACHINE_CPUARCH} == "powerpc" 1698598392cSKonstantin BelousovCFLAGS+= -fPIC 1708598392cSKonstantin Belousov.endif 1718598392cSKonstantin Belousov 172b54c389fSIan Lepore# Temporary workaround for PR 196407, which contains the fascinating details. 173c6f7b900SIan Lepore# Don't allow clang to use fpu instructions or registers in kernel modules. 174b54c389fSIan Lepore.if ${MACHINE_CPUARCH} == arm 17567e3484fSDimitry AndricCFLAGS.clang+= -mno-movt 176c6f7b900SIan LeporeCFLAGS.clang+= -mfpu=none 1771b23f9b9SAndrew TurnerCFLAGS+= -funwind-tables 178b54c389fSIan Lepore.endif 179b54c389fSIan Lepore 1803a0d123eSWarner Losh.if ${MACHINE_CPUARCH} == powerpc 18155a5dcc8SPeter GrehanCFLAGS+= -mlongcall -fno-omit-frame-pointer 182c16f7fabSBrandon Bergren.if ${LINKER_TYPE} == "lld" 183c16f7fabSBrandon Bergren# TOC optimization in LLD (9.0) currently breaks kernel modules, so disable it 184c16f7fabSBrandon BergrenLDFLAGS+= --no-toc-optimize 185c16f7fabSBrandon Bergren.endif 186fded756eSPeter Grehan.endif 187fded756eSPeter Grehan 18869745d38SAlexander Leidinger.if defined(DEBUG) || defined(DEBUG_FLAGS) 18969745d38SAlexander LeidingerCTFFLAGS+= -g 19069745d38SAlexander Leidinger.endif 19169745d38SAlexander Leidinger 1926aec1278SMax Laier.if defined(FIRMWS) 1935852ae2dSBryan Drewery${KMOD:S/$/.c/}: ${SYSDIR}/tools/fw_stub.awk 194528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/fw_stub.awk ${FIRMWS} -m${KMOD} -c${KMOD:S/$/.c/g} \ 1957bd6fde3SFlorent Thoumie ${FIRMWARE_LICENSE:C/.+/-l/}${FIRMWARE_LICENSE} 1966aec1278SMax Laier 1976aec1278SMax LaierSRCS+= ${KMOD:S/$/.c/} 1986aec1278SMax LaierCLEANFILES+= ${KMOD:S/$/.c/} 1996aec1278SMax Laier 2006aec1278SMax Laier.for _firmw in ${FIRMWS} 201a0953903SJohn Baldwin${_firmw:C/\:.*$/.fwo/:T}: ${_firmw:C/\:.*$//} ${SYSDIR}/kern/firmw.S 2026aec1278SMax Laier @${ECHO} ${_firmw:C/\:.*$//} ${.ALLSRC:M*${_firmw:C/\:.*$//}} 203a0953903SJohn Baldwin ${CC:N${CCACHE_BIN}} -c -x assembler-with-cpp -DLOCORE \ 204a0953903SJohn Baldwin ${CFLAGS} ${WERROR} \ 205a0953903SJohn Baldwin -DFIRMW_FILE="${.ALLSRC:M*${_firmw:C/\:.*$//}}" \ 206628a4156SJohn Baldwin -DFIRMW_SYMBOL="${_firmw:C/\:.*$//:C/[-.\/@]/_/g}" \ 207a0953903SJohn Baldwin ${SYSDIR}/kern/firmw.S -o ${.TARGET} 2086aec1278SMax Laier 209d9eed6f4SJohn BaldwinOBJS+= ${_firmw:C/\:.*$/.fwo/:T} 2106aec1278SMax Laier.endfor 2116aec1278SMax Laier.endif 2126aec1278SMax Laier 21335c4406dSWarner Losh# Conditionally include SRCS based on kernel config options. 21435c4406dSWarner Losh.for _o in ${KERN_OPTS} 21535c4406dSWarner LoshSRCS+=${SRCS.${_o}} 21635c4406dSWarner Losh.endfor 21735c4406dSWarner Losh 218639a2e50SGarrett WollmanOBJS+= ${SRCS:N*.h:R:S/$/.o/g} 219639a2e50SGarrett Wollman 220639a2e50SGarrett Wollman.if !defined(PROG) 22190f60fc9SMike SmithPROG= ${KMOD}.ko 22290f60fc9SMike Smith.endif 223639a2e50SGarrett Wollman 224e3709cfeSEd Maste.if !defined(DEBUG_FLAGS) || ${MK_SPLIT_KERNEL_DEBUG} == "no" 225f6611608SSheldon HearnFULLPROG= ${PROG} 226f6611608SSheldon Hearn.else 22705117b57SEd MasteFULLPROG= ${PROG}.full 2285852ae2dSBryan Drewery${PROG}: ${FULLPROG} ${PROG}.debug 22905117b57SEd Maste ${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROG}.debug \ 23098b45a8fSRuslan Ermilov ${FULLPROG} ${.TARGET} 2315852ae2dSBryan Drewery${PROG}.debug: ${FULLPROG} 23298b45a8fSRuslan Ermilov ${OBJCOPY} --only-keep-debug ${FULLPROG} ${.TARGET} 233f6611608SSheldon Hearn.endif 234f6611608SSheldon Hearn 2353a0d123eSWarner Losh.if ${__KLD_SHARED} == yes 2365852ae2dSBryan Drewery${FULLPROG}: ${KMOD}.kld 23782dd4542SDimitry Andric ${LD} -m ${LD_EMULATION} -Bshareable -znotext -znorelro ${_LDFLAGS} \ 23859642947SEd Maste -o ${.TARGET} ${KMOD}.kld 239817b59bfSRuslan Ermilov.if !defined(DEBUG_FLAGS) 240817b59bfSRuslan Ermilov ${OBJCOPY} --strip-debug ${.TARGET} 2414c293d35SRuslan Ermilov.endif 2424d6bcc83SPeter Wemm.endif 24309be11baSPeter Wemm 24493f03548SMike SmithEXPORT_SYMS?= NO 24593f03548SMike Smith.if ${EXPORT_SYMS} != YES 2461f089616SRuslan ErmilovCLEANFILES+= export_syms 2470b3178a4SMike Smith.endif 2480b3178a4SMike Smith 2492754373fSAndrew Turner.if exists(${SYSDIR}/conf/ldscript.kmod.${MACHINE}) 2502754373fSAndrew TurnerLDSCRIPT_FLAGS?= -T ${SYSDIR}/conf/ldscript.kmod.${MACHINE} 251d6793db2SMark Johnston.endif 252d6793db2SMark Johnston 2533a0d123eSWarner Losh.if ${__KLD_SHARED} == yes 254e8dca53aSWarner Losh${KMOD}.kld: ${OBJS} ${BLOB_OBJS} 2554d6bcc83SPeter Wemm.else 256e8dca53aSWarner Losh${FULLPROG}: ${OBJS} ${BLOB_OBJS} 2574d6bcc83SPeter Wemm.endif 2580817c8dcSDimitry Andric ${LD} -m ${LD_EMULATION} ${_LDFLAGS} ${LDSCRIPT_FLAGS} -r \ 259e8dca53aSWarner Losh -o ${.TARGET} ${OBJS} ${BLOB_OBJS} 260724afafaSWarner Losh.if ${MK_CTF} != "no" 261e8dca53aSWarner Losh ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} ${BLOB_OBJS} 262cd49c2e8SMax Khon.endif 2630b3178a4SMike Smith.if defined(EXPORT_SYMS) 26493f03548SMike Smith.if ${EXPORT_SYMS} != YES 2650b3178a4SMike Smith.if ${EXPORT_SYMS} == NO 2668b3ae668SDag-Erling Smørgrav :> export_syms 2670b3178a4SMike Smith.elif !exists(${.CURDIR}/${EXPORT_SYMS}) 268b8283138SEd Maste echo -n "${EXPORT_SYMS:@s@$s${.newline}@}" > export_syms 2690b3178a4SMike Smith.else 2701f089616SRuslan Ermilov grep -v '^#' < ${EXPORT_SYMS} > export_syms 2710b3178a4SMike Smith.endif 27211f1d284SMark Johnston ${AWK} -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \ 2731f089616SRuslan Ermilov export_syms | xargs -J% ${OBJCOPY} % ${.TARGET} 27493f03548SMike Smith.endif 275b8283138SEd Maste.endif # defined(EXPORT_SYMS) 276dc6a41b9SJonathan T. Looney.if defined(PREFIX_SYMS) 277dc6a41b9SJonathan T. Looney ${AWK} -v prefix=${PREFIX_SYMS} -f ${SYSDIR}/conf/kmod_syms_prefix.awk \ 278dc6a41b9SJonathan T. Looney ${.TARGET} /dev/null | xargs -J% ${OBJCOPY} % ${.TARGET} 279dc6a41b9SJonathan T. Looney.endif 2803a0d123eSWarner Losh.if !defined(DEBUG_FLAGS) && ${__KLD_SHARED} == no 2814d6bcc83SPeter Wemm ${OBJCOPY} --strip-debug ${.TARGET} 2824d6bcc83SPeter Wemm.endif 2830b3178a4SMike Smith 2847114b176SMark Johnston_MAP_DEBUG_PREFIX= yes 2857114b176SMark Johnston 286528013d5SWarner Losh_ILINKS=machine 287544de89dSJohn Baldwin.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" 288544de89dSJohn Baldwin_ILINKS+=x86 289544de89dSJohn Baldwin.endif 290d07600c5SBrooks Davis.if ${MACHINE_CPUARCH} == "amd64" 291d07600c5SBrooks Davis_ILINKS+=i386 292d07600c5SBrooks Davis.endif 29331a01497SSean BrunoCLEANFILES+=${_ILINKS} 294639a2e50SGarrett Wollman 2951bd4272fSBryan Dreweryall: ${PROG} 2964a2d2630SBruce Evans 297db00e6c5SDavid E. O'Brienbeforedepend: ${_ILINKS} 29868d96923SBryan Drewerybeforebuild: ${_ILINKS} 299985f41afSWarner Losh 300f3cc9575SWarner Losh# Ensure that the links exist without depending on it when it exists which 301f3cc9575SWarner Losh# causes all the modules to be rebuilt when the directory pointed to changes. 3027114b176SMark Johnston# Ensure that debug info references the path in the source tree. 303f3cc9575SWarner Losh.for _link in ${_ILINKS} 304f3cc9575SWarner Losh.if !exists(${.OBJDIR}/${_link}) 3053063d216SBryan DreweryOBJS_DEPEND_GUESS+= ${_link} 306f3cc9575SWarner Losh.endif 3077114b176SMark Johnston.if defined(_MAP_DEBUG_PREFIX) 3087114b176SMark Johnston.if ${_link} == "machine" 3097114b176SMark JohnstonCFLAGS+= -fdebug-prefix-map=./machine=${SYSDIR}/${MACHINE}/include 3107114b176SMark Johnston.else 3117114b176SMark JohnstonCFLAGS+= -fdebug-prefix-map=./${_link}=${SYSDIR}/${_link}/include 3127114b176SMark Johnston.endif 3137114b176SMark Johnston.endif 314f3cc9575SWarner Losh.endfor 3154a2d2630SBruce Evans 3167750ad47SMarcel Moolenaar.NOPATH: ${_ILINKS} 3173c4368b2SMark Johnston 3184a2d2630SBruce Evans${_ILINKS}: 3199a8631b3SWarner Losh @case ${.TARGET} in \ 320df3a103dSWarner Losh machine) \ 321df3a103dSWarner Losh path=${SYSDIR}/${MACHINE}/include ;; \ 322544de89dSJohn Baldwin *) \ 3233c4368b2SMark Johnston path=${SYSDIR}/${.TARGET:T}/include ;; \ 32408a04a89SPeter Wemm esac ; \ 325bcb7f57aSMateusz Guzik path=`realpath $$path`; \ 3263c4368b2SMark Johnston ${ECHO} ${.TARGET:T} "->" $$path ; \ 327454ce383SAlex Richardson ln -fns $$path ${.TARGET:T} 3284a2d2630SBruce Evans 32974465532SRuslan ErmilovCLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} 330361186e5SMaxime Henrion 331e3709cfeSEd Maste.if defined(DEBUG_FLAGS) && ${MK_SPLIT_KERNEL_DEBUG} != "no" 33205117b57SEd MasteCLEANFILES+= ${FULLPROG} ${PROG}.debug 333361186e5SMaxime Henrion.endif 334639a2e50SGarrett Wollman 335639a2e50SGarrett Wollman.if !target(install) 336639a2e50SGarrett Wollman 337ea87b3cbSDavid E. O'Brien_INSTALLFLAGS:= ${INSTALLFLAGS} 338e902c1bbSTim Vanderhoek.for ie in ${INSTALLFLAGS_EDIT} 339e902c1bbSTim Vanderhoek_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 340e902c1bbSTim Vanderhoek.endfor 341e902c1bbSTim Vanderhoek 3422b06260dSRuslan Ermilov.if !target(realinstall) 34305117b57SEd MasteKERN_DEBUGDIR?= ${DEBUGDIR} 3442b06260dSRuslan Ermilovrealinstall: _kmodinstall 3452b06260dSRuslan Ermilov.ORDER: beforeinstall _kmodinstall 34649773547SBryan Drewery_kmodinstall: .PHONY 3471c6eb1b2SBaptiste Daroussin ${INSTALL} -T release -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 3480ed70e42SBryan Drewery ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}/ 349cd95660fSDavid E. O'Brien.if defined(DEBUG_FLAGS) && !defined(INSTALL_NODEBUG) && ${MK_KERNEL_SYMBOLS} != "no" 350697b271dSEd Maste ${INSTALL} -T dbg -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 3510ed70e42SBryan Drewery ${_INSTALLFLAGS} ${PROG}.debug ${DESTDIR}${KERN_DEBUGDIR}${KMODDIR}/ 352d24864f7SRuslan Ermilov.endif 3532b06260dSRuslan Ermilov 3542b06260dSRuslan Ermilov.include <bsd.links.mk> 3552b06260dSRuslan Ermilov 3564875819cSJake Burkholder.if !defined(NO_XREF) 3572b06260dSRuslan Ermilovafterinstall: _kldxref 3582b06260dSRuslan Ermilov.ORDER: realinstall _kldxref 3592b06260dSRuslan Ermilov.ORDER: _installlinks _kldxref 36049773547SBryan Drewery_kldxref: .PHONY 361be1d673dSRuslan Ermilov @if type kldxref >/dev/null 2>&1; then \ 3625ec57af4SMaxim Sobolev ${ECHO} ${KLDXREF_CMD} ${DESTDIR}${KMODDIR}; \ 3635ec57af4SMaxim Sobolev ${KLDXREF_CMD} ${DESTDIR}${KMODDIR}; \ 364be1d673dSRuslan Ermilov fi 365505222d3SPeter Wemm.endif 36622a8b405SMaxime Henrion.endif # !target(realinstall) 367639a2e50SGarrett Wollman 36822a8b405SMaxime Henrion.endif # !target(install) 369639a2e50SGarrett Wollman 370639a2e50SGarrett Wollman.if !target(load) 37149773547SBryan Dreweryload: ${PROG} .PHONY 3721f089616SRuslan Ermilov ${KMODLOAD} -v ${.OBJDIR}/${PROG} 373639a2e50SGarrett Wollman.endif 374639a2e50SGarrett Wollman 375639a2e50SGarrett Wollman.if !target(unload) 37649773547SBryan Dreweryunload: .PHONY 37793bffaf2SDag-Erling Smørgrav if ${KMODISLOADED} ${PROG} ; then ${KMODUNLOAD} -v ${PROG} ; fi 37893bffaf2SDag-Erling Smørgrav.endif 37993bffaf2SDag-Erling Smørgrav 38093bffaf2SDag-Erling Smørgrav.if !target(reload) 38149773547SBryan Dreweryreload: unload load .PHONY 38208a04a89SPeter Wemm.endif 3831aa57be3SGarrett Wollman 3846b1bb559SWarner Losh.if defined(KERNBUILDDIR) 3856b1bb559SWarner Losh.PATH: ${KERNBUILDDIR} 3866b1bb559SWarner LoshCFLAGS+= -I${KERNBUILDDIR} 3876b1bb559SWarner Losh.for _src in ${SRCS:Mopt_*.h} 3886b1bb559SWarner LoshCLEANFILES+= ${_src} 3896b1bb559SWarner Losh.if !target(${_src}) 3906b1bb559SWarner Losh${_src}: 39140244cc2SDavid E. O'Brien ln -sf ${KERNBUILDDIR}/${_src} ${.TARGET} 3926b1bb559SWarner Losh.endif 3936b1bb559SWarner Losh.endfor 3946b1bb559SWarner Losh.else 3954fea6704SBruce Evans.for _src in ${SRCS:Mopt_*.h} 3964fea6704SBruce EvansCLEANFILES+= ${_src} 3974fea6704SBruce Evans.if !target(${_src}) 3984fea6704SBruce Evans${_src}: 3998b3ae668SDag-Erling Smørgrav :> ${.TARGET} 4004fea6704SBruce Evans.endif 4014fea6704SBruce Evans.endfor 4026b1bb559SWarner Losh.endif 4034fea6704SBruce Evans 4044ea56599SAndrew Turner# Add the sanitizer C flags 4054ea56599SAndrew TurnerCFLAGS+= ${SAN_CFLAGS} 4064ea56599SAndrew Turner 4075426539cSMatt Macy# Add the gcov flags 4085426539cSMatt MacyCFLAGS+= ${GCOV_CFLAGS} 4095426539cSMatt Macy 4103fd1e05bSAlexander Leidinger# Respect configuration-specific C flags. 411256054fdSBrooks DavisCFLAGS+= ${ARCH_FLAGS} ${CONF_CFLAGS} 41262769330SAlexander Leidinger 413a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Mvnode_if.c) 41478b2c868SBrian FeldmanCLEANFILES+= vnode_if.c 415528013d5SWarner Loshvnode_if.c: ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src 416528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -c 4174fea6704SBruce Evans.endif 41878b2c868SBrian Feldman 419a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Mvnode_if.h) 4209f73f0e8SRuslan ErmilovCLEANFILES+= vnode_if.h vnode_if_newproto.h vnode_if_typedef.h 421528013d5SWarner Loshvnode_if.h vnode_if_newproto.h vnode_if_typedef.h: ${SYSDIR}/tools/vnode_if.awk \ 422528013d5SWarner Losh ${SYSDIR}/kern/vnode_if.src 4239f73f0e8SRuslan Ermilovvnode_if.h: vnode_if_newproto.h vnode_if_typedef.h 424528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -h 4259f73f0e8SRuslan Ermilovvnode_if_newproto.h: 426528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -p 4279f73f0e8SRuslan Ermilovvnode_if_typedef.h: 428528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -q 42978b2c868SBrian Feldman.endif 4301aa57be3SGarrett Wollman 43112f05b84SWarner Losh# Build _if.[ch] from _if.m, and clean them when we're done. 432ec4047adSBryan Drewery# __MPATH defined in config.mk 4332cd2ff0eSJohn Baldwin_MFILES=${__MPATH:T:O} 4342cd2ff0eSJohn Baldwin_MPATH=${__MPATH:H:O:u} 43512f05b84SWarner Losh.PATH.m: ${_MPATH} 436160c44feSWarner Losh.for _i in ${SRCS:M*_if.[ch]} 4372cd2ff0eSJohn Baldwin_MATCH=M${_i:R:S/$/.m/} 4382cd2ff0eSJohn Baldwin_MATCHES=${_MFILES:${_MATCH}} 4392cd2ff0eSJohn Baldwin.if !empty(_MATCHES) 4402cd2ff0eSJohn BaldwinCLEANFILES+= ${_i} 4412cd2ff0eSJohn Baldwin.endif 442160c44feSWarner Losh.endfor # _i 4435852ae2dSBryan Drewery.m.c: ${SYSDIR}/tools/makeobjops.awk 44412f05b84SWarner Losh ${AWK} -f ${SYSDIR}/tools/makeobjops.awk ${.IMPSRC} -c 44512f05b84SWarner Losh 4465852ae2dSBryan Drewery.m.h: ${SYSDIR}/tools/makeobjops.awk 44712f05b84SWarner Losh ${AWK} -f ${SYSDIR}/tools/makeobjops.awk ${.IMPSRC} -h 44812f05b84SWarner Losh 4494e91eaf2SWarner Losh.for _i in mii pccard 450a7d30e5fSDavid E. O'Brien.if !empty(SRCS:M${_i}devs.h) 451dba6dd17SWarner LoshCLEANFILES+= ${_i}devs.h 4525852ae2dSBryan Drewery${_i}devs.h: ${SYSDIR}/tools/${_i}devs2h.awk ${SYSDIR}/dev/${_i}/${_i}devs 453528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/${_i}devs2h.awk ${SYSDIR}/dev/${_i}/${_i}devs 4542d3ce713SDavid E. O'Brien.endif 455dba6dd17SWarner Losh.endfor # _i 4562d3ce713SDavid E. O'Brien 457e83ce340SAdrian Chadd.if !empty(SRCS:Mbhnd_nvram_map.h) 458e83ce340SAdrian ChaddCLEANFILES+= bhnd_nvram_map.h 459e83ce340SAdrian Chaddbhnd_nvram_map.h: ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.awk \ 460e83ce340SAdrian Chadd ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.sh \ 4615852ae2dSBryan Drewery ${SYSDIR}/dev/bhnd/nvram/nvram_map 4625852ae2dSBryan Drewerybhnd_nvram_map.h: 46316fba18fSDimitry Andric sh ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.sh \ 464e83ce340SAdrian Chadd ${SYSDIR}/dev/bhnd/nvram/nvram_map -h 465e83ce340SAdrian Chadd.endif 466e83ce340SAdrian Chadd 467e83ce340SAdrian Chadd.if !empty(SRCS:Mbhnd_nvram_map_data.h) 468e83ce340SAdrian ChaddCLEANFILES+= bhnd_nvram_map_data.h 469e83ce340SAdrian Chaddbhnd_nvram_map_data.h: ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.awk \ 470e83ce340SAdrian Chadd ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.sh \ 4715852ae2dSBryan Drewery ${SYSDIR}/dev/bhnd/nvram/nvram_map 4725852ae2dSBryan Drewerybhnd_nvram_map_data.h: 47316fba18fSDimitry Andric sh ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.sh \ 474e83ce340SAdrian Chadd ${SYSDIR}/dev/bhnd/nvram/nvram_map -d 475e83ce340SAdrian Chadd.endif 476e83ce340SAdrian Chadd 477a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Musbdevs.h) 4784e91eaf2SWarner LoshCLEANFILES+= usbdevs.h 4795852ae2dSBryan Dreweryusbdevs.h: ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs 480528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs -h 4814e91eaf2SWarner Losh.endif 4824e91eaf2SWarner Losh 483a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Musbdevs_data.h) 4844e91eaf2SWarner LoshCLEANFILES+= usbdevs_data.h 4855852ae2dSBryan Dreweryusbdevs_data.h: ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs 486528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs -d 4874e91eaf2SWarner Losh.endif 4884e91eaf2SWarner Losh 48967ca7330SBjoern A. Zeeb.if !empty(SRCS:Msdiodevs.h) 49067ca7330SBjoern A. ZeebCLEANFILES+= sdiodevs.h 49167ca7330SBjoern A. Zeebsdiodevs.h: ${SYSDIR}/tools/sdiodevs2h.awk ${SYSDIR}/dev/sdio/sdiodevs 49267ca7330SBjoern A. Zeeb ${AWK} -f ${SYSDIR}/tools/sdiodevs2h.awk ${SYSDIR}/dev/sdio/sdiodevs -h 49367ca7330SBjoern A. Zeeb.endif 49467ca7330SBjoern A. Zeeb 49567ca7330SBjoern A. Zeeb.if !empty(SRCS:Msdiodevs_data.h) 49667ca7330SBjoern A. ZeebCLEANFILES+= sdiodevs_data.h 49767ca7330SBjoern A. Zeebsdiodevs_data.h: ${SYSDIR}/tools/sdiodevs2h.awk ${SYSDIR}/dev/sdio/sdiodevs 49867ca7330SBjoern A. Zeeb ${AWK} -f ${SYSDIR}/tools/sdiodevs2h.awk ${SYSDIR}/dev/sdio/sdiodevs -d 49967ca7330SBjoern A. Zeeb.endif 50067ca7330SBjoern A. Zeeb 501a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Macpi_quirks.h) 502684c1c1dSNate LawsonCLEANFILES+= acpi_quirks.h 5035852ae2dSBryan Dreweryacpi_quirks.h: ${SYSDIR}/tools/acpi_quirks2h.awk ${SYSDIR}/dev/acpica/acpi_quirks 504528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/acpi_quirks2h.awk ${SYSDIR}/dev/acpica/acpi_quirks 505684c1c1dSNate Lawson.endif 506684c1c1dSNate Lawson 507fc2a8776SEd Maste.if !empty(SRCS:Massym.inc) || !empty(DPSRCS:Massym.inc) 5089d2b4c4fSBryan DreweryCLEANFILES+= assym.inc genassym.o 509ccca101fSBryan DreweryDEPENDOBJS+= genassym.o 510ccca101fSBryan DreweryDPSRCS+= offset.inc 511ccca101fSBryan Drewery.endif 51282c98d01SBryan Drewery.if defined(MODULE_TIED) 51382c98d01SBryan DreweryDPSRCS+= offset.inc 51482c98d01SBryan Drewery.endif 515ccca101fSBryan Drewery.if !empty(SRCS:Moffset.inc) || !empty(DPSRCS:Moffset.inc) 516ccca101fSBryan DreweryCLEANFILES+= offset.inc genoffset.o 517ccca101fSBryan DreweryDEPENDOBJS+= genoffset.o 518ccca101fSBryan Drewery.endif 519fc2a8776SEd Masteassym.inc: genassym.o 5208bedbb4dSMatt Macyoffset.inc: genoffset.o 521fc2a8776SEd Masteassym.inc: ${SYSDIR}/kern/genassym.sh 522528013d5SWarner Losh sh ${SYSDIR}/kern/genassym.sh genassym.o > ${.TARGET} 523d69d8a46SBryan Drewerygenassym.o: ${SYSDIR}/${MACHINE}/${MACHINE}/genassym.c offset.inc 5245852ae2dSBryan Drewerygenassym.o: ${SRCS:Mopt_*.h} 525a8976aecSAlex Richardson ${CC} -c ${CFLAGS:N-flto:N-fno-common} -fcommon \ 5267dd824c3SEd Maste ${SYSDIR}/${MACHINE}/${MACHINE}/genassym.c 5278bedbb4dSMatt Macyoffset.inc: ${SYSDIR}/kern/genoffset.sh genoffset.o 5288bedbb4dSMatt Macy sh ${SYSDIR}/kern/genoffset.sh genoffset.o > ${.TARGET} 529d69d8a46SBryan Drewerygenoffset.o: ${SYSDIR}/kern/genoffset.c 5308bedbb4dSMatt Macygenoffset.o: ${SRCS:Mopt_*.h} 531a8976aecSAlex Richardson ${CC} -c ${CFLAGS:N-flto:N-fno-common} -fcommon \ 532d69d8a46SBryan Drewery ${SYSDIR}/kern/genoffset.c 533705d63cdSIan Dowse 534de1a3bd9SBryan DreweryCLEANDEPENDFILES+= ${_ILINKS} 53574465532SRuslan Ermilov# .depend needs include links so we remove them only together. 53674465532SRuslan Ermilovcleanilinks: 53774465532SRuslan Ermilov rm -f ${_ILINKS} 53874465532SRuslan Ermilov 539d7beff08SBryan DreweryOBJS_DEPEND_GUESS+= ${SRCS:M*.h} 540817f7baaSBryan Drewery.if defined(KERNBUILDDIR) 541817f7baaSBryan DreweryOBJS_DEPEND_GUESS+= opt_global.h 542817f7baaSBryan Drewery.endif 54388fe1f7aSBryan Drewery 5449e5787d2SMatt MacyZINCDIR=${SYSDIR}/contrib/openzfs/include 5459e5787d2SMatt MacyOPENZFS_CFLAGS= \ 5469e5787d2SMatt Macy -D_SYS_VMEM_H_ \ 5479e5787d2SMatt Macy -D__KERNEL__ \ 5489e5787d2SMatt Macy -nostdinc \ 5499e5787d2SMatt Macy -DSMP \ 5509e5787d2SMatt Macy -I${ZINCDIR} \ 5519e5787d2SMatt Macy -I${ZINCDIR}/os/freebsd \ 5529e5787d2SMatt Macy -I${ZINCDIR}/os/freebsd/spl \ 5539e5787d2SMatt Macy -I${ZINCDIR}/os/freebsd/zfs \ 5549e5787d2SMatt Macy -I${SYSDIR}/cddl/compat/opensolaris \ 5559e5787d2SMatt Macy -I${SYSDIR}/cddl/contrib/opensolaris/uts/common \ 5569e5787d2SMatt Macy -include ${ZINCDIR}/os/freebsd/spl/sys/ccompile.h 557d021434aSRyan LibbyOPENZFS_CWARNFLAGS= \ 558c227269eSJohn Baldwin -Wno-nested-externs 5599e5787d2SMatt Macy 56088fe1f7aSBryan Drewery.include <bsd.dep.mk> 561aae63957SBryan Drewery.include <bsd.clang-analyze.mk> 562afba897fSBruce Evans.include <bsd.obj.mk> 563ddc474a8SRuslan Ermilov.include "kern.mk" 564