xref: /freebsd/sys/conf/kmod.mk (revision 8e537d168674d6b65869f73c20813001af875738)
1#	From: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2#	$Id: bsd.kmod.mk,v 1.25 1996/08/31 14:46:58 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# 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 -Wunused -Wpointer-arith
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: _SUBDIR
138all-man:
139.endif
140
141.MAIN: all
142all: objwarn ${PROG} all-man _SUBDIR
143
144CLEANFILES+=${PROG} ${OBJS}
145
146.if !target(install)
147.if !target(beforeinstall)
148beforeinstall:
149.endif
150.if !target(afterinstall)
151afterinstall:
152.endif
153
154realinstall: _SUBDIR
155	${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
156	    ${INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
157.if defined(LINKS) && !empty(LINKS)
158	@set ${LINKS}; \
159	while test $$# -ge 2; do \
160		l=${DESTDIR}$$1; \
161		shift; \
162		t=${DESTDIR}$$1; \
163		shift; \
164		${ECHO} $$t -\> $$l; \
165		rm -f $$t; \
166		ln ${LN_FLAGS} $$l $$t; \
167	done; true
168.endif
169
170install: afterinstall _SUBDIR
171.if !defined(NOMAN)
172afterinstall: realinstall maninstall
173.else
174afterinstall: realinstall
175.endif
176realinstall: beforeinstall
177.endif
178
179DISTRIBUTION?=	bin
180.if !target(distribute)
181distribute: _SUBDIR
182	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${DISTRIBUTION} SHARED=copies
183.endif
184
185.if !target(tags)
186tags: ${SRCS} _SUBDIR
187.if defined(PROG)
188	-cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC} | \
189	    sed "s;\${.CURDIR}/;;" > tags
190.endif
191.endif
192
193
194.if !target(load)
195load:	${PROG}
196	/sbin/modload -o ${KMOD} -e${KMOD} ${PROG}
197.endif
198
199.if !target(unload)
200unload:	${PROG}
201	/sbin/modunload -n ${KMOD}
202.endif
203
204KERN=	${.CURDIR}/../../sys/kern
205
206vnode_if.h:	${KERN}/vnode_if.sh ${KERN}/vnode_if.src
207	sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src
208
209./vnode_if.h:	vnode_if.h
210
211.include <bsd.obj.mk>
212.include <bsd.dep.mk>
213