kmod.mk revision 38749
1#	From: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2#	$Id: bsd.kmod.mk,v 1.51 1998/08/08 07:02:07 peter Exp $
3#
4# The include file <bsd.kmod.mk> handles installing Loadable Kernel Modules.
5#
6#
7# +++ variables +++
8#
9# CLEANFILES	Additional files to remove for the clean and cleandir targets.
10#
11# DISTRIBUTION  Name of distribution. [bin]
12#
13# EXPORT_SYMS	???
14#
15# KERN		Main Kernel source directory. [${.CURDIR}/../../sys/kern]
16#
17# KMOD          The name of the loadable kernel module to build.
18#
19# KMODDIR	Base path for loadable kernel modules
20#		(see lkm(4)). [/lkm]
21#
22# KMODOWN	LKM owner. [${BINOWN}]
23#
24# KMODGRP	LKM group. [${BINGRP}]
25#
26# KMODMODE	LKM mode. [${BINMODE}]
27#
28# LINKS		The list of LKM links; should be full pathnames, the
29#               linked-to file coming first, followed by the linked
30#               file.  The files are hard-linked.  For example, to link
31#               /lkm/master and /lkm/meister, use:
32#
33#			LINKS=  /lkm/master /lkm/meister
34#
35# LN_FLAGS	Flags for ln(1) (see variable LINKS)
36#
37# MODLOAD	Command to load a kernel module [/sbin/modload]
38#
39# MODUNLOAD	Command to unload a kernel module [/sbin/modunload]
40#
41# NOMAN		LKM does not have a manual page if set.
42#
43# PROG          The name of the loadable kernel module to build. 
44#		If not supplied, ${KMOD}.o is used.
45#
46# PSEUDO_LKM	???
47#
48# SRCS          List of source files 
49#
50# SUBDIR        A list of subdirectories that should be built as well.
51#               Each of the targets will execute the same target in the
52#               subdirectories.
53#
54# DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk)
55#
56#
57# +++ targets +++
58#
59#       distribute:
60#               This is a variant of install, which will
61#               put the stuff into the right "distribution".
62#
63# 	install:
64#               install the program and its manual pages; if the Makefile
65#               does not itself define the target install, the targets
66#               beforeinstall and afterinstall may also be used to cause
67#               actions immediately before and after the install target
68#		is executed.
69#
70# 	load:	
71#		Load LKM.
72#
73# 	unload:
74#		Unload LKM.
75#
76# bsd.obj.mk: clean, cleandir and obj
77# bsd.dep.mk: cleandepend, depend and tags
78# bsd.man.mk: maninstall
79#
80
81MODLOAD?=	/sbin/modload
82MODUNLOAD?=	/sbin/modunload
83
84.if !target(__initialized__)
85__initialized__:
86.if exists(${.CURDIR}/../Makefile.inc)
87.include "${.CURDIR}/../Makefile.inc"
88.endif
89.endif
90
91.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
92
93CFLAGS+=	${COPTS} -DKERNEL -DACTUALLY_LKM_NOT_KERNEL ${CWARNFLAGS}
94
95# Don't use any standard or source-relative include directories.
96# Since -nostdinc will annull any previous -I paths, we repeat all
97# such paths after -nostdinc.  It doesn't seem to be possible to
98# add to the front of `make' variable.
99_ICFLAGS:=	${CFLAGS:M-I*}
100CFLAGS+=	-nostdinc -I- ${_ICFLAGS}
101
102# Add -I paths for system headers.  Individual LKM makefiles don't
103# need any -I paths for this.  Similar defaults for .PATH can't be
104# set because there are no standard paths for non-headers.
105CFLAGS+=	-I${.OBJDIR} -I${.OBJDIR}/@
106
107# XXX this is now dubious.
108.if defined(DESTDIR)
109CFLAGS+=	-I${DESTDIR}/usr/include
110.endif
111
112# XXX temporary until we build ELF kernels.
113CFLAGS+=	-aout
114LDFLAGS+=	-aout
115
116.if defined(NOSHARED) && ( ${NOSHARED} != "no" && ${NOSHARED} != "NO" )
117LDFLAGS+= -static
118.endif
119
120EXPORT_SYMS?= _${KMOD}
121
122.if defined(VFS_LKM)
123CFLAGS+= -DVFS_LKM -DMODVNOPS=${KMOD}vnops
124SRCS+=	vnode_if.h
125CLEANFILES+=	vnode_if.h vnode_if.c
126.endif
127
128.if defined(PSEUDO_LKM)
129CFLAGS+= -DPSEUDO_LKM
130.endif
131
132OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
133
134.if !defined(PROG)
135PROG=	${KMOD}.o
136.endif
137
138${PROG}: ${OBJS} ${DPADD} 
139	${LD} -r ${LDFLAGS:N-static} -o tmp.o ${OBJS}
140.if defined(EXPORT_SYMS)
141	rm -f symb.tmp
142	for i in ${EXPORT_SYMS} ; do echo $$i >> symb.tmp ; done
143	symorder -c symb.tmp tmp.o
144	rm -f symb.tmp
145.endif
146	mv tmp.o ${.TARGET}
147
148.if !defined(NOMAN)
149.include <bsd.man.mk>
150.if !defined(_MANPAGES) || empty(_MANPAGES)
151MAN1=	${KMOD}.4
152.endif
153
154.elif !target(maninstall)
155maninstall: _SUBDIR
156all-man:
157.endif
158
159_ILINKS=@ machine
160
161.MAIN: all
162all: objwarn ${PROG} all-man _SUBDIR
163
164beforedepend ${OBJS}: ${_ILINKS}
165
166# The search for the link targets works best if we are in a normal src
167# tree, and not too deeply below src/lkm.  If we are near "/", then
168# we may find /sys - this is harmless.  Other abnormal "sys" directories
169# found in the search are likely to cause problems.  If nothing is found,
170# then the links default to /usr/include and /usr/include/machine.
171${_ILINKS}:
172	@for up in ../.. ../../.. ; do \
173		case ${.TARGET} in \
174		machine) \
175			path=${.CURDIR}/$$up/sys/${MACHINE_ARCH}/include ; \
176			defaultpath=/usr/include/machine ;; \
177		@) \
178			path=${.CURDIR}/$$up/sys ; \
179			defaultpath=/usr/include ;; \
180		esac ; \
181		if [ -d $$path ] ; then break ; fi ; \
182		path=$$defaultpath ; \
183	done ; \
184	path=`(cd $$path && /bin/pwd)` ; \
185	${ECHO} ${.TARGET} "->" $$path ; \
186	ln -s $$path ${.TARGET}
187
188CLEANFILES+= ${KMOD} ${PROG} ${OBJS} ${_ILINKS} lkm_verify_tmp symb.tmp tmp.o
189
190.if !target(install)
191.if !target(beforeinstall)
192beforeinstall:
193.endif
194.if !target(afterinstall)
195afterinstall:
196.endif
197
198realinstall: _SUBDIR
199	${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
200	    ${INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
201.if defined(LINKS) && !empty(LINKS)
202	@set ${LINKS}; \
203	while test $$# -ge 2; do \
204		l=${DESTDIR}$$1; \
205		shift; \
206		t=${DESTDIR}$$1; \
207		shift; \
208		${ECHO} $$t -\> $$l; \
209		rm -f $$t; \
210		ln ${LN_FLAGS} $$l $$t; \
211	done; true
212.endif
213
214install: afterinstall _SUBDIR
215.if !defined(NOMAN)
216afterinstall: realinstall maninstall
217.else
218afterinstall: realinstall
219.endif
220realinstall: beforeinstall
221.endif
222
223DISTRIBUTION?=	bin
224.if !target(distribute)
225distribute: _SUBDIR
226.for dist in ${DISTRIBUTION}
227	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
228.endfor
229.endif
230
231.if !target(load)
232load:	${PROG}
233	${MODLOAD} -o ${KMOD} -e${KMOD} ${PROG}
234.endif
235
236.if !target(unload)
237unload:	${PROG}
238	${MODUNLOAD} -n ${KMOD}
239.endif
240
241KERN=	${.CURDIR}/../../sys/kern
242
243vnode_if.h:	${KERN}/vnode_if.sh ${KERN}/vnode_if.src
244	sh ${KERN}/vnode_if.sh ${KERN}/vnode_if.src
245
246_sysregress:	${_INLINKS} ${PROG}
247	ld -A /sys/compile/LKM/kernel ${PROG} ${DEPLKMS} -o lkm_verify_tmp
248	rm lkm_verify_tmp
249
250regress:	_sysregress
251
252.include <bsd.dep.mk>
253
254.if !exists(${DEPENDFILE})
255${OBJS}: ${SRCS:M*.h}
256.endif
257
258.include <bsd.obj.mk>
259
260.include <bsd.kern.mk>
261