kmod.mk revision 37948
1#	From: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2#	$Id: bsd.kmod.mk,v 1.49 1998/06/09 02:55:40 bde 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# 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# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk)
55#
56#
57# +++ targets +++
58#
59#       distribute:
60#               This is a variant of install, which will
61#               put the stuff into the right "distribution".
62#
63# 	install:
64#               install the program and its manual pages; if the Makefile
65#               does not itself define the target install, the targets
66#               beforeinstall and afterinstall may also be used to cause
67#               actions immediately before and after the install target
68#		is executed.
69#
70# 	load:	
71#		Load LKM.
72#
73# 	unload:
74#		Unload LKM.
75#
76# bsd.obj.mk: clean, cleandir and obj
77# bsd.dep.mk: cleandepend, depend and tags
78# bsd.man.mk: maninstall
79#
80
81MODLOAD?=	/sbin/modload
82MODUNLOAD?=	/sbin/modunload
83
84.if exists(${.CURDIR}/../Makefile.inc)
85.include "${.CURDIR}/../Makefile.inc"
86.endif
87
88.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
89
90CFLAGS+=	${COPTS} -DKERNEL -DACTUALLY_LKM_NOT_KERNEL ${CWARNFLAGS}
91
92# Don't use any standard or source-relative include directories.
93# Since -nostdinc will annull any previous -I paths, we repeat all
94# such paths after -nostdinc.  It doesn't seem to be possible to
95# add to the front of `make' variable.
96_ICFLAGS:=	${CFLAGS:M-I*}
97CFLAGS+=	-nostdinc -I- ${_ICFLAGS}
98
99# Add -I paths for system headers.  Individual LKM makefiles don't
100# need any -I paths for this.  Similar defaults for .PATH can't be
101# set because there are no standard paths for non-headers.
102CFLAGS+=	-I${.OBJDIR} -I${.OBJDIR}/@
103
104# XXX this is now dubious.
105.if defined(DESTDIR)
106CFLAGS+=	-I${DESTDIR}/usr/include
107.endif
108
109.if defined(NOSHARED) && ( ${NOSHARED} != "no" && ${NOSHARED} != "NO" )
110LDFLAGS+= -static
111.endif
112
113EXPORT_SYMS?= _${KMOD}
114
115.if defined(VFS_LKM)
116CFLAGS+= -DVFS_LKM -DMODVNOPS=${KMOD}vnops
117SRCS+=	vnode_if.h
118CLEANFILES+=	vnode_if.h vnode_if.c
119.endif
120
121.if defined(PSEUDO_LKM)
122CFLAGS+= -DPSEUDO_LKM
123.endif
124
125OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
126
127.if !defined(PROG)
128PROG=	${KMOD}.o
129.endif
130
131${PROG}: ${OBJS} ${DPADD} 
132	${LD} -r ${LDFLAGS:N-static} -o tmp.o ${OBJS}
133.if defined(EXPORT_SYMS)
134	rm -f symb.tmp
135	for i in ${EXPORT_SYMS} ; do echo $$i >> symb.tmp ; done
136	symorder -c symb.tmp tmp.o
137	rm -f symb.tmp
138.endif
139	mv tmp.o ${.TARGET}
140
141.if !defined(NOMAN)
142.include <bsd.man.mk>
143.if !defined(_MANPAGES) || empty(_MANPAGES)
144MAN1=	${KMOD}.4
145.endif
146
147.elif !target(maninstall)
148maninstall: _SUBDIR
149all-man:
150.endif
151
152_ILINKS=@ machine
153
154.MAIN: all
155all: objwarn ${PROG} all-man _SUBDIR
156
157beforedepend ${OBJS}: ${_ILINKS}
158
159# The search for the link targets works best if we are in a normal src
160# tree, and not too deeply below src/lkm.  If we are near "/", then
161# we may find /sys - this is harmless.  Other abnormal "sys" directories
162# found in the search are likely to cause problems.  If nothing is found,
163# then the links default to /usr/include and /usr/include/machine.
164${_ILINKS}:
165	@for up in ../.. ../../.. ; do \
166		case ${.TARGET} in \
167		machine) \
168			path=${.CURDIR}/$$up/sys/${MACHINE_ARCH}/include ; \
169			defaultpath=/usr/include/machine ;; \
170		@) \
171			path=${.CURDIR}/$$up/sys ; \
172			defaultpath=/usr/include ;; \
173		esac ; \
174		if [ -d $$path ] ; then break ; fi ; \
175		path=$$defaultpath ; \
176	done ; \
177	path=`(cd $$path && /bin/pwd)` ; \
178	${ECHO} ${.TARGET} "->" $$path ; \
179	ln -s $$path ${.TARGET}
180
181CLEANFILES+= ${KMOD} ${PROG} ${OBJS} ${_ILINKS} lkm_verify_tmp symb.tmp tmp.o
182
183.if !target(install)
184.if !target(beforeinstall)
185beforeinstall:
186.endif
187.if !target(afterinstall)
188afterinstall:
189.endif
190
191realinstall: _SUBDIR
192	${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
193	    ${INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
194.if defined(LINKS) && !empty(LINKS)
195	@set ${LINKS}; \
196	while test $$# -ge 2; do \
197		l=${DESTDIR}$$1; \
198		shift; \
199		t=${DESTDIR}$$1; \
200		shift; \
201		${ECHO} $$t -\> $$l; \
202		rm -f $$t; \
203		ln ${LN_FLAGS} $$l $$t; \
204	done; true
205.endif
206
207install: afterinstall _SUBDIR
208.if !defined(NOMAN)
209afterinstall: realinstall maninstall
210.else
211afterinstall: realinstall
212.endif
213realinstall: beforeinstall
214.endif
215
216DISTRIBUTION?=	bin
217.if !target(distribute)
218distribute: _SUBDIR
219.for dist in ${DISTRIBUTION}
220	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
221.endfor
222.endif
223
224.if !target(load)
225load:	${PROG}
226	${MODLOAD} -o ${KMOD} -e${KMOD} ${PROG}
227.endif
228
229.if !target(unload)
230unload:	${PROG}
231	${MODUNLOAD} -n ${KMOD}
232.endif
233
234KERN=	${.CURDIR}/../../sys/kern
235
236vnode_if.h:	${KERN}/vnode_if.sh ${KERN}/vnode_if.src
237	sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src
238
239_sysregress:	${_INLINKS} ${PROG}
240	ld -A /sys/compile/LKM/kernel ${PROG} ${DEPLKMS} -o lkm_verify_tmp
241	rm lkm_verify_tmp
242
243regress:	_sysregress
244
245.include <bsd.dep.mk>
246
247.if !exists(${DEPENDFILE})
248${OBJS}: ${SRCS:M*.h}
249.endif
250
251.include <bsd.obj.mk>
252
253.include <bsd.kern.mk>
254