kmod.mk revision 72754
1# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2# $FreeBSD: head/sys/conf/kmod.mk 72754 2001-02-20 09:37:00Z 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: ${_ILINKS} 162 @rm -f .depend 163 164${OBJS}: ${_ILINKS} 165 166# Search for kernel source tree in standard places. 167.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys 168.if !defined(SYSDIR) && exists(${_dir}/kern/) 169SYSDIR= ${_dir} 170.endif 171.endfor 172.if !defined(SYSDIR) || !exists(${SYSDIR}/kern) 173.error "can't find kernel source tree" 174.endif 175 176${_ILINKS}: 177 @case ${.TARGET} in \ 178 machine) \ 179 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \ 180 @) \ 181 path=${SYSDIR} ;; \ 182 esac ; \ 183 path=`(cd $$path && /bin/pwd)` ; \ 184 ${ECHO} ${.TARGET} "->" $$path ; \ 185 ln -s $$path ${.TARGET} 186 187CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o 188 189.if !target(install) 190.if !target(beforeinstall) 191beforeinstall: 192.endif 193.if !target(afterinstall) 194afterinstall: 195.endif 196 197_INSTALLFLAGS:= ${INSTALLFLAGS} 198.for ie in ${INSTALLFLAGS_EDIT} 199_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 200.endfor 201 202realinstall: _SUBDIR 203 ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 204 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 205.if defined(LINKS) && !empty(LINKS) 206 @set ${LINKS}; \ 207 while test $$# -ge 2; do \ 208 l=${DESTDIR}$$1; \ 209 shift; \ 210 t=${DESTDIR}$$1; \ 211 shift; \ 212 ${ECHO} $$t -\> $$l; \ 213 ln -f $$l $$t; \ 214 done; true 215.endif 216.if defined(SYMLINKS) && !empty(SYMLINKS) 217 @set ${SYMLINKS}; \ 218 while test $$# -ge 2; do \ 219 l=$$1; \ 220 shift; \ 221 t=${DESTDIR}$$1; \ 222 shift; \ 223 ${ECHO} $$t -\> $$l; \ 224 ln -fs $$l $$t; \ 225 done; true 226.endif 227 228install: afterinstall _SUBDIR 229.if !defined(NOMAN) 230afterinstall: realinstall maninstall 231.else 232afterinstall: realinstall 233.endif 234realinstall: beforeinstall 235.endif 236 237DISTRIBUTION?= bin 238.if !target(distribute) 239distribute: _SUBDIR 240.for dist in ${DISTRIBUTION} 241 cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 242.endfor 243.endif 244 245.if !target(load) 246load: ${PROG} 247 ${KMODLOAD} -v ./${KMOD}.ko 248.endif 249 250.if !target(unload) 251unload: 252 ${KMODUNLOAD} -v ${KMOD} 253.endif 254 255.for _src in ${SRCS:Mopt_*.h} 256CLEANFILES+= ${_src} 257.if !target(${_src}) 258${_src}: 259 touch ${.TARGET} 260.endif 261.endfor 262 263MFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \ 264 dev/iicbus/iicbus_if.m isa/isa_if.m dev/mii/miibus_if.m \ 265 dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \ 266 dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \ 267 dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \ 268 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m 269 270.for _srcsrc in ${MFILES} 271.for _ext in c h 272.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}} 273CLEANFILES+= ${_src} 274.if !target(${_src}) 275${_src}: @ 276.if exists(@) 277${_src}: @/kern/makeobjops.pl @/${_srcsrc} 278.endif 279 perl @/kern/makeobjops.pl -${_ext} @/${_srcsrc} 280.endif 281.endfor # _src 282.endfor # _ext 283.endfor # _srcsrc 284 285.for _ext in c h 286.if ${SRCS:Mvnode_if.${_ext}} != "" 287CLEANFILES+= vnode_if.${_ext} 288vnode_if.${_ext}: @ 289.if exists(@) 290vnode_if.${_ext}: @/kern/vnode_if.pl @/kern/vnode_if.src 291.endif 292 perl @/kern/vnode_if.pl -${_ext} @/kern/vnode_if.src 293.endif 294.endfor 295 296regress: 297 298.include <bsd.dep.mk> 299 300.if !exists(${DEPENDFILE}) 301${OBJS}: ${SRCS:M*.h} 302.endif 303 304.include <bsd.obj.mk> 305 306.include <bsd.kern.mk> 307