kmod.mk revision 32813
1#	From: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2#	$Id: bsd.kmod.mk,v 1.41 1997/11/09 15:03:13 wosch 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# 	tags:
74#		Create a tags file for the source files.
75#
76# 	unload:
77#		Unload LKM.
78#
79# bsd.obj.mk: clean, cleandir and obj
80# bsd.dep.mk: depend
81# bsd.man.mk: maninstall
82#
83
84MODLOAD?=	/sbin/modload
85MODUNLOAD?=	/sbin/modunload
86
87.if exists(${.CURDIR}/../Makefile.inc)
88.include "${.CURDIR}/../Makefile.inc"
89.endif
90
91.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
92
93CFLAGS+=	${COPTS} -DKERNEL -DACTUALLY_LKM_NOT_KERNEL ${CWARNFLAGS}
94
95# Add -I paths for system headers.  Individual LKM makefiles don't need any
96# -I paths for this.  Most of them need .PATH statement(s) for non-headers.
97CFLAGS+=	-I${.OBJDIR} -I${.OBJDIR}/@
98
99.if defined(DESTDIR)
100CFLAGS+=	-I${DESTDIR}/usr/include
101.endif
102
103EXPORT_SYMS?= _${KMOD}
104
105.if defined(VFS_LKM)
106CFLAGS+= -DVFS_LKM -DMODVNOPS=${KMOD}vnops
107SRCS+=	vnode_if.h
108CLEANFILES+=	vnode_if.h vnode_if.c
109.endif
110
111.if defined(PSEUDO_LKM)
112CFLAGS+= -DPSEUDO_LKM
113.endif
114
115DPSRCS+= ${SRCS:M*.h}
116OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
117
118.if !defined(PROG)
119PROG=	${KMOD}.o
120.endif
121
122${PROG}: ${DPSRCS} ${OBJS} ${DPADD} 
123	${LD} -r ${LDFLAGS} -o tmp.o ${OBJS}
124.if defined(EXPORT_SYMS)
125	@rm -f symb.tmp
126	@for i in ${EXPORT_SYMS} ; do echo $$i >> symb.tmp ; done
127	symorder -c symb.tmp tmp.o
128	@rm -f symb.tmp
129.endif
130	mv tmp.o ${.TARGET}
131
132.if !defined(NOMAN)
133.include <bsd.man.mk>
134.if !defined(_MANPAGES) || empty(_MANPAGES)
135MAN1=	${KMOD}.4
136.endif
137
138.elif !target(maninstall)
139maninstall: _SUBDIR
140all-man:
141.endif
142
143_ILINKS=@ machine
144
145.MAIN: all
146all: ${_ILINKS} objwarn ${PROG} all-man _SUBDIR
147
148beforedepend: ${_ILINKS}
149
150# The search for the link targets works best if we are in a normal src
151# tree, and not too deeply below src/lkm.  If we are near "/", then
152# we may find /sys - this is harmless.  Other abnormal "sys" directories
153# found in the search are likely to cause problems.  If nothing is found,
154# then the links default to /usr/include and /usr/include/machine.
155${_ILINKS}:
156	@for up in ../.. ../../.. ; do \
157		case ${.TARGET} in \
158		machine) \
159			path=${.CURDIR}/$$up/sys/${MACHINE_ARCH}/include ; \
160			defaultpath=/usr/include/machine ;; \
161		@) \
162			path=${.CURDIR}/$$up/sys ; \
163			defaultpath=/usr/include ;; \
164		esac ; \
165		if [ -d $$path ] ; then break ; fi ; \
166		path=$$defaultpath ; \
167	done ; \
168	path=`(cd $$path && /bin/pwd)` ; \
169	${ECHO} ${.TARGET} "->" $$path ; \
170	ln -s $$path ${.TARGET}
171
172CLEANFILES+= ${KMOD} ${PROG} ${OBJS} ${_ILINKS}
173
174.if !target(install)
175.if !target(beforeinstall)
176beforeinstall:
177.endif
178.if !target(afterinstall)
179afterinstall:
180.endif
181
182realinstall: _SUBDIR
183	${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
184	    ${INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
185.if defined(LINKS) && !empty(LINKS)
186	@set ${LINKS}; \
187	while test $$# -ge 2; do \
188		l=${DESTDIR}$$1; \
189		shift; \
190		t=${DESTDIR}$$1; \
191		shift; \
192		${ECHO} $$t -\> $$l; \
193		rm -f $$t; \
194		ln ${LN_FLAGS} $$l $$t; \
195	done; true
196.endif
197
198install: afterinstall _SUBDIR
199.if !defined(NOMAN)
200afterinstall: realinstall maninstall
201.else
202afterinstall: realinstall
203.endif
204realinstall: beforeinstall
205.endif
206
207DISTRIBUTION?=	bin
208.if !target(distribute)
209distribute: _SUBDIR
210.for dist in ${DISTRIBUTION}
211	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
212.endfor
213.endif
214
215.if defined(NOTAGS)
216tags:
217.endif
218
219.if !target(tags)
220tags: ${SRCS} _SUBDIR
221.if defined(PROG)
222	@cd ${.CURDIR} && gtags ${GTAGSFLAGS}
223.if defined(HTML)
224	@cd ${.CURDIR} && htags ${HTAGSFLAGS}
225.endif
226.endif
227.endif
228
229
230.if !target(load)
231load:	${PROG}
232	${MODLOAD} -o ${KMOD} -e${KMOD} ${PROG}
233.endif
234
235.if !target(unload)
236unload:	${PROG}
237	${MODUNLOAD} -n ${KMOD}
238.endif
239
240KERN=	${.CURDIR}/../../sys/kern
241
242vnode_if.h:	${KERN}/vnode_if.sh ${KERN}/vnode_if.src
243	sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src
244
245./vnode_if.h:	vnode_if.h
246
247.include <bsd.obj.mk>
248.include <bsd.dep.mk>
249.include <bsd.kern.mk>
250