1639a2e50SGarrett Wollman# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 208a04a89SPeter Wemm# $Id: bsd.kmod.mk,v 1.55 1998/10/14 04:04:22 peter 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 95fdbdd3a0SPeter WemmCFLAGS+= ${COPTS} -DKERNEL ${CWARNFLAGS} 968fe644b2SMike Smith.if defined(KLDMOD) 978fe644b2SMike SmithCFLAGS+= -DKLD_MODULE 98fdbdd3a0SPeter Wemm.else 99fdbdd3a0SPeter WemmCFLAGS+= -DACTUALLY_LKM_NOT_KERNEL 100fdbdd3a0SPeter Wemm.endif 101fdbdd3a0SPeter Wemm 102fdbdd3a0SPeter Wemm# Damn bsd.own.mk is included too early. 103fdbdd3a0SPeter Wemm.if defined(KLDMOD) 104fdbdd3a0SPeter Wemm.if ${KMODDIR} == /lkm 105fdbdd3a0SPeter WemmKMODDIR= /modules 106fdbdd3a0SPeter Wemm.endif 1078fe644b2SMike Smith.endif 1084a2d2630SBruce Evans 109021886ffSBruce Evans# Don't use any standard or source-relative include directories. 110021886ffSBruce Evans# Since -nostdinc will annull any previous -I paths, we repeat all 111021886ffSBruce Evans# such paths after -nostdinc. It doesn't seem to be possible to 112021886ffSBruce Evans# add to the front of `make' variable. 113021886ffSBruce Evans_ICFLAGS:= ${CFLAGS:M-I*} 114021886ffSBruce EvansCFLAGS+= -nostdinc -I- ${_ICFLAGS} 115021886ffSBruce Evans 116021886ffSBruce Evans# Add -I paths for system headers. Individual LKM makefiles don't 117021886ffSBruce Evans# need any -I paths for this. Similar defaults for .PATH can't be 118021886ffSBruce Evans# set because there are no standard paths for non-headers. 1194a2d2630SBruce EvansCFLAGS+= -I${.OBJDIR} -I${.OBJDIR}/@ 1204a2d2630SBruce Evans 121021886ffSBruce Evans# XXX this is now dubious. 122b3e17ba2SSatoshi Asami.if defined(DESTDIR) 123b3e17ba2SSatoshi AsamiCFLAGS+= -I${DESTDIR}/usr/include 124b3e17ba2SSatoshi Asami.endif 12556bac51bSPoul-Henning Kamp 126fdbdd3a0SPeter Wemm.if !defined(KLDMOD) 1271d0de5e5SBruce Evans# XXX temporary until we build ELF kernels. 1281d0de5e5SBruce EvansCFLAGS+= -aout 1291d0de5e5SBruce EvansLDFLAGS+= -aout 130fdbdd3a0SPeter Wemm.endif 1311d0de5e5SBruce Evans 132e0e2794cSBruce Evans.if defined(NOSHARED) && ( ${NOSHARED} != "no" && ${NOSHARED} != "NO" ) 133e0e2794cSBruce EvansLDFLAGS+= -static 134e0e2794cSBruce Evans.endif 135e0e2794cSBruce Evans 136e9dcb6beSPoul-Henning KampEXPORT_SYMS?= _${KMOD} 137e9dcb6beSPoul-Henning Kamp 1381aa57be3SGarrett Wollman.if defined(VFS_LKM) 1394a2d2630SBruce EvansCFLAGS+= -DVFS_LKM -DMODVNOPS=${KMOD}vnops 1401aa57be3SGarrett WollmanSRCS+= vnode_if.h 1411aa57be3SGarrett WollmanCLEANFILES+= vnode_if.h vnode_if.c 1421aa57be3SGarrett Wollman.endif 1431aa57be3SGarrett Wollman 14408a04a89SPeter Wemm.if defined(VFS_KLD) 14508a04a89SPeter WemmCFLAGS+= -DVFS_LKM -DVFS_KLD 14608a04a89SPeter WemmSRCS+= vnode_if.h 14708a04a89SPeter WemmCLEANFILES+= vnode_if.h vnode_if.c 14808a04a89SPeter Wemm.endif 14908a04a89SPeter Wemm 150fdbdd3a0SPeter Wemm.if defined(KLDMOD) && ${OBJFORMAT} == elf 151fdbdd3a0SPeter WemmCLEANFILES+= setdef0.c setdef1.c setdefs.h 152fdbdd3a0SPeter WemmCLEANFILES+= setdef0.o setdef1.o 153fdbdd3a0SPeter Wemm.endif 154fdbdd3a0SPeter Wemm 15527a15c94SGarrett Wollman.if defined(PSEUDO_LKM) 15627a15c94SGarrett WollmanCFLAGS+= -DPSEUDO_LKM 15727a15c94SGarrett Wollman.endif 15827a15c94SGarrett Wollman 159639a2e50SGarrett WollmanOBJS+= ${SRCS:N*.h:R:S/$/.o/g} 160639a2e50SGarrett Wollman 161639a2e50SGarrett Wollman.if !defined(PROG) 16290f60fc9SMike Smith.if defined(KLDMOD) 16390f60fc9SMike SmithPROG= ${KMOD}.ko 16490f60fc9SMike Smith.else 165639a2e50SGarrett WollmanPROG= ${KMOD}.o 166639a2e50SGarrett Wollman.endif 16790f60fc9SMike Smith.endif 168639a2e50SGarrett Wollman 169fdbdd3a0SPeter Wemm${PROG}: ${OBJS} ${DPADD} ${KMODDEPS} 17090f60fc9SMike Smith.if defined(KLDMOD) 171fdbdd3a0SPeter Wemm.if ${OBJFORMAT} == elf 172fdbdd3a0SPeter Wemm gensetdefs ${OBJS} 173fdbdd3a0SPeter Wemm ${CC} ${CFLAGS} -c setdef0.c 174fdbdd3a0SPeter Wemm ${CC} ${CFLAGS} -c setdef1.c 175fdbdd3a0SPeter Wemm ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} setdef0.o ${OBJS} setdef1.o ${KMODDEPS} 176fdbdd3a0SPeter Wemm.else 17790f60fc9SMike Smith ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${OBJS} ${KMODDEPS} 178fdbdd3a0SPeter Wemm.endif 17990f60fc9SMike Smith.else 180e0e2794cSBruce Evans ${LD} -r ${LDFLAGS:N-static} -o tmp.o ${OBJS} 181a304bf73SPoul-Henning Kamp.if defined(EXPORT_SYMS) 182e0e2794cSBruce Evans rm -f symb.tmp 183e0e2794cSBruce Evans for i in ${EXPORT_SYMS} ; do echo $$i >> symb.tmp ; done 184a304bf73SPoul-Henning Kamp symorder -c symb.tmp tmp.o 185e0e2794cSBruce Evans rm -f symb.tmp 186a304bf73SPoul-Henning Kamp.endif 187a304bf73SPoul-Henning Kamp mv tmp.o ${.TARGET} 18890f60fc9SMike Smith.endif 189639a2e50SGarrett Wollman 190fdbdd3a0SPeter Wemm.if defined(KMODDEPS) 191fdbdd3a0SPeter Wemm.for dep in ${KMODDEPS} 192fdbdd3a0SPeter WemmCLEANFILES+= ${dep} ${dep}.c 193fdbdd3a0SPeter Wemm 194fdbdd3a0SPeter Wemm${dep}: 195fdbdd3a0SPeter Wemm touch ${dep}.c 196fdbdd3a0SPeter Wemm ${CC} -shared ${CFLAGS} -o ${dep} ${dep}.c 197fdbdd3a0SPeter Wemm.endfor 198fdbdd3a0SPeter Wemm.endif 199fdbdd3a0SPeter Wemm 2005ce6c3cfSWolfram Schneider.if !defined(NOMAN) 2015ce6c3cfSWolfram Schneider.include <bsd.man.mk> 2025ce6c3cfSWolfram Schneider.if !defined(_MANPAGES) || empty(_MANPAGES) 203639a2e50SGarrett WollmanMAN1= ${KMOD}.4 204639a2e50SGarrett Wollman.endif 205639a2e50SGarrett Wollman 2065ce6c3cfSWolfram Schneider.elif !target(maninstall) 207cd9a2f5cSJordan K. Hubbardmaninstall: _SUBDIR 2085ce6c3cfSWolfram Schneiderall-man: 2095ce6c3cfSWolfram Schneider.endif 2105ce6c3cfSWolfram Schneider 2114a2d2630SBruce Evans_ILINKS=@ machine 212639a2e50SGarrett Wollman 2134a2d2630SBruce Evans.MAIN: all 21447da63c3SBruce Evansall: objwarn ${PROG} all-man _SUBDIR 2154a2d2630SBruce Evans 21647da63c3SBruce Evansbeforedepend ${OBJS}: ${_ILINKS} 2174a2d2630SBruce Evans 21808a04a89SPeter Wemm.if !defined(KLDMOD) 2194a2d2630SBruce Evans# The search for the link targets works best if we are in a normal src 2204a2d2630SBruce Evans# tree, and not too deeply below src/lkm. If we are near "/", then 2214a2d2630SBruce Evans# we may find /sys - this is harmless. Other abnormal "sys" directories 2224a2d2630SBruce Evans# found in the search are likely to cause problems. If nothing is found, 2234a2d2630SBruce Evans# then the links default to /usr/include and /usr/include/machine. 2244a2d2630SBruce Evans${_ILINKS}: 2254a2d2630SBruce Evans @for up in ../.. ../../.. ; do \ 2264a2d2630SBruce Evans case ${.TARGET} in \ 2274a2d2630SBruce Evans machine) \ 2284a2d2630SBruce Evans path=${.CURDIR}/$$up/sys/${MACHINE_ARCH}/include ; \ 2294a2d2630SBruce Evans defaultpath=/usr/include/machine ;; \ 2304a2d2630SBruce Evans @) \ 2314a2d2630SBruce Evans path=${.CURDIR}/$$up/sys ; \ 2324a2d2630SBruce Evans defaultpath=/usr/include ;; \ 2334a2d2630SBruce Evans esac ; \ 2344a2d2630SBruce Evans if [ -d $$path ] ; then break ; fi ; \ 2354a2d2630SBruce Evans path=$$defaultpath ; \ 2364a2d2630SBruce Evans done ; \ 2374a2d2630SBruce Evans path=`(cd $$path && /bin/pwd)` ; \ 2384a2d2630SBruce Evans ${ECHO} ${.TARGET} "->" $$path ; \ 2394a2d2630SBruce Evans ln -s $$path ${.TARGET} 24008a04a89SPeter Wemm.else 24108a04a89SPeter Wemm${_ILINKS}: 24208a04a89SPeter Wemm @set +x; for up in ../.. ../../.. ; do \ 24308a04a89SPeter Wemm case ${.TARGET} in \ 24408a04a89SPeter Wemm machine) \ 24508a04a89SPeter Wemm testpath=${.CURDIR}/$$up/${MACHINE_ARCH}/include ; \ 24608a04a89SPeter Wemm path=${.CURDIR}/$$up/${MACHINE_ARCH}/include ; \ 24708a04a89SPeter Wemm defaultpath=/usr/include/machine ;; \ 24808a04a89SPeter Wemm @) \ 24908a04a89SPeter Wemm testpath=${.CURDIR}/$$up/sys ; \ 25008a04a89SPeter Wemm path=${.CURDIR}/$$up ; \ 25108a04a89SPeter Wemm defaultpath=/usr/include ;; \ 25208a04a89SPeter Wemm esac ; \ 25308a04a89SPeter Wemm if [ -d $$testpath ] ; then break ; fi ; \ 25408a04a89SPeter Wemm path=$$defaultpath ; \ 25508a04a89SPeter Wemm done ; \ 25608a04a89SPeter Wemm path=`(cd $$path && /bin/pwd)` ; \ 25708a04a89SPeter Wemm ${ECHO} ${.TARGET} "->" $$path ; \ 25808a04a89SPeter Wemm ln -s $$path ${.TARGET} 25908a04a89SPeter Wemm.endif 2604a2d2630SBruce Evans 2615f1c0dcdSBruce EvansCLEANFILES+= ${KMOD} ${PROG} ${OBJS} ${_ILINKS} lkm_verify_tmp symb.tmp tmp.o 262639a2e50SGarrett Wollman 263639a2e50SGarrett Wollman.if !target(install) 264639a2e50SGarrett Wollman.if !target(beforeinstall) 265639a2e50SGarrett Wollmanbeforeinstall: 266639a2e50SGarrett Wollman.endif 267639a2e50SGarrett Wollman.if !target(afterinstall) 268639a2e50SGarrett Wollmanafterinstall: 269639a2e50SGarrett Wollman.endif 270639a2e50SGarrett Wollman 271cd9a2f5cSJordan K. Hubbardrealinstall: _SUBDIR 2725ce6c3cfSWolfram Schneider ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 2735ce6c3cfSWolfram Schneider ${INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 274639a2e50SGarrett Wollman.if defined(LINKS) && !empty(LINKS) 275639a2e50SGarrett Wollman @set ${LINKS}; \ 276639a2e50SGarrett Wollman while test $$# -ge 2; do \ 277639a2e50SGarrett Wollman l=${DESTDIR}$$1; \ 278639a2e50SGarrett Wollman shift; \ 279639a2e50SGarrett Wollman t=${DESTDIR}$$1; \ 280639a2e50SGarrett Wollman shift; \ 281639a2e50SGarrett Wollman ${ECHO} $$t -\> $$l; \ 282639a2e50SGarrett Wollman rm -f $$t; \ 28360983531SJordan K. Hubbard ln ${LN_FLAGS} $$l $$t; \ 284639a2e50SGarrett Wollman done; true 285639a2e50SGarrett Wollman.endif 286639a2e50SGarrett Wollman 287cd9a2f5cSJordan K. Hubbardinstall: afterinstall _SUBDIR 288639a2e50SGarrett Wollman.if !defined(NOMAN) 289639a2e50SGarrett Wollmanafterinstall: realinstall maninstall 290639a2e50SGarrett Wollman.else 291639a2e50SGarrett Wollmanafterinstall: realinstall 292639a2e50SGarrett Wollman.endif 293639a2e50SGarrett Wollmanrealinstall: beforeinstall 294639a2e50SGarrett Wollman.endif 295639a2e50SGarrett Wollman 296d9584d76SJordan K. HubbardDISTRIBUTION?= bin 29755ff8fb1SPoul-Henning Kamp.if !target(distribute) 298cd9a2f5cSJordan K. Hubbarddistribute: _SUBDIR 299398ac038SJordan K. Hubbard.for dist in ${DISTRIBUTION} 300398ac038SJordan K. Hubbard cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 301398ac038SJordan K. Hubbard.endfor 30255ff8fb1SPoul-Henning Kamp.endif 30355ff8fb1SPoul-Henning Kamp 304639a2e50SGarrett Wollman.if !target(load) 305639a2e50SGarrett Wollmanload: ${PROG} 3067bc830bbSWolfram Schneider ${MODLOAD} -o ${KMOD} -e${KMOD} ${PROG} 307639a2e50SGarrett Wollman.endif 308639a2e50SGarrett Wollman 309639a2e50SGarrett Wollman.if !target(unload) 310639a2e50SGarrett Wollmanunload: ${PROG} 3117bc830bbSWolfram Schneider ${MODUNLOAD} -n ${KMOD} 312639a2e50SGarrett Wollman.endif 313639a2e50SGarrett Wollman 31408a04a89SPeter Wemm.if exists(${.CURDIR}/../../kern) 31508a04a89SPeter WemmKERN= ${.CURDIR}/../../kern 31608a04a89SPeter Wemm.else 3171aa57be3SGarrett WollmanKERN= ${.CURDIR}/../../sys/kern 31808a04a89SPeter Wemm.endif 3191aa57be3SGarrett Wollman 3201aa57be3SGarrett Wollmanvnode_if.h: ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 3211aa57be3SGarrett Wollman sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 3221aa57be3SGarrett Wollman 32369b87d3eSEivind Eklund_sysregress: ${_INLINKS} ${PROG} 32469b87d3eSEivind Eklund ld -A /sys/compile/LKM/kernel ${PROG} ${DEPLKMS} -o lkm_verify_tmp 32569b87d3eSEivind Eklund rm lkm_verify_tmp 32669b87d3eSEivind Eklund 32769b87d3eSEivind Eklundregress: _sysregress 32869b87d3eSEivind Eklund 32968e00b92SJordan K. Hubbard.include <bsd.dep.mk> 33047da63c3SBruce Evans 33147da63c3SBruce Evans.if !exists(${DEPENDFILE}) 332589d9341SBruce Evans${OBJS}: ${SRCS:M*.h} 33347da63c3SBruce Evans.endif 33447da63c3SBruce Evans 335afba897fSBruce Evans.include <bsd.obj.mk> 336afba897fSBruce Evans 3379e72552fSBruce Evans.include <bsd.kern.mk> 338