1# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2# $FreeBSD$ 3# 4# The include file <bsd.kmod.mk> handles installing Kernel Loadable Device 5# drivers (KLD's). 6# 7# 8# +++ variables +++ 9# 10# CLEANFILES Additional files to remove for the clean and cleandir targets. 11# 12# KMOD The name of the kernel module to build. 13# 14# KMODDIR Base path for kernel modules (see kld(4)). [/boot/kernel] 15# 16# KMODOWN KLD owner. [${BINOWN}] 17# 18# KMODGRP KLD group. [${BINGRP}] 19# 20# KMODMODE KLD mode. [${BINMODE}] 21# 22# KMODLOAD Command to load a kernel module [/sbin/kldload] 23# 24# KMODUNLOAD Command to unload a kernel module [/sbin/kldunload] 25# 26# PROG The name of the kernel module to build. 27# If not supplied, ${KMOD}.o is used. 28# 29# SRCS List of source files 30# 31# DESTDIR Change the tree where the module gets installed. [not set] 32# 33# MFILES Optionally a list of interfaces used by the module. 34# This file contains a default list of interfaces. 35# 36# EXPORT_SYMS A list of symbols that should be exported from the module, 37# or the name of a file containing a list of symbols, or YES 38# to export all symbols. If not defined, no symbols are 39# exported. 40# 41# +++ targets +++ 42# 43# install: 44# install the kernel module; if the Makefile 45# does not itself define the target install, the targets 46# beforeinstall and afterinstall may also be used to cause 47# actions immediately before and after the install target 48# is executed. 49# 50# load: 51# Load KLD. 52# 53# unload: 54# Unload KLD. 55# 56# bsd.obj.mk: clean, cleandir and obj 57# bsd.dep.mk: cleandepend, depend and tags 58# 59 60AWK?= awk 61KMODLOAD?= /sbin/kldload 62KMODUNLOAD?= /sbin/kldunload 63OBJCOPY?= objcopy 64 65.if defined(KMODDEPS) 66.error "Do not use KMODDEPS on 5.0+, use MODULE_VERSION/MODULE_DEPEND" 67.endif 68 69.include <bsd.init.mk> 70 71.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 72 73CFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS} 74CFLAGS+= -DKLD_MODULE 75 76# Don't use any standard or source-relative include directories. 77# Since -nostdinc will annull any previous -I paths, we repeat all 78# such paths after -nostdinc. It doesn't seem to be possible to 79# add to the front of `make' variable. 80_ICFLAGS:= ${CFLAGS:M-I*} 81CFLAGS+= -nostdinc -I- ${INCLMAGIC} ${_ICFLAGS} 82 83# Add -I paths for system headers. Individual KLD makefiles don't 84# need any -I paths for this. Similar defaults for .PATH can't be 85# set because there are no standard paths for non-headers. 86CFLAGS+= -I. -I@ 87 88# Add a -I path to standard headers like <stddef.h>. Use a relative 89# path to src/include if possible. If the @ symlink hasn't been built 90# yet, then we can't tell if the relative path exists. Add both the 91# potential relative path and an absolute path in that case. 92.if exists(@) 93.if exists(@/../include) 94CFLAGS+= -I@/../include 95.else 96CFLAGS+= -I${DESTDIR}/usr/include 97.endif 98.else # !@ 99CFLAGS+= -I@/../include -I${DESTDIR}/usr/include 100.endif # @ 101 102INLINE_LIMIT?= 15000 103CFLAGS+= -finline-limit=${INLINE_LIMIT} 104 105# Disallow common variables, and if we end up with commons from 106# somewhere unexpected, allocate storage for them in the module itself. 107CFLAGS+= -fno-common 108LDFLAGS+= -d -warn-common 109 110CFLAGS+= ${DEBUG_FLAGS} 111 112OBJS+= ${SRCS:N*.h:R:S/$/.o/g} 113 114.if !defined(PROG) 115PROG= ${KMOD}.ko 116.endif 117 118.if !defined(DEBUG) 119FULLPROG= ${PROG} 120.else 121FULLPROG= ${PROG}.debug 122${PROG}: ${FULLPROG} 123 ${OBJCOPY} --strip-debug ${FULLPROG} ${PROG} 124.endif 125 126${FULLPROG}: ${KMOD}.kld 127 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld 128 129EXPORT_SYMS?= NO 130.if ${EXPORT_SYMS} != YES 131CLEANFILES+= ${.OBJDIR}/export_syms 132.endif 133 134${KMOD}.kld: ${OBJS} 135 ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS} 136.if defined(EXPORT_SYMS) 137.if ${EXPORT_SYMS} != YES 138.if ${EXPORT_SYMS} == NO 139 touch ${.OBJDIR}/export_syms 140.elif !exists(${.CURDIR}/${EXPORT_SYMS}) 141 echo ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 142.else 143 grep -v '^#' < ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 144.endif 145 awk -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \ 146 ${.OBJDIR}/export_syms | \ 147 xargs -J% ${OBJCOPY} % ${.TARGET} 148.endif 149.endif 150 151_ILINKS=@ machine 152 153all: objwarn ${PROG} 154 155beforedepend: ${_ILINKS} 156 @rm -f .depend 157 158# Ensure that the links exist without depending on it when it exists which 159# causes all the modules to be rebuilt when the directory pointed to changes. 160.for _link in ${_ILINKS} 161.if !exists(${.OBJDIR}/${_link}) 162${OBJS}: ${_link} 163.endif 164.endfor 165 166# Search for kernel source tree in standard places. 167.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys 168.if !defined(SYSDIR) && exists(${_dir}/kern/) 169SYSDIR= ${_dir} 170.endif 171.endfor 172.if !defined(SYSDIR) || !exists(${SYSDIR}/kern) 173.error "can't find kernel source tree" 174.endif 175 176${_ILINKS}: 177 @case ${.TARGET} in \ 178 machine) \ 179 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \ 180 @) \ 181 path=${SYSDIR} ;; \ 182 esac ; \ 183 path=`(cd $$path && /bin/pwd)` ; \ 184 ${ECHO} ${.TARGET} "->" $$path ; \ 185 ln -s $$path ${.TARGET} 186 187CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o 188 189.if defined(DEBUG) 190CLEANFILES+= ${FULLPROG} 191.endif 192 193.if !target(install) 194 195_INSTALLFLAGS:= ${INSTALLFLAGS} 196.for ie in ${INSTALLFLAGS_EDIT} 197_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 198.endfor 199 200.if defined(DEBUG) 201install.debug: 202 cd ${.CURDIR}; ${MAKE} -DINSTALL_DEBUG install 203.endif 204 205.if !target(realinstall) 206realinstall: _kmodinstall 207.ORDER: beforeinstall _kmodinstall 208.if defined(DEBUG) && defined(INSTALL_DEBUG) 209_kmodinstall: 210 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 211 ${_INSTALLFLAGS} ${FULLPROG} ${DESTDIR}${KMODDIR} 212.else 213_kmodinstall: 214 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 215 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 216 217.include <bsd.links.mk> 218 219.if !defined(NO_XREF) 220afterinstall: _kldxref 221.ORDER: realinstall _kldxref 222.ORDER: _installlinks _kldxref 223_kldxref: 224 @if type kldxref >/dev/null 2>&1; then \ 225 ${ECHO} kldxref ${DESTDIR}${KMODDIR}; \ 226 kldxref ${DESTDIR}${KMODDIR}; \ 227 fi 228.endif 229.endif 230.endif !target(realinstall) 231 232.endif !target(install) 233 234.if !target(load) 235load: ${PROG} 236 ${KMODLOAD} -v ${.OBJDIR}/${KMOD}.ko 237.endif 238 239.if !target(unload) 240unload: 241 ${KMODUNLOAD} -v ${KMOD} 242.endif 243 244.for _src in ${SRCS:Mopt_*.h} 245CLEANFILES+= ${_src} 246.if !target(${_src}) 247${_src}: 248 touch ${.TARGET} 249.endif 250.endfor 251 252MFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \ 253 dev/iicbus/iicbus_if.m isa/isa_if.m \ 254 libkern/iconv_converter_if.m \ 255 dev/mii/miibus_if.m \ 256 dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \ 257 dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \ 258 dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ 259 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m pci/agp_if.m \ 260 opencrypto/crypto_if.m pc98/pc98/canbus_if.m dev/uart/uart_if.m 261 262.for _srcsrc in ${MFILES} 263.for _ext in c h 264.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}} 265CLEANFILES+= ${_src} 266.if !target(${_src}) 267.if !exists(@) 268${_src}: @ 269.endif 270.if exists(@) 271${_src}: @/tools/makeobjops.awk @/${_srcsrc} 272.endif 273 ${AWK} -f @/tools/makeobjops.awk @/${_srcsrc} -${_ext} 274.endif 275.endfor # _src 276.endfor # _ext 277.endfor # _srcsrc 278 279.for _ext in c h 280.if ${SRCS:Mvnode_if.${_ext}} != "" 281CLEANFILES+= vnode_if.${_ext} 282.if !exists(@) 283vnode_if.${_ext}: @ 284.endif 285.if exists(@) 286vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src 287.endif 288 ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -${_ext} 289.endif 290.endfor 291 292.if ${SRCS:Mmiidevs.h} != "" 293CLEANFILES+= miidevs.h 294.if !exists(@) 295miidevs.h: @ 296.endif 297.if exists(@) 298miidevs.h: @/tools/devlist2h.awk @/dev/mii/miidevs 299.endif 300 ${AWK} -f @/tools/devlist2h.awk @/dev/mii/miidevs 301.endif 302 303regress: 304 305lint: ${SRCS} 306 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC:M*.c} 307 308.include <bsd.dep.mk> 309 310.if !exists(${.OBJDIR}/${DEPENDFILE}) 311${OBJS}: ${SRCS:M*.h} 312.endif 313 314.include <bsd.obj.mk> 315.include "kern.mk" 316