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 79*5d4447e0SBryan Drewery# Search for kernel source tree in standard places. 80*5d4447e0SBryan Drewery.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys 81*5d4447e0SBryan Drewery.if !defined(SYSDIR) && exists(${_dir}/kern/) 82*5d4447e0SBryan DrewerySYSDIR= ${_dir:tA} 83*5d4447e0SBryan Drewery.endif 84*5d4447e0SBryan Drewery.endfor 85*5d4447e0SBryan Drewery.if !defined(SYSDIR) || !exists(${SYSDIR}/kern/) 86*5d4447e0SBryan Drewery.error "can't find kernel source tree" 87*5d4447e0SBryan Drewery.endif 88*5d4447e0SBryan Drewery 8912f05b84SWarner Losh.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S .m 90639a2e50SGarrett Wollman 913a0d123eSWarner Losh# amd64 and mips use direct linking for kmod, all others use shared binaries 923a0d123eSWarner Losh.if ${MACHINE_CPUARCH} != amd64 && ${MACHINE_CPUARCH} != mips 933a0d123eSWarner Losh__KLD_SHARED=yes 943a0d123eSWarner Losh.else 953a0d123eSWarner Losh__KLD_SHARED=no 963a0d123eSWarner Losh.endif 973a0d123eSWarner Losh 98f165cb7cSRuslan Ermilov.if !empty(CFLAGS:M-O[23s]) && empty(CFLAGS:M-fno-strict-aliasing) 99db0cd7e1SDavid E. O'BrienCFLAGS+= -fno-strict-aliasing 100db0cd7e1SDavid E. O'Brien.endif 1015d3b2922SRuslan ErmilovWERROR?= -Werror 102daaea395SWarner LoshCFLAGS+= ${WERROR} 10348aea4daSRuslan ErmilovCFLAGS+= -D_KERNEL 1048fe644b2SMike SmithCFLAGS+= -DKLD_MODULE 1054a2d2630SBruce Evans 106021886ffSBruce Evans# Don't use any standard or source-relative include directories. 10706d6e4fcSTom RhodesNOSTDINC= -nostdinc 108da3bcc92SAlexander KabaevCFLAGS:= ${CFLAGS:N-I*} ${NOSTDINC} ${INCLMAGIC} ${CFLAGS:M-I*} 1098fa793d0SBrian Feldman.if defined(KERNBUILDDIR) 1100c063641SGleb SmirnoffCFLAGS+= -DHAVE_KERNEL_OPTION_HEADERS -include ${KERNBUILDDIR}/opt_global.h 1118fa793d0SBrian Feldman.endif 112021886ffSBruce Evans 1131f089616SRuslan Ermilov# Add -I paths for system headers. Individual module makefiles don't 114021886ffSBruce Evans# need any -I paths for this. Similar defaults for .PATH can't be 115021886ffSBruce Evans# set because there are no standard paths for non-headers. 116528013d5SWarner LoshCFLAGS+= -I. -I${SYSDIR} 1174a2d2630SBruce Evans 11822ba0b2fSWarner LoshCFLAGS.gcc+= -finline-limit=${INLINE_LIMIT} 119cc4a90c4SGleb SmirnoffCFLAGS.gcc+= -fms-extensions 12022ba0b2fSWarner LoshCFLAGS.gcc+= --param inline-unit-growth=100 12122ba0b2fSWarner LoshCFLAGS.gcc+= --param large-function-growth=1000 1222a51529fSPeter Wemm 1230b3178a4SMike Smith# Disallow common variables, and if we end up with commons from 1240b3178a4SMike Smith# somewhere unexpected, allocate storage for them in the module itself. 1250b3178a4SMike SmithCFLAGS+= -fno-common 1260b3178a4SMike SmithLDFLAGS+= -d -warn-common 1270b3178a4SMike Smith 1289e4be63dSBruce EvansCFLAGS+= ${DEBUG_FLAGS} 1293a0d123eSWarner Losh.if ${MACHINE_CPUARCH} == amd64 1302565edc4SAndriy GaponCFLAGS+= -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer 13183c457dcSIan Dowse.endif 1329e4be63dSBruce Evans 1338598392cSKonstantin Belousov.if ${MACHINE_CPUARCH} == "aarch64" 1348598392cSKonstantin BelousovCFLAGS+= -fPIC 1358598392cSKonstantin Belousov.endif 1368598392cSKonstantin Belousov 137b54c389fSIan Lepore# Temporary workaround for PR 196407, which contains the fascinating details. 138c6f7b900SIan Lepore# Don't allow clang to use fpu instructions or registers in kernel modules. 139b54c389fSIan Lepore.if ${MACHINE_CPUARCH} == arm 14067e3484fSDimitry Andric.if ${COMPILER_VERSION} < 30800 141b54c389fSIan LeporeCFLAGS.clang+= -mllvm -arm-use-movt=0 14267e3484fSDimitry Andric.else 14367e3484fSDimitry AndricCFLAGS.clang+= -mno-movt 14467e3484fSDimitry Andric.endif 145c6f7b900SIan LeporeCFLAGS.clang+= -mfpu=none 1461b23f9b9SAndrew TurnerCFLAGS+= -funwind-tables 147b54c389fSIan Lepore.endif 148b54c389fSIan Lepore 1493a0d123eSWarner Losh.if ${MACHINE_CPUARCH} == powerpc 15055a5dcc8SPeter GrehanCFLAGS+= -mlongcall -fno-omit-frame-pointer 151fded756eSPeter Grehan.endif 152fded756eSPeter Grehan 1533a0d123eSWarner Losh.if ${MACHINE_CPUARCH} == mips 1546f3c6327SNeel NatuCFLAGS+= -G0 -fno-pic -mno-abicalls -mlong-calls 1556f3c6327SNeel Natu.endif 1566f3c6327SNeel Natu 15769745d38SAlexander Leidinger.if defined(DEBUG) || defined(DEBUG_FLAGS) 15869745d38SAlexander LeidingerCTFFLAGS+= -g 15969745d38SAlexander Leidinger.endif 16069745d38SAlexander Leidinger 1616aec1278SMax Laier.if defined(FIRMWS) 16228849c57SBryan Drewery${KMOD:S/$/.c/}: ${SYSDIR}/tools/fw_stub.awk ${OP_META} 163528013d5SWarner Losh ${AWK} -f ${SYSDIR}/tools/fw_stub.awk ${FIRMWS} -m${KMOD} -c${KMOD:S/$/.c/g} \ 1647bd6fde3SFlorent Thoumie ${FIRMWARE_LICENSE:C/.+/-l/}${FIRMWARE_LICENSE} 1656aec1278SMax Laier 1666aec1278SMax LaierSRCS+= ${KMOD:S/$/.c/} 1676aec1278SMax LaierCLEANFILES+= ${KMOD:S/$/.c/} 1686aec1278SMax Laier 1696aec1278SMax Laier.for _firmw in ${FIRMWS} 17028849c57SBryan Drewery${_firmw:C/\:.*$/.fwo/:T}: ${_firmw:C/\:.*$//} ${OP_META} 1716aec1278SMax Laier @${ECHO} ${_firmw:C/\:.*$//} ${.ALLSRC:M*${_firmw:C/\:.*$//}} 172009b3d3dSMax Laier @if [ -e ${_firmw:C/\:.*$//} ]; then \ 1735b6dc2efSSimon J. Gerraty ${LD} -b binary --no-warn-mismatch ${_LDFLAGS} \ 174ba6a2bb3SMarcel Moolenaar -r -d -o ${.TARGET} ${_firmw:C/\:.*$//}; \ 175ff8e7669SMax Laier else \ 176ff8e7669SMax Laier ln -s ${.ALLSRC:M*${_firmw:C/\:.*$//}} ${_firmw:C/\:.*$//}; \ 1775b6dc2efSSimon J. Gerraty ${LD} -b binary --no-warn-mismatch ${_LDFLAGS} \ 178ba6a2bb3SMarcel Moolenaar -r -d -o ${.TARGET} ${_firmw:C/\:.*$//}; \ 179ff8e7669SMax Laier rm ${_firmw:C/\:.*$//}; \ 180ff8e7669SMax Laier fi 1816aec1278SMax Laier 182d9eed6f4SJohn BaldwinOBJS+= ${_firmw:C/\:.*$/.fwo/:T} 1836aec1278SMax Laier.endfor 1846aec1278SMax Laier.endif 1856aec1278SMax Laier 18635c4406dSWarner Losh# Conditionally include SRCS based on kernel config options. 18735c4406dSWarner Losh.for _o in ${KERN_OPTS} 18835c4406dSWarner LoshSRCS+=${SRCS.${_o}} 18935c4406dSWarner Losh.endfor 19035c4406dSWarner Losh 191639a2e50SGarrett WollmanOBJS+= ${SRCS:N*.h:R:S/$/.o/g} 192639a2e50SGarrett Wollman 193639a2e50SGarrett Wollman.if !defined(PROG) 19490f60fc9SMike SmithPROG= ${KMOD}.ko 19590f60fc9SMike Smith.endif 196639a2e50SGarrett Wollman 197817b59bfSRuslan Ermilov.if !defined(DEBUG_FLAGS) 198f6611608SSheldon HearnFULLPROG= ${PROG} 199f6611608SSheldon Hearn.else 20005117b57SEd MasteFULLPROG= ${PROG}.full 20128849c57SBryan Drewery${PROG}: ${FULLPROG} ${PROG}.debug ${OP_META} 20205117b57SEd Maste ${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROG}.debug \ 20398b45a8fSRuslan Ermilov ${FULLPROG} ${.TARGET} 20428849c57SBryan Drewery${PROG}.debug: ${FULLPROG} ${OP_META} 20598b45a8fSRuslan Ermilov ${OBJCOPY} --only-keep-debug ${FULLPROG} ${.TARGET} 206f6611608SSheldon Hearn.endif 207f6611608SSheldon Hearn 2083a0d123eSWarner Losh.if ${__KLD_SHARED} == yes 20928849c57SBryan Drewery${FULLPROG}: ${KMOD}.kld ${OP_META} 2108598392cSKonstantin Belousov.if ${MACHINE_CPUARCH} != "aarch64" 2115b6dc2efSSimon J. Gerraty ${LD} -Bshareable ${_LDFLAGS} -o ${.TARGET} ${KMOD}.kld 2128598392cSKonstantin Belousov.else 2138598392cSKonstantin Belousov#XXXKIB Relocatable linking in aarch64 ld from binutils 2.25.1 does 2148598392cSKonstantin Belousov# not work. The linker corrupts the references to the external 2158598392cSKonstantin Belousov# symbols which are defined by other object in the linking set 2168598392cSKonstantin Belousov# and should therefore loose the GOT entry. The problem seems 2178598392cSKonstantin Belousov# to be fixed in the binutils-gdb git HEAD as of 2015-10-04. Hack 2188598392cSKonstantin Belousov# below allows to get partially functioning modules for now. 2198598392cSKonstantin Belousov ${LD} -Bshareable ${_LDFLAGS} -o ${.TARGET} ${OBJS} 2208598392cSKonstantin Belousov.endif 221817b59bfSRuslan Ermilov.if !defined(DEBUG_FLAGS) 222817b59bfSRuslan Ermilov ${OBJCOPY} --strip-debug ${.TARGET} 2234c293d35SRuslan Ermilov.endif 2244d6bcc83SPeter Wemm.endif 22509be11baSPeter Wemm 22693f03548SMike SmithEXPORT_SYMS?= NO 22793f03548SMike Smith.if ${EXPORT_SYMS} != YES 2281f089616SRuslan ErmilovCLEANFILES+= export_syms 2290b3178a4SMike Smith.endif 2300b3178a4SMike Smith 2313a0d123eSWarner Losh.if ${__KLD_SHARED} == yes 23228849c57SBryan Drewery${KMOD}.kld: ${OBJS} ${OP_META} 2334d6bcc83SPeter Wemm.else 23428849c57SBryan Drewery${FULLPROG}: ${OBJS} ${OP_META} 2354d6bcc83SPeter Wemm.endif 2365b6dc2efSSimon J. Gerraty ${LD} ${_LDFLAGS} -r -d -o ${.TARGET} ${OBJS} 237724afafaSWarner Losh.if ${MK_CTF} != "no" 238cd49c2e8SMax Khon ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} 239cd49c2e8SMax Khon.endif 2400b3178a4SMike Smith.if defined(EXPORT_SYMS) 24193f03548SMike Smith.if ${EXPORT_SYMS} != YES 2420b3178a4SMike Smith.if ${EXPORT_SYMS} == NO 2438b3ae668SDag-Erling Smørgrav :> export_syms 2440b3178a4SMike Smith.elif !exists(${.CURDIR}/${EXPORT_SYMS}) 2451f089616SRuslan Ermilov echo ${EXPORT_SYMS} > export_syms 2460b3178a4SMike Smith.else 2471f089616SRuslan Ermilov grep -v '^#' < ${EXPORT_SYMS} > export_syms 2480b3178a4SMike Smith.endif 24911f1d284SMark Johnston ${AWK} -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \ 2501f089616SRuslan Ermilov export_syms | xargs -J% ${OBJCOPY} % ${.TARGET} 25193f03548SMike Smith.endif 2520b3178a4SMike Smith.endif 2533a0d123eSWarner Losh.if !defined(DEBUG_FLAGS) && ${__KLD_SHARED} == no 2544d6bcc83SPeter Wemm ${OBJCOPY} --strip-debug ${.TARGET} 2554d6bcc83SPeter Wemm.endif 2560b3178a4SMike Smith 257528013d5SWarner Losh_ILINKS=machine 2588598392cSKonstantin Belousov.if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64" 259915b4b09SNathan Whitehorn_ILINKS+=${MACHINE_CPUARCH} 260df3a103dSWarner Losh.endif 261544de89dSJohn Baldwin.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" 262544de89dSJohn Baldwin_ILINKS+=x86 263544de89dSJohn Baldwin.endif 26431a01497SSean BrunoCLEANFILES+=${_ILINKS} 265639a2e50SGarrett Wollman 2661bd4272fSBryan Dreweryall: ${PROG} 2674a2d2630SBruce Evans 268db00e6c5SDavid E. O'Brienbeforedepend: ${_ILINKS} 26968d96923SBryan Drewerybeforebuild: ${_ILINKS} 270985f41afSWarner Losh 271f3cc9575SWarner Losh# Ensure that the links exist without depending on it when it exists which 272f3cc9575SWarner Losh# causes all the modules to be rebuilt when the directory pointed to changes. 273f3cc9575SWarner Losh.for _link in ${_ILINKS} 274f3cc9575SWarner Losh.if !exists(${.OBJDIR}/${_link}) 2758cf80600SSimon J. Gerraty${OBJS}: ${_link} 276f3cc9575SWarner Losh.endif 277f3cc9575SWarner Losh.endfor 2784a2d2630SBruce Evans 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 40028849c57SBryan Drewery.m.c: ${SYSDIR}/tools/makeobjops.awk ${OP_META} 40112f05b84SWarner Losh ${AWK} -f ${SYSDIR}/tools/makeobjops.awk ${.IMPSRC} -c 40212f05b84SWarner Losh 40328849c57SBryan 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 40928849c57SBryan 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 \ 41828849c57SBryan Drewery ${SYSDIR}/dev/bhnd/nvram/nvram_map \ 41928849c57SBryan Drewery ${OP_META} 42028849c57SBryan 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 \ 42928849c57SBryan Drewery ${SYSDIR}/dev/bhnd/nvram/nvram_map \ 43028849c57SBryan Drewery ${OP_META} 43128849c57SBryan 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 43828849c57SBryan 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 44428849c57SBryan 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 45028849c57SBryan 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 46028849c57SBryan 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 46328849c57SBryan 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