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