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 7912f05b84SWarner Losh.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S .m 80639a2e50SGarrett Wollman 813a0d123eSWarner Losh# amd64 and mips use direct linking for kmod, all others use shared binaries 823a0d123eSWarner Losh.if ${MACHINE_CPUARCH} != amd64 && ${MACHINE_CPUARCH} != mips 833a0d123eSWarner Losh__KLD_SHARED=yes 843a0d123eSWarner Losh.else 853a0d123eSWarner Losh__KLD_SHARED=no 863a0d123eSWarner Losh.endif 873a0d123eSWarner Losh 88f165cb7cSRuslan Ermilov.if !empty(CFLAGS:M-O[23s]) && empty(CFLAGS:M-fno-strict-aliasing) 89db0cd7e1SDavid E. O'BrienCFLAGS+= -fno-strict-aliasing 90db0cd7e1SDavid E. O'Brien.endif 915d3b2922SRuslan ErmilovWERROR?= -Werror 92daaea395SWarner LoshCFLAGS+= ${WERROR} 9348aea4daSRuslan ErmilovCFLAGS+= -D_KERNEL 948fe644b2SMike SmithCFLAGS+= -DKLD_MODULE 954a2d2630SBruce Evans 96021886ffSBruce Evans# Don't use any standard or source-relative include directories. 9706d6e4fcSTom RhodesNOSTDINC= -nostdinc 98da3bcc92SAlexander KabaevCFLAGS:= ${CFLAGS:N-I*} ${NOSTDINC} ${INCLMAGIC} ${CFLAGS:M-I*} 998fa793d0SBrian Feldman.if defined(KERNBUILDDIR) 1000c063641SGleb SmirnoffCFLAGS+= -DHAVE_KERNEL_OPTION_HEADERS -include ${KERNBUILDDIR}/opt_global.h 1018fa793d0SBrian Feldman.endif 102021886ffSBruce Evans 1031f089616SRuslan Ermilov# Add -I paths for system headers. Individual module makefiles don't 104021886ffSBruce Evans# need any -I paths for this. Similar defaults for .PATH can't be 105021886ffSBruce Evans# set because there are no standard paths for non-headers. 106528013d5SWarner LoshCFLAGS+= -I. -I${SYSDIR} 1074a2d2630SBruce Evans 10822ba0b2fSWarner LoshCFLAGS.gcc+= -finline-limit=${INLINE_LIMIT} 109cc4a90c4SGleb SmirnoffCFLAGS.gcc+= -fms-extensions 11022ba0b2fSWarner LoshCFLAGS.gcc+= --param inline-unit-growth=100 11122ba0b2fSWarner LoshCFLAGS.gcc+= --param large-function-growth=1000 1122a51529fSPeter Wemm 1130b3178a4SMike Smith# Disallow common variables, and if we end up with commons from 1140b3178a4SMike Smith# somewhere unexpected, allocate storage for them in the module itself. 1150b3178a4SMike SmithCFLAGS+= -fno-common 1160b3178a4SMike SmithLDFLAGS+= -d -warn-common 1170b3178a4SMike Smith 1189e4be63dSBruce EvansCFLAGS+= ${DEBUG_FLAGS} 1193a0d123eSWarner Losh.if ${MACHINE_CPUARCH} == amd64 1202565edc4SAndriy GaponCFLAGS+= -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer 12183c457dcSIan Dowse.endif 1229e4be63dSBruce Evans 1238598392cSKonstantin Belousov.if ${MACHINE_CPUARCH} == "aarch64" 1248598392cSKonstantin BelousovCFLAGS+= -fPIC 1258598392cSKonstantin Belousov.endif 1268598392cSKonstantin Belousov 127b54c389fSIan Lepore# Temporary workaround for PR 196407, which contains the fascinating details. 128c6f7b900SIan Lepore# Don't allow clang to use fpu instructions or registers in kernel modules. 129b54c389fSIan Lepore.if ${MACHINE_CPUARCH} == arm 13067e3484fSDimitry Andric.if ${COMPILER_VERSION} < 30800 131b54c389fSIan LeporeCFLAGS.clang+= -mllvm -arm-use-movt=0 13267e3484fSDimitry Andric.else 13367e3484fSDimitry AndricCFLAGS.clang+= -mno-movt 13467e3484fSDimitry Andric.endif 135c6f7b900SIan LeporeCFLAGS.clang+= -mfpu=none 1361b23f9b9SAndrew TurnerCFLAGS+= -funwind-tables 137b54c389fSIan Lepore.endif 138b54c389fSIan Lepore 1393a0d123eSWarner Losh.if ${MACHINE_CPUARCH} == powerpc 14055a5dcc8SPeter GrehanCFLAGS+= -mlongcall -fno-omit-frame-pointer 141fded756eSPeter Grehan.endif 142fded756eSPeter Grehan 1433a0d123eSWarner Losh.if ${MACHINE_CPUARCH} == mips 1446f3c6327SNeel NatuCFLAGS+= -G0 -fno-pic -mno-abicalls -mlong-calls 1456f3c6327SNeel Natu.endif 1466f3c6327SNeel Natu 14769745d38SAlexander Leidinger.if defined(DEBUG) || defined(DEBUG_FLAGS) 14869745d38SAlexander LeidingerCTFFLAGS+= -g 14969745d38SAlexander Leidinger.endif 15069745d38SAlexander Leidinger 1516aec1278SMax Laier.if defined(FIRMWS) 152*28849c57SBryan Drewery${KMOD:S/$/.c/}: ${SYSDIR}/tools/fw_stub.awk ${OP_META} 153528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/fw_stub.awk ${FIRMWS} -m${KMOD} -c${KMOD:S/$/.c/g} \ 1547bd6fde3SFlorent Thoumie ${FIRMWARE_LICENSE:C/.+/-l/}${FIRMWARE_LICENSE} 1556aec1278SMax Laier 1566aec1278SMax LaierSRCS+= ${KMOD:S/$/.c/} 1576aec1278SMax LaierCLEANFILES+= ${KMOD:S/$/.c/} 1586aec1278SMax Laier 1596aec1278SMax Laier.for _firmw in ${FIRMWS} 160*28849c57SBryan Drewery${_firmw:C/\:.*$/.fwo/:T}: ${_firmw:C/\:.*$//} ${OP_META} 1616aec1278SMax Laier @${ECHO} ${_firmw:C/\:.*$//} ${.ALLSRC:M*${_firmw:C/\:.*$//}} 162009b3d3dSMax Laier @if [ -e ${_firmw:C/\:.*$//} ]; then \ 1635b6dc2efSSimon J. Gerraty ${LD} -b binary --no-warn-mismatch ${_LDFLAGS} \ 164ba6a2bb3SMarcel Moolenaar -r -d -o ${.TARGET} ${_firmw:C/\:.*$//}; \ 165ff8e7669SMax Laier else \ 166ff8e7669SMax Laier ln -s ${.ALLSRC:M*${_firmw:C/\:.*$//}} ${_firmw:C/\:.*$//}; \ 1675b6dc2efSSimon J. Gerraty ${LD} -b binary --no-warn-mismatch ${_LDFLAGS} \ 168ba6a2bb3SMarcel Moolenaar -r -d -o ${.TARGET} ${_firmw:C/\:.*$//}; \ 169ff8e7669SMax Laier rm ${_firmw:C/\:.*$//}; \ 170ff8e7669SMax Laier fi 1716aec1278SMax Laier 172d9eed6f4SJohn BaldwinOBJS+= ${_firmw:C/\:.*$/.fwo/:T} 1736aec1278SMax Laier.endfor 1746aec1278SMax Laier.endif 1756aec1278SMax Laier 17635c4406dSWarner Losh# Conditionally include SRCS based on kernel config options. 17735c4406dSWarner Losh.for _o in ${KERN_OPTS} 17835c4406dSWarner LoshSRCS+=${SRCS.${_o}} 17935c4406dSWarner Losh.endfor 18035c4406dSWarner Losh 181639a2e50SGarrett WollmanOBJS+= ${SRCS:N*.h:R:S/$/.o/g} 182639a2e50SGarrett Wollman 183639a2e50SGarrett Wollman.if !defined(PROG) 18490f60fc9SMike SmithPROG= ${KMOD}.ko 18590f60fc9SMike Smith.endif 186639a2e50SGarrett Wollman 187817b59bfSRuslan Ermilov.if !defined(DEBUG_FLAGS) 188f6611608SSheldon HearnFULLPROG= ${PROG} 189f6611608SSheldon Hearn.else 19005117b57SEd MasteFULLPROG= ${PROG}.full 191*28849c57SBryan Drewery${PROG}: ${FULLPROG} ${PROG}.debug ${OP_META} 19205117b57SEd Maste ${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROG}.debug \ 19398b45a8fSRuslan Ermilov ${FULLPROG} ${.TARGET} 194*28849c57SBryan Drewery${PROG}.debug: ${FULLPROG} ${OP_META} 19598b45a8fSRuslan Ermilov ${OBJCOPY} --only-keep-debug ${FULLPROG} ${.TARGET} 196f6611608SSheldon Hearn.endif 197f6611608SSheldon Hearn 1983a0d123eSWarner Losh.if ${__KLD_SHARED} == yes 199*28849c57SBryan Drewery${FULLPROG}: ${KMOD}.kld ${OP_META} 2008598392cSKonstantin Belousov.if ${MACHINE_CPUARCH} != "aarch64" 2015b6dc2efSSimon J. Gerraty ${LD} -Bshareable ${_LDFLAGS} -o ${.TARGET} ${KMOD}.kld 2028598392cSKonstantin Belousov.else 2038598392cSKonstantin Belousov#XXXKIB Relocatable linking in aarch64 ld from binutils 2.25.1 does 2048598392cSKonstantin Belousov# not work. The linker corrupts the references to the external 2058598392cSKonstantin Belousov# symbols which are defined by other object in the linking set 2068598392cSKonstantin Belousov# and should therefore loose the GOT entry. The problem seems 2078598392cSKonstantin Belousov# to be fixed in the binutils-gdb git HEAD as of 2015-10-04. Hack 2088598392cSKonstantin Belousov# below allows to get partially functioning modules for now. 2098598392cSKonstantin Belousov ${LD} -Bshareable ${_LDFLAGS} -o ${.TARGET} ${OBJS} 2108598392cSKonstantin Belousov.endif 211817b59bfSRuslan Ermilov.if !defined(DEBUG_FLAGS) 212817b59bfSRuslan Ermilov ${OBJCOPY} --strip-debug ${.TARGET} 2134c293d35SRuslan Ermilov.endif 2144d6bcc83SPeter Wemm.endif 21509be11baSPeter Wemm 21693f03548SMike SmithEXPORT_SYMS?= NO 21793f03548SMike Smith.if ${EXPORT_SYMS} != YES 2181f089616SRuslan ErmilovCLEANFILES+= export_syms 2190b3178a4SMike Smith.endif 2200b3178a4SMike Smith 2213a0d123eSWarner Losh.if ${__KLD_SHARED} == yes 222*28849c57SBryan Drewery${KMOD}.kld: ${OBJS} ${OP_META} 2234d6bcc83SPeter Wemm.else 224*28849c57SBryan Drewery${FULLPROG}: ${OBJS} ${OP_META} 2254d6bcc83SPeter Wemm.endif 2265b6dc2efSSimon J. Gerraty ${LD} ${_LDFLAGS} -r -d -o ${.TARGET} ${OBJS} 227724afafaSWarner Losh.if ${MK_CTF} != "no" 228cd49c2e8SMax Khon ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} 229cd49c2e8SMax Khon.endif 2300b3178a4SMike Smith.if defined(EXPORT_SYMS) 23193f03548SMike Smith.if ${EXPORT_SYMS} != YES 2320b3178a4SMike Smith.if ${EXPORT_SYMS} == NO 2338b3ae668SDag-Erling Smørgrav :> export_syms 2340b3178a4SMike Smith.elif !exists(${.CURDIR}/${EXPORT_SYMS}) 2351f089616SRuslan Ermilov echo ${EXPORT_SYMS} > export_syms 2360b3178a4SMike Smith.else 2371f089616SRuslan Ermilov grep -v '^#' < ${EXPORT_SYMS} > export_syms 2380b3178a4SMike Smith.endif 23911f1d284SMark Johnston ${AWK} -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \ 2401f089616SRuslan Ermilov export_syms | xargs -J% ${OBJCOPY} % ${.TARGET} 24193f03548SMike Smith.endif 2420b3178a4SMike Smith.endif 2433a0d123eSWarner Losh.if !defined(DEBUG_FLAGS) && ${__KLD_SHARED} == no 2444d6bcc83SPeter Wemm ${OBJCOPY} --strip-debug ${.TARGET} 2454d6bcc83SPeter Wemm.endif 2460b3178a4SMike Smith 247528013d5SWarner Losh_ILINKS=machine 2488598392cSKonstantin Belousov.if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64" 249915b4b09SNathan Whitehorn_ILINKS+=${MACHINE_CPUARCH} 250df3a103dSWarner Losh.endif 251544de89dSJohn Baldwin.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" 252544de89dSJohn Baldwin_ILINKS+=x86 253544de89dSJohn Baldwin.endif 25431a01497SSean BrunoCLEANFILES+=${_ILINKS} 255639a2e50SGarrett Wollman 2561bd4272fSBryan Dreweryall: ${PROG} 2574a2d2630SBruce Evans 258db00e6c5SDavid E. O'Brienbeforedepend: ${_ILINKS} 25968d96923SBryan Drewerybeforebuild: ${_ILINKS} 260985f41afSWarner Losh 261f3cc9575SWarner Losh# Ensure that the links exist without depending on it when it exists which 262f3cc9575SWarner Losh# causes all the modules to be rebuilt when the directory pointed to changes. 263f3cc9575SWarner Losh.for _link in ${_ILINKS} 264f3cc9575SWarner Losh.if !exists(${.OBJDIR}/${_link}) 2658cf80600SSimon J. Gerraty${OBJS}: ${_link} 266f3cc9575SWarner Losh.endif 267f3cc9575SWarner Losh.endfor 2684a2d2630SBruce Evans 2699a8631b3SWarner Losh# Search for kernel source tree in standard places. 2709a8631b3SWarner Losh.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys 271776f50b9SRuslan Ermilov.if !defined(SYSDIR) && exists(${_dir}/kern/) 2729a8631b3SWarner LoshSYSDIR= ${_dir} 2739a8631b3SWarner Losh.endif 2749a8631b3SWarner Losh.endfor 275776f50b9SRuslan Ermilov.if !defined(SYSDIR) || !exists(${SYSDIR}/kern/) 2769a8631b3SWarner Losh.error "can't find kernel source tree" 2779a8631b3SWarner Losh.endif 2789a8631b3SWarner Losh 2797750ad47SMarcel Moolenaar.NOPATH: ${_ILINKS} 2803c4368b2SMark Johnston 2814a2d2630SBruce Evans${_ILINKS}: 2829a8631b3SWarner Losh @case ${.TARGET} in \ 283df3a103dSWarner Losh machine) \ 284df3a103dSWarner Losh path=${SYSDIR}/${MACHINE}/include ;; \ 285544de89dSJohn Baldwin *) \ 2863c4368b2SMark Johnston path=${SYSDIR}/${.TARGET:T}/include ;; \ 28708a04a89SPeter Wemm esac ; \ 28808a04a89SPeter Wemm path=`(cd $$path && /bin/pwd)` ; \ 2893c4368b2SMark Johnston ${ECHO} ${.TARGET:T} "->" $$path ; \ 2903c4368b2SMark Johnston ln -sf $$path ${.TARGET:T} 2914a2d2630SBruce Evans 29274465532SRuslan ErmilovCLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} 293361186e5SMaxime Henrion 294817b59bfSRuslan Ermilov.if defined(DEBUG_FLAGS) 29505117b57SEd MasteCLEANFILES+= ${FULLPROG} ${PROG}.debug 296361186e5SMaxime Henrion.endif 297639a2e50SGarrett Wollman 298639a2e50SGarrett Wollman.if !target(install) 299639a2e50SGarrett Wollman 300ea87b3cbSDavid E. O'Brien_INSTALLFLAGS:= ${INSTALLFLAGS} 301e902c1bbSTim Vanderhoek.for ie in ${INSTALLFLAGS_EDIT} 302e902c1bbSTim Vanderhoek_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 303e902c1bbSTim Vanderhoek.endfor 304e902c1bbSTim Vanderhoek 3052b06260dSRuslan Ermilov.if !target(realinstall) 30605117b57SEd MasteKERN_DEBUGDIR?= ${DEBUGDIR} 3072b06260dSRuslan Ermilovrealinstall: _kmodinstall 3082b06260dSRuslan Ermilov.ORDER: beforeinstall _kmodinstall 30949773547SBryan Drewery_kmodinstall: .PHONY 3101c6eb1b2SBaptiste Daroussin ${INSTALL} -T release -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 3110ed70e42SBryan Drewery ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}/ 312cd95660fSDavid E. O'Brien.if defined(DEBUG_FLAGS) && !defined(INSTALL_NODEBUG) && ${MK_KERNEL_SYMBOLS} != "no" 3131c6eb1b2SBaptiste Daroussin ${INSTALL} -T debug -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 3140ed70e42SBryan Drewery ${_INSTALLFLAGS} ${PROG}.debug ${DESTDIR}${KERN_DEBUGDIR}${KMODDIR}/ 315d24864f7SRuslan Ermilov.endif 3162b06260dSRuslan Ermilov 3172b06260dSRuslan Ermilov.include <bsd.links.mk> 3182b06260dSRuslan Ermilov 3194875819cSJake Burkholder.if !defined(NO_XREF) 3202b06260dSRuslan Ermilovafterinstall: _kldxref 3212b06260dSRuslan Ermilov.ORDER: realinstall _kldxref 3222b06260dSRuslan Ermilov.ORDER: _installlinks _kldxref 32349773547SBryan Drewery_kldxref: .PHONY 324be1d673dSRuslan Ermilov @if type kldxref >/dev/null 2>&1; then \ 325be1d673dSRuslan Ermilov ${ECHO} kldxref ${DESTDIR}${KMODDIR}; \ 326be1d673dSRuslan Ermilov kldxref ${DESTDIR}${KMODDIR}; \ 327be1d673dSRuslan Ermilov fi 328505222d3SPeter Wemm.endif 32922a8b405SMaxime Henrion.endif # !target(realinstall) 330639a2e50SGarrett Wollman 33122a8b405SMaxime Henrion.endif # !target(install) 332639a2e50SGarrett Wollman 333639a2e50SGarrett Wollman.if !target(load) 33449773547SBryan Dreweryload: ${PROG} .PHONY 3351f089616SRuslan Ermilov ${KMODLOAD} -v ${.OBJDIR}/${PROG} 336639a2e50SGarrett Wollman.endif 337639a2e50SGarrett Wollman 338639a2e50SGarrett Wollman.if !target(unload) 33949773547SBryan Dreweryunload: .PHONY 34093bffaf2SDag-Erling Smørgrav if ${KMODISLOADED} ${PROG} ; then ${KMODUNLOAD} -v ${PROG} ; fi 34193bffaf2SDag-Erling Smørgrav.endif 34293bffaf2SDag-Erling Smørgrav 34393bffaf2SDag-Erling Smørgrav.if !target(reload) 34449773547SBryan Dreweryreload: unload load .PHONY 34508a04a89SPeter Wemm.endif 3461aa57be3SGarrett Wollman 3476b1bb559SWarner Losh.if defined(KERNBUILDDIR) 3486b1bb559SWarner Losh.PATH: ${KERNBUILDDIR} 3496b1bb559SWarner LoshCFLAGS+= -I${KERNBUILDDIR} 3506b1bb559SWarner Losh.for _src in ${SRCS:Mopt_*.h} 3516b1bb559SWarner LoshCLEANFILES+= ${_src} 3526b1bb559SWarner Losh.if !target(${_src}) 3536b1bb559SWarner Losh${_src}: 35440244cc2SDavid E. O'Brien ln -sf ${KERNBUILDDIR}/${_src} ${.TARGET} 3556b1bb559SWarner Losh.endif 3566b1bb559SWarner Losh.endfor 3576b1bb559SWarner Losh.else 3584fea6704SBruce Evans.for _src in ${SRCS:Mopt_*.h} 3594fea6704SBruce EvansCLEANFILES+= ${_src} 3604fea6704SBruce Evans.if !target(${_src}) 3614fea6704SBruce Evans${_src}: 3628b3ae668SDag-Erling Smørgrav :> ${.TARGET} 3634fea6704SBruce Evans.endif 3644fea6704SBruce Evans.endfor 3656b1bb559SWarner Losh.endif 3664fea6704SBruce Evans 3673fd1e05bSAlexander Leidinger# Respect configuration-specific C flags. 36862769330SAlexander LeidingerCFLAGS+= ${CONF_CFLAGS} 36962769330SAlexander Leidinger 370a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Mvnode_if.c) 37178b2c868SBrian FeldmanCLEANFILES+= vnode_if.c 372528013d5SWarner Loshvnode_if.c: ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src 373528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -c 3744fea6704SBruce Evans.endif 37578b2c868SBrian Feldman 376a7d30e5fSDavid E. O'Brien.if !empty(SRCS:Mvnode_if.h) 3779f73f0e8SRuslan ErmilovCLEANFILES+= vnode_if.h vnode_if_newproto.h vnode_if_typedef.h 378528013d5SWarner Loshvnode_if.h vnode_if_newproto.h vnode_if_typedef.h: ${SYSDIR}/tools/vnode_if.awk \ 379528013d5SWarner Losh ${SYSDIR}/kern/vnode_if.src 3809f73f0e8SRuslan Ermilovvnode_if.h: vnode_if_newproto.h vnode_if_typedef.h 381528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -h 3829f73f0e8SRuslan Ermilovvnode_if_newproto.h: 383528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -p 3849f73f0e8SRuslan Ermilovvnode_if_typedef.h: 385528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src -q 38678b2c868SBrian Feldman.endif 3871aa57be3SGarrett Wollman 38812f05b84SWarner Losh# Build _if.[ch] from _if.m, and clean them when we're done. 389ec4047adSBryan Drewery# __MPATH defined in config.mk 3902cd2ff0eSJohn Baldwin_MFILES=${__MPATH:T:O} 3912cd2ff0eSJohn Baldwin_MPATH=${__MPATH:H:O:u} 39212f05b84SWarner Losh.PATH.m: ${_MPATH} 393160c44feSWarner Losh.for _i in ${SRCS:M*_if.[ch]} 3942cd2ff0eSJohn Baldwin_MATCH=M${_i:R:S/$/.m/} 3952cd2ff0eSJohn Baldwin_MATCHES=${_MFILES:${_MATCH}} 3962cd2ff0eSJohn Baldwin.if !empty(_MATCHES) 3972cd2ff0eSJohn BaldwinCLEANFILES+= ${_i} 3982cd2ff0eSJohn Baldwin.endif 399160c44feSWarner Losh.endfor # _i 400*28849c57SBryan Drewery.m.c: ${SYSDIR}/tools/makeobjops.awk ${OP_META} 40112f05b84SWarner Losh ${AWK} -f ${SYSDIR}/tools/makeobjops.awk ${.IMPSRC} -c 40212f05b84SWarner Losh 403*28849c57SBryan Drewery.m.h: ${SYSDIR}/tools/makeobjops.awk ${OP_META} 40412f05b84SWarner Losh ${AWK} -f ${SYSDIR}/tools/makeobjops.awk ${.IMPSRC} -h 40512f05b84SWarner Losh 4064e91eaf2SWarner Losh.for _i in mii pccard 407a7d30e5fSDavid E. O'Brien.if !empty(SRCS:M${_i}devs.h) 408dba6dd17SWarner LoshCLEANFILES+= ${_i}devs.h 409*28849c57SBryan Drewery${_i}devs.h: ${SYSDIR}/tools/${_i}devs2h.awk ${SYSDIR}/dev/${_i}/${_i}devs ${OP_META} 410528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/${_i}devs2h.awk ${SYSDIR}/dev/${_i}/${_i}devs 4112d3ce713SDavid E. O'Brien.endif 412dba6dd17SWarner Losh.endfor # _i 4132d3ce713SDavid E. O'Brien 414e83ce340SAdrian Chadd.if !empty(SRCS:Mbhnd_nvram_map.h) 415e83ce340SAdrian ChaddCLEANFILES+= bhnd_nvram_map.h 416e83ce340SAdrian Chaddbhnd_nvram_map.h: ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.awk \ 417e83ce340SAdrian Chadd ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.sh \ 418*28849c57SBryan Drewery ${SYSDIR}/dev/bhnd/nvram/nvram_map \ 419*28849c57SBryan Drewery ${OP_META} 420*28849c57SBryan Drewerybhnd_nvram_map.h: ${OP_META} 42116fba18fSDimitry Andric sh ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.sh \ 422e83ce340SAdrian Chadd ${SYSDIR}/dev/bhnd/nvram/nvram_map -h 423e83ce340SAdrian Chadd.endif 424e83ce340SAdrian Chadd 425e83ce340SAdrian Chadd.if !empty(SRCS:Mbhnd_nvram_map_data.h) 426e83ce340SAdrian ChaddCLEANFILES+= bhnd_nvram_map_data.h 427e83ce340SAdrian Chaddbhnd_nvram_map_data.h: ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.awk \ 428e83ce340SAdrian Chadd ${SYSDIR}/dev/bhnd/tools/nvram_map_gen.sh \ 429*28849c57SBryan Drewery ${SYSDIR}/dev/bhnd/nvram/nvram_map \ 430*28849c57SBryan Drewery ${OP_META} 431*28849c57SBryan Drewerybhnd_nvram_map_data.h: ${OP_META} 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 438*28849c57SBryan Dreweryusbdevs.h: ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs ${OP_META} 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 444*28849c57SBryan Dreweryusbdevs_data.h: ${SYSDIR}/tools/usbdevs2h.awk ${SYSDIR}/dev/usb/usbdevs ${OP_META} 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 450*28849c57SBryan Dreweryacpi_quirks.h: ${SYSDIR}/tools/acpi_quirks2h.awk ${SYSDIR}/dev/acpica/acpi_quirks ${OP_META} 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 460*28849c57SBryan Dreweryassym.s: ${SYSDIR}/kern/genassym.sh ${OP_META} 461528013d5SWarner Losh sh ${SYSDIR}/kern/genassym.sh genassym.o > ${.TARGET} 4627dd824c3SEd Mastegenassym.o: ${SYSDIR}/${MACHINE}/${MACHINE}/genassym.c 463*28849c57SBryan Drewerygenassym.o: ${SRCS:Mopt_*.h} ${OP_META} 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