kmod.mk revision 39883
1# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2# $Id: bsd.kmod.mk,v 1.53 1998/10/02 04:51:10 msmith Exp $ 3# 4# The include file <bsd.kmod.mk> handles installing Loadable Kernel Modules. 5# 6# 7# +++ variables +++ 8# 9# CLEANFILES Additional files to remove for the clean and cleandir targets. 10# 11# DISTRIBUTION Name of distribution. [bin] 12# 13# EXPORT_SYMS ??? 14# 15# KERN Main Kernel source directory. [${.CURDIR}/../../sys/kern] 16# 17# KMOD The name of the loadable kernel module to build. 18# 19# KMODDIR Base path for loadable kernel modules 20# (see lkm(4)). [/lkm] 21# 22# KMODOWN LKM owner. [${BINOWN}] 23# 24# KMODGRP LKM group. [${BINGRP}] 25# 26# KMODMODE LKM mode. [${BINMODE}] 27# 28# LINKS The list of LKM links; should be full pathnames, the 29# linked-to file coming first, followed by the linked 30# file. The files are hard-linked. For example, to link 31# /lkm/master and /lkm/meister, use: 32# 33# LINKS= /lkm/master /lkm/meister 34# 35# LN_FLAGS Flags for ln(1) (see variable LINKS) 36# 37# MODLOAD Command to load a kernel module [/sbin/modload] 38# 39# MODUNLOAD Command to unload a kernel module [/sbin/modunload] 40# 41# NOMAN LKM does not have a manual page if set. 42# 43# PROG The name of the loadable kernel module to build. 44# If not supplied, ${KMOD}.o is used. 45# 46# PSEUDO_LKM ??? 47# 48# SRCS List of source files 49# 50# KMODDEPS List of modules which this one is dependant on 51# 52# SUBDIR A list of subdirectories that should be built as well. 53# Each of the targets will execute the same target in the 54# subdirectories. 55# 56# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk) 57# 58# 59# +++ targets +++ 60# 61# distribute: 62# This is a variant of install, which will 63# put the stuff into the right "distribution". 64# 65# install: 66# install the program and its manual pages; if the Makefile 67# does not itself define the target install, the targets 68# beforeinstall and afterinstall may also be used to cause 69# actions immediately before and after the install target 70# is executed. 71# 72# load: 73# Load LKM. 74# 75# unload: 76# Unload LKM. 77# 78# bsd.obj.mk: clean, cleandir and obj 79# bsd.dep.mk: cleandepend, depend and tags 80# bsd.man.mk: maninstall 81# 82 83MODLOAD?= /sbin/modload 84MODUNLOAD?= /sbin/modunload 85 86.if !target(__initialized__) 87__initialized__: 88.if exists(${.CURDIR}/../Makefile.inc) 89.include "${.CURDIR}/../Makefile.inc" 90.endif 91.endif 92 93.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 94 95CFLAGS+= ${COPTS} -DKERNEL -DACTUALLY_LKM_NOT_KERNEL ${CWARNFLAGS} 96.if defined(KLDMOD) 97CFLAGS+= -DKLD_MODULE 98.endif 99 100# Don't use any standard or source-relative include directories. 101# Since -nostdinc will annull any previous -I paths, we repeat all 102# such paths after -nostdinc. It doesn't seem to be possible to 103# add to the front of `make' variable. 104_ICFLAGS:= ${CFLAGS:M-I*} 105CFLAGS+= -nostdinc -I- ${_ICFLAGS} 106 107# Add -I paths for system headers. Individual LKM makefiles don't 108# need any -I paths for this. Similar defaults for .PATH can't be 109# set because there are no standard paths for non-headers. 110CFLAGS+= -I${.OBJDIR} -I${.OBJDIR}/@ 111 112# XXX this is now dubious. 113.if defined(DESTDIR) 114CFLAGS+= -I${DESTDIR}/usr/include 115.endif 116 117# XXX temporary until we build ELF kernels. 118CFLAGS+= -aout 119LDFLAGS+= -aout 120 121.if defined(NOSHARED) && ( ${NOSHARED} != "no" && ${NOSHARED} != "NO" ) 122LDFLAGS+= -static 123.endif 124 125EXPORT_SYMS?= _${KMOD} 126 127.if defined(VFS_LKM) 128CFLAGS+= -DVFS_LKM -DMODVNOPS=${KMOD}vnops 129SRCS+= vnode_if.h 130CLEANFILES+= vnode_if.h vnode_if.c 131.endif 132 133.if defined(PSEUDO_LKM) 134CFLAGS+= -DPSEUDO_LKM 135.endif 136 137OBJS+= ${SRCS:N*.h:R:S/$/.o/g} 138 139.if !defined(PROG) 140.if defined(KLDMOD) 141PROG= ${KMOD}.ko 142.else 143PROG= ${KMOD}.o 144.endif 145.endif 146 147${PROG}: ${OBJS} ${DPADD} 148.if defined(KLDMOD) 149 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${OBJS} ${KMODDEPS} 150.else 151 ${LD} -r ${LDFLAGS:N-static} -o tmp.o ${OBJS} 152.if defined(EXPORT_SYMS) 153 rm -f symb.tmp 154 for i in ${EXPORT_SYMS} ; do echo $$i >> symb.tmp ; done 155 symorder -c symb.tmp tmp.o 156 rm -f symb.tmp 157.endif 158 mv tmp.o ${.TARGET} 159.endif 160 161.if !defined(NOMAN) 162.include <bsd.man.mk> 163.if !defined(_MANPAGES) || empty(_MANPAGES) 164MAN1= ${KMOD}.4 165.endif 166 167.elif !target(maninstall) 168maninstall: _SUBDIR 169all-man: 170.endif 171 172_ILINKS=@ machine 173 174.MAIN: all 175all: objwarn ${PROG} all-man _SUBDIR 176 177beforedepend ${OBJS}: ${_ILINKS} 178 179# The search for the link targets works best if we are in a normal src 180# tree, and not too deeply below src/lkm. If we are near "/", then 181# we may find /sys - this is harmless. Other abnormal "sys" directories 182# found in the search are likely to cause problems. If nothing is found, 183# then the links default to /usr/include and /usr/include/machine. 184${_ILINKS}: 185 @for up in ../.. ../../.. ; do \ 186 case ${.TARGET} in \ 187 machine) \ 188 path=${.CURDIR}/$$up/sys/${MACHINE_ARCH}/include ; \ 189 defaultpath=/usr/include/machine ;; \ 190 @) \ 191 path=${.CURDIR}/$$up/sys ; \ 192 defaultpath=/usr/include ;; \ 193 esac ; \ 194 if [ -d $$path ] ; then break ; fi ; \ 195 path=$$defaultpath ; \ 196 done ; \ 197 path=`(cd $$path && /bin/pwd)` ; \ 198 ${ECHO} ${.TARGET} "->" $$path ; \ 199 ln -s $$path ${.TARGET} 200 201CLEANFILES+= ${KMOD} ${PROG} ${OBJS} ${_ILINKS} lkm_verify_tmp symb.tmp tmp.o 202 203.if !target(install) 204.if !target(beforeinstall) 205beforeinstall: 206.endif 207.if !target(afterinstall) 208afterinstall: 209.endif 210 211realinstall: _SUBDIR 212 ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 213 ${INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 214.if defined(LINKS) && !empty(LINKS) 215 @set ${LINKS}; \ 216 while test $$# -ge 2; do \ 217 l=${DESTDIR}$$1; \ 218 shift; \ 219 t=${DESTDIR}$$1; \ 220 shift; \ 221 ${ECHO} $$t -\> $$l; \ 222 rm -f $$t; \ 223 ln ${LN_FLAGS} $$l $$t; \ 224 done; true 225.endif 226 227install: afterinstall _SUBDIR 228.if !defined(NOMAN) 229afterinstall: realinstall maninstall 230.else 231afterinstall: realinstall 232.endif 233realinstall: beforeinstall 234.endif 235 236DISTRIBUTION?= bin 237.if !target(distribute) 238distribute: _SUBDIR 239.for dist in ${DISTRIBUTION} 240 cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 241.endfor 242.endif 243 244.if !target(load) 245load: ${PROG} 246 ${MODLOAD} -o ${KMOD} -e${KMOD} ${PROG} 247.endif 248 249.if !target(unload) 250unload: ${PROG} 251 ${MODUNLOAD} -n ${KMOD} 252.endif 253 254KERN= ${.CURDIR}/../../sys/kern 255 256vnode_if.h: ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 257 sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 258 259_sysregress: ${_INLINKS} ${PROG} 260 ld -A /sys/compile/LKM/kernel ${PROG} ${DEPLKMS} -o lkm_verify_tmp 261 rm lkm_verify_tmp 262 263regress: _sysregress 264 265.include <bsd.dep.mk> 266 267.if !exists(${DEPENDFILE}) 268${OBJS}: ${SRCS:M*.h} 269.endif 270 271.include <bsd.obj.mk> 272 273.include <bsd.kern.mk> 274