kmod.mk revision 32813
1151427Sphk# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2151427Sphk# $Id: bsd.kmod.mk,v 1.41 1997/11/09 15:03:13 wosch Exp $ 3151427Sphk# 4151427Sphk# The include file <bsd.kmod.mk> handles installing Loadable Kernel Modules. 5151427Sphk# 6151427Sphk# 7151427Sphk# +++ variables +++ 8151427Sphk# 9151427Sphk# CLEANFILES Additional files to remove for the clean and cleandir targets. 10151427Sphk# 11151427Sphk# DISTRIBUTION Name of distribution. [bin] 12151427Sphk# 13151427Sphk# EXPORT_SYMS ??? 14151427Sphk# 15151427Sphk# KERN Main Kernel source directory. [${.CURDIR}/../../sys/kern] 16151427Sphk# 17151427Sphk# KMOD The name of the loadable kernel module to build. 18151427Sphk# 19151427Sphk# KMODDIR Base path for loadable kernel modules 20151427Sphk# (see lkm(4)). [/lkm] 21151427Sphk# 22151427Sphk# KMODOWN LKM owner. [${BINOWN}] 23151427Sphk# 24151427Sphk# KMODGRP LKM group. [${BINGRP}] 25151427Sphk# 26151427Sphk# KMODMODE LKM mode. [${BINMODE}] 27151427Sphk# 28151427Sphk# LINKS The list of LKM links; should be full pathnames, the 29151427Sphk# linked-to file coming first, followed by the linked 30151427Sphk# file. The files are hard-linked. For example, to link 31151427Sphk# /lkm/master and /lkm/meister, use: 32193188Sed# 33193188Sed# LINKS= /lkm/master /lkm/meister 34151427Sphk# 35151427Sphk# LN_FLAGS Flags for ln(1) (see variable LINKS) 36151427Sphk# 37151427Sphk# MODLOAD Command to load a kernel module [/sbin/modload] 38151427Sphk# 39151427Sphk# MODUNLOAD Command to unload a kernel module [/sbin/modunload] 40151427Sphk# 41151427Sphk# NOMAN LKM does not have a manual page if set. 42151427Sphk# 43151427Sphk# PROG The name of the loadable kernel module to build. 44162011Ssam# If not supplied, ${KMOD}.o is used. 45162011Ssam# 46162011Ssam# PSEUDO_LKM ??? 47162011Ssam# 48151427Sphk# SRCS List of source files 49151427Sphk# 50151427Sphk# SUBDIR A list of subdirectories that should be built as well. 51151427Sphk# Each of the targets will execute the same target in the 52151427Sphk# subdirectories. 53151427Sphk# 54151427Sphk# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk) 55151427Sphk# 56151427Sphk# 57151427Sphk# +++ targets +++ 58151427Sphk# 59151427Sphk# distribute: 60151427Sphk# This is a variant of install, which will 61151427Sphk# put the stuff into the right "distribution". 62151427Sphk# 63151427Sphk# install: 64151427Sphk# install the program and its manual pages; if the Makefile 65151427Sphk# does not itself define the target install, the targets 66193188Sed# beforeinstall and afterinstall may also be used to cause 67193188Sed# actions immediately before and after the install target 68151427Sphk# is executed. 69151427Sphk# 70151427Sphk# load: 71151427Sphk# Load LKM. 72193188Sed# 73193188Sed# tags: 74151427Sphk# Create a tags file for the source files. 75151427Sphk# 76151427Sphk# unload: 77151427Sphk# Unload LKM. 78151427Sphk# 79151427Sphk# bsd.obj.mk: clean, cleandir and obj 80151427Sphk# bsd.dep.mk: depend 81151427Sphk# bsd.man.mk: maninstall 82151427Sphk# 83193188Sed 84193188SedMODLOAD?= /sbin/modload 85151427SphkMODUNLOAD?= /sbin/modunload 86193188Sed 87151427Sphk.if exists(${.CURDIR}/../Makefile.inc) 88151427Sphk.include "${.CURDIR}/../Makefile.inc" 89151427Sphk.endif 90229403Sed 91193188Sed.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 92151427Sphk 93193188SedCFLAGS+= ${COPTS} -DKERNEL -DACTUALLY_LKM_NOT_KERNEL ${CWARNFLAGS} 94151427Sphk 95151427Sphk# Add -I paths for system headers. Individual LKM makefiles don't need any 96151427Sphk# -I paths for this. Most of them need .PATH statement(s) for non-headers. 97151427SphkCFLAGS+= -I${.OBJDIR} -I${.OBJDIR}/@ 98193188Sed 99193188Sed.if defined(DESTDIR) 100193188SedCFLAGS+= -I${DESTDIR}/usr/include 101193188Sed.endif 102151427Sphk 103193188SedEXPORT_SYMS?= _${KMOD} 104193188Sed 105193188Sed.if defined(VFS_LKM) 106193188SedCFLAGS+= -DVFS_LKM -DMODVNOPS=${KMOD}vnops 107193188SedSRCS+= vnode_if.h 108151427SphkCLEANFILES+= vnode_if.h vnode_if.c 109193188Sed.endif 110193188Sed 111193188Sed.if defined(PSEUDO_LKM) 112193188SedCFLAGS+= -DPSEUDO_LKM 113193188Sed.endif 114151427Sphk 115151427SphkDPSRCS+= ${SRCS:M*.h} 116151427SphkOBJS+= ${SRCS:N*.h:R:S/$/.o/g} 117193188Sed 118193188Sed.if !defined(PROG) 119151427SphkPROG= ${KMOD}.o 120193188Sed.endif 121193188Sed 122193188Sed${PROG}: ${DPSRCS} ${OBJS} ${DPADD} 123193188Sed ${LD} -r ${LDFLAGS} -o tmp.o ${OBJS} 124193188Sed.if defined(EXPORT_SYMS) 125193188Sed @rm -f symb.tmp 126193188Sed @for i in ${EXPORT_SYMS} ; do echo $$i >> symb.tmp ; done 127193188Sed symorder -c symb.tmp tmp.o 128193188Sed @rm -f symb.tmp 129193188Sed.endif 130193188Sed mv tmp.o ${.TARGET} 131193188Sed 132193188Sed.if !defined(NOMAN) 133193188Sed.include <bsd.man.mk> 134193188Sed.if !defined(_MANPAGES) || empty(_MANPAGES) 135193188SedMAN1= ${KMOD}.4 136193188Sed.endif 137193188Sed 138193188Sed.elif !target(maninstall) 139193188Sedmaninstall: _SUBDIR 140193188Sedall-man: 141193188Sed.endif 142193188Sed 143193188Sed_ILINKS=@ machine 144193188Sed 145193188Sed.MAIN: all 146193188Sedall: ${_ILINKS} objwarn ${PROG} all-man _SUBDIR 147193188Sed 148193188Sedbeforedepend: ${_ILINKS} 149151427Sphk 150151427Sphk# The search for the link targets works best if we are in a normal src 151193188Sed# tree, and not too deeply below src/lkm. If we are near "/", then 152193188Sed# we may find /sys - this is harmless. Other abnormal "sys" directories 153151427Sphk# found in the search are likely to cause problems. If nothing is found, 154151427Sphk# then the links default to /usr/include and /usr/include/machine. 155151427Sphk${_ILINKS}: 156151427Sphk @for up in ../.. ../../.. ; do \ 157151427Sphk case ${.TARGET} in \ 158151427Sphk machine) \ 159151427Sphk path=${.CURDIR}/$$up/sys/${MACHINE_ARCH}/include ; \ 160151427Sphk defaultpath=/usr/include/machine ;; \ 161151427Sphk @) \ 162151427Sphk path=${.CURDIR}/$$up/sys ; \ 163151427Sphk defaultpath=/usr/include ;; \ 164151427Sphk esac ; \ 165151427Sphk if [ -d $$path ] ; then break ; fi ; \ 166151427Sphk path=$$defaultpath ; \ 167151427Sphk done ; \ 168151427Sphk path=`(cd $$path && /bin/pwd)` ; \ 169151427Sphk ${ECHO} ${.TARGET} "->" $$path ; \ 170151427Sphk ln -s $$path ${.TARGET} 171151427Sphk 172151427SphkCLEANFILES+= ${KMOD} ${PROG} ${OBJS} ${_ILINKS} 173151427Sphk 174151427Sphk.if !target(install) 175151427Sphk.if !target(beforeinstall) 176151427Sphkbeforeinstall: 177151427Sphk.endif 178151427Sphk.if !target(afterinstall) 179151427Sphkafterinstall: 180151427Sphk.endif 181151427Sphk 182151427Sphkrealinstall: _SUBDIR 183151427Sphk ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 184151427Sphk ${INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 185151427Sphk.if defined(LINKS) && !empty(LINKS) 186151427Sphk @set ${LINKS}; \ 187151427Sphk while test $$# -ge 2; do \ 188151427Sphk l=${DESTDIR}$$1; \ 189151427Sphk shift; \ 190151427Sphk t=${DESTDIR}$$1; \ 191151427Sphk shift; \ 192151427Sphk ${ECHO} $$t -\> $$l; \ 193151427Sphk rm -f $$t; \ 194151427Sphk ln ${LN_FLAGS} $$l $$t; \ 195151427Sphk done; true 196151427Sphk.endif 197151427Sphk 198151427Sphkinstall: afterinstall _SUBDIR 199151427Sphk.if !defined(NOMAN) 200151427Sphkafterinstall: realinstall maninstall 201151427Sphk.else 202151427Sphkafterinstall: realinstall 203151427Sphk.endif 204151427Sphkrealinstall: beforeinstall 205151427Sphk.endif 206151427Sphk 207151427SphkDISTRIBUTION?= bin 208151427Sphk.if !target(distribute) 209151427Sphkdistribute: _SUBDIR 210151427Sphk.for dist in ${DISTRIBUTION} 211151427Sphk cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 212151427Sphk.endfor 213151427Sphk.endif 214151427Sphk 215151427Sphk.if defined(NOTAGS) 216151427Sphktags: 217151427Sphk.endif 218151427Sphk 219151427Sphk.if !target(tags) 220151427Sphktags: ${SRCS} _SUBDIR 221151427Sphk.if defined(PROG) 222151427Sphk @cd ${.CURDIR} && gtags ${GTAGSFLAGS} 223151427Sphk.if defined(HTML) 224151427Sphk @cd ${.CURDIR} && htags ${HTAGSFLAGS} 225151427Sphk.endif 226151427Sphk.endif 227151427Sphk.endif 228151427Sphk 229151427Sphk 230151427Sphk.if !target(load) 231151427Sphkload: ${PROG} 232151427Sphk ${MODLOAD} -o ${KMOD} -e${KMOD} ${PROG} 233151427Sphk.endif 234151427Sphk 235151427Sphk.if !target(unload) 236151427Sphkunload: ${PROG} 237151427Sphk ${MODUNLOAD} -n ${KMOD} 238151427Sphk.endif 239151427Sphk 240151427SphkKERN= ${.CURDIR}/../../sys/kern 241151427Sphk 242151427Sphkvnode_if.h: ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 243151427Sphk sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 244151427Sphk 245151427Sphk./vnode_if.h: vnode_if.h 246151427Sphk 247151427Sphk.include <bsd.obj.mk> 248151427Sphk.include <bsd.dep.mk> 249151427Sphk.include <bsd.kern.mk> 250151427Sphk