1# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2# $FreeBSD: src/sys/conf/kmod.mk,v 1.82.2.15 2003/02/10 13:11:50 nyan Exp $ 3# $DragonFly: src/sys/conf/kmod.mk,v 1.35 2008/08/27 16:35:19 hasso Exp $ 4# 5# The include file <bsd.kmod.mk> handles installing Kernel Loadable Device 6# drivers (KLD's). 7# 8# 9# +++ variables +++ 10# 11# CLEANFILES Additional files to remove for the clean and cleandir targets. 12# 13# KMOD The name of the kernel module to build. 14# 15# KMODDIR Base path for kernel modules (see kld(4)). 16# [${DESTKERNDIR}/${DESTMODULESNAME}] 17# 18# KMODOWN KLD owner. [${BINOWN}] 19# 20# KMODGRP KLD group. [${BINGRP}] 21# 22# KMODMODE KLD mode. [${BINMODE}] 23# 24# KMODLOAD Command to load a kernel module [/sbin/kldload] 25# 26# KMODUNLOAD Command to unload a kernel module [/sbin/kldunload] 27# 28# NOMAN KLD does not have a manual page if set. 29# 30# PROG The name of the kernel module to build. 31# If not supplied, ${KMOD}.o is used. 32# 33# SRCS List of source files 34# 35# KMODDEPS List of modules which this one is dependant on 36# 37# DESTKERNDIR Change the tree where the kernel and the modules get 38# installed. [/boot] ${DESTDIR} changes the root of the tree 39# pointed to by ${DESTKERNDIR}. 40# 41# MFILES Optionally a list of interfaces used by the module. 42# This file contains a default list of interfaces. 43# 44# +++ targets +++ 45# 46# install: 47# install the kernel module and its manual pages; if the Makefile 48# does not itself define the target install, the targets 49# beforeinstall and afterinstall may also be used to cause 50# actions immediately before and after the install target 51# is executed. 52# 53# load: 54# Load KLD. 55# 56# unload: 57# Unload KLD. 58# 59# bsd.obj.mk: clean, cleandir and obj 60# bsd.dep.mk: cleandepend, depend and tags 61# bsd.man.mk: maninstall 62# 63 64OBJCOPY?= objcopy 65KMODLOAD?= /sbin/kldload 66KMODUNLOAD?= /sbin/kldunload 67 68KMODDIR?= ${DESTKERNDIR}/${DESTMODULESNAME} 69KMODOWN?= ${BINOWN} 70KMODGRP?= ${BINGRP} 71KMODMODE?= ${BINMODE} 72 73.include <bsd.init.mk> 74 75.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 76 77CFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS} 78CFLAGS+= -DKLD_MODULE 79 80# Don't use any standard include directories. 81# Since -nostdinc will annull any previous -I paths, we repeat all 82# such paths after -nostdinc. It doesn't seem to be possible to 83# add to the front of `make' variable. 84# 85# Don't use -I- anymore, source-relative includes are desireable. 86_ICFLAGS:= ${CFLAGS:M-I*} 87CFLAGS+= -nostdinc ${_ICFLAGS} 88 89# Add -I paths for system headers. Individual KLD makefiles don't 90# need any -I paths for this. Similar defaults for .PATH can't be 91# set because there are no standard paths for non-headers. 92# 93# NOTE! Traditional architecture paths such as <i386/i386/blah.h> 94# must run through the "machine_base" softlink using 95# <machine_base/i386/blah.h>. An explicit cross-architecture path must 96# operate relative to /usr/src/sys using e.g. <arch/i386/i386/blah.h> 97# 98CFLAGS+= -I. -I@ 99 100# Add -I paths for headers in the kernel build directory 101# 102.if defined(BUILDING_WITH_KERNEL) 103CFLAGS+= -I${BUILDING_WITH_KERNEL} 104_MACHINE_FWD= ${BUILDING_WITH_KERNEL} 105.else 106.if defined(MAKEOBJDIRPREFIX) 107_MACHINE_FWD= ${MAKEOBJDIRPREFIX}/${SYSDIR}/forwarder_${MACHINE_ARCH} 108.else 109_MACHINE_FWD= ${.OBJDIR}/forwarder_${MACHINE_ARCH} 110CLEANDIRS+= ${_MACHINE_FWD} 111.endif 112.endif 113CFLAGS+= -I${_MACHINE_FWD}/include 114.include "kern.fwd.mk" 115 116# Add a -I path to standard headers like <stddef.h>. Use a relative 117# path to src/include if possible. If the @ symlink hasn't been built 118# yet, then we can't tell if the relative path exists. Add both the 119# potential relative path and an absolute path in that case. 120.if exists(@) 121.if exists(@/../include) 122CFLAGS+= -I@/../include 123.else 124CFLAGS+= -I${DESTDIR}/usr/include 125.endif 126.else # !@ 127CFLAGS+= -I@/../include -I${DESTDIR}/usr/include 128.endif # @ 129 130.if defined(BUILDING_WITH_KERNEL) && \ 131 exists(${BUILDING_WITH_KERNEL}/opt_global.h) 132CFLAGS+= -include ${BUILDING_WITH_KERNEL}/opt_global.h 133.endif 134 135CFLAGS+= ${DEBUG_FLAGS} 136 137.include <bsd.patch.mk> 138 139OBJS+= ${SRCS:N*.h:N*.patch:R:S/$/.o/g} 140 141.if !defined(PROG) 142PROG= ${KMOD}.ko 143.endif 144 145.if ${MACHINE_ARCH} != amd64 146${PROG}: ${KMOD}.kld ${KMODDEPS} 147 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld ${KMODDEPS} 148.endif 149 150.if defined(KMODDEPS) 151.for dep in ${KMODDEPS} 152CLEANFILES+= ${dep} __${dep}_hack_dep.c 153 154${dep}: 155 touch __${dep}_hack_dep.c 156 ${CC} -shared ${CFLAGS} -o ${dep} __${dep}_hack_dep.c 157.endfor 158.endif 159 160.if ${MACHINE_ARCH} != amd64 161${KMOD}.kld: ${OBJS} 162 ${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS} 163.else 164${PROG}: ${OBJS} 165.endif 166 167.if !defined(NOMAN) 168.include <bsd.man.mk> 169.endif 170 171# links to platform and cpu architecture include files. If we are 172# building with a kernel these already exist in the kernel build dir. 173# '@' is a link to the system source. 174.if defined(BUILDING_WITH_KERNEL) 175_ILINKS=@ 176.else 177_ILINKS=@ machine_base machine cpu_base cpu 178.endif 179 180.if defined(ARCH) 181_ILINKS+=${ARCH} 182.endif 183 184all: objwarn fwheaders ${PROG} 185.if !defined(NOMAN) 186all: _manpages 187.endif 188 189beforedepend: fwheaders 190fwheaders: ${_ILINKS} ${FORWARD_HEADERS_COOKIE} 191# Ensure that the links exist without depending on it when it exists which 192# causes all the modules to be rebuilt when the directory pointed to changes. 193.for _link in ${_ILINKS} 194.if !exists(${.OBJDIR}/${_link}) 195${OBJS}: ${_link} 196.endif 197.endfor 198 199# Search for kernel source tree in standard places. 200.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. ${.CURDIR}/../../../.. /sys /usr/src/sys 201.if !defined(SYSDIR) && exists(${_dir}/kern/) 202SYSDIR= ${_dir} 203.endif 204.endfor 205.if !defined(SYSDIR) || !exists(${SYSDIR}/kern) 206.error "can't find kernel source tree" 207.endif 208S= ${SYSDIR} 209 210# path=`(cd $$path && /bin/pwd)` ; 211 212${_ILINKS}: 213 @case ${.TARGET} in \ 214 machine) \ 215 path=${SYSDIR}/platform/${MACHINE_PLATFORM}/include ;; \ 216 machine_base) \ 217 path=${SYSDIR}/platform/${MACHINE_PLATFORM} ;; \ 218 cpu) \ 219 path=${SYSDIR}/cpu/${MACHINE_ARCH}/include ;; \ 220 cpu_base) \ 221 path=${SYSDIR}/cpu/${MACHINE_ARCH} ;; \ 222 @) \ 223 path=${SYSDIR} ;; \ 224 arch_*) \ 225 path=${.CURDIR}/${MACHINE_ARCH} ;; \ 226 esac ; \ 227 ${ECHO} ${.TARGET} "->" $$path ; \ 228 ${LN} -s $$path ${.TARGET} 229 230CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o 231 232.if !target(install) 233 234_INSTALLFLAGS:= ${INSTALLFLAGS} 235.for ie in ${INSTALLFLAGS_EDIT} 236_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 237.endfor 238 239.if !target(realinstall) 240realinstall: _kmodinstall 241.ORDER: beforeinstall _kmodinstall 242_kmodinstall: 243.if defined(INSTALLSTRIPPEDMODULES) 244 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 245 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 246 ${OBJCOPY} --strip-debug ${DESTDIR}${KMODDIR}/${PROG} 247.else 248 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 249 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 250.endif 251.endif # !target(realinstall) 252 253.include <bsd.links.mk> 254 255.if !defined(NOMAN) 256realinstall: _maninstall 257.ORDER: beforeinstall _maninstall 258.endif 259 260.endif # !target(install) 261 262.if !target(load) 263load: ${PROG} 264 ${KMODLOAD} -v ./${KMOD}.ko 265.endif 266 267.if !target(unload) 268unload: 269 ${KMODUNLOAD} -v ${KMOD} 270.endif 271 272.for _src in ${SRCS:Mopt_*.h} ${SRCS:Muse_*.h} 273CLEANFILES+= ${_src} 274.if !target(${_src}) 275.if defined(BUILDING_WITH_KERNEL) && exists(${BUILDING_WITH_KERNEL}/${_src}) 276${_src}: ${BUILDING_WITH_KERNEL}/${_src} 277# we do not have to copy these files any more, the kernel build 278# directory is included in the path now. 279# cp ${BUILDING_WITH_KERNEL}/${_src} ${.TARGET} 280.else 281${_src}: 282 touch ${.TARGET} 283.endif # BUILDING_WITH_KERNEL 284.endif 285.endfor 286 287MFILES?= kern/bus_if.m kern/device_if.m bus/iicbus/iicbb_if.m \ 288 bus/iicbus/iicbus_if.m bus/isa/isa_if.m dev/netif/mii_layer/miibus_if.m \ 289 bus/pccard/card_if.m bus/pccard/power_if.m bus/pci/pci_if.m \ 290 bus/pci/pcib_if.m \ 291 bus/ppbus/ppbus_if.m bus/smbus/smbus_if.m bus/usb/usb_if.m \ 292 dev/acpica5/acpi_if.m dev/disk/nata/ata_if.m \ 293 dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ 294 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \ 295 libiconv/iconv_converter_if.m dev/agp/agp_if.m opencrypto/crypto_if.m 296 297.for _srcsrc in ${MFILES} 298.for _ext in c h 299.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}} 300CLEANFILES+= ${_src} 301.if !target(${_src}) 302${_src}: @ 303.if exists(@) 304${_src}: @/tools/makeobjops.awk @/${_srcsrc} 305.endif 306 307.if defined(BUILDING_WITH_KERNEL) && \ 308 exists(${BUILDING_WITH_KERNEL}/${_src}) 309.else 310 awk -f @/tools/makeobjops.awk -- -${_ext} @/${_srcsrc} 311.endif 312.endif 313.endfor # _src 314.endfor # _ext 315.endfor # _srcsrc 316 317#.for _ext in c h 318#.if ${SRCS:Mvnode_if.${_ext}} != "" 319#CLEANFILES+= vnode_if.${_ext} 320#vnode_if.${_ext}: @ 321#.if exists(@) 322#vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src 323#.endif 324# awk -f @/tools/vnode_if.awk -- -${_ext} @/kern/vnode_if.src 325#.endif 326#.endfor 327 328regress: 329 330.include <bsd.dep.mk> 331 332.if !exists(${DEPENDFILE}) 333${OBJS}: ${SRCS:M*.h} 334.endif 335 336.include <bsd.obj.mk> 337.include "bsd.kern.mk" 338 339# Behaves like MODULE_OVERRIDE 340.if defined(KLD_DEPS) 341all: _kdeps_all 342_kdeps_all: @ 343.for _mdep in ${KLD_DEPS} 344 cd ${SYSDIR}/${_mdep} && make all 345.endfor 346depend: _kdeps_depend 347_kdeps_depend: @ 348.for _mdep in ${KLD_DEPS} 349 cd ${SYSDIR}/${_mdep} && make depend 350.endfor 351install: _kdeps_install 352_kdeps_install: @ 353.for _mdep in ${KLD_DEPS} 354 cd ${SYSDIR}/${_mdep} && make install 355.endfor 356clean: _kdeps_clean 357_kdeps_clean: @ 358.for _mdep in ${KLD_DEPS} 359 cd ${SYSDIR}/${_mdep} && make clean 360.endfor 361.endif 362