kmod.mk revision 34677
1254885Sdumbbell# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2254885Sdumbbell# $Id: bsd.kmod.mk,v 1.47 1998/03/12 20:02:11 eivind Exp $ 3254885Sdumbbell# 4254885Sdumbbell# The include file <bsd.kmod.mk> handles installing Loadable Kernel Modules. 5254885Sdumbbell# 6254885Sdumbbell# 7254885Sdumbbell# +++ variables +++ 8254885Sdumbbell# 9254885Sdumbbell# CLEANFILES Additional files to remove for the clean and cleandir targets. 10254885Sdumbbell# 11254885Sdumbbell# DISTRIBUTION Name of distribution. [bin] 12254885Sdumbbell# 13254885Sdumbbell# EXPORT_SYMS ??? 14254885Sdumbbell# 15254885Sdumbbell# KERN Main Kernel source directory. [${.CURDIR}/../../sys/kern] 16254885Sdumbbell# 17254885Sdumbbell# KMOD The name of the loadable kernel module to build. 18254885Sdumbbell# 19254885Sdumbbell# KMODDIR Base path for loadable kernel modules 20254885Sdumbbell# (see lkm(4)). [/lkm] 21254885Sdumbbell# 22254885Sdumbbell# KMODOWN LKM owner. [${BINOWN}] 23254885Sdumbbell# 24254885Sdumbbell# KMODGRP LKM group. [${BINGRP}] 25254885Sdumbbell# 26254885Sdumbbell# KMODMODE LKM mode. [${BINMODE}] 27254885Sdumbbell# 28254885Sdumbbell# LINKS The list of LKM links; should be full pathnames, the 29254885Sdumbbell# linked-to file coming first, followed by the linked 30254885Sdumbbell# file. The files are hard-linked. For example, to link 31254885Sdumbbell# /lkm/master and /lkm/meister, use: 32254885Sdumbbell# 33254885Sdumbbell# LINKS= /lkm/master /lkm/meister 34254885Sdumbbell# 35254885Sdumbbell# LN_FLAGS Flags for ln(1) (see variable LINKS) 36254885Sdumbbell# 37254885Sdumbbell# MODLOAD Command to load a kernel module [/sbin/modload] 38254885Sdumbbell# 39254885Sdumbbell# MODUNLOAD Command to unload a kernel module [/sbin/modunload] 40254885Sdumbbell# 41254885Sdumbbell# NOMAN LKM does not have a manual page if set. 42254885Sdumbbell# 43254885Sdumbbell# PROG The name of the loadable kernel module to build. 44254885Sdumbbell# If not supplied, ${KMOD}.o is used. 45254885Sdumbbell# 46254885Sdumbbell# PSEUDO_LKM ??? 47254885Sdumbbell# 48254885Sdumbbell# SRCS List of source files 49254885Sdumbbell# 50254885Sdumbbell# SUBDIR A list of subdirectories that should be built as well. 51254885Sdumbbell# Each of the targets will execute the same target in the 52254885Sdumbbell# subdirectories. 53254885Sdumbbell# 54254885Sdumbbell# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk) 55254885Sdumbbell# 56254885Sdumbbell# 57254885Sdumbbell# +++ targets +++ 58254885Sdumbbell# 59254885Sdumbbell# distribute: 60254885Sdumbbell# This is a variant of install, which will 61254885Sdumbbell# put the stuff into the right "distribution". 62254885Sdumbbell# 63254885Sdumbbell# install: 64254885Sdumbbell# install the program and its manual pages; if the Makefile 65254885Sdumbbell# does not itself define the target install, the targets 66254885Sdumbbell# beforeinstall and afterinstall may also be used to cause 67254885Sdumbbell# actions immediately before and after the install target 68254885Sdumbbell# is executed. 69254885Sdumbbell# 70254885Sdumbbell# load: 71254885Sdumbbell# Load LKM. 72254885Sdumbbell# 73254885Sdumbbell# unload: 74254885Sdumbbell# Unload LKM. 75254885Sdumbbell# 76254885Sdumbbell# bsd.obj.mk: clean, cleandir and obj 77254885Sdumbbell# bsd.dep.mk: cleandepend, depend and tags 78254885Sdumbbell# bsd.man.mk: maninstall 79254885Sdumbbell# 80254885Sdumbbell 81254885SdumbbellMODLOAD?= /sbin/modload 82254885SdumbbellMODUNLOAD?= /sbin/modunload 83254885Sdumbbell 84254885Sdumbbell.if exists(${.CURDIR}/../Makefile.inc) 85254885Sdumbbell.include "${.CURDIR}/../Makefile.inc" 86254885Sdumbbell.endif 87254885Sdumbbell 88254885Sdumbbell.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 89254885Sdumbbell 90254885SdumbbellCFLAGS+= ${COPTS} -DKERNEL -DACTUALLY_LKM_NOT_KERNEL ${CWARNFLAGS} 91254885Sdumbbell 92254885Sdumbbell# Don't use any standard or source-relative include directories. 93254885Sdumbbell# Since -nostdinc will annull any previous -I paths, we repeat all 94254885Sdumbbell# such paths after -nostdinc. It doesn't seem to be possible to 95254885Sdumbbell# add to the front of `make' variable. 96254885Sdumbbell_ICFLAGS:= ${CFLAGS:M-I*} 97254885SdumbbellCFLAGS+= -nostdinc -I- ${_ICFLAGS} 98254885Sdumbbell 99254885Sdumbbell# Add -I paths for system headers. Individual LKM makefiles don't 100254885Sdumbbell# need any -I paths for this. Similar defaults for .PATH can't be 101254885Sdumbbell# set because there are no standard paths for non-headers. 102254885SdumbbellCFLAGS+= -I${.OBJDIR} -I${.OBJDIR}/@ 103254885Sdumbbell 104254885Sdumbbell# XXX this is now dubious. 105254885Sdumbbell.if defined(DESTDIR) 106254885SdumbbellCFLAGS+= -I${DESTDIR}/usr/include 107254885Sdumbbell.endif 108254885Sdumbbell 109254885SdumbbellEXPORT_SYMS?= _${KMOD} 110254885Sdumbbell 111254885Sdumbbell.if defined(VFS_LKM) 112254885SdumbbellCFLAGS+= -DVFS_LKM -DMODVNOPS=${KMOD}vnops 113254885SdumbbellSRCS+= vnode_if.h 114254885SdumbbellCLEANFILES+= vnode_if.h vnode_if.c 115254885Sdumbbell.endif 116254885Sdumbbell 117254885Sdumbbell.if defined(PSEUDO_LKM) 118254885SdumbbellCFLAGS+= -DPSEUDO_LKM 119254885Sdumbbell.endif 120254885Sdumbbell 121254885SdumbbellOBJS+= ${SRCS:N*.h:R:S/$/.o/g} 122254885Sdumbbell 123254885Sdumbbell.if !defined(PROG) 124254885SdumbbellPROG= ${KMOD}.o 125254885Sdumbbell.endif 126254885Sdumbbell 127254885Sdumbbell${PROG}: ${OBJS} ${DPADD} 128254885Sdumbbell ${LD} -r ${LDFLAGS} -o tmp.o ${OBJS} 129254885Sdumbbell.if defined(EXPORT_SYMS) 130254885Sdumbbell @rm -f symb.tmp 131254885Sdumbbell @for i in ${EXPORT_SYMS} ; do echo $$i >> symb.tmp ; done 132254885Sdumbbell symorder -c symb.tmp tmp.o 133254885Sdumbbell @rm -f symb.tmp 134254885Sdumbbell.endif 135254885Sdumbbell mv tmp.o ${.TARGET} 136254885Sdumbbell 137254885Sdumbbell.if !defined(NOMAN) 138254885Sdumbbell.include <bsd.man.mk> 139254885Sdumbbell.if !defined(_MANPAGES) || empty(_MANPAGES) 140254885SdumbbellMAN1= ${KMOD}.4 141254885Sdumbbell.endif 142254885Sdumbbell 143254885Sdumbbell.elif !target(maninstall) 144254885Sdumbbellmaninstall: _SUBDIR 145254885Sdumbbellall-man: 146254885Sdumbbell.endif 147254885Sdumbbell 148254885Sdumbbell_ILINKS=@ machine 149254885Sdumbbell 150254885Sdumbbell.MAIN: all 151254885Sdumbbellall: objwarn ${PROG} all-man _SUBDIR 152254885Sdumbbell 153254885Sdumbbellbeforedepend ${OBJS}: ${_ILINKS} 154254885Sdumbbell 155254885Sdumbbell# The search for the link targets works best if we are in a normal src 156254885Sdumbbell# tree, and not too deeply below src/lkm. If we are near "/", then 157254885Sdumbbell# we may find /sys - this is harmless. Other abnormal "sys" directories 158254885Sdumbbell# found in the search are likely to cause problems. If nothing is found, 159254885Sdumbbell# then the links default to /usr/include and /usr/include/machine. 160254885Sdumbbell${_ILINKS}: 161254885Sdumbbell @for up in ../.. ../../.. ; do \ 162254885Sdumbbell case ${.TARGET} in \ 163254885Sdumbbell machine) \ 164254885Sdumbbell path=${.CURDIR}/$$up/sys/${MACHINE_ARCH}/include ; \ 165254885Sdumbbell defaultpath=/usr/include/machine ;; \ 166254885Sdumbbell @) \ 167254885Sdumbbell path=${.CURDIR}/$$up/sys ; \ 168254885Sdumbbell defaultpath=/usr/include ;; \ 169254885Sdumbbell esac ; \ 170254885Sdumbbell if [ -d $$path ] ; then break ; fi ; \ 171254885Sdumbbell path=$$defaultpath ; \ 172254885Sdumbbell done ; \ 173254885Sdumbbell path=`(cd $$path && /bin/pwd)` ; \ 174254885Sdumbbell ${ECHO} ${.TARGET} "->" $$path ; \ 175254885Sdumbbell ln -s $$path ${.TARGET} 176254885Sdumbbell 177254885SdumbbellCLEANFILES+= ${KMOD} ${PROG} ${OBJS} ${_ILINKS} lkm_verify_tmp symb.tmp tmp.o 178254885Sdumbbell 179254885Sdumbbell.if !target(install) 180254885Sdumbbell.if !target(beforeinstall) 181254885Sdumbbellbeforeinstall: 182254885Sdumbbell.endif 183254885Sdumbbell.if !target(afterinstall) 184254885Sdumbbellafterinstall: 185254885Sdumbbell.endif 186254885Sdumbbell 187254885Sdumbbellrealinstall: _SUBDIR 188254885Sdumbbell ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 189254885Sdumbbell ${INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 190254885Sdumbbell.if defined(LINKS) && !empty(LINKS) 191254885Sdumbbell @set ${LINKS}; \ 192254885Sdumbbell while test $$# -ge 2; do \ 193254885Sdumbbell l=${DESTDIR}$$1; \ 194254885Sdumbbell shift; \ 195254885Sdumbbell t=${DESTDIR}$$1; \ 196254885Sdumbbell shift; \ 197254885Sdumbbell ${ECHO} $$t -\> $$l; \ 198254885Sdumbbell rm -f $$t; \ 199254885Sdumbbell ln ${LN_FLAGS} $$l $$t; \ 200254885Sdumbbell done; true 201254885Sdumbbell.endif 202254885Sdumbbell 203254885Sdumbbellinstall: afterinstall _SUBDIR 204254885Sdumbbell.if !defined(NOMAN) 205254885Sdumbbellafterinstall: realinstall maninstall 206254885Sdumbbell.else 207254885Sdumbbellafterinstall: realinstall 208254885Sdumbbell.endif 209254885Sdumbbellrealinstall: beforeinstall 210254885Sdumbbell.endif 211254885Sdumbbell 212254885SdumbbellDISTRIBUTION?= bin 213254885Sdumbbell.if !target(distribute) 214254885Sdumbbelldistribute: _SUBDIR 215254885Sdumbbell.for dist in ${DISTRIBUTION} 216254885Sdumbbell cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 217254885Sdumbbell.endfor 218254885Sdumbbell.endif 219254885Sdumbbell 220254885Sdumbbell.if !target(load) 221254885Sdumbbellload: ${PROG} 222254885Sdumbbell ${MODLOAD} -o ${KMOD} -e${KMOD} ${PROG} 223254885Sdumbbell.endif 224254885Sdumbbell 225254885Sdumbbell.if !target(unload) 226254885Sdumbbellunload: ${PROG} 227254885Sdumbbell ${MODUNLOAD} -n ${KMOD} 228254885Sdumbbell.endif 229254885Sdumbbell 230254885SdumbbellKERN= ${.CURDIR}/../../sys/kern 231254885Sdumbbell 232254885Sdumbbellvnode_if.h: ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 233254885Sdumbbell sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 234254885Sdumbbell 235254885Sdumbbell_sysregress: ${_INLINKS} ${PROG} 236254885Sdumbbell ld -A /sys/compile/LKM/kernel ${PROG} ${DEPLKMS} -o lkm_verify_tmp 237254885Sdumbbell rm lkm_verify_tmp 238254885Sdumbbell 239254885Sdumbbellregress: _sysregress 240254885Sdumbbell 241254885Sdumbbell.include <bsd.obj.mk> 242254885Sdumbbell.include <bsd.dep.mk> 243254885Sdumbbell 244254885Sdumbbell.if !exists(${DEPENDFILE}) 245254885Sdumbbell${OBJS}: ${SRCS:M*.h} 246254885Sdumbbell.endif 247254885Sdumbbell 248254885Sdumbbell.include <bsd.kern.mk> 249254885Sdumbbell