kmod.mk revision 72672
1# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2# $FreeBSD: head/sys/conf/kmod.mk 72672 2001-02-18 20:23:22Z peter $ 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# +++ targets +++ 55# 56# distribute: 57# This is a variant of install, which will 58# put the stuff into the right "distribution". 59# 60# install: 61# install the program and its manual pages; if the Makefile 62# does not itself define the target install, the targets 63# beforeinstall and afterinstall may also be used to cause 64# actions immediately before and after the install target 65# is executed. 66# 67# load: 68# Load KLD. 69# 70# unload: 71# Unload KLD. 72# 73# bsd.obj.mk: clean, cleandir and obj 74# bsd.dep.mk: cleandepend, depend and tags 75# bsd.man.mk: maninstall 76# 77 78KMODLOAD?= /sbin/kldload 79KMODUNLOAD?= /sbin/kldunload 80 81.if !target(__initialized__) 82__initialized__: 83.if exists(${.CURDIR}/../Makefile.inc) 84.include "${.CURDIR}/../Makefile.inc" 85.endif 86.endif 87 88.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 89 90CFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS} 91CFLAGS+= -DKLD_MODULE 92 93# Don't use any standard or source-relative include directories. 94# Since -nostdinc will annull any previous -I paths, we repeat all 95# such paths after -nostdinc. It doesn't seem to be possible to 96# add to the front of `make' variable. 97_ICFLAGS:= ${CFLAGS:M-I*} 98CFLAGS+= -nostdinc -I- ${INCLMAGIC} ${_ICFLAGS} 99 100# Add -I paths for system headers. Individual KLD makefiles don't 101# need any -I paths for this. Similar defaults for .PATH can't be 102# set because there are no standard paths for non-headers. 103CFLAGS+= -I. -I@ -I@/dev 104 105# Add a -I path to standard headers like <stddef.h>. Use a relative 106# path to src/include if possible. If the @ symlink hasn't been built 107# yet, then we can't tell if the relative path exists. Add both the 108# potential relative path and an absolute path in that case. 109.if exists(@) 110.if exists(@/../include) 111CFLAGS+= -I@/../include 112.else 113CFLAGS+= -I${DESTDIR}/usr/include 114.endif 115.else # !@ 116CFLAGS+= -I@/../include -I${DESTDIR}/usr/include 117.endif # @ 118 119CFLAGS+= ${DEBUG_FLAGS} 120 121.if ${OBJFORMAT} == elf 122CLEANFILES+= setdef0.c setdef1.c setdefs.h 123CLEANFILES+= setdef0.o setdef1.o 124.endif 125 126OBJS+= ${SRCS:N*.h:R:S/$/.o/g} 127 128.if !defined(PROG) 129PROG= ${KMOD}.ko 130.endif 131 132${PROG}: ${KMOD}.kld 133.if ${OBJFORMAT} == elf 134 perl5 @/kern/gensetdefs.pl ${KMOD}.kld 135 ${CC} ${CFLAGS} -c setdef0.c 136 ${CC} ${CFLAGS} -c setdef1.c 137 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} setdef0.o ${KMOD}.kld setdef1.o 138.else 139 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld 140.endif 141 142${KMOD}.kld: ${OBJS} 143 ${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS} 144 145.if !defined(NOMAN) 146.include <bsd.man.mk> 147.if !defined(_MANPAGES) || empty(_MANPAGES) 148MAN1= ${KMOD}.4 149.endif 150 151.elif !target(maninstall) 152maninstall: _SUBDIR 153all-man: 154.endif 155 156_ILINKS=@ machine 157 158.MAIN: all 159all: objwarn ${PROG} all-man _SUBDIR 160 161beforedepend ${OBJS}: ${_ILINKS} 162 @rm -f .depend 163 164# Search for kernel source tree in standard places. 165.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys 166.if !defined(SYSDIR) && exists(${_dir}/kern/) 167SYSDIR= ${_dir} 168.endif 169.endfor 170.if !defined(SYSDIR) || !exists(${SYSDIR}/kern) 171.error "can't find kernel source tree" 172.endif 173 174${_ILINKS}: 175 @case ${.TARGET} in \ 176 machine) \ 177 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \ 178 @) \ 179 path=${SYSDIR} ;; \ 180 esac ; \ 181 path=`(cd $$path && /bin/pwd)` ; \ 182 ${ECHO} ${.TARGET} "->" $$path ; \ 183 ln -s $$path ${.TARGET} 184 185CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o 186 187.if !target(install) 188.if !target(beforeinstall) 189beforeinstall: 190.endif 191.if !target(afterinstall) 192afterinstall: 193.endif 194 195_INSTALLFLAGS:= ${INSTALLFLAGS} 196.for ie in ${INSTALLFLAGS_EDIT} 197_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 198.endfor 199 200realinstall: _SUBDIR 201 ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 202 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 203.if defined(LINKS) && !empty(LINKS) 204 @set ${LINKS}; \ 205 while test $$# -ge 2; do \ 206 l=${DESTDIR}$$1; \ 207 shift; \ 208 t=${DESTDIR}$$1; \ 209 shift; \ 210 ${ECHO} $$t -\> $$l; \ 211 ln -f $$l $$t; \ 212 done; true 213.endif 214.if defined(SYMLINKS) && !empty(SYMLINKS) 215 @set ${SYMLINKS}; \ 216 while test $$# -ge 2; do \ 217 l=$$1; \ 218 shift; \ 219 t=${DESTDIR}$$1; \ 220 shift; \ 221 ${ECHO} $$t -\> $$l; \ 222 ln -fs $$l $$t; \ 223 done; true 224.endif 225 226install: afterinstall _SUBDIR 227.if !defined(NOMAN) 228afterinstall: realinstall maninstall 229.else 230afterinstall: realinstall 231.endif 232realinstall: beforeinstall 233.endif 234 235DISTRIBUTION?= bin 236.if !target(distribute) 237distribute: _SUBDIR 238.for dist in ${DISTRIBUTION} 239 cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 240.endfor 241.endif 242 243.if !target(load) 244load: ${PROG} 245 ${KMODLOAD} -v ./${KMOD}.ko 246.endif 247 248.if !target(unload) 249unload: 250 ${KMODUNLOAD} -v ${KMOD} 251.endif 252 253.for _src in ${SRCS:Mopt_*.h} 254CLEANFILES+= ${_src} 255.if !target(${_src}) 256${_src}: 257 touch ${.TARGET} 258.endif 259.endfor 260 261MFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \ 262 dev/iicbus/iicbus_if.m isa/isa_if.m dev/mii/miibus_if.m \ 263 dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \ 264 dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \ 265 dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ 266 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m 267 268.for _srcsrc in ${MFILES} 269.for _ext in c h 270.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}} 271CLEANFILES+= ${_src} 272.if !target(${_src}) 273${_src}: @ 274.if exists(@) 275${_src}: @/kern/makeobjops.pl @/${_srcsrc} 276.endif 277 perl @/kern/makeobjops.pl -${_ext} @/${_srcsrc} 278.endif 279.endfor # _src 280.endfor # _ext 281.endfor # _srcsrc 282 283.for _ext in c h 284.if ${SRCS:Mvnode_if.${_ext}} != "" 285CLEANFILES+= vnode_if.${_ext} 286vnode_if.${_ext}: @ 287.if exists(@) 288vnode_if.${_ext}: @/kern/vnode_if.pl @/kern/vnode_if.src 289.endif 290 perl @/kern/vnode_if.pl -${_ext} @/kern/vnode_if.src 291.endif 292.endfor 293 294regress: 295 296.include <bsd.dep.mk> 297 298.if !exists(${DEPENDFILE}) 299${OBJS}: ${SRCS:M*.h} 300.endif 301 302.include <bsd.obj.mk> 303 304.include <bsd.kern.mk> 305