xref: /dragonfly/sys/conf/kmod.mk (revision 1de703da)
1#	From: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2# $FreeBSD: src/sys/conf/kmod.mk,v 1.82.2.15 2003/02/10 13:11:50 nyan Exp $
3# $DragonFly: src/sys/conf/kmod.mk,v 1.2 2003/06/17 04:28:20 dillon Exp $
4#
5# The include file <bsd.kmod.mk> handles installing Kernel Loadable Device
6# drivers (KLD's).
7#
8#
9# +++ variables +++
10#
11# CLEANFILES	Additional files to remove for the clean and cleandir targets.
12#
13# KMOD          The name of the kernel module to build.
14#
15# KMODDIR	Base path for kernel modules (see kld(4)). [/modules]
16#
17# KMODOWN	KLD owner. [${BINOWN}]
18#
19# KMODGRP	KLD group. [${BINGRP}]
20#
21# KMODMODE	KLD mode. [${BINMODE}]
22#
23# KMODLOAD	Command to load a kernel module [/sbin/kldload]
24#
25# KMODUNLOAD	Command to unload a kernel module [/sbin/kldunload]
26#
27# NOMAN		KLD does not have a manual page if set.
28#
29# PROG          The name of the kernel module to build.
30#		If not supplied, ${KMOD}.o is used.
31#
32# SRCS          List of source files
33#
34# KMODDEPS	List of modules which this one is dependant on
35#
36# DESTDIR	Change the tree where the module gets installed. [not set]
37#
38# MFILES	Optionally a list of interfaces used by the module.
39#		This file contains a default list of interfaces.
40#
41# +++ targets +++
42#
43# 	install:
44#               install the kernel module and its manual pages; if the Makefile
45#               does not itself define the target install, the targets
46#               beforeinstall and afterinstall may also be used to cause
47#               actions immediately before and after the install target
48#		is executed.
49#
50# 	load:
51#		Load KLD.
52#
53# 	unload:
54#		Unload KLD.
55#
56# bsd.obj.mk: clean, cleandir and obj
57# bsd.dep.mk: cleandepend, depend and tags
58# bsd.man.mk: maninstall
59#
60
61KMODLOAD?=	/sbin/kldload
62KMODUNLOAD?=	/sbin/kldunload
63
64.include <bsd.init.mk>
65
66.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
67
68CFLAGS+=	${COPTS} -D_KERNEL ${CWARNFLAGS}
69CFLAGS+=	-DKLD_MODULE
70
71# Don't use any standard or source-relative include directories.
72# Since -nostdinc will annull any previous -I paths, we repeat all
73# such paths after -nostdinc.  It doesn't seem to be possible to
74# add to the front of `make' variable.
75_ICFLAGS:=	${CFLAGS:M-I*}
76CFLAGS+=	-nostdinc -I- ${_ICFLAGS}
77
78# Add -I paths for system headers.  Individual KLD makefiles don't
79# need any -I paths for this.  Similar defaults for .PATH can't be
80# set because there are no standard paths for non-headers.
81CFLAGS+=	-I. -I@
82
83# Add a -I path to standard headers like <stddef.h>.  Use a relative
84# path to src/include if possible.  If the @ symlink hasn't been built
85# yet, then we can't tell if the relative path exists.  Add both the
86# potential relative path and an absolute path in that case.
87.if exists(@)
88.if exists(@/../include)
89CFLAGS+=	-I@/../include
90.else
91CFLAGS+=	-I${DESTDIR}/usr/include
92.endif
93.else # !@
94CFLAGS+=	-I@/../include -I${DESTDIR}/usr/include
95.endif # @
96
97CFLAGS+=	${DEBUG_FLAGS}
98
99.if ${OBJFORMAT} == elf
100CLEANFILES+=	setdef0.c setdef1.c setdefs.h
101CLEANFILES+=	setdef0.o setdef1.o
102.endif
103
104OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
105
106.if !defined(PROG)
107PROG=	${KMOD}.ko
108.endif
109
110${PROG}: ${KMOD}.kld ${KMODDEPS}
111.if ${OBJFORMAT} == elf
112	gensetdefs ${KMOD}.kld
113	${CC} ${CFLAGS} -c setdef0.c
114	${CC} ${CFLAGS} -c setdef1.c
115	${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} setdef0.o ${KMOD}.kld setdef1.o ${KMODDEPS}
116.else
117	${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld ${KMODDEPS}
118.endif
119
120.if defined(KMODDEPS)
121.for dep in ${KMODDEPS}
122CLEANFILES+=	${dep} __${dep}_hack_dep.c
123
124${dep}:
125	touch __${dep}_hack_dep.c
126	${CC} -shared ${CFLAGS} -o ${dep} __${dep}_hack_dep.c
127.endfor
128.endif
129
130${KMOD}.kld: ${OBJS}
131	${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS}
132
133.if !defined(NOMAN)
134.include <bsd.man.mk>
135.endif
136
137_ILINKS=@ machine
138
139all: objwarn ${PROG}
140.if !defined(NOMAN)
141all: _manpages
142.endif
143
144beforedepend: ${_ILINKS}
145# Ensure that the links exist without depending on it when it exists which
146# causes all the modules to be rebuilt when the directory pointed to changes.
147.for _link in ${_ILINKS}
148.if !exists(${.OBJDIR}/${_link})
149${OBJS}: ${_link}
150.endif
151.endfor
152
153# Search for kernel source tree in standard places.
154.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys
155.if !defined(SYSDIR) && exists(${_dir}/kern/)
156SYSDIR=	${_dir}
157.endif
158.endfor
159.if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
160.error "can't find kernel source tree"
161.endif
162
163${_ILINKS}:
164	@case ${.TARGET} in \
165	machine) \
166		path=${SYSDIR}/${MACHINE_ARCH}/include ;; \
167	@) \
168		path=${SYSDIR} ;; \
169	esac ; \
170	path=`(cd $$path && /bin/pwd)` ; \
171	${ECHO} ${.TARGET} "->" $$path ; \
172	ln -s $$path ${.TARGET}
173
174CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
175
176.if !target(install)
177
178_INSTALLFLAGS:=	${INSTALLFLAGS}
179.for ie in ${INSTALLFLAGS_EDIT}
180_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
181.endfor
182
183.if !target(realinstall)
184realinstall: _kmodinstall
185.ORDER: beforeinstall _kmodinstall
186_kmodinstall:
187	${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
188	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
189.endif !target(realinstall)
190
191.include <bsd.links.mk>
192
193.if !defined(NOMAN)
194realinstall: _maninstall
195.ORDER: beforeinstall _maninstall
196.endif
197
198.endif !target(install)
199
200.if !target(load)
201load:	${PROG}
202	${KMODLOAD} -v ./${KMOD}.ko
203.endif
204
205.if !target(unload)
206unload:
207	${KMODUNLOAD} -v ${KMOD}
208.endif
209
210.for _src in ${SRCS:Mopt_*.h}
211CLEANFILES+=	${_src}
212.if !target(${_src})
213${_src}:
214	touch ${.TARGET}
215.endif
216.endfor
217
218MFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \
219    dev/iicbus/iicbus_if.m isa/isa_if.m dev/mii/miibus_if.m \
220    dev/pccard/card_if.m dev/pccard/power_if.m pci/pci_if.m \
221    dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m dev/usb/usb_if.m \
222    dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
223    dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \
224    libkern/iconv_converter_if.m pci/agp_if.m opencrypto/crypto_if.m \
225    pc98/pc98/canbus_if.m
226
227.for _srcsrc in ${MFILES}
228.for _ext in c h
229.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
230CLEANFILES+=	${_src}
231.if !target(${_src})
232${_src}: @
233.if exists(@)
234${_src}: @/kern/makeops.pl @/${_srcsrc}
235.endif
236	perl @/kern/makeops.pl -${_ext} @/${_srcsrc}
237.endif
238.endfor # _src
239.endfor # _ext
240.endfor # _srcsrc
241
242.for _ext in c h
243.if ${SRCS:Mvnode_if.${_ext}} != ""
244CLEANFILES+=	vnode_if.${_ext}
245vnode_if.${_ext}: @
246.if exists(@)
247vnode_if.${_ext}: @/kern/vnode_if.pl @/kern/vnode_if.src
248.endif
249	perl @/kern/vnode_if.pl -${_ext} @/kern/vnode_if.src
250.endif
251.endfor
252
253regress:
254
255.include <bsd.dep.mk>
256
257.if !exists(${DEPENDFILE})
258${OBJS}: ${SRCS:M*.h}
259.endif
260
261.include <bsd.obj.mk>
262.include <bsd.kern.mk>
263