kmod.mk revision 92491
190926Snectar# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2233294Sstas# $FreeBSD: head/sys/conf/kmod.mk 92491 2002-03-17 10:05:57Z markm $ 390926Snectar# 490926Snectar# The include file <bsd.kmod.mk> handles installing Kernel Loadable Device 5233294Sstas# drivers (KLD's). 690926Snectar# 790926Snectar# 890926Snectar# +++ variables +++ 9233294Sstas# 1090926Snectar# CLEANFILES Additional files to remove for the clean and cleandir targets. 1190926Snectar# 12233294Sstas# DISTRIBUTION Name of distribution. [bin] 1390926Snectar# 1490926Snectar# KMOD The name of the kernel module to build. 1590926Snectar# 16233294Sstas# KMODDIR Base path for kernel modules (see kld(4)). [/boot/kernel] 1790926Snectar# 1890926Snectar# KMODOWN KLD owner. [${BINOWN}] 1990926Snectar# 20233294Sstas# KMODGRP KLD group. [${BINGRP}] 2190926Snectar# 2290926Snectar# KMODMODE KLD mode. [${BINMODE}] 2390926Snectar# 2490926Snectar# LINKS The list of KLD links; should be full pathnames, the 2590926Snectar# linked-to file coming first, followed by the linked 2690926Snectar# file. The files are hard-linked. For example, to link 2790926Snectar# /modules/master and /modules/meister, use: 2890926Snectar# 2990926Snectar# LINKS= /modules/master /modules/meister 3090926Snectar# 3190926Snectar# KMODLOAD Command to load a kernel module [/sbin/kldload] 3290926Snectar# 3390926Snectar# KMODUNLOAD Command to unload a kernel module [/sbin/kldunload] 3490926Snectar# 3590926Snectar# PROG The name of the kernel module to build. 36178825Sdfr# If not supplied, ${KMOD}.o is used. 3790926Snectar# 3890926Snectar# SRCS List of source files 3990926Snectar# 4090926Snectar# SUBDIR A list of subdirectories that should be built as well. 4190926Snectar# Each of the targets will execute the same target in the 4290926Snectar# subdirectories. 4390926Snectar# 4490926Snectar# SYMLINKS Same as LINKS, except it creates symlinks and the 4590926Snectar# linked-to pathname may be relative. 4690926Snectar# 4790926Snectar# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk) 4890926Snectar# 4990926Snectar# MFILES Optionally a list of interfaces used by the module. 5090926Snectar# This file contains a default list of interfaces. 5190926Snectar# 5290926Snectar# EXPORT_SYMS A list of symbols that should be exported from the module, 5390926Snectar# or the name of a file containing a list of symbols, or YES 5490926Snectar# to export all symbols. If not defined, no symbols are 5590926Snectar# exported. 5690926Snectar# 5790926Snectar# +++ targets +++ 5890926Snectar# 5990926Snectar# distribute: 6090926Snectar# This is a variant of install, which will 6190926Snectar# put the stuff into the right "distribution". 6290926Snectar# 63233294Sstas# install: 6490926Snectar# install the kernel module; if the Makefile 6590926Snectar# does not itself define the target install, the targets 6690926Snectar# beforeinstall and afterinstall may also be used to cause 6790926Snectar# actions immediately before and after the install target 6890926Snectar# is executed. 6990926Snectar# 7090926Snectar# load: 71178825Sdfr# Load KLD. 72178825Sdfr# 7390926Snectar# unload: 7490926Snectar# Unload KLD. 7590926Snectar# 7690926Snectar# bsd.obj.mk: clean, cleandir and obj 7790926Snectar# bsd.dep.mk: cleandepend, depend and tags 7890926Snectar# 7990926Snectar 8090926SnectarAWK?= awk 8190926SnectarKMODLOAD?= /sbin/kldload 8290926SnectarKMODUNLOAD?= /sbin/kldunload 8390926SnectarOBJCOPY?= objcopy 8490926Snectar 85233294SstasTARGET_ARCH?= ${MACHINE_ARCH} 8690926Snectar 8790926Snectar.if !target(__initialized__) 8890926Snectar__initialized__: 8990926Snectar.if exists(${.CURDIR}/../Makefile.inc) 90233294Sstas.include "${.CURDIR}/../Makefile.inc" 9190926Snectar.endif 9290926Snectar.endif 9390926Snectar 9490926Snectar.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 9590926Snectar 9690926SnectarCFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS} 97CFLAGS+= -DKLD_MODULE 98 99# Don't use any standard or source-relative include directories. 100# Since -nostdinc will annull any previous -I paths, we repeat all 101# such paths after -nostdinc. It doesn't seem to be possible to 102# add to the front of `make' variable. 103_ICFLAGS:= ${CFLAGS:M-I*} 104CFLAGS+= -nostdinc -I- ${INCLMAGIC} ${_ICFLAGS} 105 106# Add -I paths for system headers. Individual KLD makefiles don't 107# need any -I paths for this. Similar defaults for .PATH can't be 108# set because there are no standard paths for non-headers. 109CFLAGS+= -I. -I@ -I@/dev 110 111# Add a -I path to standard headers like <stddef.h>. Use a relative 112# path to src/include if possible. If the @ symlink hasn't been built 113# yet, then we can't tell if the relative path exists. Add both the 114# potential relative path and an absolute path in that case. 115.if exists(@) 116.if exists(@/../include) 117CFLAGS+= -I@/../include 118.else 119CFLAGS+= -I${DESTDIR}/usr/include 120.endif 121.else # !@ 122CFLAGS+= -I@/../include -I${DESTDIR}/usr/include 123.endif # @ 124 125# Disallow common variables, and if we end up with commons from 126# somewhere unexpected, allocate storage for them in the module itself. 127CFLAGS+= -fno-common 128LDFLAGS+= -d -warn-common 129 130CFLAGS+= ${DEBUG_FLAGS} 131 132.if ${OBJFORMAT} == elf 133CLEANFILES+= setdef0.c setdef1.c setdefs.h 134CLEANFILES+= setdef0.o setdef1.o 135.endif 136 137OBJS+= ${SRCS:N*.h:R:S/$/.o/g} 138 139.if !defined(PROG) 140PROG= ${KMOD}.ko 141.endif 142 143.if !defined(DEBUG) 144FULLPROG= ${PROG} 145.else 146FULLPROG= ${PROG}.debug 147${PROG}: ${FULLPROG} 148 ${OBJCOPY} --strip-debug ${FULLPROG} ${PROG} 149.endif 150 151${FULLPROG}: ${KMOD}.kld 152 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld 153 154EXPORT_SYMS?= NO 155.if ${EXPORT_SYMS} != YES 156CLEANFILES+= ${.OBJDIR}/export_syms 157.endif 158 159${KMOD}.kld: ${OBJS} 160 ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS} 161.if defined(EXPORT_SYMS) 162.if ${EXPORT_SYMS} != YES 163.if ${EXPORT_SYMS} == NO 164 touch ${.OBJDIR}/export_syms 165.elif !exists(${.CURDIR}/${EXPORT_SYMS}) 166 echo ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 167.else 168 grep -v '^#' < ${EXPORT_SYMS} > ${.OBJDIR}/export_syms 169.endif 170 awk -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \ 171 ${.OBJDIR}/export_syms | \ 172 xargs -J% ${OBJCOPY} % ${.TARGET} 173.endif 174.endif 175 176 177.if !target(all-man) 178all-man: _SUBDIR 179.endif 180.if !target(maninstall) 181maninstall: _SUBDIR 182.endif 183 184_ILINKS=@ machine 185 186.MAIN: all 187all: objwarn ${PROG} _SUBDIR 188 189beforedepend: ${_ILINKS} 190 @rm -f .depend 191 192# Ensure that the links exist without depending on it when it exists which 193# causes all the modules to be rebuilt when the directory pointed to changes. 194.for _link in ${_ILINKS} 195.if !exists(${.OBJDIR}/${_link}) 196${OBJS}: ${_link} 197.endif 198.endfor 199 200# Search for kernel source tree in standard places. 201.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys 202.if !defined(SYSDIR) && exists(${_dir}/kern/) 203SYSDIR= ${_dir} 204.endif 205.endfor 206.if !defined(SYSDIR) || !exists(${SYSDIR}/kern) 207.error "can't find kernel source tree" 208.endif 209 210${_ILINKS}: 211 @case ${.TARGET} in \ 212 machine) \ 213 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \ 214 @) \ 215 path=${SYSDIR} ;; \ 216 esac ; \ 217 path=`(cd $$path && /bin/pwd)` ; \ 218 ${ECHO} ${.TARGET} "->" $$path ; \ 219 ln -s $$path ${.TARGET} 220 221CLEANFILES+= ${PROG} ${FULLPROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o 222 223.if !target(install) 224.if !target(beforeinstall) 225beforeinstall: 226.endif 227.if !target(afterinstall) 228afterinstall: 229.endif 230 231_INSTALLFLAGS:= ${INSTALLFLAGS} 232.for ie in ${INSTALLFLAGS_EDIT} 233_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 234.endfor 235 236install.debug: _SUBDIR 237 ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 238 ${_INSTALLFLAGS} ${FULLPROG} ${DESTDIR}${KMODDIR}/ 239 240realinstall: _SUBDIR 241 ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 242 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}/ 243.if defined(LINKS) && !empty(LINKS) 244 @set ${LINKS}; \ 245 while test $$# -ge 2; do \ 246 l=${DESTDIR}$$1; \ 247 shift; \ 248 t=${DESTDIR}$$1; \ 249 shift; \ 250 ${ECHO} $$t -\> $$l; \ 251 ln -f $$l $$t; \ 252 done; true 253.endif 254.if defined(SYMLINKS) && !empty(SYMLINKS) 255 @set ${SYMLINKS}; \ 256 while test $$# -ge 2; do \ 257 l=$$1; \ 258 shift; \ 259 t=${DESTDIR}$$1; \ 260 shift; \ 261 ${ECHO} $$t -\> $$l; \ 262 ln -fs $$l $$t; \ 263 done; true 264.endif 265.if !defined(NO_XREF) 266 -kldxref ${DESTDIR}${KMODDIR} 267.endif 268 269install: afterinstall _SUBDIR 270afterinstall: realinstall 271realinstall: beforeinstall 272.endif 273 274DISTRIBUTION?= bin 275.if !target(distribute) 276distribute: _SUBDIR 277.for dist in ${DISTRIBUTION} 278 cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 279.endfor 280.endif 281 282.if !target(load) 283load: ${PROG} 284 ${KMODLOAD} -v ${.CURDIR}/${KMOD}.ko 285.endif 286 287.if !target(unload) 288unload: 289 ${KMODUNLOAD} -v ${KMOD} 290.endif 291 292.for _src in ${SRCS:Mopt_*.h} 293CLEANFILES+= ${_src} 294.if !target(${_src}) 295${_src}: 296 touch ${.TARGET} 297.endif 298.endfor 299 300MFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \ 301 dev/iicbus/iicbus_if.m isa/isa_if.m \ 302 libkern/iconv_converter_if.m \ 303 dev/mii/miibus_if.m \ 304 dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \ 305 dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \ 306 dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ 307 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m pci/agp_if.m 308 309.for _srcsrc in ${MFILES} 310.for _ext in c h 311.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}} 312CLEANFILES+= ${_src} 313.if !target(${_src}) 314.if !exists(@) 315${_src}: @ 316.endif 317.if exists(@) 318${_src}: @/kern/makeobjops.pl @/${_srcsrc} 319.endif 320 perl @/kern/makeobjops.pl -${_ext} @/${_srcsrc} 321.endif 322.endfor # _src 323.endfor # _ext 324.endfor # _srcsrc 325 326.for _ext in c h 327.if ${SRCS:Mvnode_if.${_ext}} != "" 328CLEANFILES+= vnode_if.${_ext} 329.if !exists(@) 330vnode_if.${_ext}: @ 331.endif 332.if exists(@) 333vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src 334.endif 335 ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -${_ext} 336.endif 337.endfor 338 339regress: 340 341lint: ${SRCS} 342 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC:M*.c} | more 2>&1 343 344.include <bsd.dep.mk> 345 346.if !exists(${DEPENDFILE}) 347${OBJS}: ${SRCS:M*.h} 348.endif 349 350.include <bsd.obj.mk> 351 352.include <bsd.kern.mk> 353