kmod.mk revision 34087
154359Sroberto#	From: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
254359Sroberto#	$Id: bsd.kmod.mk,v 1.45 1998/03/06 05:43:46 bde Exp $
354359Sroberto#
454359Sroberto# The include file <bsd.kmod.mk> handles installing Loadable Kernel Modules.
554359Sroberto#
654359Sroberto#
754359Sroberto# +++ variables +++
854359Sroberto#
954359Sroberto# CLEANFILES	Additional files to remove for the clean and cleandir targets.
1054359Sroberto#
1154359Sroberto# DISTRIBUTION  Name of distribution. [bin]
1254359Sroberto#
1354359Sroberto# EXPORT_SYMS	???
1454359Sroberto#
1554359Sroberto# KERN		Main Kernel source directory. [${.CURDIR}/../../sys/kern]
16182007Sroberto#
1754359Sroberto# KMOD          The name of the loadable kernel module to build.
1854359Sroberto#
1954359Sroberto# KMODDIR	Base path for loadable kernel modules
2054359Sroberto#		(see lkm(4)). [/lkm]
2154359Sroberto#
2254359Sroberto# KMODOWN	LKM owner. [${BINOWN}]
2354359Sroberto#
2454359Sroberto# KMODGRP	LKM group. [${BINGRP}]
2554359Sroberto#
2654359Sroberto# KMODMODE	LKM mode. [${BINMODE}]
2754359Sroberto#
2854359Sroberto# LINKS		The list of LKM links; should be full pathnames, the
2954359Sroberto#               linked-to file coming first, followed by the linked
3054359Sroberto#               file.  The files are hard-linked.  For example, to link
3154359Sroberto#               /lkm/master and /lkm/meister, use:
3254359Sroberto#
3354359Sroberto#			LINKS=  /lkm/master /lkm/meister
3454359Sroberto#
3554359Sroberto# LN_FLAGS	Flags for ln(1) (see variable LINKS)
3654359Sroberto#
3754359Sroberto# MODLOAD	Command to load a kernel module [/sbin/modload]
3854359Sroberto#
3954359Sroberto# MODUNLOAD	Command to unload a kernel module [/sbin/modunload]
4054359Sroberto#
4154359Sroberto# NOMAN		LKM does not have a manual page if set.
4254359Sroberto#
4354359Sroberto# PROG          The name of the loadable kernel module to build. 
4454359Sroberto#		If not supplied, ${KMOD}.o is used.
4554359Sroberto#
4654359Sroberto# PSEUDO_LKM	???
4754359Sroberto#
4854359Sroberto# SRCS          List of source files 
4954359Sroberto#
5054359Sroberto# SUBDIR        A list of subdirectories that should be built as well.
5154359Sroberto#               Each of the targets will execute the same target in the
5254359Sroberto#               subdirectories.
5354359Sroberto#
5454359Sroberto# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk)
5554359Sroberto#
5654359Sroberto#
5754359Sroberto# +++ targets +++
58182007Sroberto#
59182007Sroberto#       distribute:
6054359Sroberto#               This is a variant of install, which will
61182007Sroberto#               put the stuff into the right "distribution".
62182007Sroberto#
63182007Sroberto# 	install:
64182007Sroberto#               install the program and its manual pages; if the Makefile
65182007Sroberto#               does not itself define the target install, the targets
66182007Sroberto#               beforeinstall and afterinstall may also be used to cause
67182007Sroberto#               actions immediately before and after the install target
68182007Sroberto#		is executed.
69182007Sroberto#
70182007Sroberto# 	load:	
71182007Sroberto#		Load LKM.
72182007Sroberto#
73182007Sroberto# 	unload:
74182007Sroberto#		Unload LKM.
75182007Sroberto#
76182007Sroberto# bsd.obj.mk: clean, cleandir and obj
77182007Sroberto# bsd.dep.mk: cleandepend, depend and tags
7854359Sroberto# bsd.man.mk: maninstall
7954359Sroberto#
8054359Sroberto
8154359SrobertoMODLOAD?=	/sbin/modload
8254359SrobertoMODUNLOAD?=	/sbin/modunload
8354359Sroberto
8454359Sroberto.if exists(${.CURDIR}/../Makefile.inc)
8554359Sroberto.include "${.CURDIR}/../Makefile.inc"
8654359Sroberto.endif
8754359Sroberto
8854359Sroberto.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
8954359Sroberto
9054359SrobertoCFLAGS+=	${COPTS} -DKERNEL -DACTUALLY_LKM_NOT_KERNEL ${CWARNFLAGS}
9154359Sroberto
9254359Sroberto# Don't use any standard or source-relative include directories.
9354359Sroberto# Since -nostdinc will annull any previous -I paths, we repeat all
9454359Sroberto# such paths after -nostdinc.  It doesn't seem to be possible to
9554359Sroberto# add to the front of `make' variable.
9654359Sroberto_ICFLAGS:=	${CFLAGS:M-I*}
9754359SrobertoCFLAGS+=	-nostdinc -I- ${_ICFLAGS}
9854359Sroberto
9954359Sroberto# Add -I paths for system headers.  Individual LKM makefiles don't
10054359Sroberto# need any -I paths for this.  Similar defaults for .PATH can't be
10154359Sroberto# set because there are no standard paths for non-headers.
10254359SrobertoCFLAGS+=	-I${.OBJDIR} -I${.OBJDIR}/@
10354359Sroberto
10454359Sroberto# XXX this is now dubious.
10554359Sroberto.if defined(DESTDIR)
10654359SrobertoCFLAGS+=	-I${DESTDIR}/usr/include
10754359Sroberto.endif
10854359Sroberto
10954359SrobertoEXPORT_SYMS?= _${KMOD}
11054359Sroberto
11154359Sroberto.if defined(VFS_LKM)
11254359SrobertoCFLAGS+= -DVFS_LKM -DMODVNOPS=${KMOD}vnops
11354359SrobertoSRCS+=	vnode_if.h
11454359SrobertoCLEANFILES+=	vnode_if.h vnode_if.c
11554359Sroberto.endif
11654359Sroberto
11754359Sroberto.if defined(PSEUDO_LKM)
11854359SrobertoCFLAGS+= -DPSEUDO_LKM
11954359Sroberto.endif
12054359Sroberto
12154359SrobertoOBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
12254359Sroberto
12354359Sroberto.if !defined(PROG)
12454359SrobertoPROG=	${KMOD}.o
12554359Sroberto.endif
12654359Sroberto
12754359Sroberto${PROG}: ${OBJS} ${DPADD} 
12854359Sroberto	${LD} -r ${LDFLAGS} -o tmp.o ${OBJS}
12954359Sroberto.if defined(EXPORT_SYMS)
13054359Sroberto	@rm -f symb.tmp
13154359Sroberto	@for i in ${EXPORT_SYMS} ; do echo $$i >> symb.tmp ; done
13254359Sroberto	symorder -c symb.tmp tmp.o
13354359Sroberto	@rm -f symb.tmp
13454359Sroberto.endif
13554359Sroberto	mv tmp.o ${.TARGET}
13654359Sroberto
13754359Sroberto.if !defined(NOMAN)
13854359Sroberto.include <bsd.man.mk>
13954359Sroberto.if !defined(_MANPAGES) || empty(_MANPAGES)
14054359SrobertoMAN1=	${KMOD}.4
14154359Sroberto.endif
14254359Sroberto
14354359Sroberto.elif !target(maninstall)
14454359Srobertomaninstall: _SUBDIR
14554359Srobertoall-man:
14654359Sroberto.endif
14754359Sroberto
14854359Sroberto_ILINKS=@ machine
14954359Sroberto
15054359Sroberto.MAIN: all
15154359Srobertoall: objwarn ${PROG} all-man _SUBDIR
15254359Sroberto
15354359Srobertobeforedepend ${OBJS}: ${_ILINKS}
15454359Sroberto
15554359Sroberto# The search for the link targets works best if we are in a normal src
15654359Sroberto# tree, and not too deeply below src/lkm.  If we are near "/", then
15754359Sroberto# we may find /sys - this is harmless.  Other abnormal "sys" directories
15854359Sroberto# found in the search are likely to cause problems.  If nothing is found,
15954359Sroberto# then the links default to /usr/include and /usr/include/machine.
16054359Sroberto${_ILINKS}:
16154359Sroberto	@for up in ../.. ../../.. ; do \
16254359Sroberto		case ${.TARGET} in \
16354359Sroberto		machine) \
16454359Sroberto			path=${.CURDIR}/$$up/sys/${MACHINE_ARCH}/include ; \
16554359Sroberto			defaultpath=/usr/include/machine ;; \
16654359Sroberto		@) \
16754359Sroberto			path=${.CURDIR}/$$up/sys ; \
16854359Sroberto			defaultpath=/usr/include ;; \
16954359Sroberto		esac ; \
17054359Sroberto		if [ -d $$path ] ; then break ; fi ; \
17154359Sroberto		path=$$defaultpath ; \
17254359Sroberto	done ; \
17354359Sroberto	path=`(cd $$path && /bin/pwd)` ; \
17454359Sroberto	${ECHO} ${.TARGET} "->" $$path ; \
17554359Sroberto	ln -s $$path ${.TARGET}
17654359Sroberto
17754359SrobertoCLEANFILES+= ${KMOD} ${PROG} ${OBJS} ${_ILINKS}
17854359Sroberto
17954359Sroberto.if !target(install)
18054359Sroberto.if !target(beforeinstall)
18154359Srobertobeforeinstall:
18254359Sroberto.endif
18354359Sroberto.if !target(afterinstall)
18454359Srobertoafterinstall:
18554359Sroberto.endif
18654359Sroberto
18754359Srobertorealinstall: _SUBDIR
18854359Sroberto	${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
18954359Sroberto	    ${INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
19054359Sroberto.if defined(LINKS) && !empty(LINKS)
191182007Sroberto	@set ${LINKS}; \
192182007Sroberto	while test $$# -ge 2; do \
19354359Sroberto		l=${DESTDIR}$$1; \
19454359Sroberto		shift; \
19554359Sroberto		t=${DESTDIR}$$1; \
19654359Sroberto		shift; \
19754359Sroberto		${ECHO} $$t -\> $$l; \
19854359Sroberto		rm -f $$t; \
19954359Sroberto		ln ${LN_FLAGS} $$l $$t; \
20054359Sroberto	done; true
20154359Sroberto.endif
20254359Sroberto
20354359Srobertoinstall: afterinstall _SUBDIR
20454359Sroberto.if !defined(NOMAN)
20554359Srobertoafterinstall: realinstall maninstall
20654359Sroberto.else
20754359Srobertoafterinstall: realinstall
20854359Sroberto.endif
20954359Srobertorealinstall: beforeinstall
21054359Sroberto.endif
21154359Sroberto
21254359SrobertoDISTRIBUTION?=	bin
21354359Sroberto.if !target(distribute)
21454359Srobertodistribute: _SUBDIR
21554359Sroberto.for dist in ${DISTRIBUTION}
21654359Sroberto	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
21754359Sroberto.endfor
21854359Sroberto.endif
21954359Sroberto
22054359Sroberto.if !target(load)
22154359Srobertoload:	${PROG}
22254359Sroberto	${MODLOAD} -o ${KMOD} -e${KMOD} ${PROG}
22354359Sroberto.endif
22454359Sroberto
22554359Sroberto.if !target(unload)
22654359Srobertounload:	${PROG}
22754359Sroberto	${MODUNLOAD} -n ${KMOD}
22854359Sroberto.endif
22954359Sroberto
23054359SrobertoKERN=	${.CURDIR}/../../sys/kern
23154359Sroberto
23254359Srobertovnode_if.h:	${KERN}/vnode_if.sh ${KERN}/vnode_if.src
23354359Sroberto	sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src
23454359Sroberto
23554359Sroberto.include <bsd.obj.mk>
23654359Sroberto.include <bsd.dep.mk>
237132451Sroberto
23854359Sroberto.if !exists(${DEPENDFILE})
23954359Sroberto${OBJS}: ${SRCS:M*.h}
24054359Sroberto.endif
24154359Sroberto
24254359Sroberto.include <bsd.kern.mk>
24354359Sroberto