Add stge(4).
[dragonfly.git] / sys / conf / kmod.mk
CommitLineData
984263bc
MD
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 $
a9295349 3# $DragonFly: src/sys/conf/kmod.mk,v 1.28 2006/11/07 06:43:22 dillon Exp $
984263bc
MD
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
c2c83759 61OBJCOPY?= objcopy
984263bc
MD
62KMODLOAD?= /sbin/kldload
63KMODUNLOAD?= /sbin/kldunload
64
65.include <bsd.init.mk>
66
67.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
68
69CFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS}
70CFLAGS+= -DKLD_MODULE
71
e5d18209 72# Don't use any standard include directories.
984263bc
MD
73# Since -nostdinc will annull any previous -I paths, we repeat all
74# such paths after -nostdinc. It doesn't seem to be possible to
75# add to the front of `make' variable.
e5d18209
MD
76#
77# Don't use -I- anymore, source-relative includes are desireable.
984263bc 78_ICFLAGS:= ${CFLAGS:M-I*}
e5d18209 79CFLAGS+= -nostdinc ${_ICFLAGS}
984263bc
MD
80
81# Add -I paths for system headers. Individual KLD makefiles don't
82# need any -I paths for this. Similar defaults for .PATH can't be
83# set because there are no standard paths for non-headers.
39619464 84#
f8334305 85# NOTE! Traditional architecture paths such as <i386/i386/blah.h>
a9295349
MD
86# must run through the "machine_base" softlink using
87# <machine_base/i386/blah.h>. An explicit cross-architecture path must
88# operate relative to /usr/src/sys using e.g. <arch/i386/i386/blah.h>
39619464 89#
f8334305 90CFLAGS+= -I. -I@
984263bc 91
a9295349
MD
92# Add -I paths for headers in the kernel build directory
93#
94.if defined(BUILDING_WITH_KERNEL)
95CFLAGS+= -I${BUILDING_WITH_KERNEL}
96CFLAGS+= -I${BUILDING_WITH_KERNEL}/include
97.endif
98
984263bc
MD
99# Add a -I path to standard headers like <stddef.h>. Use a relative
100# path to src/include if possible. If the @ symlink hasn't been built
101# yet, then we can't tell if the relative path exists. Add both the
102# potential relative path and an absolute path in that case.
103.if exists(@)
104.if exists(@/../include)
105CFLAGS+= -I@/../include
106.else
107CFLAGS+= -I${DESTDIR}/usr/include
108.endif
109.else # !@
110CFLAGS+= -I@/../include -I${DESTDIR}/usr/include
111.endif # @
112
deee08c4
SS
113.if defined(BUILDING_WITH_KERNEL) && \
114 exists(${BUILDING_WITH_KERNEL}/opt_global.h)
115CFLAGS+= -include ${BUILDING_WITH_KERNEL}/opt_global.h
116.endif
117
984263bc
MD
118CFLAGS+= ${DEBUG_FLAGS}
119
285638ea
SS
120.include <bsd.patch.mk>
121
145b818c 122OBJS+= ${SRCS:N*.h:N*.patch:R:S/$/.o/g}
984263bc
MD
123
124.if !defined(PROG)
125PROG= ${KMOD}.ko
126.endif
127
128${PROG}: ${KMOD}.kld ${KMODDEPS}
984263bc 129 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld ${KMODDEPS}
984263bc
MD
130
131.if defined(KMODDEPS)
132.for dep in ${KMODDEPS}
133CLEANFILES+= ${dep} __${dep}_hack_dep.c
134
135${dep}:
136 touch __${dep}_hack_dep.c
137 ${CC} -shared ${CFLAGS} -o ${dep} __${dep}_hack_dep.c
138.endfor
139.endif
140
141${KMOD}.kld: ${OBJS}
142 ${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS}
143
144.if !defined(NOMAN)
145.include <bsd.man.mk>
146.endif
147
a9295349
MD
148# links to platform and cpu architecture include files. If we are
149# building with a kernel these already exist in the kernel build dir.
150# '@' is a link to the system source.
151.if defined(BUILDING_WITH_KERNEL)
152_ILINKS=@
153.else
154_ILINKS=@ machine_base machine cpu_base cpu
155.endif
156
932f49b9
MD
157.if defined(ARCH)
158_ILINKS+=${ARCH}
159.endif
984263bc
MD
160
161all: objwarn ${PROG}
162.if !defined(NOMAN)
163all: _manpages
164.endif
165
166beforedepend: ${_ILINKS}
167# Ensure that the links exist without depending on it when it exists which
168# causes all the modules to be rebuilt when the directory pointed to changes.
169.for _link in ${_ILINKS}
170.if !exists(${.OBJDIR}/${_link})
171${OBJS}: ${_link}
172.endif
173.endfor
174
175# Search for kernel source tree in standard places.
932f49b9 176.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. ${.CURDIR}/../../../.. /sys /usr/src/sys
984263bc
MD
177.if !defined(SYSDIR) && exists(${_dir}/kern/)
178SYSDIR= ${_dir}
179.endif
180.endfor
181.if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
182.error "can't find kernel source tree"
183.endif
edbe133c 184S= ${SYSDIR}
984263bc 185
932f49b9
MD
186# path=`(cd $$path && /bin/pwd)` ;
187
984263bc
MD
188${_ILINKS}:
189 @case ${.TARGET} in \
190 machine) \
a9295349
MD
191 path=${SYSDIR}/machine/${MACHINE}/include ;; \
192 machine_base) \
193 path=${SYSDIR}/machine/${MACHINE} ;; \
194 cpu) \
195 path=${SYSDIR}/cpu/${MACHINE_ARCH}/include ;; \
196 cpu_base) \
197 path=${SYSDIR}/cpu/${MACHINE_ARCH} ;; \
984263bc
MD
198 @) \
199 path=${SYSDIR} ;; \
932f49b9
MD
200 arch_*) \
201 path=${.CURDIR}/${MACHINE_ARCH} ;; \
984263bc 202 esac ; \
984263bc 203 ${ECHO} ${.TARGET} "->" $$path ; \
062db326 204 ${LN} -s $$path ${.TARGET}
984263bc
MD
205
206CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
207
208.if !target(install)
209
210_INSTALLFLAGS:= ${INSTALLFLAGS}
211.for ie in ${INSTALLFLAGS_EDIT}
212_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
213.endfor
214
215.if !target(realinstall)
216realinstall: _kmodinstall
217.ORDER: beforeinstall _kmodinstall
218_kmodinstall:
c2c83759 219.if defined(INSTALLSTRIPPEDMODULES)
984263bc
MD
220 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
221 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
c2c83759
MD
222 ${OBJCOPY} --strip-debug ${DESTDIR}${KMODDIR}/${PROG}
223.else
224 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
225 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
226.endif
905fbe6b 227.endif # !target(realinstall)
984263bc
MD
228
229.include <bsd.links.mk>
230
231.if !defined(NOMAN)
232realinstall: _maninstall
233.ORDER: beforeinstall _maninstall
234.endif
235
905fbe6b 236.endif # !target(install)
984263bc
MD
237
238.if !target(load)
239load: ${PROG}
240 ${KMODLOAD} -v ./${KMOD}.ko
241.endif
242
243.if !target(unload)
244unload:
245 ${KMODUNLOAD} -v ${KMOD}
246.endif
247
1b29ad66 248.for _src in ${SRCS:Mopt_*.h} ${SRCS:Muse_*.h}
984263bc
MD
249CLEANFILES+= ${_src}
250.if !target(${_src})
1b29ad66
SS
251.if defined(BUILDING_WITH_KERNEL) && exists(${BUILDING_WITH_KERNEL}/${_src})
252${_src}: ${BUILDING_WITH_KERNEL}/${_src}
a9295349
MD
253# we do not have to copy these files any more, the kernel build
254# directory is included in the path now.
255# cp ${BUILDING_WITH_KERNEL}/${_src} ${.TARGET}
1b29ad66 256.else
984263bc
MD
257${_src}:
258 touch ${.TARGET}
1b29ad66 259.endif # BUILDING_WITH_KERNEL
984263bc
MD
260.endif
261.endfor
262
1f2de5d4
MD
263MFILES?= kern/bus_if.m kern/device_if.m bus/iicbus/iicbb_if.m \
264 bus/iicbus/iicbus_if.m bus/isa/isa_if.m dev/netif/mii_layer/miibus_if.m \
666d2603
JS
265 bus/pccard/card_if.m bus/pccard/power_if.m bus/pci/pci_if.m \
266 bus/pci/pcib_if.m \
1f2de5d4 267 bus/ppbus/ppbus_if.m bus/smbus/smbus_if.m bus/usb/usb_if.m \
984263bc
MD
268 dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
269 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \
f8e80553 270 libiconv/iconv_converter_if.m dev/agp/agp_if.m opencrypto/crypto_if.m
984263bc
MD
271
272.for _srcsrc in ${MFILES}
273.for _ext in c h
274.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
275CLEANFILES+= ${_src}
276.if !target(${_src})
277${_src}: @
278.if exists(@)
be59a52f 279${_src}: @/tools/makeobjops.awk @/${_srcsrc}
984263bc 280.endif
a9295349
MD
281
282.if defined(BUILDING_WITH_KERNEL) && \
283 exists(${BUILDING_WITH_KERNEL}/${_src})
284.else
145a9824 285 awk -f @/tools/makeobjops.awk -- -${_ext} @/${_srcsrc}
984263bc 286.endif
a9295349 287.endif
984263bc
MD
288.endfor # _src
289.endfor # _ext
290.endfor # _srcsrc
291
0961aa92
MD
292#.for _ext in c h
293#.if ${SRCS:Mvnode_if.${_ext}} != ""
294#CLEANFILES+= vnode_if.${_ext}
295#vnode_if.${_ext}: @
296#.if exists(@)
297#vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src
298#.endif
299# awk -f @/tools/vnode_if.awk -- -${_ext} @/kern/vnode_if.src
300#.endif
301#.endfor
984263bc
MD
302
303regress:
304
305.include <bsd.dep.mk>
306
307.if !exists(${DEPENDFILE})
308${OBJS}: ${SRCS:M*.h}
309.endif
310
311.include <bsd.obj.mk>
5e9c1061 312.include "bsd.kern.mk"
d4ef9227
JS
313
314# Behaves like MODULE_OVERRIDE
315.if defined(KLD_DEPS)
316all: _kdeps_all
317_kdeps_all: @
318.for _mdep in ${KLD_DEPS}
319 cd ${SYSDIR}/${_mdep} && make all
320.endfor
321depend: _kdeps_depend
322_kdeps_depend: @
323.for _mdep in ${KLD_DEPS}
324 cd ${SYSDIR}/${_mdep} && make depend
325.endfor
326install: _kdeps_install
327_kdeps_install: @
328.for _mdep in ${KLD_DEPS}
329 cd ${SYSDIR}/${_mdep} && make install
330.endfor
331clean: _kdeps_clean
332_kdeps_clean: @
333.for _mdep in ${KLD_DEPS}
334 cd ${SYSDIR}/${_mdep} && make clean
335.endfor
336.endif