kmod.mk revision 36780
1252867Sdelphij#	From: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2270810Sdelphij#	$Id: bsd.kmod.mk,v 1.48 1998/03/19 13:22:46 bde Exp $
3252867Sdelphij#
4252867Sdelphij# The include file <bsd.kmod.mk> handles installing Loadable Kernel Modules.
5252867Sdelphij#
6270810Sdelphij#
7270810Sdelphij# +++ variables +++
8270810Sdelphij#
9270810Sdelphij# CLEANFILES	Additional files to remove for the clean and cleandir targets.
10270810Sdelphij#
11270810Sdelphij# DISTRIBUTION  Name of distribution. [bin]
12270810Sdelphij#
13270810Sdelphij# EXPORT_SYMS	???
14270810Sdelphij#
15252867Sdelphij# KERN		Main Kernel source directory. [${.CURDIR}/../../sys/kern]
16270810Sdelphij#
17252867Sdelphij# KMOD          The name of the loadable kernel module to build.
18252867Sdelphij#
19252867Sdelphij# KMODDIR	Base path for loadable kernel modules
20252867Sdelphij#		(see lkm(4)). [/lkm]
21252867Sdelphij#
22252867Sdelphij# KMODOWN	LKM owner. [${BINOWN}]
23252867Sdelphij#
24252867Sdelphij# KMODGRP	LKM group. [${BINGRP}]
25252867Sdelphij#
26252867Sdelphij# KMODMODE	LKM mode. [${BINMODE}]
27252867Sdelphij#
28252867Sdelphij# LINKS		The list of LKM links; should be full pathnames, the
29252867Sdelphij#               linked-to file coming first, followed by the linked
30252867Sdelphij#               file.  The files are hard-linked.  For example, to link
31252867Sdelphij#               /lkm/master and /lkm/meister, use:
32252867Sdelphij#
33252867Sdelphij#			LINKS=  /lkm/master /lkm/meister
34252867Sdelphij#
35252867Sdelphij# LN_FLAGS	Flags for ln(1) (see variable LINKS)
36252867Sdelphij#
37252867Sdelphij# MODLOAD	Command to load a kernel module [/sbin/modload]
38252867Sdelphij#
39252867Sdelphij# MODUNLOAD	Command to unload a kernel module [/sbin/modunload]
40252867Sdelphij#
41252867Sdelphij# NOMAN		LKM does not have a manual page if set.
42252867Sdelphij#
43252867Sdelphij# PROG          The name of the loadable kernel module to build. 
44252867Sdelphij#		If not supplied, ${KMOD}.o is used.
45252867Sdelphij#
46252867Sdelphij# PSEUDO_LKM	???
47252867Sdelphij#
48252867Sdelphij# SRCS          List of source files 
49252867Sdelphij#
50252867Sdelphij# SUBDIR        A list of subdirectories that should be built as well.
51252867Sdelphij#               Each of the targets will execute the same target in the
52270810Sdelphij#               subdirectories.
53252867Sdelphij#
54252867Sdelphij# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk)
55252867Sdelphij#
56252867Sdelphij#
57252867Sdelphij# +++ targets +++
58252867Sdelphij#
59252867Sdelphij#       distribute:
60252867Sdelphij#               This is a variant of install, which will
61252867Sdelphij#               put the stuff into the right "distribution".
62252867Sdelphij#
63252867Sdelphij# 	install:
64252867Sdelphij#               install the program and its manual pages; if the Makefile
65252867Sdelphij#               does not itself define the target install, the targets
66252867Sdelphij#               beforeinstall and afterinstall may also be used to cause
67252867Sdelphij#               actions immediately before and after the install target
68252867Sdelphij#		is executed.
69252867Sdelphij#
70252867Sdelphij# 	load:	
71252867Sdelphij#		Load LKM.
72252867Sdelphij#
73252867Sdelphij# 	unload:
74252867Sdelphij#		Unload LKM.
75252867Sdelphij#
76252867Sdelphij# bsd.obj.mk: clean, cleandir and obj
77252867Sdelphij# bsd.dep.mk: cleandepend, depend and tags
78252867Sdelphij# bsd.man.mk: maninstall
79252867Sdelphij#
80252867Sdelphij
81252867SdelphijMODLOAD?=	/sbin/modload
82252867SdelphijMODUNLOAD?=	/sbin/modunload
83252867Sdelphij
84252867Sdelphij.if exists(${.CURDIR}/../Makefile.inc)
85252867Sdelphij.include "${.CURDIR}/../Makefile.inc"
86252867Sdelphij.endif
87252867Sdelphij
88252867Sdelphij.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
89252867Sdelphij
90252867SdelphijCFLAGS+=	${COPTS} -DKERNEL -DACTUALLY_LKM_NOT_KERNEL ${CWARNFLAGS}
91252867Sdelphij
92252867Sdelphij# Don't use any standard or source-relative include directories.
93252867Sdelphij# Since -nostdinc will annull any previous -I paths, we repeat all
94252867Sdelphij# such paths after -nostdinc.  It doesn't seem to be possible to
95252867Sdelphij# add to the front of `make' variable.
96252867Sdelphij_ICFLAGS:=	${CFLAGS:M-I*}
97252867SdelphijCFLAGS+=	-nostdinc -I- ${_ICFLAGS}
98252867Sdelphij
99252867Sdelphij# Add -I paths for system headers.  Individual LKM makefiles don't
100252867Sdelphij# need any -I paths for this.  Similar defaults for .PATH can't be
101252867Sdelphij# set because there are no standard paths for non-headers.
102252867SdelphijCFLAGS+=	-I${.OBJDIR} -I${.OBJDIR}/@
103252867Sdelphij
104252867Sdelphij# XXX this is now dubious.
105252867Sdelphij.if defined(DESTDIR)
106252867SdelphijCFLAGS+=	-I${DESTDIR}/usr/include
107252867Sdelphij.endif
108252867Sdelphij
109252867SdelphijEXPORT_SYMS?= _${KMOD}
110252867Sdelphij
111252867Sdelphij.if defined(VFS_LKM)
112252867SdelphijCFLAGS+= -DVFS_LKM -DMODVNOPS=${KMOD}vnops
113252867SdelphijSRCS+=	vnode_if.h
114252867SdelphijCLEANFILES+=	vnode_if.h vnode_if.c
115252867Sdelphij.endif
116252867Sdelphij
117252867Sdelphij.if defined(PSEUDO_LKM)
118252867SdelphijCFLAGS+= -DPSEUDO_LKM
119252867Sdelphij.endif
120252867Sdelphij
121252867SdelphijOBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
122252867Sdelphij
123252867Sdelphij.if !defined(PROG)
124252867SdelphijPROG=	${KMOD}.o
125252867Sdelphij.endif
126252867Sdelphij
127252867Sdelphij${PROG}: ${OBJS} ${DPADD} 
128252867Sdelphij	${LD} -r ${LDFLAGS} -o tmp.o ${OBJS}
129252867Sdelphij.if defined(EXPORT_SYMS)
130252867Sdelphij	@rm -f symb.tmp
131252867Sdelphij	@for i in ${EXPORT_SYMS} ; do echo $$i >> symb.tmp ; done
132252867Sdelphij	symorder -c symb.tmp tmp.o
133252867Sdelphij	@rm -f symb.tmp
134252867Sdelphij.endif
135252867Sdelphij	mv tmp.o ${.TARGET}
136252867Sdelphij
137252867Sdelphij.if !defined(NOMAN)
138252867Sdelphij.include <bsd.man.mk>
139252867Sdelphij.if !defined(_MANPAGES) || empty(_MANPAGES)
140252867SdelphijMAN1=	${KMOD}.4
141252867Sdelphij.endif
142252867Sdelphij
143252867Sdelphij.elif !target(maninstall)
144252867Sdelphijmaninstall: _SUBDIR
145252867Sdelphijall-man:
146252867Sdelphij.endif
147252867Sdelphij
148252867Sdelphij_ILINKS=@ machine
149252867Sdelphij
150252867Sdelphij.MAIN: all
151252867Sdelphijall: objwarn ${PROG} all-man _SUBDIR
152252867Sdelphij
153252867Sdelphijbeforedepend ${OBJS}: ${_ILINKS}
154252867Sdelphij
155252867Sdelphij# The search for the link targets works best if we are in a normal src
156252867Sdelphij# tree, and not too deeply below src/lkm.  If we are near "/", then
157252867Sdelphij# we may find /sys - this is harmless.  Other abnormal "sys" directories
158252867Sdelphij# found in the search are likely to cause problems.  If nothing is found,
159252867Sdelphij# then the links default to /usr/include and /usr/include/machine.
160252867Sdelphij${_ILINKS}:
161252867Sdelphij	@for up in ../.. ../../.. ; do \
162252867Sdelphij		case ${.TARGET} in \
163252867Sdelphij		machine) \
164252867Sdelphij			path=${.CURDIR}/$$up/sys/${MACHINE_ARCH}/include ; \
165252867Sdelphij			defaultpath=/usr/include/machine ;; \
166252867Sdelphij		@) \
167252867Sdelphij			path=${.CURDIR}/$$up/sys ; \
168252867Sdelphij			defaultpath=/usr/include ;; \
169252867Sdelphij		esac ; \
170252867Sdelphij		if [ -d $$path ] ; then break ; fi ; \
171252867Sdelphij		path=$$defaultpath ; \
172252867Sdelphij	done ; \
173252867Sdelphij	path=`(cd $$path && /bin/pwd)` ; \
174252867Sdelphij	${ECHO} ${.TARGET} "->" $$path ; \
175252867Sdelphij	ln -s $$path ${.TARGET}
176252867Sdelphij
177252867SdelphijCLEANFILES+= ${KMOD} ${PROG} ${OBJS} ${_ILINKS} lkm_verify_tmp symb.tmp tmp.o
178252867Sdelphij
179252867Sdelphij.if !target(install)
180252867Sdelphij.if !target(beforeinstall)
181252867Sdelphijbeforeinstall:
182252867Sdelphij.endif
183252867Sdelphij.if !target(afterinstall)
184252867Sdelphijafterinstall:
185252867Sdelphij.endif
186252867Sdelphij
187252867Sdelphijrealinstall: _SUBDIR
188252867Sdelphij	${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
189252867Sdelphij	    ${INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
190252867Sdelphij.if defined(LINKS) && !empty(LINKS)
191252867Sdelphij	@set ${LINKS}; \
192252867Sdelphij	while test $$# -ge 2; do \
193252867Sdelphij		l=${DESTDIR}$$1; \
194252867Sdelphij		shift; \
195252867Sdelphij		t=${DESTDIR}$$1; \
196252867Sdelphij		shift; \
197252867Sdelphij		${ECHO} $$t -\> $$l; \
198252867Sdelphij		rm -f $$t; \
199252867Sdelphij		ln ${LN_FLAGS} $$l $$t; \
200252867Sdelphij	done; true
201252867Sdelphij.endif
202252867Sdelphij
203252867Sdelphijinstall: afterinstall _SUBDIR
204252867Sdelphij.if !defined(NOMAN)
205252867Sdelphijafterinstall: realinstall maninstall
206.else
207afterinstall: realinstall
208.endif
209realinstall: beforeinstall
210.endif
211
212DISTRIBUTION?=	bin
213.if !target(distribute)
214distribute: _SUBDIR
215.for dist in ${DISTRIBUTION}
216	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
217.endfor
218.endif
219
220.if !target(load)
221load:	${PROG}
222	${MODLOAD} -o ${KMOD} -e${KMOD} ${PROG}
223.endif
224
225.if !target(unload)
226unload:	${PROG}
227	${MODUNLOAD} -n ${KMOD}
228.endif
229
230KERN=	${.CURDIR}/../../sys/kern
231
232vnode_if.h:	${KERN}/vnode_if.sh ${KERN}/vnode_if.src
233	sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src
234
235_sysregress:	${_INLINKS} ${PROG}
236	ld -A /sys/compile/LKM/kernel ${PROG} ${DEPLKMS} -o lkm_verify_tmp
237	rm lkm_verify_tmp
238
239regress:	_sysregress
240
241.include <bsd.dep.mk>
242
243.if !exists(${DEPENDFILE})
244${OBJS}: ${SRCS:M*.h}
245.endif
246
247.include <bsd.obj.mk>
248
249.include <bsd.kern.mk>
250