kmod.mk revision 15903
1#	From: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2#	$Id: bsd.kmod.mk,v 1.20 1996/04/29 15:37:30 wosch 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# NOMAN		LKM does not have a manual page if set.
41#
42# PROG          The name of the loadable kernel module to build. 
43#		If not supplied, ${KMOD} is used.
44#
45# PSEUDO_LKM	???
46#
47# SRCS          List of source files 
48#
49# SUBDIR        A list of subdirectories that should be built as well.
50#               Each of the targets will execute the same target in the
51#               subdirectories.
52#
53# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk)
54#
55#
56# +++ targets +++
57#
58#       distribute:
59#               This is a variant of install, which will
60#               put the stuff into the right "distribution".
61#
62# 	install:
63#               install the program and its manual pages; if the Makefile
64#               does not itself define the target install, the targets
65#               beforeinstall and afterinstall may also be used to cause
66#               actions immediately before and after the install target
67#		is executed.
68#
69# 	load:	
70#		Load LKM.
71#
72# 	tags:
73#		Create a tags file for the source files.
74#
75# 	unload:
76#		Unload LKM.
77#
78# bsd.obj.mk: clean, cleandir and obj
79# bsd.dep.mk: depend
80# bsd.man.mk: maninstall
81#
82
83.if exists(${.CURDIR}/../Makefile.inc)
84.include "${.CURDIR}/../Makefile.inc"
85.endif
86
87.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
88
89#
90# Assume that we are in /usr/src/foo/bar, so /sys is
91# ${.CURDIR}/../../sys.  We don't bother adding a .PATH since nothing
92# actually lives in /sys directly.
93#
94CWARNFLAGS?= -W -Wreturn-type -Wcomment -Wredundant-decls -Wimplicit \
95	-Wnested-externs -Wstrict-prototypes -Wmissing-prototypes \
96	-Winline
97
98CFLAGS+=${COPTS} -DKERNEL -DACTUALLY_LKM_NOT_KERNEL -I${.CURDIR}/../../sys \
99	${CWARNFLAGS}
100
101EXPORT_SYMS?= _${KMOD}
102
103.if defined(VFS_LKM)
104CFLAGS+= -DVFS_LKM -DMODVNOPS=${KMOD}vnops -I.
105SRCS+=	vnode_if.h
106CLEANFILES+=	vnode_if.h vnode_if.c
107.endif
108
109.if defined(PSEUDO_LKM)
110CFLAGS+= -DPSEUDO_LKM
111.endif
112
113DPSRCS+= ${SRCS:M*.h}
114OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
115
116.if !defined(PROG)
117PROG=	${KMOD}.o
118.endif
119
120${PROG}: ${DPSRCS} ${OBJS} ${DPADD} 
121	${LD} -r ${LDFLAGS} -o tmp.o ${OBJS}
122.if defined(EXPORT_SYMS)
123	@rm -f symb.tmp
124	@for i in ${EXPORT_SYMS} ; do echo $$i >> symb.tmp ; done
125	symorder -c symb.tmp tmp.o
126	@rm -f symb.tmp
127.endif
128	mv tmp.o ${.TARGET}
129
130.if !defined(NOMAN)
131.include <bsd.man.mk>
132.if !defined(_MANPAGES) || empty(_MANPAGES)
133MAN1=	${KMOD}.4
134.endif
135
136.elif !target(maninstall)
137maninstall:
138all-man:
139.endif
140
141_PROGSUBDIR: .USE
142.if defined(SUBDIR) && !empty(SUBDIR)
143	@for entry in ${SUBDIR}; do \
144		(${ECHODIR} "===> $$entry"; \
145		if test -d ${.CURDIR}/$${entry}.${MACHINE}; then \
146			cd ${.CURDIR}/$${entry}.${MACHINE}; \
147		else \
148			cd ${.CURDIR}/$${entry}; \
149		fi; \
150		${MAKE} ${.TARGET:S/realinstall/install/:S/.depend/depend/}); \
151	done
152.endif
153
154.MAIN: all
155all: ${PROG} all-man _PROGSUBDIR
156
157CLEANFILES+=${PROG} ${OBJS} 
158
159.if !target(install)
160.if !target(beforeinstall)
161beforeinstall:
162.endif
163.if !target(afterinstall)
164afterinstall:
165.endif
166
167realinstall: _PROGSUBDIR
168	${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
169	    ${INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
170.if defined(LINKS) && !empty(LINKS)
171	@set ${LINKS}; \
172	while test $$# -ge 2; do \
173		l=${DESTDIR}$$1; \
174		shift; \
175		t=${DESTDIR}$$1; \
176		shift; \
177		${ECHO} $$t -\> $$l; \
178		rm -f $$t; \
179		ln ${LN_FLAGS} $$l $$t; \
180	done; true
181.endif
182
183install: afterinstall
184.if !defined(NOMAN)
185afterinstall: realinstall maninstall
186.else
187afterinstall: realinstall
188.endif
189realinstall: beforeinstall
190.endif
191
192DISTRIBUTION?=	bin
193.if !target(distribute)
194distribute:
195	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${DISTRIBUTION} SHARED=copies
196.endif
197
198.if !target(tags)
199tags: ${SRCS} _PROGSUBDIR
200.if defined(PROG)
201	-cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC} | \
202	    sed "s;\${.CURDIR}/;;" > tags
203.endif
204.endif
205
206
207.if !target(load)
208load:	${PROG}
209	/sbin/modload -o ${KMOD} -e${KMOD} ${PROG}
210.endif
211
212.if !target(unload)
213unload:	${PROG}
214	/sbin/modunload -n ${KMOD}
215.endif
216
217KERN=	${.CURDIR}/../../sys/kern
218
219vnode_if.h:	${KERN}/vnode_if.sh ${KERN}/vnode_if.src
220	sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src
221
222./vnode_if.h:	vnode_if.h
223
224_DEPSUBDIR=	_PROGSUBDIR
225_SUBDIRUSE:	_PROGSUBDIR
226.include <bsd.obj.mk>
227.include <bsd.dep.mk>
228
229