kmod.mk revision 50476
1275970Scy# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2275970Scy# $FreeBSD: head/sys/conf/kmod.mk 50476 1999-08-28 00:22:10Z peter $ 3275970Scy# 4275970Scy# The include file <bsd.kmod.mk> handles installing Loadable Kernel Modules. 5275970Scy# 6285612Sdelphij# 7275970Scy# +++ variables +++ 8275970Scy# 9275970Scy# CLEANFILES Additional files to remove for the clean and cleandir targets. 10275970Scy# 11275970Scy# DISTRIBUTION Name of distribution. [bin] 12275970Scy# 13275970Scy# KERN Main Kernel source directory. [${.CURDIR}/../../sys/kern] 14275970Scy# 15275970Scy# KMOD The name of the loadable kernel module to build. 16275970Scy# 17275970Scy# KMODDIR Base path for loadable kernel modules 18275970Scy# (see kld(4)). [/modules] 19275970Scy# 20275970Scy# KMODOWN LKM owner. [${BINOWN}] 21275970Scy# 22275970Scy# KMODGRP LKM group. [${BINGRP}] 23275970Scy# 24275970Scy# KMODMODE LKM mode. [${BINMODE}] 25275970Scy# 26275970Scy# LINKS The list of LKM links; should be full pathnames, the 27275970Scy# linked-to file coming first, followed by the linked 28275970Scy# file. The files are hard-linked. For example, to link 29275970Scy# /modules/master and /modules/meister, use: 30275970Scy# 31275970Scy# LINKS= /modules/master /modules/meister 32275970Scy# 33275970Scy# MODLOAD Command to load a kernel module [/sbin/modload] 34275970Scy# 35275970Scy# MODUNLOAD Command to unload a kernel module [/sbin/modunload] 36275970Scy# 37275970Scy# NOMAN LKM does not have a manual page if set. 38275970Scy# 39275970Scy# PROG The name of the loadable kernel module to build. 40275970Scy# If not supplied, ${KMOD}.o is used. 41275970Scy# 42275970Scy# SRCS List of source files 43275970Scy# 44275970Scy# KMODDEPS List of modules which this one is dependant on 45275970Scy# 46275970Scy# SUBDIR A list of subdirectories that should be built as well. 47275970Scy# Each of the targets will execute the same target in the 48275970Scy# subdirectories. 49275970Scy# 50275970Scy# SYMLINKS Same as LINKS, except it creates symlinks and the 51275970Scy# linked-to pathname may be relative. 52275970Scy# 53275970Scy# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk) 54285612Sdelphij# 55285612Sdelphij# 56275970Scy# +++ targets +++ 57275970Scy# 58275970Scy# distribute: 59275970Scy# This is a variant of install, which will 60275970Scy# put the stuff into the right "distribution". 61275970Scy# 62275970Scy# install: 63275970Scy# install the program and its manual pages; if the Makefile 64275970Scy# does not itself define the target install, the targets 65275970Scy# beforeinstall and afterinstall may also be used to cause 66275970Scy# actions immediately before and after the install target 67275970Scy# is executed. 68275970Scy# 69275970Scy# load: 70275970Scy# Load LKM. 71275970Scy# 72275970Scy# unload: 73275970Scy# Unload LKM. 74275970Scy# 75275970Scy# bsd.obj.mk: clean, cleandir and obj 76275970Scy# bsd.dep.mk: cleandepend, depend and tags 77275970Scy# bsd.man.mk: maninstall 78275970Scy# 79275970Scy 80275970ScyMODLOAD?= /sbin/modload 81275970ScyMODUNLOAD?= /sbin/modunload 82275970Scy 83275970Scy.if !target(__initialized__) 84275970Scy__initialized__: 85275970Scy.if exists(${.CURDIR}/../Makefile.inc) 86275970Scy.include "${.CURDIR}/../Makefile.inc" 87275970Scy.endif 88275970Scy.endif 89275970Scy 90275970Scy.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 91285612Sdelphij 92275970ScyCFLAGS+= ${COPTS} -DKERNEL ${CWARNFLAGS} 93275970ScyCFLAGS+= -DKLD_MODULE 94275970Scy 95275970Scy# Don't use any standard or source-relative include directories. 96275970Scy# Since -nostdinc will annull any previous -I paths, we repeat all 97275970Scy# such paths after -nostdinc. It doesn't seem to be possible to 98275970Scy# add to the front of `make' variable. 99275970Scy_ICFLAGS:= ${CFLAGS:M-I*} 100275970ScyCFLAGS+= -nostdinc -I- ${_ICFLAGS} 101275970Scy 102275970Scy# Add -I paths for system headers. Individual LKM makefiles don't 103275970Scy# need any -I paths for this. Similar defaults for .PATH can't be 104275970Scy# set because there are no standard paths for non-headers. 105275970ScyCFLAGS+= -I${.OBJDIR} -I${.OBJDIR}/@ 106275970Scy 107275970Scy# XXX this is now dubious. 108275970Scy.if defined(DESTDIR) 109275970ScyCFLAGS+= -I${DESTDIR}/usr/include 110275970Scy.endif 111275970Scy 112275970Scy.if defined(VFS_KLD) 113275970ScySRCS+= vnode_if.h 114275970ScyCLEANFILES+= vnode_if.h vnode_if.c 115275970Scy.endif 116275970Scy 117275970Scy.if ${OBJFORMAT} == elf 118275970ScyCLEANFILES+= setdef0.c setdef1.c setdefs.h 119275970ScyCLEANFILES+= setdef0.o setdef1.o 120275970Scy.endif 121275970Scy 122275970ScyOBJS+= ${SRCS:N*.h:R:S/$/.o/g} 123275970Scy 124275970Scy.if !defined(PROG) 125275970ScyPROG= ${KMOD}.ko 126275970Scy.endif 127275970Scy 128275970Scy${PROG}: ${OBJS} ${DPADD} ${KMODDEPS} 129275970Scy.if ${OBJFORMAT} == elf 130275970Scy gensetdefs ${OBJS} 131275970Scy ${CC} ${CFLAGS} -c setdef0.c 132275970Scy ${CC} ${CFLAGS} -c setdef1.c 133275970Scy ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} setdef0.o ${OBJS} setdef1.o ${KMODDEPS} 134275970Scy.else 135275970Scy ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${OBJS} ${KMODDEPS} 136285612Sdelphij.endif 137275970Scy 138275970Scy.if defined(KMODDEPS) 139275970Scy.for dep in ${KMODDEPS} 140275970ScyCLEANFILES+= ${dep} __${dep}_hack_dep.c 141275970Scy 142275970Scy${dep}: 143275970Scy touch __${dep}_hack_dep.c 144275970Scy ${CC} -shared ${CFLAGS} -o ${dep} __${dep}_hack_dep.c 145275970Scy.endfor 146275970Scy.endif 147275970Scy 148275970Scy.if !defined(NOMAN) 149275970Scy.include <bsd.man.mk> 150275970Scy.if !defined(_MANPAGES) || empty(_MANPAGES) 151275970ScyMAN1= ${KMOD}.4 152275970Scy.endif 153275970Scy 154275970Scy.elif !target(maninstall) 155275970Scymaninstall: _SUBDIR 156275970Scyall-man: 157275970Scy.endif 158275970Scy 159275970Scy_ILINKS=@ machine 160275970Scy 161275970Scy.MAIN: all 162275970Scyall: objwarn ${PROG} all-man _SUBDIR 163275970Scy 164275970Scybeforedepend ${OBJS}: ${_ILINKS} 165275970Scy 166275970Scy# The search for the link targets works best if we are in a normal src 167275970Scy# tree, and not too deeply below src/sys/modules. If we are near "/", then 168275970Scy# we may find /sys - this is harmless. Other abnormal "sys" directories 169275970Scy# found in the search are likely to cause problems. If nothing is found, 170275970Scy# then the links default to /usr/include and /usr/include/machine. 171275970Scy${_ILINKS}: 172275970Scy @set +x; for up in ../.. ../../.. ; do \ 173 case ${.TARGET} in \ 174 machine) \ 175 testpath=${.CURDIR}/$$up/${MACHINE_ARCH}/include ; \ 176 path=${.CURDIR}/$$up/${MACHINE_ARCH}/include ; \ 177 defaultpath=/usr/include/machine ;; \ 178 @) \ 179 testpath=${.CURDIR}/$$up/sys ; \ 180 path=${.CURDIR}/$$up ; \ 181 defaultpath=/usr/include ;; \ 182 esac ; \ 183 if [ -d $$testpath ] ; then break ; fi ; \ 184 path=$$defaultpath ; \ 185 done ; \ 186 path=`(cd $$path && /bin/pwd)` ; \ 187 ${ECHO} ${.TARGET} "->" $$path ; \ 188 ln -s $$path ${.TARGET} 189 190CLEANFILES+= ${PROG} ${OBJS} ${_ILINKS} symb.tmp tmp.o 191 192.if !target(install) 193.if !target(beforeinstall) 194beforeinstall: 195.endif 196.if !target(afterinstall) 197afterinstall: 198.endif 199 200_INSTALLFLAGS:= ${INSTALLFLAGS} 201.for ie in ${INSTALLFLAGS_EDIT} 202_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 203.endfor 204 205realinstall: _SUBDIR 206 ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 207 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 208.if defined(LINKS) && !empty(LINKS) 209 @set ${LINKS}; \ 210 while test $$# -ge 2; do \ 211 l=${DESTDIR}$$1; \ 212 shift; \ 213 t=${DESTDIR}$$1; \ 214 shift; \ 215 ${ECHO} $$t -\> $$l; \ 216 ln -f $$l $$t; \ 217 done; true 218.endif 219.if defined(SYMLINKS) && !empty(SYMLINKS) 220 @set ${SYMLINKS}; \ 221 while test $$# -ge 2; do \ 222 l=$$1; \ 223 shift; \ 224 t=${DESTDIR}$$1; \ 225 shift; \ 226 ${ECHO} $$t -\> $$l; \ 227 ln -fs $$l $$t; \ 228 done; true 229.endif 230 231install: afterinstall _SUBDIR 232.if !defined(NOMAN) 233afterinstall: realinstall maninstall 234.else 235afterinstall: realinstall 236.endif 237realinstall: beforeinstall 238.endif 239 240DISTRIBUTION?= bin 241.if !target(distribute) 242distribute: _SUBDIR 243.for dist in ${DISTRIBUTION} 244 cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 245.endfor 246.endif 247 248.if !target(load) 249load: ${PROG} 250 ${MODLOAD} -o ${KMOD} -e${KMOD} ${PROG} 251.endif 252 253.if !target(unload) 254unload: ${PROG} 255 ${MODUNLOAD} -n ${KMOD} 256.endif 257 258.if exists(${.CURDIR}/../../kern) 259KERN= ${.CURDIR}/../../kern 260.else 261KERN= ${.CURDIR}/../../sys/kern 262.endif 263 264vnode_if.h: ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 265 sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 266 267regress: 268 269.include <bsd.dep.mk> 270 271.if !exists(${DEPENDFILE}) 272${OBJS}: ${SRCS:M*.h} 273.endif 274 275.include <bsd.obj.mk> 276 277.include <bsd.kern.mk> 278