nrelease: Exclude distfiles as well when we tar pkgsrc.
[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 $
676159d4 3# $DragonFly: src/sys/conf/kmod.mk,v 1.35 2008/08/27 16:35:19 hasso 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}
a7f2f51f
SZ
96_MACHINE_FWD= ${BUILDING_WITH_KERNEL}
97.else
98.if defined(MAKEOBJDIRPREFIX)
99_MACHINE_FWD= ${MAKEOBJDIRPREFIX}/${SYSDIR}/forwarder_${MACHINE_ARCH}
100.else
101_MACHINE_FWD= ${.OBJDIR}/forwarder_${MACHINE_ARCH}
102CLEANDIRS+= ${_MACHINE_FWD}
103.endif
a9295349 104.endif
a7f2f51f
SZ
105CFLAGS+= -I${_MACHINE_FWD}/include
106.include "kern.fwd.mk"
a9295349 107
984263bc
MD
108# Add a -I path to standard headers like <stddef.h>. Use a relative
109# path to src/include if possible. If the @ symlink hasn't been built
110# yet, then we can't tell if the relative path exists. Add both the
111# potential relative path and an absolute path in that case.
112.if exists(@)
113.if exists(@/../include)
114CFLAGS+= -I@/../include
115.else
116CFLAGS+= -I${DESTDIR}/usr/include
117.endif
118.else # !@
119CFLAGS+= -I@/../include -I${DESTDIR}/usr/include
120.endif # @
121
deee08c4
SS
122.if defined(BUILDING_WITH_KERNEL) && \
123 exists(${BUILDING_WITH_KERNEL}/opt_global.h)
124CFLAGS+= -include ${BUILDING_WITH_KERNEL}/opt_global.h
125.endif
126
984263bc
MD
127CFLAGS+= ${DEBUG_FLAGS}
128
285638ea
SS
129.include <bsd.patch.mk>
130
145b818c 131OBJS+= ${SRCS:N*.h:N*.patch:R:S/$/.o/g}
984263bc
MD
132
133.if !defined(PROG)
134PROG= ${KMOD}.ko
135.endif
136
8d565796 137.if ${MACHINE_ARCH} != amd64
984263bc 138${PROG}: ${KMOD}.kld ${KMODDEPS}
984263bc 139 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld ${KMODDEPS}
8d565796 140.endif
984263bc
MD
141
142.if defined(KMODDEPS)
143.for dep in ${KMODDEPS}
144CLEANFILES+= ${dep} __${dep}_hack_dep.c
145
146${dep}:
147 touch __${dep}_hack_dep.c
148 ${CC} -shared ${CFLAGS} -o ${dep} __${dep}_hack_dep.c
149.endfor
150.endif
151
8d565796 152.if ${MACHINE_ARCH} != amd64
984263bc
MD
153${KMOD}.kld: ${OBJS}
154 ${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS}
8d565796
MD
155.else
156${PROG}: ${OBJS}
157.endif
984263bc
MD
158
159.if !defined(NOMAN)
160.include <bsd.man.mk>
161.endif
162
a9295349
MD
163# links to platform and cpu architecture include files. If we are
164# building with a kernel these already exist in the kernel build dir.
165# '@' is a link to the system source.
166.if defined(BUILDING_WITH_KERNEL)
167_ILINKS=@
168.else
169_ILINKS=@ machine_base machine cpu_base cpu
170.endif
171
932f49b9
MD
172.if defined(ARCH)
173_ILINKS+=${ARCH}
174.endif
984263bc 175
82f3e8c4 176all: objwarn fwheaders ${PROG}
984263bc
MD
177.if !defined(NOMAN)
178all: _manpages
179.endif
180
82f3e8c4
SS
181beforedepend: fwheaders
182fwheaders: ${_ILINKS} ${FORWARD_HEADERS_COOKIE}
984263bc
MD
183# Ensure that the links exist without depending on it when it exists which
184# causes all the modules to be rebuilt when the directory pointed to changes.
185.for _link in ${_ILINKS}
186.if !exists(${.OBJDIR}/${_link})
187${OBJS}: ${_link}
188.endif
189.endfor
190
191# Search for kernel source tree in standard places.
932f49b9 192.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. ${.CURDIR}/../../../.. /sys /usr/src/sys
984263bc
MD
193.if !defined(SYSDIR) && exists(${_dir}/kern/)
194SYSDIR= ${_dir}
195.endif
196.endfor
197.if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
198.error "can't find kernel source tree"
199.endif
edbe133c 200S= ${SYSDIR}
984263bc 201
932f49b9
MD
202# path=`(cd $$path && /bin/pwd)` ;
203
984263bc
MD
204${_ILINKS}:
205 @case ${.TARGET} in \
206 machine) \
0955fd91 207 path=${SYSDIR}/platform/${MACHINE_PLATFORM}/include ;; \
a9295349 208 machine_base) \
0955fd91 209 path=${SYSDIR}/platform/${MACHINE_PLATFORM} ;; \
a9295349
MD
210 cpu) \
211 path=${SYSDIR}/cpu/${MACHINE_ARCH}/include ;; \
212 cpu_base) \
213 path=${SYSDIR}/cpu/${MACHINE_ARCH} ;; \
984263bc
MD
214 @) \
215 path=${SYSDIR} ;; \
932f49b9
MD
216 arch_*) \
217 path=${.CURDIR}/${MACHINE_ARCH} ;; \
984263bc 218 esac ; \
984263bc 219 ${ECHO} ${.TARGET} "->" $$path ; \
062db326 220 ${LN} -s $$path ${.TARGET}
984263bc
MD
221
222CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
223
224.if !target(install)
225
226_INSTALLFLAGS:= ${INSTALLFLAGS}
227.for ie in ${INSTALLFLAGS_EDIT}
228_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
229.endfor
230
231.if !target(realinstall)
232realinstall: _kmodinstall
233.ORDER: beforeinstall _kmodinstall
234_kmodinstall:
c2c83759 235.if defined(INSTALLSTRIPPEDMODULES)
984263bc
MD
236 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
237 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
c2c83759
MD
238 ${OBJCOPY} --strip-debug ${DESTDIR}${KMODDIR}/${PROG}
239.else
240 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
241 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
242.endif
905fbe6b 243.endif # !target(realinstall)
984263bc
MD
244
245.include <bsd.links.mk>
246
247.if !defined(NOMAN)
248realinstall: _maninstall
249.ORDER: beforeinstall _maninstall
250.endif
251
905fbe6b 252.endif # !target(install)
984263bc
MD
253
254.if !target(load)
255load: ${PROG}
256 ${KMODLOAD} -v ./${KMOD}.ko
257.endif
258
259.if !target(unload)
260unload:
261 ${KMODUNLOAD} -v ${KMOD}
262.endif
263
1b29ad66 264.for _src in ${SRCS:Mopt_*.h} ${SRCS:Muse_*.h}
984263bc
MD
265CLEANFILES+= ${_src}
266.if !target(${_src})
1b29ad66
SS
267.if defined(BUILDING_WITH_KERNEL) && exists(${BUILDING_WITH_KERNEL}/${_src})
268${_src}: ${BUILDING_WITH_KERNEL}/${_src}
a9295349
MD
269# we do not have to copy these files any more, the kernel build
270# directory is included in the path now.
271# cp ${BUILDING_WITH_KERNEL}/${_src} ${.TARGET}
1b29ad66 272.else
984263bc
MD
273${_src}:
274 touch ${.TARGET}
1b29ad66 275.endif # BUILDING_WITH_KERNEL
984263bc
MD
276.endif
277.endfor
278
1f2de5d4
MD
279MFILES?= kern/bus_if.m kern/device_if.m bus/iicbus/iicbb_if.m \
280 bus/iicbus/iicbus_if.m bus/isa/isa_if.m dev/netif/mii_layer/miibus_if.m \
666d2603
JS
281 bus/pccard/card_if.m bus/pccard/power_if.m bus/pci/pci_if.m \
282 bus/pci/pcib_if.m \
1f2de5d4 283 bus/ppbus/ppbus_if.m bus/smbus/smbus_if.m bus/usb/usb_if.m \
676159d4 284 dev/acpica5/acpi_if.m dev/disk/nata/ata_if.m \
984263bc
MD
285 dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
286 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \
f8e80553 287 libiconv/iconv_converter_if.m dev/agp/agp_if.m opencrypto/crypto_if.m
984263bc
MD
288
289.for _srcsrc in ${MFILES}
290.for _ext in c h
291.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
292CLEANFILES+= ${_src}
293.if !target(${_src})
294${_src}: @
295.if exists(@)
be59a52f 296${_src}: @/tools/makeobjops.awk @/${_srcsrc}
984263bc 297.endif
a9295349
MD
298
299.if defined(BUILDING_WITH_KERNEL) && \
300 exists(${BUILDING_WITH_KERNEL}/${_src})
301.else
145a9824 302 awk -f @/tools/makeobjops.awk -- -${_ext} @/${_srcsrc}
984263bc 303.endif
a9295349 304.endif
984263bc
MD
305.endfor # _src
306.endfor # _ext
307.endfor # _srcsrc
308
0961aa92
MD
309#.for _ext in c h
310#.if ${SRCS:Mvnode_if.${_ext}} != ""
311#CLEANFILES+= vnode_if.${_ext}
312#vnode_if.${_ext}: @
313#.if exists(@)
314#vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src
315#.endif
316# awk -f @/tools/vnode_if.awk -- -${_ext} @/kern/vnode_if.src
317#.endif
318#.endfor
984263bc
MD
319
320regress:
321
322.include <bsd.dep.mk>
323
324.if !exists(${DEPENDFILE})
325${OBJS}: ${SRCS:M*.h}
326.endif
327
328.include <bsd.obj.mk>
5e9c1061 329.include "bsd.kern.mk"
d4ef9227
JS
330
331# Behaves like MODULE_OVERRIDE
332.if defined(KLD_DEPS)
333all: _kdeps_all
334_kdeps_all: @
335.for _mdep in ${KLD_DEPS}
336 cd ${SYSDIR}/${_mdep} && make all
337.endfor
338depend: _kdeps_depend
339_kdeps_depend: @
340.for _mdep in ${KLD_DEPS}
341 cd ${SYSDIR}/${_mdep} && make depend
342.endfor
343install: _kdeps_install
344_kdeps_install: @
345.for _mdep in ${KLD_DEPS}
346 cd ${SYSDIR}/${_mdep} && make install
347.endfor
348clean: _kdeps_clean
349_kdeps_clean: @
350.for _mdep in ${KLD_DEPS}
351 cd ${SYSDIR}/${_mdep} && make clean
352.endfor
353.endif