kmod.mk revision 25302
1178173Simp#	From: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2178173Simp#	$Id: bsd.kmod.mk,v 1.32 1997/04/28 00:02:22 fsmp Exp $
3178173Simp#
4178173Simp# The include file <bsd.kmod.mk> handles installing Loadable Kernel Modules.
5178173Simp# <bsd.kmod.mk> includes the file named "../Makefile.inc" if it exists,
6178173Simp# as well as the include file <bsd.obj.mk>, <bsd.dep.mk>, and
7178173Simp# may be <bsd.man.mk>
8178173Simp#
9178173Simp#
10178173Simp# +++ variables +++
11178173Simp#
12178173Simp# CLEANFILES	Additional files to remove for the clean and cleandir targets.
13178173Simp#
14178173Simp# DISTRIBUTION  Name of distribution. [bin]
15178173Simp#
16178173Simp# EXPORT_SYMS	???
17178173Simp#
18178173Simp# KERN		Main Kernel source directory. [${.CURDIR}/../../sys/kern]
19178173Simp#
20178173Simp# KMOD          The name of the loadable kernel module to build.
21178173Simp#
22178173Simp# KMODDIR	Base path for loadable kernel modules
23178173Simp#		(see lkm(4)). [/lkm]
24178173Simp#
25178173Simp# KMODOWN	LKM owner. [${BINOWN}]
26178173Simp#
27178173Simp# KMODGRP	LKM group. [${BINGRP}]
28178173Simp#
29178173Simp# KMODMODE	LKM mode. [${BINMODE}]
30178173Simp#
31178173Simp# LINKS		The list of LKM links; should be full pathnames, the
32178173Simp#               linked-to file coming first, followed by the linked
33178173Simp#               file.  The files are hard-linked.  For example, to link
34178173Simp#               /lkm/master and /lkm/meister, use:
35178173Simp#
36178173Simp#			LINKS=  /lkm/master /lkm/meister
37178173Simp#
38178173Simp# LN_FLAGS	Flags for ln(1) (see variable LINKS)
39178173Simp#
40178173Simp# MODLOAD	Command to load a kernel module [/sbin/modload]
41178173Simp#
42178173Simp# MODUNLOAD	Command to unload a kernel module [/sbin/modunload]
43178173Simp#
44178173Simp# NOMAN		LKM does not have a manual page if set.
45178173Simp#
46178173Simp# PROG          The name of the loadable kernel module to build. 
47178173Simp#		If not supplied, ${KMOD}.o is used.
48178173Simp#
49178173Simp# PSEUDO_LKM	???
50178173Simp#
51178173Simp# SRCS          List of source files 
52178173Simp#
53178173Simp# SUBDIR        A list of subdirectories that should be built as well.
54178173Simp#               Each of the targets will execute the same target in the
55178173Simp#               subdirectories.
56178173Simp#
57178173Simp# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk)
58178173Simp#
59178173Simp#
60178173Simp# +++ targets +++
61178173Simp#
62178173Simp#       distribute:
63178173Simp#               This is a variant of install, which will
64178173Simp#               put the stuff into the right "distribution".
65178173Simp#
66178173Simp# 	install:
67178173Simp#               install the program and its manual pages; if the Makefile
68178173Simp#               does not itself define the target install, the targets
69178173Simp#               beforeinstall and afterinstall may also be used to cause
70178173Simp#               actions immediately before and after the install target
71178173Simp#		is executed.
72178173Simp#
73178173Simp# 	load:	
74178173Simp#		Load LKM.
75178173Simp#
76178173Simp# 	tags:
77178173Simp#		Create a tags file for the source files.
78178173Simp#
79178173Simp# 	unload:
80178173Simp#		Unload LKM.
81178173Simp#
82178173Simp# bsd.obj.mk: clean, cleandir and obj
83178173Simp# bsd.dep.mk: depend
84178173Simp# bsd.man.mk: maninstall
85178173Simp#
86178173Simp
87178173SimpMODLOAD?=	/sbin/modload
88178173SimpMODUNLOAD?=	/sbin/modunload
89178173Simp
90178173Simp.if exists(${.CURDIR}/../Makefile.inc)
91178173Simp.include "${.CURDIR}/../Makefile.inc"
92178173Simp.endif
93178173Simp
94178173Simp.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
95178173Simp
96178173Simp#
97178173Simp# A temporary fix to survive SMP changes.   
98178173Simp#
99178173SimpCFLAGS+= -I.
100178173Simpbeforedepend: opt_smp.h opt_smp_invltlb.h
101178173Simp
102178173Simpopt_smp.h:
103178173Simp	touch opt_smp.h
104178173Simp
105178173Simpopt_smp_invltlb.h:
106178173Simp	touch opt_smp_invltlb.h
107178173Simp
108178173Simp#
109178173Simp# Assume that we are in /usr/src/foo/bar, so /sys is
110178173Simp# ${.CURDIR}/../../sys.  We don't bother adding a .PATH since nothing
111178173Simp# actually lives in /sys directly.
112182901Sgonzo#
113182901SgonzoCFLAGS+=${COPTS} -DKERNEL -DACTUALLY_LKM_NOT_KERNEL -I${.CURDIR}/../../sys \
114182901Sgonzo	${CWARNFLAGS}
115178173Simp
116178173SimpEXPORT_SYMS?= _${KMOD}
117178173Simp
118178173Simp.if defined(VFS_LKM)
119178173SimpCFLAGS+= -DVFS_LKM -DMODVNOPS=${KMOD}vnops -I.
120178173SimpSRCS+=	vnode_if.h
121178173SimpCLEANFILES+=	vnode_if.h vnode_if.c
122178173Simp.endif
123178173Simp
124178173Simp.if defined(PSEUDO_LKM)
125178173SimpCFLAGS+= -DPSEUDO_LKM
126178173Simp.endif
127178173Simp
128178173SimpDPSRCS+= ${SRCS:M*.h}
129178173SimpOBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
130178173Simp
131199762Sjhb.if !defined(PROG)
132178173SimpPROG=	${KMOD}.o
133178173Simp.endif
134178173Simp
135178173Simp${PROG}: ${DPSRCS} ${OBJS} ${DPADD} 
136178173Simp	${LD} -r ${LDFLAGS} -o tmp.o ${OBJS}
137178173Simp.if defined(EXPORT_SYMS)
138178173Simp	@rm -f symb.tmp
139178173Simp	@for i in ${EXPORT_SYMS} ; do echo $$i >> symb.tmp ; done
140178173Simp	symorder -c symb.tmp tmp.o
141178173Simp	@rm -f symb.tmp
142178173Simp.endif
143178173Simp	mv tmp.o ${.TARGET}
144178173Simp
145178173Simp.if !defined(NOMAN)
146178173Simp.include <bsd.man.mk>
147178173Simp.if !defined(_MANPAGES) || empty(_MANPAGES)
148178173SimpMAN1=	${KMOD}.4
149178173Simp.endif
150178173Simp
151178173Simp.elif !target(maninstall)
152178173Simpmaninstall: _SUBDIR
153178173Simpall-man:
154194342Sbz.endif
155178173Simp
156178173Simp.MAIN: all
157178173Simpall: objwarn ${PROG} all-man _SUBDIR
158178173Simp
159178173SimpCLEANFILES+=${PROG} ${OBJS} 
160178173Simp
161178173Simp.if !target(install)
162178173Simp.if !target(beforeinstall)
163178173Simpbeforeinstall:
164178173Simp.endif
165178173Simp.if !target(afterinstall)
166178173Simpafterinstall:
167178173Simp.endif
168178173Simp
169178173Simprealinstall: _SUBDIR
170178173Simp	${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
171178173Simp	    ${INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
172178173Simp.if defined(LINKS) && !empty(LINKS)
173178173Simp	@set ${LINKS}; \
174178173Simp	while test $$# -ge 2; do \
175178173Simp		l=${DESTDIR}$$1; \
176178173Simp		shift; \
177178173Simp		t=${DESTDIR}$$1; \
178178173Simp		shift; \
179178173Simp		${ECHO} $$t -\> $$l; \
180178173Simp		rm -f $$t; \
181178173Simp		ln ${LN_FLAGS} $$l $$t; \
182178173Simp	done; true
183178173Simp.endif
184178173Simp
185178173Simpinstall: afterinstall _SUBDIR
186178173Simp.if !defined(NOMAN)
187178173Simpafterinstall: realinstall maninstall
188178173Simp.else
189178173Simpafterinstall: realinstall
190178173Simp.endif
191178173Simprealinstall: beforeinstall
192178173Simp.endif
193178173Simp
194178173SimpDISTRIBUTION?=	bin
195178173Simp.if !target(distribute)
196178173Simpdistribute: _SUBDIR
197178173Simp	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${DISTRIBUTION} SHARED=copies
198178173Simp.endif
199178173Simp
200178173Simp.if defined(NOTAGS)
201178173Simptags:
202178173Simp.endif
203178173Simp
204178173Simp.if !target(tags)
205178173Simptags: ${SRCS} _SUBDIR
206178173Simp.if defined(PROG)
207178173Simp	@cd ${.CURDIR} && gtags ${GTAGSFLAGS}
208178173Simp.if defined(HTML)
209178173Simp	@cd ${.CURDIR} && htags ${HTAGSFLAGS}
210178173Simp.endif
211178173Simp.endif
212178173Simp.endif
213178173Simp
214178173Simp
215178173Simp.if !target(load)
216178173Simpload:	${PROG}
217178173Simp	${MODLOAD} -o ${KMOD} -e${KMOD} ${PROG}
218178173Simp.endif
219178173Simp
220178173Simp.if !target(unload)
221178173Simpunload:	${PROG}
222178173Simp	${MODUNLOAD} -n ${KMOD}
223178173Simp.endif
224178173Simp
225178173SimpKERN=	${.CURDIR}/../../sys/kern
226178173Simp
227178173Simpvnode_if.h:	${KERN}/vnode_if.sh ${KERN}/vnode_if.src
228178173Simp	sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src
229178173Simp
230178173Simp./vnode_if.h:	vnode_if.h
231178173Simp
232178173Simp.include <bsd.obj.mk>
233178173Simp.include <bsd.dep.mk>
234178173Simp.include <bsd.kern.mk>
235178173Simp