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 73.if ${CC} == "icc" 74CFLAGS:= ${CFLAGS:C/(-x[^M^K^W]+)[MKW]+|-x[MKW]+/\1/} 75.endif 76CFLAGS+= ${COPTS} -D_KERNEL 77CFLAGS+= -DKLD_MODULE 78 79# Don't use any standard or source-relative include directories. 80# Since -nostdinc will annull any previous -I paths, we repeat all 81# such paths after -nostdinc. It doesn't seem to be possible to 82# add to the front of `make' variable. 83_ICFLAGS:= ${CFLAGS:M-I*} 84.if ${CC} == "icc" 85NOSTDINC= -X 86.else 87NOSTDINC= -nostdinc 88.endif 89CFLAGS+= ${NOSTDINC} -I- ${INCLMAGIC} ${_ICFLAGS} 90.if defined(KERNBUILDDIR) 91CFLAGS+= -include ${KERNBUILDDIR}/opt_global.h 92.endif 93 94# Add -I paths for system headers. Individual KLD makefiles don't 95# need any -I paths for this. Similar defaults for .PATH can't be 96# set because there are no standard paths for non-headers. 97CFLAGS+= -I. -I@ 98 99# Add a -I path to standard headers like <stddef.h>. Use a relative 100# path to src/include if possible. If the @ symlink hasn't been built 101# yet, then we can't tell if the relative path exists. Add both the 102# potential relative path and an absolute path in that case. 103.if exists(@) 104.if exists(@/../include) 105CFLAGS+= -I@/../include 106.else 107CFLAGS+= -I${DESTDIR}/usr/include 108.endif 109.else # !@ 110CFLAGS+= -I@/../include -I${DESTDIR}/usr/include 111.endif # @ 112 113.if ${CC} != "icc" 114CFLAGS+= -finline-limit=${INLINE_LIMIT} 115.endif 116 117# Disallow common variables, and if we end up with commons from 118# somewhere unexpected, allocate storage for them in the module itself. 119.if ${CC} != "icc" 120CFLAGS+= -fno-common 121.endif 122LDFLAGS+= -d -warn-common 123 124CFLAGS+= ${DEBUG_FLAGS} 125 126OBJS+= ${SRCS:N*.h:R:S/$/.o/g} 127 128.if !defined(PROG) 129PROG= ${KMOD}.ko 130.endif 131 132.if !defined(DEBUG_FLAGS) 133FULLPROG= ${PROG} 134.else 135FULLPROG= ${PROG}.debug 136${PROG}: ${FULLPROG} 137 ${OBJCOPY} --strip-debug ${FULLPROG} ${PROG} 138.endif 139 140${FULLPROG}: ${KMOD}.kld 141 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld 142.if !defined(DEBUG_FLAGS) 143 ${OBJCOPY} --strip-debug ${.TARGET} 144.endif 145 146EXPORT_SYMS?= NO 147.if ${EXPORT_SYMS} != YES 148CLEANFILES+= ${.OBJDIR}/export_syms 149.endif 150 151${KMOD}.kld: ${OBJS} 152 ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS} 153.if defined(EXPORT_SYMS) 154.if ${EXPORT_SYMS} != YES 155.if ${EXPORT_SYMS} == NO 156 touch ${.OBJDIR}/export_syms 157.elif !exists(${.CURDIR}/${EXPORT_SYMS}) 158 echo ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 159.else 160 grep -v '^#' < ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 161.endif 162 awk -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \ 163 ${.OBJDIR}/export_syms | \ 164 xargs -J% ${OBJCOPY} % ${.TARGET} 165.endif 166.endif 167 168_ILINKS=@ machine 169 170all: objwarn ${PROG} 171 172beforedepend: ${_ILINKS} 173 @rm -f .depend 174 175# Ensure that the links exist without depending on it when it exists which 176# causes all the modules to be rebuilt when the directory pointed to changes. 177.for _link in ${_ILINKS} 178.if !exists(${.OBJDIR}/${_link}) 179${OBJS}: ${_link} 180.endif 181.endfor 182 183# Search for kernel source tree in standard places. 184.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys 185.if !defined(SYSDIR) && exists(${_dir}/kern/) 186SYSDIR= ${_dir} 187.endif 188.endfor 189.if !defined(SYSDIR) || !exists(${SYSDIR}/kern/) 190.error "can't find kernel source tree" 191.endif 192 193${_ILINKS}: 194 @case ${.TARGET} in \ 195 machine) \ 196 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \ 197 @) \ 198 path=${SYSDIR} ;; \ 199 esac ; \ 200 path=`(cd $$path && /bin/pwd)` ; \ 201 ${ECHO} ${.TARGET} "->" $$path ; \ 202 ln -s $$path ${.TARGET} 203 204CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o 205 206.if defined(DEBUG_FLAGS) 207CLEANFILES+= ${FULLPROG} 208.endif 209 210.if !target(install) 211 212_INSTALLFLAGS:= ${INSTALLFLAGS} 213.for ie in ${INSTALLFLAGS_EDIT} 214_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 215.endfor 216 217.if defined(DEBUG_FLAGS) 218install.debug: 219 cd ${.CURDIR}; ${MAKE} -DINSTALL_DEBUG install 220.endif 221 222.if !target(realinstall) 223realinstall: _kmodinstall 224.ORDER: beforeinstall _kmodinstall 225_kmodinstall: 226.if defined(DEBUG_FLAGS) && defined(INSTALL_DEBUG) 227 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 228 ${_INSTALLFLAGS} ${FULLPROG} ${DESTDIR}${KMODDIR} 229.else 230 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 231 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 232 233.include <bsd.links.mk> 234 235.if !defined(NO_XREF) 236afterinstall: _kldxref 237.ORDER: realinstall _kldxref 238.ORDER: _installlinks _kldxref 239_kldxref: 240 @if type kldxref >/dev/null 2>&1; then \ 241 ${ECHO} kldxref ${DESTDIR}${KMODDIR}; \ 242 kldxref ${DESTDIR}${KMODDIR}; \ 243 fi 244.endif 245.endif 246.endif !target(realinstall) 247 248.endif !target(install) 249 250.if !target(load) 251load: ${PROG} 252 ${KMODLOAD} -v ${.OBJDIR}/${KMOD}.ko 253.endif 254 255.if !target(unload) 256unload: 257 ${KMODUNLOAD} -v ${KMOD} 258.endif 259 260.if defined(KERNBUILDDIR) 261.PATH: ${KERNBUILDDIR} 262CFLAGS += -I${KERNBUILDDIR} 263.for _src in ${SRCS:Mopt_*.h} 264CLEANFILES+= ${_src} 265.if !target(${_src}) 266${_src}: 267 ln -s ${KERNBUILDDIR}/${_src} ${.TARGET} 268.endif 269.endfor 270.else 271.for _src in ${SRCS:Mopt_*.h} 272CLEANFILES+= ${_src} 273.if !target(${_src}) 274${_src}: 275 touch ${.TARGET} 276.endif 277.endfor 278.endif 279 280MFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \ 281 dev/iicbus/iicbus_if.m isa/isa_if.m \ 282 libkern/iconv_converter_if.m \ 283 dev/mii/miibus_if.m \ 284 dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \ 285 dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \ 286 dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ 287 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m pci/agp_if.m \ 288 opencrypto/crypto_if.m pc98/pc98/canbus_if.m dev/uart/uart_if.m 289 290.for _srcsrc in ${MFILES} 291.for _ext in c h 292.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}} 293CLEANFILES+= ${_src} 294.if !target(${_src}) 295.if !exists(@) 296${_src}: @ 297.endif 298.if exists(@) 299${_src}: @/tools/makeobjops.awk @/${_srcsrc} 300.endif 301 ${AWK} -f @/tools/makeobjops.awk @/${_srcsrc} -${_ext} 302.endif 303.endfor # _src 304.endfor # _ext 305.endfor # _srcsrc 306 307.for _ext in c h 308.if ${SRCS:Mvnode_if.${_ext}} != "" 309CLEANFILES+= vnode_if.${_ext} 310.if !exists(@) 311vnode_if.${_ext}: @ 312.endif 313.if exists(@) 314vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src 315.endif 316 ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -${_ext} 317.endif 318.endfor 319 320.if ${SRCS:Mmiidevs.h} != "" 321CLEANFILES+= miidevs.h 322.if !exists(@) 323miidevs.h: @ 324.endif 325.if exists(@) 326miidevs.h: @/tools/devlist2h.awk @/dev/mii/miidevs 327.endif 328 ${AWK} -f @/tools/devlist2h.awk @/dev/mii/miidevs 329.endif 330 331regress: 332 333lint: ${SRCS} 334 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC:M*.c} 335 336.include <bsd.dep.mk> 337 338.if !exists(${.OBJDIR}/${DEPENDFILE}) 339${OBJS}: ${SRCS:M*.h} 340.endif 341 342.include <bsd.obj.mk> 343.include "kern.mk" 344