1639a2e50SGarrett Wollman# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 28fe644b2SMike Smith# $Id: bsd.kmod.mk,v 1.53 1998/10/02 04:51:10 msmith Exp $ 353996fadSWolfram Schneider# 453996fadSWolfram Schneider# The include file <bsd.kmod.mk> handles installing Loadable Kernel Modules. 553996fadSWolfram Schneider# 653996fadSWolfram Schneider# 753996fadSWolfram Schneider# +++ variables +++ 853996fadSWolfram Schneider# 953996fadSWolfram Schneider# CLEANFILES Additional files to remove for the clean and cleandir targets. 1053996fadSWolfram Schneider# 1153996fadSWolfram Schneider# DISTRIBUTION Name of distribution. [bin] 1253996fadSWolfram Schneider# 1353996fadSWolfram Schneider# EXPORT_SYMS ??? 1453996fadSWolfram Schneider# 1553996fadSWolfram Schneider# KERN Main Kernel source directory. [${.CURDIR}/../../sys/kern] 1653996fadSWolfram Schneider# 1753996fadSWolfram Schneider# KMOD The name of the loadable kernel module to build. 1853996fadSWolfram Schneider# 1953996fadSWolfram Schneider# KMODDIR Base path for loadable kernel modules 2053996fadSWolfram Schneider# (see lkm(4)). [/lkm] 2153996fadSWolfram Schneider# 2253996fadSWolfram Schneider# KMODOWN LKM owner. [${BINOWN}] 2353996fadSWolfram Schneider# 2453996fadSWolfram Schneider# KMODGRP LKM group. [${BINGRP}] 2553996fadSWolfram Schneider# 2653996fadSWolfram Schneider# KMODMODE LKM mode. [${BINMODE}] 2753996fadSWolfram Schneider# 2853996fadSWolfram Schneider# LINKS The list of LKM links; should be full pathnames, the 2953996fadSWolfram Schneider# linked-to file coming first, followed by the linked 3053996fadSWolfram Schneider# file. The files are hard-linked. For example, to link 3153996fadSWolfram Schneider# /lkm/master and /lkm/meister, use: 3253996fadSWolfram Schneider# 3353996fadSWolfram Schneider# LINKS= /lkm/master /lkm/meister 3453996fadSWolfram Schneider# 3553996fadSWolfram Schneider# LN_FLAGS Flags for ln(1) (see variable LINKS) 3653996fadSWolfram Schneider# 377bc830bbSWolfram Schneider# MODLOAD Command to load a kernel module [/sbin/modload] 387bc830bbSWolfram Schneider# 397bc830bbSWolfram Schneider# MODUNLOAD Command to unload a kernel module [/sbin/modunload] 407bc830bbSWolfram Schneider# 4153996fadSWolfram Schneider# NOMAN LKM does not have a manual page if set. 4253996fadSWolfram Schneider# 4353996fadSWolfram Schneider# PROG The name of the loadable kernel module to build. 447bc830bbSWolfram Schneider# If not supplied, ${KMOD}.o is used. 4553996fadSWolfram Schneider# 4653996fadSWolfram Schneider# PSEUDO_LKM ??? 4753996fadSWolfram Schneider# 4853996fadSWolfram Schneider# SRCS List of source files 4953996fadSWolfram Schneider# 5090f60fc9SMike Smith# KMODDEPS List of modules which this one is dependant on 5190f60fc9SMike Smith# 5253996fadSWolfram Schneider# SUBDIR A list of subdirectories that should be built as well. 5353996fadSWolfram Schneider# Each of the targets will execute the same target in the 5453996fadSWolfram Schneider# subdirectories. 5553996fadSWolfram Schneider# 5653996fadSWolfram Schneider# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk) 5753996fadSWolfram Schneider# 5853996fadSWolfram Schneider# 5953996fadSWolfram Schneider# +++ targets +++ 6053996fadSWolfram Schneider# 6153996fadSWolfram Schneider# distribute: 6253996fadSWolfram Schneider# This is a variant of install, which will 6353996fadSWolfram Schneider# put the stuff into the right "distribution". 6453996fadSWolfram Schneider# 6553996fadSWolfram Schneider# install: 6653996fadSWolfram Schneider# install the program and its manual pages; if the Makefile 6753996fadSWolfram Schneider# does not itself define the target install, the targets 6853996fadSWolfram Schneider# beforeinstall and afterinstall may also be used to cause 6953996fadSWolfram Schneider# actions immediately before and after the install target 7053996fadSWolfram Schneider# is executed. 7153996fadSWolfram Schneider# 7253996fadSWolfram Schneider# load: 7353996fadSWolfram Schneider# Load LKM. 7453996fadSWolfram Schneider# 7553996fadSWolfram Schneider# unload: 7653996fadSWolfram Schneider# Unload LKM. 7753996fadSWolfram Schneider# 7853996fadSWolfram Schneider# bsd.obj.mk: clean, cleandir and obj 79161e8999SBruce Evans# bsd.dep.mk: cleandepend, depend and tags 8053996fadSWolfram Schneider# bsd.man.mk: maninstall 8153996fadSWolfram Schneider# 82639a2e50SGarrett Wollman 837bc830bbSWolfram SchneiderMODLOAD?= /sbin/modload 847bc830bbSWolfram SchneiderMODUNLOAD?= /sbin/modunload 857bc830bbSWolfram Schneider 86e0301e5dSPeter Wemm.if !target(__initialized__) 87e0301e5dSPeter Wemm__initialized__: 88639a2e50SGarrett Wollman.if exists(${.CURDIR}/../Makefile.inc) 89639a2e50SGarrett Wollman.include "${.CURDIR}/../Makefile.inc" 90639a2e50SGarrett Wollman.endif 91e0301e5dSPeter Wemm.endif 92639a2e50SGarrett Wollman 93639a2e50SGarrett Wollman.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 94639a2e50SGarrett Wollman 954a2d2630SBruce EvansCFLAGS+= ${COPTS} -DKERNEL -DACTUALLY_LKM_NOT_KERNEL ${CWARNFLAGS} 968fe644b2SMike Smith.if defined(KLDMOD) 978fe644b2SMike SmithCFLAGS+= -DKLD_MODULE 988fe644b2SMike Smith.endif 994a2d2630SBruce Evans 100021886ffSBruce Evans# Don't use any standard or source-relative include directories. 101021886ffSBruce Evans# Since -nostdinc will annull any previous -I paths, we repeat all 102021886ffSBruce Evans# such paths after -nostdinc. It doesn't seem to be possible to 103021886ffSBruce Evans# add to the front of `make' variable. 104021886ffSBruce Evans_ICFLAGS:= ${CFLAGS:M-I*} 105021886ffSBruce EvansCFLAGS+= -nostdinc -I- ${_ICFLAGS} 106021886ffSBruce Evans 107021886ffSBruce Evans# Add -I paths for system headers. Individual LKM makefiles don't 108021886ffSBruce Evans# need any -I paths for this. Similar defaults for .PATH can't be 109021886ffSBruce Evans# set because there are no standard paths for non-headers. 1104a2d2630SBruce EvansCFLAGS+= -I${.OBJDIR} -I${.OBJDIR}/@ 1114a2d2630SBruce Evans 112021886ffSBruce Evans# XXX this is now dubious. 113b3e17ba2SSatoshi Asami.if defined(DESTDIR) 114b3e17ba2SSatoshi AsamiCFLAGS+= -I${DESTDIR}/usr/include 115b3e17ba2SSatoshi Asami.endif 11656bac51bSPoul-Henning Kamp 1171d0de5e5SBruce Evans# XXX temporary until we build ELF kernels. 1181d0de5e5SBruce EvansCFLAGS+= -aout 1191d0de5e5SBruce EvansLDFLAGS+= -aout 1201d0de5e5SBruce Evans 121e0e2794cSBruce Evans.if defined(NOSHARED) && ( ${NOSHARED} != "no" && ${NOSHARED} != "NO" ) 122e0e2794cSBruce EvansLDFLAGS+= -static 123e0e2794cSBruce Evans.endif 124e0e2794cSBruce Evans 125e9dcb6beSPoul-Henning KampEXPORT_SYMS?= _${KMOD} 126e9dcb6beSPoul-Henning Kamp 1271aa57be3SGarrett Wollman.if defined(VFS_LKM) 1284a2d2630SBruce EvansCFLAGS+= -DVFS_LKM -DMODVNOPS=${KMOD}vnops 1291aa57be3SGarrett WollmanSRCS+= vnode_if.h 1301aa57be3SGarrett WollmanCLEANFILES+= vnode_if.h vnode_if.c 1311aa57be3SGarrett Wollman.endif 1321aa57be3SGarrett Wollman 13327a15c94SGarrett Wollman.if defined(PSEUDO_LKM) 13427a15c94SGarrett WollmanCFLAGS+= -DPSEUDO_LKM 13527a15c94SGarrett Wollman.endif 13627a15c94SGarrett Wollman 137639a2e50SGarrett WollmanOBJS+= ${SRCS:N*.h:R:S/$/.o/g} 138639a2e50SGarrett Wollman 139639a2e50SGarrett Wollman.if !defined(PROG) 14090f60fc9SMike Smith.if defined(KLDMOD) 14190f60fc9SMike SmithPROG= ${KMOD}.ko 14290f60fc9SMike Smith.else 143639a2e50SGarrett WollmanPROG= ${KMOD}.o 144639a2e50SGarrett Wollman.endif 14590f60fc9SMike Smith.endif 146639a2e50SGarrett Wollman 14747da63c3SBruce Evans${PROG}: ${OBJS} ${DPADD} 14890f60fc9SMike Smith.if defined(KLDMOD) 14990f60fc9SMike Smith ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${OBJS} ${KMODDEPS} 15090f60fc9SMike Smith.else 151e0e2794cSBruce Evans ${LD} -r ${LDFLAGS:N-static} -o tmp.o ${OBJS} 152a304bf73SPoul-Henning Kamp.if defined(EXPORT_SYMS) 153e0e2794cSBruce Evans rm -f symb.tmp 154e0e2794cSBruce Evans for i in ${EXPORT_SYMS} ; do echo $$i >> symb.tmp ; done 155a304bf73SPoul-Henning Kamp symorder -c symb.tmp tmp.o 156e0e2794cSBruce Evans rm -f symb.tmp 157a304bf73SPoul-Henning Kamp.endif 158a304bf73SPoul-Henning Kamp mv tmp.o ${.TARGET} 15990f60fc9SMike Smith.endif 160639a2e50SGarrett Wollman 1615ce6c3cfSWolfram Schneider.if !defined(NOMAN) 1625ce6c3cfSWolfram Schneider.include <bsd.man.mk> 1635ce6c3cfSWolfram Schneider.if !defined(_MANPAGES) || empty(_MANPAGES) 164639a2e50SGarrett WollmanMAN1= ${KMOD}.4 165639a2e50SGarrett Wollman.endif 166639a2e50SGarrett Wollman 1675ce6c3cfSWolfram Schneider.elif !target(maninstall) 168cd9a2f5cSJordan K. Hubbardmaninstall: _SUBDIR 1695ce6c3cfSWolfram Schneiderall-man: 1705ce6c3cfSWolfram Schneider.endif 1715ce6c3cfSWolfram Schneider 1724a2d2630SBruce Evans_ILINKS=@ machine 173639a2e50SGarrett Wollman 1744a2d2630SBruce Evans.MAIN: all 17547da63c3SBruce Evansall: objwarn ${PROG} all-man _SUBDIR 1764a2d2630SBruce Evans 17747da63c3SBruce Evansbeforedepend ${OBJS}: ${_ILINKS} 1784a2d2630SBruce Evans 1794a2d2630SBruce Evans# The search for the link targets works best if we are in a normal src 1804a2d2630SBruce Evans# tree, and not too deeply below src/lkm. If we are near "/", then 1814a2d2630SBruce Evans# we may find /sys - this is harmless. Other abnormal "sys" directories 1824a2d2630SBruce Evans# found in the search are likely to cause problems. If nothing is found, 1834a2d2630SBruce Evans# then the links default to /usr/include and /usr/include/machine. 1844a2d2630SBruce Evans${_ILINKS}: 1854a2d2630SBruce Evans @for up in ../.. ../../.. ; do \ 1864a2d2630SBruce Evans case ${.TARGET} in \ 1874a2d2630SBruce Evans machine) \ 1884a2d2630SBruce Evans path=${.CURDIR}/$$up/sys/${MACHINE_ARCH}/include ; \ 1894a2d2630SBruce Evans defaultpath=/usr/include/machine ;; \ 1904a2d2630SBruce Evans @) \ 1914a2d2630SBruce Evans path=${.CURDIR}/$$up/sys ; \ 1924a2d2630SBruce Evans defaultpath=/usr/include ;; \ 1934a2d2630SBruce Evans esac ; \ 1944a2d2630SBruce Evans if [ -d $$path ] ; then break ; fi ; \ 1954a2d2630SBruce Evans path=$$defaultpath ; \ 1964a2d2630SBruce Evans done ; \ 1974a2d2630SBruce Evans path=`(cd $$path && /bin/pwd)` ; \ 1984a2d2630SBruce Evans ${ECHO} ${.TARGET} "->" $$path ; \ 1994a2d2630SBruce Evans ln -s $$path ${.TARGET} 2004a2d2630SBruce Evans 2015f1c0dcdSBruce EvansCLEANFILES+= ${KMOD} ${PROG} ${OBJS} ${_ILINKS} lkm_verify_tmp symb.tmp tmp.o 202639a2e50SGarrett Wollman 203639a2e50SGarrett Wollman.if !target(install) 204639a2e50SGarrett Wollman.if !target(beforeinstall) 205639a2e50SGarrett Wollmanbeforeinstall: 206639a2e50SGarrett Wollman.endif 207639a2e50SGarrett Wollman.if !target(afterinstall) 208639a2e50SGarrett Wollmanafterinstall: 209639a2e50SGarrett Wollman.endif 210639a2e50SGarrett Wollman 211cd9a2f5cSJordan K. Hubbardrealinstall: _SUBDIR 2125ce6c3cfSWolfram Schneider ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 2135ce6c3cfSWolfram Schneider ${INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 214639a2e50SGarrett Wollman.if defined(LINKS) && !empty(LINKS) 215639a2e50SGarrett Wollman @set ${LINKS}; \ 216639a2e50SGarrett Wollman while test $$# -ge 2; do \ 217639a2e50SGarrett Wollman l=${DESTDIR}$$1; \ 218639a2e50SGarrett Wollman shift; \ 219639a2e50SGarrett Wollman t=${DESTDIR}$$1; \ 220639a2e50SGarrett Wollman shift; \ 221639a2e50SGarrett Wollman ${ECHO} $$t -\> $$l; \ 222639a2e50SGarrett Wollman rm -f $$t; \ 22360983531SJordan K. Hubbard ln ${LN_FLAGS} $$l $$t; \ 224639a2e50SGarrett Wollman done; true 225639a2e50SGarrett Wollman.endif 226639a2e50SGarrett Wollman 227cd9a2f5cSJordan K. Hubbardinstall: afterinstall _SUBDIR 228639a2e50SGarrett Wollman.if !defined(NOMAN) 229639a2e50SGarrett Wollmanafterinstall: realinstall maninstall 230639a2e50SGarrett Wollman.else 231639a2e50SGarrett Wollmanafterinstall: realinstall 232639a2e50SGarrett Wollman.endif 233639a2e50SGarrett Wollmanrealinstall: beforeinstall 234639a2e50SGarrett Wollman.endif 235639a2e50SGarrett Wollman 236d9584d76SJordan K. HubbardDISTRIBUTION?= bin 23755ff8fb1SPoul-Henning Kamp.if !target(distribute) 238cd9a2f5cSJordan K. Hubbarddistribute: _SUBDIR 239398ac038SJordan K. Hubbard.for dist in ${DISTRIBUTION} 240398ac038SJordan K. Hubbard cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 241398ac038SJordan K. Hubbard.endfor 24255ff8fb1SPoul-Henning Kamp.endif 24355ff8fb1SPoul-Henning Kamp 244639a2e50SGarrett Wollman.if !target(load) 245639a2e50SGarrett Wollmanload: ${PROG} 2467bc830bbSWolfram Schneider ${MODLOAD} -o ${KMOD} -e${KMOD} ${PROG} 247639a2e50SGarrett Wollman.endif 248639a2e50SGarrett Wollman 249639a2e50SGarrett Wollman.if !target(unload) 250639a2e50SGarrett Wollmanunload: ${PROG} 2517bc830bbSWolfram Schneider ${MODUNLOAD} -n ${KMOD} 252639a2e50SGarrett Wollman.endif 253639a2e50SGarrett Wollman 2541aa57be3SGarrett WollmanKERN= ${.CURDIR}/../../sys/kern 2551aa57be3SGarrett Wollman 2561aa57be3SGarrett Wollmanvnode_if.h: ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 2571aa57be3SGarrett Wollman sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 2581aa57be3SGarrett Wollman 25969b87d3eSEivind Eklund_sysregress: ${_INLINKS} ${PROG} 26069b87d3eSEivind Eklund ld -A /sys/compile/LKM/kernel ${PROG} ${DEPLKMS} -o lkm_verify_tmp 26169b87d3eSEivind Eklund rm lkm_verify_tmp 26269b87d3eSEivind Eklund 26369b87d3eSEivind Eklundregress: _sysregress 26469b87d3eSEivind Eklund 26568e00b92SJordan K. Hubbard.include <bsd.dep.mk> 26647da63c3SBruce Evans 26747da63c3SBruce Evans.if !exists(${DEPENDFILE}) 268589d9341SBruce Evans${OBJS}: ${SRCS:M*.h} 26947da63c3SBruce Evans.endif 27047da63c3SBruce Evans 271afba897fSBruce Evans.include <bsd.obj.mk> 272afba897fSBruce Evans 2739e72552fSBruce Evans.include <bsd.kern.mk> 274