kmod.mk revision 25302
1#	From: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2#	$Id: bsd.kmod.mk,v 1.32 1997/04/28 00:02:22 fsmp Exp $
3#
4# The include file <bsd.kmod.mk> handles installing Loadable Kernel Modules.
5# <bsd.kmod.mk> includes the file named "../Makefile.inc" if it exists,
6# as well as the include file <bsd.obj.mk>, <bsd.dep.mk>, and
7# may be <bsd.man.mk>
8#
9#
10# +++ variables +++
11#
12# CLEANFILES	Additional files to remove for the clean and cleandir targets.
13#
14# DISTRIBUTION  Name of distribution. [bin]
15#
16# EXPORT_SYMS	???
17#
18# KERN		Main Kernel source directory. [${.CURDIR}/../../sys/kern]
19#
20# KMOD          The name of the loadable kernel module to build.
21#
22# KMODDIR	Base path for loadable kernel modules
23#		(see lkm(4)). [/lkm]
24#
25# KMODOWN	LKM owner. [${BINOWN}]
26#
27# KMODGRP	LKM group. [${BINGRP}]
28#
29# KMODMODE	LKM mode. [${BINMODE}]
30#
31# LINKS		The list of LKM links; should be full pathnames, the
32#               linked-to file coming first, followed by the linked
33#               file.  The files are hard-linked.  For example, to link
34#               /lkm/master and /lkm/meister, use:
35#
36#			LINKS=  /lkm/master /lkm/meister
37#
38# LN_FLAGS	Flags for ln(1) (see variable LINKS)
39#
40# MODLOAD	Command to load a kernel module [/sbin/modload]
41#
42# MODUNLOAD	Command to unload a kernel module [/sbin/modunload]
43#
44# NOMAN		LKM does not have a manual page if set.
45#
46# PROG          The name of the loadable kernel module to build. 
47#		If not supplied, ${KMOD}.o is used.
48#
49# PSEUDO_LKM	???
50#
51# SRCS          List of source files 
52#
53# SUBDIR        A list of subdirectories that should be built as well.
54#               Each of the targets will execute the same target in the
55#               subdirectories.
56#
57# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk)
58#
59#
60# +++ targets +++
61#
62#       distribute:
63#               This is a variant of install, which will
64#               put the stuff into the right "distribution".
65#
66# 	install:
67#               install the program and its manual pages; if the Makefile
68#               does not itself define the target install, the targets
69#               beforeinstall and afterinstall may also be used to cause
70#               actions immediately before and after the install target
71#		is executed.
72#
73# 	load:	
74#		Load LKM.
75#
76# 	tags:
77#		Create a tags file for the source files.
78#
79# 	unload:
80#		Unload LKM.
81#
82# bsd.obj.mk: clean, cleandir and obj
83# bsd.dep.mk: depend
84# bsd.man.mk: maninstall
85#
86
87MODLOAD?=	/sbin/modload
88MODUNLOAD?=	/sbin/modunload
89
90.if exists(${.CURDIR}/../Makefile.inc)
91.include "${.CURDIR}/../Makefile.inc"
92.endif
93
94.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
95
96#
97# A temporary fix to survive SMP changes.   
98#
99CFLAGS+= -I.
100beforedepend: opt_smp.h opt_smp_invltlb.h
101
102opt_smp.h:
103	touch opt_smp.h
104
105opt_smp_invltlb.h:
106	touch opt_smp_invltlb.h
107
108#
109# Assume that we are in /usr/src/foo/bar, so /sys is
110# ${.CURDIR}/../../sys.  We don't bother adding a .PATH since nothing
111# actually lives in /sys directly.
112#
113CFLAGS+=${COPTS} -DKERNEL -DACTUALLY_LKM_NOT_KERNEL -I${.CURDIR}/../../sys \
114	${CWARNFLAGS}
115
116EXPORT_SYMS?= _${KMOD}
117
118.if defined(VFS_LKM)
119CFLAGS+= -DVFS_LKM -DMODVNOPS=${KMOD}vnops -I.
120SRCS+=	vnode_if.h
121CLEANFILES+=	vnode_if.h vnode_if.c
122.endif
123
124.if defined(PSEUDO_LKM)
125CFLAGS+= -DPSEUDO_LKM
126.endif
127
128DPSRCS+= ${SRCS:M*.h}
129OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
130
131.if !defined(PROG)
132PROG=	${KMOD}.o
133.endif
134
135${PROG}: ${DPSRCS} ${OBJS} ${DPADD} 
136	${LD} -r ${LDFLAGS} -o tmp.o ${OBJS}
137.if defined(EXPORT_SYMS)
138	@rm -f symb.tmp
139	@for i in ${EXPORT_SYMS} ; do echo $$i >> symb.tmp ; done
140	symorder -c symb.tmp tmp.o
141	@rm -f symb.tmp
142.endif
143	mv tmp.o ${.TARGET}
144
145.if !defined(NOMAN)
146.include <bsd.man.mk>
147.if !defined(_MANPAGES) || empty(_MANPAGES)
148MAN1=	${KMOD}.4
149.endif
150
151.elif !target(maninstall)
152maninstall: _SUBDIR
153all-man:
154.endif
155
156.MAIN: all
157all: objwarn ${PROG} all-man _SUBDIR
158
159CLEANFILES+=${PROG} ${OBJS} 
160
161.if !target(install)
162.if !target(beforeinstall)
163beforeinstall:
164.endif
165.if !target(afterinstall)
166afterinstall:
167.endif
168
169realinstall: _SUBDIR
170	${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
171	    ${INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
172.if defined(LINKS) && !empty(LINKS)
173	@set ${LINKS}; \
174	while test $$# -ge 2; do \
175		l=${DESTDIR}$$1; \
176		shift; \
177		t=${DESTDIR}$$1; \
178		shift; \
179		${ECHO} $$t -\> $$l; \
180		rm -f $$t; \
181		ln ${LN_FLAGS} $$l $$t; \
182	done; true
183.endif
184
185install: afterinstall _SUBDIR
186.if !defined(NOMAN)
187afterinstall: realinstall maninstall
188.else
189afterinstall: realinstall
190.endif
191realinstall: beforeinstall
192.endif
193
194DISTRIBUTION?=	bin
195.if !target(distribute)
196distribute: _SUBDIR
197	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${DISTRIBUTION} SHARED=copies
198.endif
199
200.if defined(NOTAGS)
201tags:
202.endif
203
204.if !target(tags)
205tags: ${SRCS} _SUBDIR
206.if defined(PROG)
207	@cd ${.CURDIR} && gtags ${GTAGSFLAGS}
208.if defined(HTML)
209	@cd ${.CURDIR} && htags ${HTAGSFLAGS}
210.endif
211.endif
212.endif
213
214
215.if !target(load)
216load:	${PROG}
217	${MODLOAD} -o ${KMOD} -e${KMOD} ${PROG}
218.endif
219
220.if !target(unload)
221unload:	${PROG}
222	${MODUNLOAD} -n ${KMOD}
223.endif
224
225KERN=	${.CURDIR}/../../sys/kern
226
227vnode_if.h:	${KERN}/vnode_if.sh ${KERN}/vnode_if.src
228	sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src
229
230./vnode_if.h:	vnode_if.h
231
232.include <bsd.obj.mk>
233.include <bsd.dep.mk>
234.include <bsd.kern.mk>
235