kmod.mk revision 89243
1# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2# $FreeBSD: head/sys/conf/kmod.mk 89243 2002-01-11 01:11:44Z msmith $ 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# DISTRIBUTION Name of distribution. [bin] 13# 14# KMOD The name of the kernel module to build. 15# 16# KMODDIR Base path for kernel modules (see kld(4)). [/boot/kernel] 17# 18# KMODOWN KLD owner. [${BINOWN}] 19# 20# KMODGRP KLD group. [${BINGRP}] 21# 22# KMODMODE KLD mode. [${BINMODE}] 23# 24# LINKS The list of KLD links; should be full pathnames, the 25# linked-to file coming first, followed by the linked 26# file. The files are hard-linked. For example, to link 27# /modules/master and /modules/meister, use: 28# 29# LINKS= /modules/master /modules/meister 30# 31# KMODLOAD Command to load a kernel module [/sbin/kldload] 32# 33# KMODUNLOAD Command to unload a kernel module [/sbin/kldunload] 34# 35# NOMAN KLD does not have a manual page if set. 36# 37# PROG The name of the kernel module to build. 38# If not supplied, ${KMOD}.o is used. 39# 40# SRCS List of source files 41# 42# SUBDIR A list of subdirectories that should be built as well. 43# Each of the targets will execute the same target in the 44# subdirectories. 45# 46# SYMLINKS Same as LINKS, except it creates symlinks and the 47# linked-to pathname may be relative. 48# 49# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk) 50# 51# MFILES Optionally a list of interfaces used by the module. 52# This file contains a default list of interfaces. 53# 54# EXPORT_SYMS A list of symbols that should be exported from the module, 55# or the name of a file containing a list of symbols, or YES 56# to export all symbols. If not defined, no symbols are 57# exported. 58# 59# +++ targets +++ 60# 61# distribute: 62# This is a variant of install, which will 63# put the stuff into the right "distribution". 64# 65# install: 66# install the program and its manual pages; if the Makefile 67# does not itself define the target install, the targets 68# beforeinstall and afterinstall may also be used to cause 69# actions immediately before and after the install target 70# is executed. 71# 72# load: 73# Load KLD. 74# 75# unload: 76# Unload KLD. 77# 78# bsd.obj.mk: clean, cleandir and obj 79# bsd.dep.mk: cleandepend, depend and tags 80# bsd.man.mk: maninstall 81# 82 83KMODLOAD?= /sbin/kldload 84KMODUNLOAD?= /sbin/kldunload 85OBJCOPY?= objcopy 86 87TARGET_ARCH?= ${MACHINE_ARCH} 88 89.if !target(__initialized__) 90__initialized__: 91.if exists(${.CURDIR}/../Makefile.inc) 92.include "${.CURDIR}/../Makefile.inc" 93.endif 94.endif 95 96.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 97 98CFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS} 99CFLAGS+= -DKLD_MODULE 100 101# Don't use any standard or source-relative include directories. 102# Since -nostdinc will annull any previous -I paths, we repeat all 103# such paths after -nostdinc. It doesn't seem to be possible to 104# add to the front of `make' variable. 105_ICFLAGS:= ${CFLAGS:M-I*} 106CFLAGS+= -nostdinc -I- ${INCLMAGIC} ${_ICFLAGS} 107 108# Add -I paths for system headers. Individual KLD makefiles don't 109# need any -I paths for this. Similar defaults for .PATH can't be 110# set because there are no standard paths for non-headers. 111CFLAGS+= -I. -I@ -I@/dev 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) 119CFLAGS+= -I@/../include 120.else 121CFLAGS+= -I${DESTDIR}/usr/include 122.endif 123.else # !@ 124CFLAGS+= -I@/../include -I${DESTDIR}/usr/include 125.endif # @ 126 127# Disallow common variables, and if we end up with commons from 128# somewhere unexpected, allocate storage for them in the module itself. 129CFLAGS+= -fno-common 130LDFLAGS+= -d -warn-common 131 132CFLAGS+= ${DEBUG_FLAGS} 133 134.if ${OBJFORMAT} == elf 135CLEANFILES+= setdef0.c setdef1.c setdefs.h 136CLEANFILES+= setdef0.o setdef1.o 137.endif 138 139OBJS+= ${SRCS:N*.h:R:S/$/.o/g} 140 141.if !defined(PROG) 142PROG= ${KMOD}.ko 143.endif 144 145.if !defined(DEBUG) 146FULLPROG= ${PROG} 147.else 148FULLPROG= ${PROG}.debug 149${PROG}: ${FULLPROG} 150 ${OBJCOPY} --strip-debug ${FULLPROG} ${PROG} 151.endif 152 153${FULLPROG}: ${KMOD}.kld 154 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld 155 156EXPORT_SYMS?= NO 157.if ${EXPORT_SYMS} != YES 158CLEANFILES+= ${.OBJDIR}/export_syms 159.endif 160 161${KMOD}.kld: ${OBJS} 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 178 179.if !defined(NOMAN) 180.if 0 181MAN?= ${KMOD}.4 182.endif 183.include <bsd.man.mk> 184.else 185.if !target(all-man) 186all-man: _SUBDIR 187.endif 188.if !target(maninstall) 189maninstall: _SUBDIR 190.endif 191.endif 192 193_ILINKS=@ machine 194 195.MAIN: all 196all: objwarn ${PROG} all-man _SUBDIR 197 198beforedepend: ${_ILINKS} 199 @rm -f .depend 200 201# Ensure that the links exist without depending on it when it exists which 202# causes all the modules to be rebuilt when the directory pointed to changes. 203.for _link in ${_ILINKS} 204.if !exists(${.OBJDIR}/${_link}) 205${OBJS}: ${_link} 206.endif 207.endfor 208 209# Search for kernel source tree in standard places. 210.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys 211.if !defined(SYSDIR) && exists(${_dir}/kern/) 212SYSDIR= ${_dir} 213.endif 214.endfor 215.if !defined(SYSDIR) || !exists(${SYSDIR}/kern) 216.error "can't find kernel source tree" 217.endif 218 219${_ILINKS}: 220 @case ${.TARGET} in \ 221 machine) \ 222 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \ 223 @) \ 224 path=${SYSDIR} ;; \ 225 esac ; \ 226 path=`(cd $$path && /bin/pwd)` ; \ 227 ${ECHO} ${.TARGET} "->" $$path ; \ 228 ln -s $$path ${.TARGET} 229 230CLEANFILES+= ${PROG} ${FULLPROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o 231 232.if !target(install) 233.if !target(beforeinstall) 234beforeinstall: 235.endif 236.if !target(afterinstall) 237afterinstall: 238.endif 239 240_INSTALLFLAGS:= ${INSTALLFLAGS} 241.for ie in ${INSTALLFLAGS_EDIT} 242_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 243.endfor 244 245install.debug: _SUBDIR 246 ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 247 ${_INSTALLFLAGS} ${FULLPROG} ${DESTDIR}${KMODDIR}/ 248 249realinstall: _SUBDIR 250 ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 251 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}/ 252.if defined(LINKS) && !empty(LINKS) 253 @set ${LINKS}; \ 254 while test $$# -ge 2; do \ 255 l=${DESTDIR}$$1; \ 256 shift; \ 257 t=${DESTDIR}$$1; \ 258 shift; \ 259 ${ECHO} $$t -\> $$l; \ 260 ln -f $$l $$t; \ 261 done; true 262.endif 263.if defined(SYMLINKS) && !empty(SYMLINKS) 264 @set ${SYMLINKS}; \ 265 while test $$# -ge 2; do \ 266 l=$$1; \ 267 shift; \ 268 t=${DESTDIR}$$1; \ 269 shift; \ 270 ${ECHO} $$t -\> $$l; \ 271 ln -fs $$l $$t; \ 272 done; true 273.endif 274.if !defined(NO_XREF) 275 -kldxref ${DESTDIR}${KMODDIR} 276.endif 277 278install: afterinstall _SUBDIR 279.if !defined(NOMAN) 280afterinstall: realinstall maninstall 281.else 282afterinstall: realinstall 283.endif 284realinstall: beforeinstall 285.endif 286 287DISTRIBUTION?= bin 288.if !target(distribute) 289distribute: _SUBDIR 290.for dist in ${DISTRIBUTION} 291 cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 292.endfor 293.endif 294 295.if !target(load) 296load: ${PROG} 297 ${KMODLOAD} -v ${.CURDIR}/${KMOD}.ko 298.endif 299 300.if !target(unload) 301unload: 302 ${KMODUNLOAD} -v ${KMOD} 303.endif 304 305.for _src in ${SRCS:Mopt_*.h} 306CLEANFILES+= ${_src} 307.if !target(${_src}) 308${_src}: 309 touch ${.TARGET} 310.endif 311.endfor 312 313MFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \ 314 dev/iicbus/iicbus_if.m isa/isa_if.m \ 315 libkern/iconv_converter_if.m \ 316 dev/mii/miibus_if.m \ 317 dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \ 318 dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \ 319 dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ 320 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m pci/agp_if.m 321 322.for _srcsrc in ${MFILES} 323.for _ext in c h 324.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}} 325CLEANFILES+= ${_src} 326.if !target(${_src}) 327.if !exists(@) 328${_src}: @ 329.endif 330.if exists(@) 331${_src}: @/kern/makeobjops.pl @/${_srcsrc} 332.endif 333 perl @/kern/makeobjops.pl -${_ext} @/${_srcsrc} 334.endif 335.endfor # _src 336.endfor # _ext 337.endfor # _srcsrc 338 339.for _ext in c h 340.if ${SRCS:Mvnode_if.${_ext}} != "" 341CLEANFILES+= vnode_if.${_ext} 342.if !exists(@) 343vnode_if.${_ext}: @ 344.endif 345.if exists(@) 346vnode_if.${_ext}: @/kern/vnode_if.pl @/kern/vnode_if.src 347.endif 348 perl @/kern/vnode_if.pl -${_ext} @/kern/vnode_if.src 349.endif 350.endfor 351 352regress: 353 354.include <bsd.dep.mk> 355 356.if !exists(${DEPENDFILE}) 357${OBJS}: ${SRCS:M*.h} 358.endif 359 360.include <bsd.obj.mk> 361 362.include <bsd.kern.mk> 363