kmod.mk revision 31074
1#	From: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2#	$Id: bsd.kmod.mk,v 1.40 1997/07/21 16:04:41 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# 	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
93#
94# Assume that we are in /usr/src/foo/bar, so /sys is
95# ${.CURDIR}/../../sys.  We don't bother adding a .PATH since nothing
96# actually lives in /sys directly.
97#
98CFLAGS+=${COPTS} -DKERNEL -DACTUALLY_LKM_NOT_KERNEL -I${.CURDIR}/../../sys \
99	${CWARNFLAGS}
100.if defined(DESTDIR)
101CFLAGS+=	-I${DESTDIR}/usr/include
102.endif
103
104EXPORT_SYMS?= _${KMOD}
105
106.if defined(VFS_LKM)
107CFLAGS+= -DVFS_LKM -DMODVNOPS=${KMOD}vnops -I.
108SRCS+=	vnode_if.h
109CLEANFILES+=	vnode_if.h vnode_if.c
110.endif
111
112.if defined(PSEUDO_LKM)
113CFLAGS+= -DPSEUDO_LKM
114.endif
115
116DPSRCS+= ${SRCS:M*.h}
117OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
118
119.if !defined(PROG)
120PROG=	${KMOD}.o
121.endif
122
123${PROG}: ${DPSRCS} ${OBJS} ${DPADD} 
124	${LD} -r ${LDFLAGS} -o tmp.o ${OBJS}
125.if defined(EXPORT_SYMS)
126	@rm -f symb.tmp
127	@for i in ${EXPORT_SYMS} ; do echo $$i >> symb.tmp ; done
128	symorder -c symb.tmp tmp.o
129	@rm -f symb.tmp
130.endif
131	mv tmp.o ${.TARGET}
132
133.if !defined(NOMAN)
134.include <bsd.man.mk>
135.if !defined(_MANPAGES) || empty(_MANPAGES)
136MAN1=	${KMOD}.4
137.endif
138
139.elif !target(maninstall)
140maninstall: _SUBDIR
141all-man:
142.endif
143
144.MAIN: all
145all: objwarn ${PROG} all-man _SUBDIR
146
147CLEANFILES+= ${KMOD} ${PROG} ${OBJS} 
148
149.if !target(install)
150.if !target(beforeinstall)
151beforeinstall:
152.endif
153.if !target(afterinstall)
154afterinstall:
155.endif
156
157realinstall: _SUBDIR
158	${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
159	    ${INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
160.if defined(LINKS) && !empty(LINKS)
161	@set ${LINKS}; \
162	while test $$# -ge 2; do \
163		l=${DESTDIR}$$1; \
164		shift; \
165		t=${DESTDIR}$$1; \
166		shift; \
167		${ECHO} $$t -\> $$l; \
168		rm -f $$t; \
169		ln ${LN_FLAGS} $$l $$t; \
170	done; true
171.endif
172
173install: afterinstall _SUBDIR
174.if !defined(NOMAN)
175afterinstall: realinstall maninstall
176.else
177afterinstall: realinstall
178.endif
179realinstall: beforeinstall
180.endif
181
182DISTRIBUTION?=	bin
183.if !target(distribute)
184distribute: _SUBDIR
185.for dist in ${DISTRIBUTION}
186	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
187.endfor
188.endif
189
190.if defined(NOTAGS)
191tags:
192.endif
193
194.if !target(tags)
195tags: ${SRCS} _SUBDIR
196.if defined(PROG)
197	@cd ${.CURDIR} && gtags ${GTAGSFLAGS}
198.if defined(HTML)
199	@cd ${.CURDIR} && htags ${HTAGSFLAGS}
200.endif
201.endif
202.endif
203
204
205.if !target(load)
206load:	${PROG}
207	${MODLOAD} -o ${KMOD} -e${KMOD} ${PROG}
208.endif
209
210.if !target(unload)
211unload:	${PROG}
212	${MODUNLOAD} -n ${KMOD}
213.endif
214
215KERN=	${.CURDIR}/../../sys/kern
216
217vnode_if.h:	${KERN}/vnode_if.sh ${KERN}/vnode_if.src
218	sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src
219
220./vnode_if.h:	vnode_if.h
221
222.include <bsd.obj.mk>
223.include <bsd.dep.mk>
224.include <bsd.kern.mk>
225