kmod.mk revision 40335
1# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2# $Id: bsd.kmod.mk,v 1.54 1998/10/02 05:08:09 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 ${CWARNFLAGS} 96.if defined(KLDMOD) 97CFLAGS+= -DKLD_MODULE 98.else 99CFLAGS+= -DACTUALLY_LKM_NOT_KERNEL 100.endif 101 102# Damn bsd.own.mk is included too early. 103.if defined(KLDMOD) 104.if ${KMODDIR} == /lkm 105KMODDIR= /modules 106.endif 107.endif 108 109# Don't use any standard or source-relative include directories. 110# Since -nostdinc will annull any previous -I paths, we repeat all 111# such paths after -nostdinc. It doesn't seem to be possible to 112# add to the front of `make' variable. 113_ICFLAGS:= ${CFLAGS:M-I*} 114CFLAGS+= -nostdinc -I- ${_ICFLAGS} 115 116# Add -I paths for system headers. Individual LKM makefiles don't 117# need any -I paths for this. Similar defaults for .PATH can't be 118# set because there are no standard paths for non-headers. 119CFLAGS+= -I${.OBJDIR} -I${.OBJDIR}/@ 120 121# XXX this is now dubious. 122.if defined(DESTDIR) 123CFLAGS+= -I${DESTDIR}/usr/include 124.endif 125 126.if !defined(KLDMOD) 127# XXX temporary until we build ELF kernels. 128CFLAGS+= -aout 129LDFLAGS+= -aout 130.endif 131 132.if defined(NOSHARED) && ( ${NOSHARED} != "no" && ${NOSHARED} != "NO" ) 133LDFLAGS+= -static 134.endif 135 136EXPORT_SYMS?= _${KMOD} 137 138.if defined(VFS_LKM) 139CFLAGS+= -DVFS_LKM -DMODVNOPS=${KMOD}vnops 140SRCS+= vnode_if.h 141CLEANFILES+= vnode_if.h vnode_if.c 142.endif 143 144.if defined(KLDMOD) && ${OBJFORMAT} == elf 145CLEANFILES+= setdef0.c setdef1.c setdefs.h 146CLEANFILES+= setdef0.o setdef1.o 147.endif 148 149.if defined(PSEUDO_LKM) 150CFLAGS+= -DPSEUDO_LKM 151.endif 152 153OBJS+= ${SRCS:N*.h:R:S/$/.o/g} 154 155.if !defined(PROG) 156.if defined(KLDMOD) 157PROG= ${KMOD}.ko 158.else 159PROG= ${KMOD}.o 160.endif 161.endif 162 163${PROG}: ${OBJS} ${DPADD} ${KMODDEPS} 164.if defined(KLDMOD) 165.if ${OBJFORMAT} == elf 166 gensetdefs ${OBJS} 167 ${CC} ${CFLAGS} -c setdef0.c 168 ${CC} ${CFLAGS} -c setdef1.c 169 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} setdef0.o ${OBJS} setdef1.o ${KMODDEPS} 170.else 171 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${OBJS} ${KMODDEPS} 172.endif 173.else 174 ${LD} -r ${LDFLAGS:N-static} -o tmp.o ${OBJS} 175.if defined(EXPORT_SYMS) 176 rm -f symb.tmp 177 for i in ${EXPORT_SYMS} ; do echo $$i >> symb.tmp ; done 178 symorder -c symb.tmp tmp.o 179 rm -f symb.tmp 180.endif 181 mv tmp.o ${.TARGET} 182.endif 183 184.if defined(KMODDEPS) 185.for dep in ${KMODDEPS} 186CLEANFILES+= ${dep} ${dep}.c 187 188${dep}: 189 touch ${dep}.c 190 ${CC} -shared ${CFLAGS} -o ${dep} ${dep}.c 191.endfor 192.endif 193 194.if !defined(NOMAN) 195.include <bsd.man.mk> 196.if !defined(_MANPAGES) || empty(_MANPAGES) 197MAN1= ${KMOD}.4 198.endif 199 200.elif !target(maninstall) 201maninstall: _SUBDIR 202all-man: 203.endif 204 205_ILINKS=@ machine 206 207.MAIN: all 208all: objwarn ${PROG} all-man _SUBDIR 209 210beforedepend ${OBJS}: ${_ILINKS} 211 212# The search for the link targets works best if we are in a normal src 213# tree, and not too deeply below src/lkm. If we are near "/", then 214# we may find /sys - this is harmless. Other abnormal "sys" directories 215# found in the search are likely to cause problems. If nothing is found, 216# then the links default to /usr/include and /usr/include/machine. 217${_ILINKS}: 218 @for up in ../.. ../../.. ; do \ 219 case ${.TARGET} in \ 220 machine) \ 221 path=${.CURDIR}/$$up/sys/${MACHINE_ARCH}/include ; \ 222 defaultpath=/usr/include/machine ;; \ 223 @) \ 224 path=${.CURDIR}/$$up/sys ; \ 225 defaultpath=/usr/include ;; \ 226 esac ; \ 227 if [ -d $$path ] ; then break ; fi ; \ 228 path=$$defaultpath ; \ 229 done ; \ 230 path=`(cd $$path && /bin/pwd)` ; \ 231 ${ECHO} ${.TARGET} "->" $$path ; \ 232 ln -s $$path ${.TARGET} 233 234CLEANFILES+= ${KMOD} ${PROG} ${OBJS} ${_ILINKS} lkm_verify_tmp symb.tmp tmp.o 235 236.if !target(install) 237.if !target(beforeinstall) 238beforeinstall: 239.endif 240.if !target(afterinstall) 241afterinstall: 242.endif 243 244realinstall: _SUBDIR 245 ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 246 ${INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 247.if defined(LINKS) && !empty(LINKS) 248 @set ${LINKS}; \ 249 while test $$# -ge 2; do \ 250 l=${DESTDIR}$$1; \ 251 shift; \ 252 t=${DESTDIR}$$1; \ 253 shift; \ 254 ${ECHO} $$t -\> $$l; \ 255 rm -f $$t; \ 256 ln ${LN_FLAGS} $$l $$t; \ 257 done; true 258.endif 259 260install: afterinstall _SUBDIR 261.if !defined(NOMAN) 262afterinstall: realinstall maninstall 263.else 264afterinstall: realinstall 265.endif 266realinstall: beforeinstall 267.endif 268 269DISTRIBUTION?= bin 270.if !target(distribute) 271distribute: _SUBDIR 272.for dist in ${DISTRIBUTION} 273 cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 274.endfor 275.endif 276 277.if !target(load) 278load: ${PROG} 279 ${MODLOAD} -o ${KMOD} -e${KMOD} ${PROG} 280.endif 281 282.if !target(unload) 283unload: ${PROG} 284 ${MODUNLOAD} -n ${KMOD} 285.endif 286 287KERN= ${.CURDIR}/../../sys/kern 288 289vnode_if.h: ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 290 sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 291 292_sysregress: ${_INLINKS} ${PROG} 293 ld -A /sys/compile/LKM/kernel ${PROG} ${DEPLKMS} -o lkm_verify_tmp 294 rm lkm_verify_tmp 295 296regress: _sysregress 297 298.include <bsd.dep.mk> 299 300.if !exists(${DEPENDFILE}) 301${OBJS}: ${SRCS:M*.h} 302.endif 303 304.include <bsd.obj.mk> 305 306.include <bsd.kern.mk> 307