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