kmod.mk revision 44946
1# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2# $Id: bsd.kmod.mk,v 1.58 1998/11/11 07:40:44 peter 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# MODLOAD Command to load a kernel module [/sbin/modload] 36# 37# MODUNLOAD Command to unload a kernel module [/sbin/modunload] 38# 39# NOMAN LKM does not have a manual page if set. 40# 41# PROG The name of the loadable kernel module to build. 42# If not supplied, ${KMOD}.o is used. 43# 44# PSEUDO_LKM ??? 45# 46# SRCS List of source files 47# 48# KMODDEPS List of modules which this one is dependant on 49# 50# SUBDIR A list of subdirectories that should be built as well. 51# Each of the targets will execute the same target in the 52# subdirectories. 53# 54# SYMLINKS Same as LINKS, except it creates symlinks and the 55# linked-to pathname may be relative. 56# 57# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk) 58# 59# 60# +++ targets +++ 61# 62# distribute: 63# This is a variant of install, which will 64# put the stuff into the right "distribution". 65# 66# install: 67# install the program and its manual pages; if the Makefile 68# does not itself define the target install, the targets 69# beforeinstall and afterinstall may also be used to cause 70# actions immediately before and after the install target 71# is executed. 72# 73# load: 74# Load LKM. 75# 76# unload: 77# Unload LKM. 78# 79# bsd.obj.mk: clean, cleandir and obj 80# bsd.dep.mk: cleandepend, depend and tags 81# bsd.man.mk: maninstall 82# 83 84MODLOAD?= /sbin/modload 85MODUNLOAD?= /sbin/modunload 86 87.if !target(__initialized__) 88__initialized__: 89.if exists(${.CURDIR}/../Makefile.inc) 90.include "${.CURDIR}/../Makefile.inc" 91.endif 92.endif 93 94.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S 95 96CFLAGS+= ${COPTS} -DKERNEL ${CWARNFLAGS} 97.if defined(KLDMOD) 98CFLAGS+= -DKLD_MODULE 99.else 100CFLAGS+= -DACTUALLY_LKM_NOT_KERNEL 101.endif 102 103# Damn bsd.own.mk is included too early. 104.if defined(KLDMOD) 105.if ${KMODDIR} == /lkm 106KMODDIR= /modules 107.endif 108.endif 109 110# Don't use any standard or source-relative include directories. 111# Since -nostdinc will annull any previous -I paths, we repeat all 112# such paths after -nostdinc. It doesn't seem to be possible to 113# add to the front of `make' variable. 114_ICFLAGS:= ${CFLAGS:M-I*} 115CFLAGS+= -nostdinc -I- ${_ICFLAGS} 116 117# Add -I paths for system headers. Individual LKM makefiles don't 118# need any -I paths for this. Similar defaults for .PATH can't be 119# set because there are no standard paths for non-headers. 120CFLAGS+= -I${.OBJDIR} -I${.OBJDIR}/@ 121 122# XXX this is now dubious. 123.if defined(DESTDIR) 124CFLAGS+= -I${DESTDIR}/usr/include 125.endif 126 127.if !defined(KLDMOD) 128# XXX temporary until we build ELF kernels. 129CFLAGS+= -aout 130LDFLAGS+= -aout 131.endif 132 133.if defined(NOSHARED) && ( ${NOSHARED} != "no" && ${NOSHARED} != "NO" ) 134LDFLAGS+= -static 135.endif 136 137EXPORT_SYMS?= _${KMOD} 138 139.if defined(VFS_LKM) 140CFLAGS+= -DVFS_LKM -DMODVNOPS=${KMOD}vnops 141SRCS+= vnode_if.h 142CLEANFILES+= vnode_if.h vnode_if.c 143.endif 144 145.if defined(VFS_KLD) 146CFLAGS+= -DVFS_LKM -DVFS_KLD 147SRCS+= vnode_if.h 148CLEANFILES+= vnode_if.h vnode_if.c 149.endif 150 151.if defined(KLDMOD) && ${OBJFORMAT} == elf 152CLEANFILES+= setdef0.c setdef1.c setdefs.h 153CLEANFILES+= setdef0.o setdef1.o 154.endif 155 156.if defined(PSEUDO_LKM) 157CFLAGS+= -DPSEUDO_LKM 158.endif 159 160OBJS+= ${SRCS:N*.h:R:S/$/.o/g} 161 162.if !defined(PROG) 163.if defined(KLDMOD) 164PROG= ${KMOD}.ko 165.else 166PROG= ${KMOD}.o 167.endif 168.endif 169 170${PROG}: ${OBJS} ${DPADD} ${KMODDEPS} 171.if defined(KLDMOD) 172.if ${OBJFORMAT} == elf 173 gensetdefs ${OBJS} 174 ${CC} ${CFLAGS} -c setdef0.c 175 ${CC} ${CFLAGS} -c setdef1.c 176 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} setdef0.o ${OBJS} setdef1.o ${KMODDEPS} 177.else 178 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${OBJS} ${KMODDEPS} 179.endif 180.else 181 ${LD} -r ${LDFLAGS:N-static} -o tmp.o ${OBJS} 182.if defined(EXPORT_SYMS) 183 rm -f symb.tmp 184 for i in ${EXPORT_SYMS} ; do echo $$i >> symb.tmp ; done 185 symorder -c symb.tmp tmp.o 186 rm -f symb.tmp 187.endif 188 mv tmp.o ${.TARGET} 189.endif 190 191.if defined(KMODDEPS) 192.for dep in ${KMODDEPS} 193CLEANFILES+= ${dep} __${dep}_hack_dep.c 194 195${dep}: 196 touch __${dep}_hack_dep.c 197 ${CC} -shared ${CFLAGS} -o ${dep} __${dep}_hack_dep.c 198.endfor 199.endif 200 201.if !defined(NOMAN) 202.include <bsd.man.mk> 203.if !defined(_MANPAGES) || empty(_MANPAGES) 204MAN1= ${KMOD}.4 205.endif 206 207.elif !target(maninstall) 208maninstall: _SUBDIR 209all-man: 210.endif 211 212_ILINKS=@ machine 213 214.MAIN: all 215all: objwarn ${PROG} all-man _SUBDIR 216 217beforedepend ${OBJS}: ${_ILINKS} 218 219.if !defined(KLDMOD) 220# The search for the link targets works best if we are in a normal src 221# tree, and not too deeply below src/lkm. If we are near "/", then 222# we may find /sys - this is harmless. Other abnormal "sys" directories 223# found in the search are likely to cause problems. If nothing is found, 224# then the links default to /usr/include and /usr/include/machine. 225${_ILINKS}: 226 @for up in ../.. ../../.. ; do \ 227 case ${.TARGET} in \ 228 machine) \ 229 path=${.CURDIR}/$$up/sys/${MACHINE_ARCH}/include ; \ 230 defaultpath=/usr/include/machine ;; \ 231 @) \ 232 path=${.CURDIR}/$$up/sys ; \ 233 defaultpath=/usr/include ;; \ 234 esac ; \ 235 if [ -d $$path ] ; then break ; fi ; \ 236 path=$$defaultpath ; \ 237 done ; \ 238 path=`(cd $$path && /bin/pwd)` ; \ 239 ${ECHO} ${.TARGET} "->" $$path ; \ 240 ln -s $$path ${.TARGET} 241.else 242${_ILINKS}: 243 @set +x; for up in ../.. ../../.. ; do \ 244 case ${.TARGET} in \ 245 machine) \ 246 testpath=${.CURDIR}/$$up/${MACHINE_ARCH}/include ; \ 247 path=${.CURDIR}/$$up/${MACHINE_ARCH}/include ; \ 248 defaultpath=/usr/include/machine ;; \ 249 @) \ 250 testpath=${.CURDIR}/$$up/sys ; \ 251 path=${.CURDIR}/$$up ; \ 252 defaultpath=/usr/include ;; \ 253 esac ; \ 254 if [ -d $$testpath ] ; then break ; fi ; \ 255 path=$$defaultpath ; \ 256 done ; \ 257 path=`(cd $$path && /bin/pwd)` ; \ 258 ${ECHO} ${.TARGET} "->" $$path ; \ 259 ln -s $$path ${.TARGET} 260.endif 261 262CLEANFILES+= ${PROG} ${OBJS} ${_ILINKS} lkm_verify_tmp symb.tmp tmp.o 263 264.if !target(install) 265.if !target(beforeinstall) 266beforeinstall: 267.endif 268.if !target(afterinstall) 269afterinstall: 270.endif 271 272realinstall: _SUBDIR 273 ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 274 ${INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 275.if defined(LINKS) && !empty(LINKS) 276 @set ${LINKS}; \ 277 while test $$# -ge 2; do \ 278 l=${DESTDIR}$$1; \ 279 shift; \ 280 t=${DESTDIR}$$1; \ 281 shift; \ 282 ${ECHO} $$t -\> $$l; \ 283 ln -f $$l $$t; \ 284 done; true 285.endif 286.if defined(SYMLINKS) && !empty(SYMLINKS) 287 @set ${SYMLINKS}; \ 288 while test $$# -ge 2; do \ 289 l=$$1; \ 290 shift; \ 291 t=${DESTDIR}$$1; \ 292 shift; \ 293 ${ECHO} $$t -\> $$l; \ 294 ln -fs $$l $$t; \ 295 done; true 296.endif 297 298install: afterinstall _SUBDIR 299.if !defined(NOMAN) 300afterinstall: realinstall maninstall 301.else 302afterinstall: realinstall 303.endif 304realinstall: beforeinstall 305.endif 306 307DISTRIBUTION?= bin 308.if !target(distribute) 309distribute: _SUBDIR 310.for dist in ${DISTRIBUTION} 311 cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 312.endfor 313.endif 314 315.if !target(load) 316load: ${PROG} 317 ${MODLOAD} -o ${KMOD} -e${KMOD} ${PROG} 318.endif 319 320.if !target(unload) 321unload: ${PROG} 322 ${MODUNLOAD} -n ${KMOD} 323.endif 324 325.if exists(${.CURDIR}/../../kern) 326KERN= ${.CURDIR}/../../kern 327.else 328KERN= ${.CURDIR}/../../sys/kern 329.endif 330 331vnode_if.h: ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 332 sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 333 334_sysregress: ${_INLINKS} ${PROG} 335 ld -A /sys/compile/LKM/kernel ${PROG} ${DEPLKMS} -o lkm_verify_tmp 336 rm lkm_verify_tmp 337 338regress: _sysregress 339 340.include <bsd.dep.mk> 341 342.if !exists(${DEPENDFILE}) 343${OBJS}: ${SRCS:M*.h} 344.endif 345 346.include <bsd.obj.mk> 347 348.include <bsd.kern.mk> 349