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