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