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.if ${MACHINE_ARCH} != amd64 141${FULLPROG}: ${KMOD}.kld 142 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld 143.if !defined(DEBUG_FLAGS) 144 ${OBJCOPY} --strip-debug ${.TARGET} 145.endif 146.endif 147 148EXPORT_SYMS?= NO 149.if ${EXPORT_SYMS} != YES 150CLEANFILES+= ${.OBJDIR}/export_syms 151.endif 152 153.if ${MACHINE_ARCH} != amd64 154${KMOD}.kld: ${OBJS} 155.else 156${FULLPROG}: ${OBJS} 157.endif 158 ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS} 159.if defined(EXPORT_SYMS) 160.if ${EXPORT_SYMS} != YES 161.if ${EXPORT_SYMS} == NO 162 touch ${.OBJDIR}/export_syms 163.elif !exists(${.CURDIR}/${EXPORT_SYMS}) 164 echo ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 165.else 166 grep -v '^#' < ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 167.endif 168 awk -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \ 169 ${.OBJDIR}/export_syms | \ 170 xargs -J% ${OBJCOPY} % ${.TARGET} 171.endif 172.endif 173.if !defined(DEBUG_FLAGS) && ${MACHINE_ARCH} == amd64 174 ${OBJCOPY} --strip-debug ${.TARGET} 175.endif 176 177_ILINKS=@ machine 178 179all: objwarn ${PROG} 180 181beforedepend: ${_ILINKS} 182 @rm -f .depend 183 184# Ensure that the links exist without depending on it when it exists which 185# causes all the modules to be rebuilt when the directory pointed to changes. 186.for _link in ${_ILINKS} 187.if !exists(${.OBJDIR}/${_link}) 188${OBJS}: ${_link} 189.endif 190.endfor 191 192# Search for kernel source tree in standard places. 193.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys 194.if !defined(SYSDIR) && exists(${_dir}/kern/) 195SYSDIR= ${_dir} 196.endif 197.endfor 198.if !defined(SYSDIR) || !exists(${SYSDIR}/kern/) 199.error "can't find kernel source tree" 200.endif 201 202${_ILINKS}: 203 @case ${.TARGET} in \ 204 machine) \ 205 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \ 206 @) \ 207 path=${SYSDIR} ;; \ 208 esac ; \ 209 path=`(cd $$path && /bin/pwd)` ; \ 210 ${ECHO} ${.TARGET} "->" $$path ; \ 211 ln -s $$path ${.TARGET} 212 213CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o 214 215.if defined(DEBUG_FLAGS) 216CLEANFILES+= ${FULLPROG} 217.endif 218 219.if !target(install) 220 221_INSTALLFLAGS:= ${INSTALLFLAGS} 222.for ie in ${INSTALLFLAGS_EDIT} 223_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 224.endfor 225 226.if defined(DEBUG_FLAGS) 227install.debug: 228 cd ${.CURDIR}; ${MAKE} -DINSTALL_DEBUG install 229.endif 230 231.if !target(realinstall) 232realinstall: _kmodinstall 233.ORDER: beforeinstall _kmodinstall 234_kmodinstall: 235.if defined(DEBUG_FLAGS) && defined(INSTALL_DEBUG) 236 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 237 ${_INSTALLFLAGS} ${FULLPROG} ${DESTDIR}${KMODDIR} 238.else 239 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 240 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 241 242.include <bsd.links.mk> 243 244.if !defined(NO_XREF) 245afterinstall: _kldxref 246.ORDER: realinstall _kldxref 247.ORDER: _installlinks _kldxref 248_kldxref: 249 @if type kldxref >/dev/null 2>&1; then \ 250 ${ECHO} kldxref ${DESTDIR}${KMODDIR}; \ 251 kldxref ${DESTDIR}${KMODDIR}; \ 252 fi 253.endif 254.endif 255.endif !target(realinstall) 256 257.endif !target(install) 258 259.if !target(load) 260load: ${PROG} 261 ${KMODLOAD} -v ${.OBJDIR}/${KMOD}.ko 262.endif 263 264.if !target(unload) 265unload: 266 ${KMODUNLOAD} -v ${KMOD} 267.endif 268 269.if defined(KERNBUILDDIR) 270.PATH: ${KERNBUILDDIR} 271CFLAGS += -I${KERNBUILDDIR} 272.for _src in ${SRCS:Mopt_*.h} 273CLEANFILES+= ${_src} 274.if !target(${_src}) 275${_src}: 276 ln -s ${KERNBUILDDIR}/${_src} ${.TARGET} 277.endif 278.endfor 279.else 280.for _src in ${SRCS:Mopt_*.h} 281CLEANFILES+= ${_src} 282.if !target(${_src}) 283${_src}: 284 touch ${.TARGET} 285.endif 286.endfor 287.endif 288 289MFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \ 290 dev/iicbus/iicbus_if.m isa/isa_if.m \ 291 libkern/iconv_converter_if.m \ 292 dev/mii/miibus_if.m \ 293 dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \ 294 dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \ 295 dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ 296 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m pci/agp_if.m \ 297 opencrypto/crypto_if.m pc98/pc98/canbus_if.m dev/uart/uart_if.m 298 299.for _srcsrc in ${MFILES} 300.for _ext in c h 301.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}} 302CLEANFILES+= ${_src} 303.if !target(${_src}) 304.if !exists(@) 305${_src}: @ 306.endif 307.if exists(@) 308${_src}: @/tools/makeobjops.awk @/${_srcsrc} 309.endif 310 ${AWK} -f @/tools/makeobjops.awk @/${_srcsrc} -${_ext} 311.endif 312.endfor # _src 313.endfor # _ext 314.endfor # _srcsrc 315 316.for _ext in c h 317.if ${SRCS:Mvnode_if.${_ext}} != "" 318CLEANFILES+= vnode_if.${_ext} 319.if !exists(@) 320vnode_if.${_ext}: @ 321.endif 322.if exists(@) 323vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src 324.endif 325 ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -${_ext} 326.endif 327.endfor 328 329.for _i in mii pccard usb 330.if ${SRCS:M${_i}devs.h} != "" 331CLEANFILES+= ${_i}devs.h 332.if !exists(@) 333${_i}devs.h: @ 334.endif 335.if exists(@) 336${_i}devs.h: @/tools/${_i}devs2h.awk @/dev/${_i}/${_i}devs 337.endif 338 ${AWK} -f @/tools/${_i}devs2h.awk @/dev/${_i}/${_i}devs 339.endif 340.endfor # _i 341 342regress: 343 344lint: ${SRCS} 345 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC:M*.c} 346 347.include <bsd.dep.mk> 348 349.if !exists(${.OBJDIR}/${DEPENDFILE}) 350${OBJS}: ${SRCS:M*.h} 351.endif 352 353.include <bsd.obj.mk> 354.include "kern.mk" 355