1# From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2# $Id: bsd.kmod.mk,v 1.55 1998/10/14 04:04:22 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# 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(VFS_KLD) 145CFLAGS+= -DVFS_LKM -DVFS_KLD 146SRCS+= vnode_if.h 147CLEANFILES+= vnode_if.h vnode_if.c 148.endif 149 150.if defined(KLDMOD) && ${OBJFORMAT} == elf 151CLEANFILES+= setdef0.c setdef1.c setdefs.h 152CLEANFILES+= setdef0.o setdef1.o 153.endif 154 155.if defined(PSEUDO_LKM) 156CFLAGS+= -DPSEUDO_LKM 157.endif 158 159OBJS+= ${SRCS:N*.h:R:S/$/.o/g} 160 161.if !defined(PROG) 162.if defined(KLDMOD) 163PROG= ${KMOD}.ko 164.else 165PROG= ${KMOD}.o 166.endif 167.endif 168 169${PROG}: ${OBJS} ${DPADD} ${KMODDEPS} 170.if defined(KLDMOD) 171.if ${OBJFORMAT} == elf 172 gensetdefs ${OBJS} 173 ${CC} ${CFLAGS} -c setdef0.c 174 ${CC} ${CFLAGS} -c setdef1.c 175 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} setdef0.o ${OBJS} setdef1.o ${KMODDEPS} 176.else 177 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${OBJS} ${KMODDEPS} 178.endif 179.else 180 ${LD} -r ${LDFLAGS:N-static} -o tmp.o ${OBJS} 181.if defined(EXPORT_SYMS) 182 rm -f symb.tmp 183 for i in ${EXPORT_SYMS} ; do echo $$i >> symb.tmp ; done 184 symorder -c symb.tmp tmp.o 185 rm -f symb.tmp 186.endif 187 mv tmp.o ${.TARGET} 188.endif 189 190.if defined(KMODDEPS) 191.for dep in ${KMODDEPS} 192CLEANFILES+= ${dep} ${dep}.c 193 194${dep}: 195 touch ${dep}.c 196 ${CC} -shared ${CFLAGS} -o ${dep} ${dep}.c 197.endfor 198.endif 199 200.if !defined(NOMAN) 201.include <bsd.man.mk> 202.if !defined(_MANPAGES) || empty(_MANPAGES) 203MAN1= ${KMOD}.4 204.endif 205 206.elif !target(maninstall) 207maninstall: _SUBDIR 208all-man: 209.endif 210 211_ILINKS=@ machine 212 213.MAIN: all 214all: objwarn ${PROG} all-man _SUBDIR 215 216beforedepend ${OBJS}: ${_ILINKS} 217 218.if !defined(KLDMOD) 219# The search for the link targets works best if we are in a normal src 220# tree, and not too deeply below src/lkm. If we are near "/", then 221# we may find /sys - this is harmless. Other abnormal "sys" directories 222# found in the search are likely to cause problems. If nothing is found, 223# then the links default to /usr/include and /usr/include/machine. 224${_ILINKS}: 225 @for up in ../.. ../../.. ; do \ 226 case ${.TARGET} in \ 227 machine) \ 228 path=${.CURDIR}/$$up/sys/${MACHINE_ARCH}/include ; \ 229 defaultpath=/usr/include/machine ;; \ 230 @) \ 231 path=${.CURDIR}/$$up/sys ; \ 232 defaultpath=/usr/include ;; \ 233 esac ; \ 234 if [ -d $$path ] ; then break ; fi ; \ 235 path=$$defaultpath ; \ 236 done ; \ 237 path=`(cd $$path && /bin/pwd)` ; \ 238 ${ECHO} ${.TARGET} "->" $$path ; \ 239 ln -s $$path ${.TARGET} 240.else 241${_ILINKS}: 242 @set +x; for up in ../.. ../../.. ; do \ 243 case ${.TARGET} in \ 244 machine) \ 245 testpath=${.CURDIR}/$$up/${MACHINE_ARCH}/include ; \ 246 path=${.CURDIR}/$$up/${MACHINE_ARCH}/include ; \ 247 defaultpath=/usr/include/machine ;; \ 248 @) \ 249 testpath=${.CURDIR}/$$up/sys ; \ 250 path=${.CURDIR}/$$up ; \ 251 defaultpath=/usr/include ;; \ 252 esac ; \ 253 if [ -d $$testpath ] ; then break ; fi ; \ 254 path=$$defaultpath ; \ 255 done ; \ 256 path=`(cd $$path && /bin/pwd)` ; \ 257 ${ECHO} ${.TARGET} "->" $$path ; \ 258 ln -s $$path ${.TARGET} 259.endif 260 261CLEANFILES+= ${KMOD} ${PROG} ${OBJS} ${_ILINKS} lkm_verify_tmp symb.tmp tmp.o 262 263.if !target(install) 264.if !target(beforeinstall) 265beforeinstall: 266.endif 267.if !target(afterinstall) 268afterinstall: 269.endif 270 271realinstall: _SUBDIR 272 ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \ 273 ${INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR} 274.if defined(LINKS) && !empty(LINKS) 275 @set ${LINKS}; \ 276 while test $$# -ge 2; do \ 277 l=${DESTDIR}$$1; \ 278 shift; \ 279 t=${DESTDIR}$$1; \ 280 shift; \ 281 ${ECHO} $$t -\> $$l; \ 282 rm -f $$t; \ 283 ln ${LN_FLAGS} $$l $$t; \ 284 done; true 285.endif 286 287install: afterinstall _SUBDIR 288.if !defined(NOMAN) 289afterinstall: realinstall maninstall 290.else 291afterinstall: realinstall 292.endif 293realinstall: beforeinstall 294.endif 295 296DISTRIBUTION?= bin 297.if !target(distribute) 298distribute: _SUBDIR 299.for dist in ${DISTRIBUTION} 300 cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 301.endfor 302.endif 303 304.if !target(load) 305load: ${PROG} 306 ${MODLOAD} -o ${KMOD} -e${KMOD} ${PROG} 307.endif 308 309.if !target(unload) 310unload: ${PROG} 311 ${MODUNLOAD} -n ${KMOD} 312.endif 313 314.if exists(${.CURDIR}/../../kern) 315KERN= ${.CURDIR}/../../kern 316.else 317KERN= ${.CURDIR}/../../sys/kern 318.endif 319 320vnode_if.h: ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 321 sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src 322 323_sysregress: ${_INLINKS} ${PROG} 324 ld -A /sys/compile/LKM/kernel ${PROG} ${DEPLKMS} -o lkm_verify_tmp 325 rm lkm_verify_tmp 326 327regress: _sysregress 328 329.include <bsd.dep.mk> 330 331.if !exists(${DEPENDFILE}) 332${OBJS}: ${SRCS:M*.h} 333.endif 334 335.include <bsd.obj.mk> 336 337.include <bsd.kern.mk> 338