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 111daaea395SWarner LoshCFLAGS+= ${WERROR} 11248aea4daSRuslan ErmilovCFLAGS+= -D_KERNEL 1138fe644b2SMike SmithCFLAGS+= -DKLD_MODULE 114f4b36404SMatt Macy.if defined(MODULE_TIED) 115f4b36404SMatt MacyCFLAGS+= -DKLD_TIED 116f4b36404SMatt Macy.endif 1174a2d2630SBruce Evans 118021886ffSBruce Evans# Don't use any standard or source-relative include directories. 11906d6e4fcSTom RhodesNOSTDINC= -nostdinc 120da3bcc92SAlexander KabaevCFLAGS:= ${CFLAGS:N-I*} ${NOSTDINC} ${INCLMAGIC} ${CFLAGS:M-I*} 1218fa793d0SBrian Feldman.if defined(KERNBUILDDIR) 1220c063641SGleb SmirnoffCFLAGS+= -DHAVE_KERNEL_OPTION_HEADERS -include ${KERNBUILDDIR}/opt_global.h 1230c4c5948SKyle Evans.else 1240c4c5948SKyle EvansSRCS+= opt_global.h 1250c4c5948SKyle EvansCFLAGS+= -include ${.OBJDIR}/opt_global.h 1268fa793d0SBrian Feldman.endif 127021886ffSBruce Evans 1281f089616SRuslan Ermilov# Add -I paths for system headers. Individual module makefiles don't 129021886ffSBruce Evans# need any -I paths for this. Similar defaults for .PATH can't be 130021886ffSBruce Evans# set because there are no standard paths for non-headers. 1317bf272a6SMatt MacyCFLAGS+= -I. -I${SYSDIR} -I${SYSDIR}/contrib/ck/include 1324a2d2630SBruce Evans 13322ba0b2fSWarner LoshCFLAGS.gcc+= -finline-limit=${INLINE_LIMIT} 134cc4a90c4SGleb SmirnoffCFLAGS.gcc+= -fms-extensions 13522ba0b2fSWarner LoshCFLAGS.gcc+= --param inline-unit-growth=100 13622ba0b2fSWarner LoshCFLAGS.gcc+= --param large-function-growth=1000 1372a51529fSPeter Wemm 1380b3178a4SMike Smith# Disallow common variables, and if we end up with commons from 1390b3178a4SMike Smith# somewhere unexpected, allocate storage for them in the module itself. 1408eb1a0ceSKyle Evans# 1418eb1a0ceSKyle Evans# -fno-common is the default for src builds, but this should be left in place 1428eb1a0ceSKyle Evans# until at least we catch up to GCC10/LLVM11 or otherwise enable -fno-common 1438eb1a0ceSKyle Evans# in <bsd.sys.mk> instead. For now, we will have duplicate -fno-common in 1448eb1a0ceSKyle Evans# CFLAGS for in-tree module builds as they will also pick it up from 1458eb1a0ceSKyle Evans# share/mk/src.sys.mk, but the following is important for out-of-tree modules 1468eb1a0ceSKyle Evans# (e.g. ports). 1470b3178a4SMike SmithCFLAGS+= -fno-common 1480b3178a4SMike SmithLDFLAGS+= -d -warn-common 1490b3178a4SMike Smith 150738cf81bSBryan Drewery.if defined(LINKER_FEATURES) && ${LINKER_FEATURES:Mbuild-id} 151b5155bc9SMark JohnstonLDFLAGS+= --build-id=sha1 15253e0bebaSEd Maste.endif 15353e0bebaSEd Maste 1549e4be63dSBruce EvansCFLAGS+= ${DEBUG_FLAGS} 155594389d1SAndrew Turner.if ${MACHINE_CPUARCH} == aarch64 || ${MACHINE_CPUARCH} == amd64 1562565edc4SAndriy GaponCFLAGS+= -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer 15783c457dcSIan Dowse.endif 1589e4be63dSBruce Evans 159b1f8da38SBrandon Bergren.if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "riscv" || \ 160b1f8da38SBrandon Bergren ${MACHINE_CPUARCH} == "powerpc" 1618598392cSKonstantin BelousovCFLAGS+= -fPIC 1628598392cSKonstantin Belousov.endif 1638598392cSKonstantin Belousov 164b54c389fSIan Lepore# Temporary workaround for PR 196407, which contains the fascinating details. 165c6f7b900SIan Lepore# Don't allow clang to use fpu instructions or registers in kernel modules. 166b54c389fSIan Lepore.if ${MACHINE_CPUARCH} == arm 16767e3484fSDimitry AndricCFLAGS.clang+= -mno-movt 168c6f7b900SIan LeporeCFLAGS.clang+= -mfpu=none 1691b23f9b9SAndrew TurnerCFLAGS+= -funwind-tables 170b54c389fSIan Lepore.endif 171b54c389fSIan Lepore 1723a0d123eSWarner Losh.if ${MACHINE_CPUARCH} == powerpc 17355a5dcc8SPeter GrehanCFLAGS+= -mlongcall -fno-omit-frame-pointer 174c16f7fabSBrandon Bergren.if ${LINKER_TYPE} == "lld" 175c16f7fabSBrandon Bergren# TOC optimization in LLD (9.0) currently breaks kernel modules, so disable it 176c16f7fabSBrandon BergrenLDFLAGS+= --no-toc-optimize 177c16f7fabSBrandon Bergren.endif 178fded756eSPeter Grehan.endif 179fded756eSPeter Grehan 18069745d38SAlexander Leidinger.if defined(DEBUG) || defined(DEBUG_FLAGS) 18169745d38SAlexander LeidingerCTFFLAGS+= -g 18269745d38SAlexander Leidinger.endif 18369745d38SAlexander Leidinger 1846aec1278SMax Laier.if defined(FIRMWS) 1855852ae2dSBryan Drewery${KMOD:S/$/.c/}: ${SYSDIR}/tools/fw_stub.awk 186528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/fw_stub.awk ${FIRMWS} -m${KMOD} -c${KMOD:S/$/.c/g} \ 1877bd6fde3SFlorent Thoumie ${FIRMWARE_LICENSE:C/.+/-l/}${FIRMWARE_LICENSE} 1886aec1278SMax Laier 1896aec1278SMax LaierSRCS+= ${KMOD:S/$/.c/} 1906aec1278SMax LaierCLEANFILES+= ${KMOD:S/$/.c/} 1916aec1278SMax Laier 1926aec1278SMax Laier.for _firmw in ${FIRMWS} 193a0953903SJohn Baldwin${_firmw:C/\:.*$/.fwo/:T}: ${_firmw:C/\:.*$//} ${SYSDIR}/kern/firmw.S 1946aec1278SMax Laier @${ECHO} ${_firmw:C/\:.*$//} ${.ALLSRC:M*${_firmw:C/\:.*$//}} 195a0953903SJohn Baldwin ${CC:N${CCACHE_BIN}} -c -x assembler-with-cpp -DLOCORE \ 196a0953903SJohn Baldwin ${CFLAGS} ${WERROR} \ 197a0953903SJohn Baldwin -DFIRMW_FILE="${.ALLSRC:M*${_firmw:C/\:.*$//}}" \ 198a0953903SJohn Baldwin -DFIRMW_SYMBOL="${_firmw:C/\:.*$//:C/[-.\/]/_/g}" \ 199a0953903SJohn Baldwin ${SYSDIR}/kern/firmw.S -o ${.TARGET} 2006aec1278SMax Laier 201d9eed6f4SJohn BaldwinOBJS+= ${_firmw:C/\:.*$/.fwo/:T} 2026aec1278SMax Laier.endfor 2036aec1278SMax Laier.endif 2046aec1278SMax Laier 20535c4406dSWarner Losh# Conditionally include SRCS based on kernel config options. 20635c4406dSWarner Losh.for _o in ${KERN_OPTS} 20735c4406dSWarner LoshSRCS+=${SRCS.${_o}} 20835c4406dSWarner Losh.endfor 20935c4406dSWarner Losh 210639a2e50SGarrett WollmanOBJS+= ${SRCS:N*.h:R:S/$/.o/g} 211639a2e50SGarrett Wollman 212639a2e50SGarrett Wollman.if !defined(PROG) 21390f60fc9SMike SmithPROG= ${KMOD}.ko 21490f60fc9SMike Smith.endif 215639a2e50SGarrett Wollman 2169b6edf36SConrad Meyer.if !defined(DEBUG_FLAGS) || ${MK_KERNEL_SYMBOLS} == "no" 217f6611608SSheldon HearnFULLPROG= ${PROG} 218f6611608SSheldon Hearn.else 21905117b57SEd MasteFULLPROG= ${PROG}.full 2205852ae2dSBryan Drewery${PROG}: ${FULLPROG} ${PROG}.debug 22105117b57SEd Maste ${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROG}.debug \ 22298b45a8fSRuslan Ermilov ${FULLPROG} ${.TARGET} 2235852ae2dSBryan Drewery${PROG}.debug: ${FULLPROG} 22498b45a8fSRuslan Ermilov ${OBJCOPY} --only-keep-debug ${FULLPROG} ${.TARGET} 225f6611608SSheldon Hearn.endif 226f6611608SSheldon Hearn 2273a0d123eSWarner Losh.if ${__KLD_SHARED} == yes 2285852ae2dSBryan Drewery${FULLPROG}: ${KMOD}.kld 22982dd4542SDimitry Andric ${LD} -m ${LD_EMULATION} -Bshareable -znotext -znorelro ${_LDFLAGS} \ 23059642947SEd Maste -o ${.TARGET} ${KMOD}.kld 231817b59bfSRuslan Ermilov.if !defined(DEBUG_FLAGS) 232817b59bfSRuslan Ermilov ${OBJCOPY} --strip-debug ${.TARGET} 2334c293d35SRuslan Ermilov.endif 2344d6bcc83SPeter Wemm.endif 23509be11baSPeter Wemm 23693f03548SMike SmithEXPORT_SYMS?= NO 23793f03548SMike Smith.if ${EXPORT_SYMS} != YES 2381f089616SRuslan ErmilovCLEANFILES+= export_syms 2390b3178a4SMike Smith.endif 2400b3178a4SMike Smith 2412754373fSAndrew Turner.if exists(${SYSDIR}/conf/ldscript.kmod.${MACHINE}) 2422754373fSAndrew TurnerLDSCRIPT_FLAGS?= -T ${SYSDIR}/conf/ldscript.kmod.${MACHINE} 243d6793db2SMark Johnston.endif 244d6793db2SMark Johnston 2453a0d123eSWarner Losh.if ${__KLD_SHARED} == yes 246e8dca53aSWarner Losh${KMOD}.kld: ${OBJS} ${BLOB_OBJS} 2474d6bcc83SPeter Wemm.else 248e8dca53aSWarner Losh${FULLPROG}: ${OBJS} ${BLOB_OBJS} 2494d6bcc83SPeter Wemm.endif 250ecae3df1SMark Johnston ${LD} -m ${LD_EMULATION} ${_LDFLAGS} ${LDSCRIPT_FLAGS} -r -d \ 251e8dca53aSWarner Losh -o ${.TARGET} ${OBJS} ${BLOB_OBJS} 252724afafaSWarner Losh.if ${MK_CTF} != "no" 253e8dca53aSWarner Losh ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} ${BLOB_OBJS} 254cd49c2e8SMax Khon.endif 2550b3178a4SMike Smith.if defined(EXPORT_SYMS) 25693f03548SMike Smith.if ${EXPORT_SYMS} != YES 2570b3178a4SMike Smith.if ${EXPORT_SYMS} == NO 2588b3ae668SDag-Erling Smørgrav :> export_syms 2590b3178a4SMike Smith.elif !exists(${.CURDIR}/${EXPORT_SYMS}) 260b8283138SEd Maste echo -n "${EXPORT_SYMS:@s@$s${.newline}@}" > export_syms 2610b3178a4SMike Smith.else 2621f089616SRuslan Ermilov grep -v '^#' < ${EXPORT_SYMS} > export_syms 2630b3178a4SMike Smith.endif 26411f1d284SMark Johnston ${AWK} -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \ 2651f089616SRuslan Ermilov export_syms | xargs -J% ${OBJCOPY} % ${.TARGET} 26693f03548SMike Smith.endif 267b8283138SEd Maste.endif # defined(EXPORT_SYMS) 268dc6a41b9SJonathan T. Looney.if defined(PREFIX_SYMS) 269dc6a41b9SJonathan T. Looney ${AWK} -v prefix=${PREFIX_SYMS} -f ${SYSDIR}/conf/kmod_syms_prefix.awk \ 270dc6a41b9SJonathan T. Looney ${.TARGET} /dev/null | xargs -J% ${OBJCOPY} % ${.TARGET} 271dc6a41b9SJonathan T. Looney.endif 2723a0d123eSWarner Losh.if !defined(DEBUG_FLAGS) && ${__KLD_SHARED} == no 2734d6bcc83SPeter Wemm ${OBJCOPY} --strip-debug ${.TARGET} 2744d6bcc83SPeter Wemm.endif 2750b3178a4SMike Smith 2767114b176SMark Johnston_MAP_DEBUG_PREFIX= yes 2777114b176SMark Johnston 278528013d5SWarner Losh_ILINKS=machine 279544de89dSJohn Baldwin.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" 280544de89dSJohn Baldwin_ILINKS+=x86 281544de89dSJohn Baldwin.endif 28231a01497SSean BrunoCLEANFILES+=${_ILINKS} 283639a2e50SGarrett Wollman 2841bd4272fSBryan Dreweryall: ${PROG} 2854a2d2630SBruce Evans 286db00e6c5SDavid E. O'Brienbeforedepend: ${_ILINKS} 28768d96923SBryan Drewerybeforebuild: ${_ILINKS} 288985f41afSWarner Losh 289f3cc9575SWarner Losh# Ensure that the links exist without depending on it when it exists which 290f3cc9575SWarner Losh# causes all the modules to be rebuilt when the directory pointed to changes. 2917114b176SMark Johnston# Ensure that debug info references the path in the source tree. 292f3cc9575SWarner Losh.for _link in ${_ILINKS} 293f3cc9575SWarner Losh.if !exists(${.OBJDIR}/${_link}) 2943063d216SBryan DreweryOBJS_DEPEND_GUESS+= ${_link} 295f3cc9575SWarner Losh.endif 2967114b176SMark Johnston.if defined(_MAP_DEBUG_PREFIX) 2977114b176SMark Johnston.if ${_link} == "machine" 2987114b176SMark JohnstonCFLAGS+= -fdebug-prefix-map=./machine=${SYSDIR}/${MACHINE}/include 2997114b176SMark Johnston.else 3007114b176SMark JohnstonCFLAGS+= -fdebug-prefix-map=./${_link}=${SYSDIR}/${_link}/include 3017114b176SMark Johnston.endif 3027114b176SMark Johnston.endif 303f3cc9575SWarner Losh.endfor 3044a2d2630SBruce Evans 3057750ad47SMarcel Moolenaar.NOPATH: ${_ILINKS} 3063c4368b2SMark Johnston 3074a2d2630SBruce Evans${_ILINKS}: 3089a8631b3SWarner Losh @case ${.TARGET} in \ 309df3a103dSWarner Losh machine) \ 310df3a103dSWarner Losh path=${SYSDIR}/${MACHINE}/include ;; \ 311544de89dSJohn Baldwin *) \ 3123c4368b2SMark Johnston path=${SYSDIR}/${.TARGET:T}/include ;; \ 31308a04a89SPeter Wemm esac ; \ 314bcb7f57aSMateusz Guzik path=`realpath $$path`; \ 3153c4368b2SMark Johnston ${ECHO} ${.TARGET:T} "->" $$path ; \ 316454ce383SAlex Richardson ln -fns $$path ${.TARGET:T} 3174a2d2630SBruce Evans 31874465532SRuslan ErmilovCLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} 319361186e5SMaxime Henrion 3209b6edf36SConrad Meyer.if defined(DEBUG_FLAGS) && ${MK_KERNEL_SYMBOLS} != "no" 32105117b57SEd MasteCLEANFILES+= ${FULLPROG} ${PROG}.debug 322361186e5SMaxime Henrion.endif 323639a2e50SGarrett Wollman 324639a2e50SGarrett Wollman.if !target(install) 325639a2e50SGarrett Wollman 326ea87b3cbSDavid E. O'Brien_INSTALLFLAGS:= ${INSTALLFLAGS} 327e902c1bbSTim Vanderhoek.for ie in ${INSTALLFLAGS_EDIT} 328e902c1bbSTim Vanderhoek_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 329e902c1bbSTim Vanderhoek.endfor 330e902c1bbSTim Vanderhoek 3312b06260dSRuslan Ermilov.if !target(realinstall) 33205117b57SEd MasteKERN_DEBUGDIR?= ${DEBUGDIR} 3332b06260dSRuslan Ermilovrealinstall: _kmodinstall 3342b06260dSRuslan Ermilov.ORDER: beforeinstall _kmodinstall 33549773547SBryan Drewery_kmodinstall: .PHONY 3361c6eb1b2SBaptiste Daroussin ${INSTALL} -T release -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 3370ed70e42SBryan Drewery ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}/ 338cd95660fSDavid E. O'Brien.if defined(DEBUG_FLAGS) && !defined(INSTALL_NODEBUG) && ${MK_KERNEL_SYMBOLS} != "no" 339697b271dSEd Maste ${INSTALL} -T dbg -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 3400ed70e42SBryan Drewery ${_INSTALLFLAGS} ${PROG}.debug ${DESTDIR}${KERN_DEBUGDIR}${KMODDIR}/ 341d24864f7SRuslan Ermilov.endif 3422b06260dSRuslan Ermilov 3432b06260dSRuslan Ermilov.include <bsd.links.mk> 3442b06260dSRuslan Ermilov 3454875819cSJake Burkholder.if !defined(NO_XREF) 3462b06260dSRuslan Ermilovafterinstall: _kldxref 3472b06260dSRuslan Ermilov.ORDER: realinstall _kldxref 3482b06260dSRuslan Ermilov.ORDER: _installlinks _kldxref 34949773547SBryan Drewery_kldxref: .PHONY 350be1d673dSRuslan Ermilov @if type kldxref >/dev/null 2>&1; then \ 3515ec57af4SMaxim Sobolev ${ECHO} ${KLDXREF_CMD} ${DESTDIR}${KMODDIR}; \ 3525ec57af4SMaxim Sobolev ${KLDXREF_CMD} ${DESTDIR}${KMODDIR}; \ 353be1d673dSRuslan Ermilov fi 354505222d3SPeter Wemm.endif 35522a8b405SMaxime Henrion.endif # !target(realinstall) 356639a2e50SGarrett Wollman 35722a8b405SMaxime Henrion.endif # !target(install) 358639a2e50SGarrett Wollman 359639a2e50SGarrett Wollman.if !target(load) 36049773547SBryan Dreweryload: ${PROG} .PHONY 3611f089616SRuslan Ermilov ${KMODLOAD} -v ${.OBJDIR}/${PROG} 362639a2e50SGarrett Wollman.endif 363639a2e50SGarrett Wollman 364639a2e50SGarrett Wollman.if !target(unload) 36549773547SBryan Dreweryunload: .PHONY 36693bffaf2SDag-Erling Smørgrav if ${KMODISLOADED} ${PROG} ; then ${KMODUNLOAD} -v ${PROG} ; fi 36793bffaf2SDag-Erling Smørgrav.endif 36893bffaf2SDag-Erling Smørgrav 36993bffaf2SDag-Erling Smørgrav.if !target(reload) 37049773547SBryan Dreweryreload: unload load .PHONY 37108a04a89SPeter Wemm.endif 3721aa57be3SGarrett Wollman 3736b1bb559SWarner Losh.if defined(KERNBUILDDIR) 3746b1bb559SWarner Losh.PATH: ${KERNBUILDDIR} 3756b1bb559SWarner LoshCFLAGS+= -I${KERNBUILDDIR} 3766b1bb559SWarner Losh.for _src in ${SRCS:Mopt_*.h} 3776b1bb559SWarner LoshCLEANFILES+= ${_src} 3786b1bb559SWarner Losh.if !target(${_src}) 3796b1bb559SWarner Losh${_src}: 38040244cc2SDavid E. O'Brien ln -sf ${KERNBUILDDIR}/${_src} ${.TARGET} 3816b1bb559SWarner Losh.endif 3826b1bb559SWarner Losh.endfor 3836b1bb559SWarner Losh.else 3844fea6704SBruce Evans.for _src in ${SRCS:Mopt_*.h} 3854fea6704SBruce EvansCLEANFILES+= ${_src} 3864fea6704SBruce Evans.if !target(${_src}) 3874fea6704SBruce Evans${_src}: 3888b3ae668SDag-Erling Smørgrav :> ${.TARGET} 3894fea6704SBruce Evans.endif 3904fea6704SBruce Evans.endfor 3916b1bb559SWarner Losh.endif 3924fea6704SBruce Evans 3934ea56599SAndrew Turner# Add the sanitizer C flags 3944ea56599SAndrew TurnerCFLAGS+= ${SAN_CFLAGS} 3954ea56599SAndrew Turner 3965426539cSMatt Macy# Add the gcov flags 3975426539cSMatt MacyCFLAGS+= ${GCOV_CFLAGS} 3985426539cSMatt Macy 3993fd1e05bSAlexander Leidinger# Respect configuration-specific C flags. 400256054fdSBrooks DavisCFLAGS+= ${ARCH_FLAGS} ${CONF_CFLAGS} 40162769330SAlexander Leidinger 402a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Mvnode_if.c) 40378b2c868SBrian FeldmanCLEANFILES+= vnode_if.c 404528013d5SWarner Loshvnode_if.c: ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src 405528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -c 4064fea6704SBruce Evans.endif 40778b2c868SBrian Feldman 408a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Mvnode_if.h) 4099f73f0e8SRuslan ErmilovCLEANFILES+= vnode_if.h vnode_if_newproto.h vnode_if_typedef.h 410528013d5SWarner Loshvnode_if.h vnode_if_newproto.h vnode_if_typedef.h: ${SYSDIR}/tools/vnode_if.awk \ 411528013d5SWarner Losh ${SYSDIR}/kern/vnode_if.src 4129f73f0e8SRuslan Ermilovvnode_if.h: vnode_if_newproto.h vnode_if_typedef.h 413528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -h 4149f73f0e8SRuslan Ermilovvnode_if_newproto.h: 415528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -p 4169f73f0e8SRuslan Ermilovvnode_if_typedef.h: 417528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -q 41878b2c868SBrian Feldman.endif 4191aa57be3SGarrett Wollman 42012f05b84SWarner Losh# Build _if.[ch] from _if.m, and clean them when we're done. 421ec4047adSBryan Drewery# __MPATH defined in config.mk 4222cd2ff0eSJohn Baldwin_MFILES=${__MPATH:T:O} 4232cd2ff0eSJohn Baldwin_MPATH=${__MPATH:H:O:u} 42412f05b84SWarner Losh.PATH.m: ${_MPATH} 425160c44feSWarner Losh.for _i in ${SRCS:M*_if.[ch]} 4262cd2ff0eSJohn Baldwin_MATCH=M${_i:R:S/$/.m/} 4272cd2ff0eSJohn Baldwin_MATCHES=${_MFILES:${_MATCH}} 4282cd2ff0eSJohn Baldwin.if !empty(_MATCHES) 4292cd2ff0eSJohn BaldwinCLEANFILES+= ${_i} 4302cd2ff0eSJohn Baldwin.endif 431160c44feSWarner Losh.endfor # _i 4325852ae2dSBryan Drewery.m.c: ${SYSDIR}/tools/makeobjops.awk 43312f05b84SWarner Losh ${AWK} -f ${SYSDIR}/tools/makeobjops.awk ${.IMPSRC} -c 43412f05b84SWarner Losh 4355852ae2dSBryan Drewery.m.h: ${SYSDIR}/tools/makeobjops.awk 43612f05b84SWarner Losh ${AWK} -f ${SYSDIR}/tools/makeobjops.awk ${.IMPSRC} -h 43712f05b84SWarner Losh 4384e91eaf2SWarner Losh.for _i in mii pccard 439a7d30e5fSDavid E. O'Brien.if !empty(SRCS:M${_i}devs.h) 440dba6dd17SWarner LoshCLEANFILES+= ${_i}devs.h 4415852ae2dSBryan Drewery${_i}devs.h: ${SYSDIR}/tools/${_i}devs2h.awk ${SYSDIR}/dev/${_i}/${_i}devs 442528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/${_i}devs2h.awk ${SYSDIR}/dev/${_i}/${_i}devs 4432d3ce713SDavid E. O'Brien.endif 444dba6dd17SWarner Losh.endfor # _i 4452d3ce713SDavid E. O'Brien 446e83ce340SAdrian Chadd.if !empty(SRCS:Mbhnd_nvram_map.h) 447e83ce340SAdrian ChaddCLEANFILES+= bhnd_nvram_map.h 448e83ce340SAdrian Chaddbhnd_nvram_map.h: ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.awk \ 449e83ce340SAdrian Chadd ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.sh \ 4505852ae2dSBryan Drewery ${SYSDIR}/dev/bhnd/nvram/nvram_map 4515852ae2dSBryan Drewerybhnd_nvram_map.h: 45216fba18fSDimitry Andric sh ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.sh \ 453e83ce340SAdrian Chadd ${SYSDIR}/dev/bhnd/nvram/nvram_map -h 454e83ce340SAdrian Chadd.endif 455e83ce340SAdrian Chadd 456e83ce340SAdrian Chadd.if !empty(SRCS:Mbhnd_nvram_map_data.h) 457e83ce340SAdrian ChaddCLEANFILES+= bhnd_nvram_map_data.h 458e83ce340SAdrian Chaddbhnd_nvram_map_data.h: ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.awk \ 459e83ce340SAdrian Chadd ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.sh \ 4605852ae2dSBryan Drewery ${SYSDIR}/dev/bhnd/nvram/nvram_map 4615852ae2dSBryan Drewerybhnd_nvram_map_data.h: 46216fba18fSDimitry Andric sh ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.sh \ 463e83ce340SAdrian Chadd ${SYSDIR}/dev/bhnd/nvram/nvram_map -d 464e83ce340SAdrian Chadd.endif 465e83ce340SAdrian Chadd 466a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Musbdevs.h) 4674e91eaf2SWarner LoshCLEANFILES+= usbdevs.h 4685852ae2dSBryan Dreweryusbdevs.h: ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs 469528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs -h 4704e91eaf2SWarner Losh.endif 4714e91eaf2SWarner Losh 472a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Musbdevs_data.h) 4734e91eaf2SWarner LoshCLEANFILES+= usbdevs_data.h 4745852ae2dSBryan Dreweryusbdevs_data.h: ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs 475528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs -d 4764e91eaf2SWarner Losh.endif 4774e91eaf2SWarner Losh 47867ca7330SBjoern A. Zeeb.if !empty(SRCS:Msdiodevs.h) 47967ca7330SBjoern A. ZeebCLEANFILES+= sdiodevs.h 48067ca7330SBjoern A. Zeebsdiodevs.h: ${SYSDIR}/tools/sdiodevs2h.awk ${SYSDIR}/dev/sdio/sdiodevs 48167ca7330SBjoern A. Zeeb ${AWK} -f ${SYSDIR}/tools/sdiodevs2h.awk ${SYSDIR}/dev/sdio/sdiodevs -h 48267ca7330SBjoern A. Zeeb.endif 48367ca7330SBjoern A. Zeeb 48467ca7330SBjoern A. Zeeb.if !empty(SRCS:Msdiodevs_data.h) 48567ca7330SBjoern A. ZeebCLEANFILES+= sdiodevs_data.h 48667ca7330SBjoern A. Zeebsdiodevs_data.h: ${SYSDIR}/tools/sdiodevs2h.awk ${SYSDIR}/dev/sdio/sdiodevs 48767ca7330SBjoern A. Zeeb ${AWK} -f ${SYSDIR}/tools/sdiodevs2h.awk ${SYSDIR}/dev/sdio/sdiodevs -d 48867ca7330SBjoern A. Zeeb.endif 48967ca7330SBjoern A. Zeeb 490a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Macpi_quirks.h) 491684c1c1dSNate LawsonCLEANFILES+= acpi_quirks.h 4925852ae2dSBryan Dreweryacpi_quirks.h: ${SYSDIR}/tools/acpi_quirks2h.awk ${SYSDIR}/dev/acpica/acpi_quirks 493528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/acpi_quirks2h.awk ${SYSDIR}/dev/acpica/acpi_quirks 494684c1c1dSNate Lawson.endif 495684c1c1dSNate Lawson 496fc2a8776SEd Maste.if !empty(SRCS:Massym.inc) || !empty(DPSRCS:Massym.inc) 4979d2b4c4fSBryan DreweryCLEANFILES+= assym.inc genassym.o 498ccca101fSBryan DreweryDEPENDOBJS+= genassym.o 499ccca101fSBryan DreweryDPSRCS+= offset.inc 500ccca101fSBryan Drewery.endif 50182c98d01SBryan Drewery.if defined(MODULE_TIED) 50282c98d01SBryan DreweryDPSRCS+= offset.inc 50382c98d01SBryan Drewery.endif 504ccca101fSBryan Drewery.if !empty(SRCS:Moffset.inc) || !empty(DPSRCS:Moffset.inc) 505ccca101fSBryan DreweryCLEANFILES+= offset.inc genoffset.o 506ccca101fSBryan DreweryDEPENDOBJS+= genoffset.o 507ccca101fSBryan Drewery.endif 508fc2a8776SEd Masteassym.inc: genassym.o 5098bedbb4dSMatt Macyoffset.inc: genoffset.o 510fc2a8776SEd Masteassym.inc: ${SYSDIR}/kern/genassym.sh 511528013d5SWarner Losh sh ${SYSDIR}/kern/genassym.sh genassym.o > ${.TARGET} 512d69d8a46SBryan Drewerygenassym.o: ${SYSDIR}/${MACHINE}/${MACHINE}/genassym.c offset.inc 5135852ae2dSBryan Drewerygenassym.o: ${SRCS:Mopt_*.h} 514a8976aecSAlex Richardson ${CC} -c ${CFLAGS:N-flto:N-fno-common} -fcommon \ 5157dd824c3SEd Maste ${SYSDIR}/${MACHINE}/${MACHINE}/genassym.c 5168bedbb4dSMatt Macyoffset.inc: ${SYSDIR}/kern/genoffset.sh genoffset.o 5178bedbb4dSMatt Macy sh ${SYSDIR}/kern/genoffset.sh genoffset.o > ${.TARGET} 518d69d8a46SBryan Drewerygenoffset.o: ${SYSDIR}/kern/genoffset.c 5198bedbb4dSMatt Macygenoffset.o: ${SRCS:Mopt_*.h} 520a8976aecSAlex Richardson ${CC} -c ${CFLAGS:N-flto:N-fno-common} -fcommon \ 521d69d8a46SBryan Drewery ${SYSDIR}/kern/genoffset.c 522705d63cdSIan Dowse 523de1a3bd9SBryan DreweryCLEANDEPENDFILES+= ${_ILINKS} 52474465532SRuslan Ermilov# .depend needs include links so we remove them only together. 52574465532SRuslan Ermilovcleanilinks: 52674465532SRuslan Ermilov rm -f ${_ILINKS} 52774465532SRuslan Ermilov 528d7beff08SBryan DreweryOBJS_DEPEND_GUESS+= ${SRCS:M*.h} 529817f7baaSBryan Drewery.if defined(KERNBUILDDIR) 530817f7baaSBryan DreweryOBJS_DEPEND_GUESS+= opt_global.h 531817f7baaSBryan Drewery.endif 53288fe1f7aSBryan Drewery 5339e5787d2SMatt MacyZINCDIR=${SYSDIR}/contrib/openzfs/include 5349e5787d2SMatt MacyOPENZFS_CFLAGS= \ 5359e5787d2SMatt Macy -D_SYS_VMEM_H_ \ 5369e5787d2SMatt Macy -D__KERNEL__ \ 5379e5787d2SMatt Macy -nostdinc \ 5389e5787d2SMatt Macy -DSMP \ 5399e5787d2SMatt Macy -I${ZINCDIR} \ 5409e5787d2SMatt Macy -I${ZINCDIR}/os/freebsd \ 5419e5787d2SMatt Macy -I${ZINCDIR}/os/freebsd/spl \ 5429e5787d2SMatt Macy -I${ZINCDIR}/os/freebsd/zfs \ 5439e5787d2SMatt Macy -I${SYSDIR}/cddl/compat/opensolaris \ 5449e5787d2SMatt Macy -I${SYSDIR}/cddl/contrib/opensolaris/uts/common \ 5459e5787d2SMatt Macy -include ${ZINCDIR}/os/freebsd/spl/sys/ccompile.h 546d021434aSRyan LibbyOPENZFS_CWARNFLAGS= \ 547*c227269eSJohn Baldwin -Wno-nested-externs 5489e5787d2SMatt Macy 54988fe1f7aSBryan Drewery.include <bsd.dep.mk> 550aae63957SBryan Drewery.include <bsd.clang-analyze.mk> 551afba897fSBruce Evans.include <bsd.obj.mk> 552ddc474a8SRuslan Ermilov.include "kern.mk" 553