sk(4): Initialize if_multiaddrs (in ether_ifattach), before touching it
[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 $
3#
4# The include file <bsd.kmod.mk> handles installing Kernel Loadable Device
5# drivers (KLD's).
6#
7#
8# +++ variables +++
984263bc
MD
9# CLEANFILES Additional files to remove for the clean and cleandir targets.
10#
11# KMOD The name of the kernel module to build.
12#
3b25fbd4
YT
13# KMODDIR Base path for kernel modules (see kld(4)).
14# [${DESTKERNDIR}/${DESTMODULESNAME}]
984263bc
MD
15#
16# KMODOWN KLD owner. [${BINOWN}]
17#
18# KMODGRP KLD group. [${BINGRP}]
19#
20# KMODMODE KLD mode. [${BINMODE}]
21#
22# KMODLOAD Command to load a kernel module [/sbin/kldload]
23#
24# KMODUNLOAD Command to unload a kernel module [/sbin/kldunload]
25#
984263bc
MD
26# PROG The name of the kernel module to build.
27# If not supplied, ${KMOD}.o is used.
28#
29# SRCS List of source files
30#
3b25fbd4
YT
31# DESTKERNDIR Change the tree where the kernel and the modules get
32# installed. [/boot] ${DESTDIR} changes the root of the tree
33# pointed to by ${DESTKERNDIR}.
984263bc
MD
34#
35# MFILES Optionally a list of interfaces used by the module.
36# This file contains a default list of interfaces.
37#
32e913d7
JT
38# FIRMWS Firmware module in the form filename:shortname:version
39#
984263bc
MD
40# +++ targets +++
41#
42# install:
43# install the kernel module and its manual pages; if the Makefile
44# does not itself define the target install, the targets
45# beforeinstall and afterinstall may also be used to cause
46# actions immediately before and after the install target
47# is executed.
48#
49# load:
50# Load KLD.
51#
52# unload:
53# Unload KLD.
54#
55# bsd.obj.mk: clean, cleandir and obj
56# bsd.dep.mk: cleandepend, depend and tags
984263bc
MD
57#
58
c2c83759 59OBJCOPY?= objcopy
984263bc
MD
60KMODLOAD?= /sbin/kldload
61KMODUNLOAD?= /sbin/kldunload
62
3b25fbd4
YT
63KMODDIR?= ${DESTKERNDIR}/${DESTMODULESNAME}
64KMODOWN?= ${BINOWN}
65KMODGRP?= ${BINGRP}
66KMODMODE?= ${BINMODE}
67
984263bc
MD
68.include <bsd.init.mk>
69
70.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
71
72CFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS}
73CFLAGS+= -DKLD_MODULE
74
e5d18209 75# Don't use any standard include directories.
984263bc
MD
76# Since -nostdinc will annull any previous -I paths, we repeat all
77# such paths after -nostdinc. It doesn't seem to be possible to
78# add to the front of `make' variable.
e5d18209
MD
79#
80# Don't use -I- anymore, source-relative includes are desireable.
984263bc 81_ICFLAGS:= ${CFLAGS:M-I*}
e5d18209 82CFLAGS+= -nostdinc ${_ICFLAGS}
984263bc
MD
83
84# Add -I paths for system headers. Individual KLD makefiles don't
85# need any -I paths for this. Similar defaults for .PATH can't be
86# set because there are no standard paths for non-headers.
39619464 87#
f8334305 88# NOTE! Traditional architecture paths such as <i386/i386/blah.h>
a9295349
MD
89# must run through the "machine_base" softlink using
90# <machine_base/i386/blah.h>. An explicit cross-architecture path must
91# operate relative to /usr/src/sys using e.g. <arch/i386/i386/blah.h>
39619464 92#
f8334305 93CFLAGS+= -I. -I@
984263bc 94
a9295349
MD
95# Add -I paths for headers in the kernel build directory
96#
97.if defined(BUILDING_WITH_KERNEL)
98CFLAGS+= -I${BUILDING_WITH_KERNEL}
a7f2f51f
SZ
99_MACHINE_FWD= ${BUILDING_WITH_KERNEL}
100.else
101.if defined(MAKEOBJDIRPREFIX)
102_MACHINE_FWD= ${MAKEOBJDIRPREFIX}/${SYSDIR}/forwarder_${MACHINE_ARCH}
103.else
104_MACHINE_FWD= ${.OBJDIR}/forwarder_${MACHINE_ARCH}
105CLEANDIRS+= ${_MACHINE_FWD}
106.endif
a9295349 107.endif
a7f2f51f
SZ
108CFLAGS+= -I${_MACHINE_FWD}/include
109.include "kern.fwd.mk"
a9295349 110
984263bc
MD
111# Add a -I path to standard headers like <stddef.h>. Use a relative
112# path to src/include if possible. If the @ symlink hasn't been built
113# yet, then we can't tell if the relative path exists. Add both the
114# potential relative path and an absolute path in that case.
115.if exists(@)
116.if exists(@/../include)
117CFLAGS+= -I@/../include
118.else
119CFLAGS+= -I${DESTDIR}/usr/include
120.endif
121.else # !@
122CFLAGS+= -I@/../include -I${DESTDIR}/usr/include
123.endif # @
124
deee08c4
SS
125.if defined(BUILDING_WITH_KERNEL) && \
126 exists(${BUILDING_WITH_KERNEL}/opt_global.h)
127CFLAGS+= -include ${BUILDING_WITH_KERNEL}/opt_global.h
128.endif
129
984263bc 130CFLAGS+= ${DEBUG_FLAGS}
b2b3ffcd 131.if ${MACHINE_ARCH} == x86_64
982b0507
MD
132CFLAGS+= -fno-omit-frame-pointer
133.endif
984263bc 134
285638ea
SS
135.include <bsd.patch.mk>
136
32e913d7
JT
137.if defined(FIRMWS)
138AWK=/usr/bin/awk
139.if !exists(@)
140${KMOD:S/$/.c/}: @
141.else
142${KMOD:S/$/.c/}: @/tools/fw_stub.awk
143.endif
144 ${AWK} -f @/tools/fw_stub.awk ${FIRMWS} -m${KMOD} -c${KMOD:S/$/.c/g} \
145 ${FIRMWARE_LICENSE:C/.+/-l/}${FIRMWARE_LICENSE}
146
147SRCS+= ${KMOD:S/$/.c/}
148CLEANFILES+= ${KMOD:S/$/.c/}
149
150.for _firmw in ${FIRMWS}
151${_firmw:C/\:.*$/.fwo/}: ${_firmw:C/\:.*$//}
152 @${ECHO} ${_firmw:C/\:.*$//} ${.ALLSRC:M*${_firmw:C/\:.*$//}}
153 @if [ -e ${_firmw:C/\:.*$//} ]; then \
154 ${LD} -b binary --no-warn-mismatch ${LDFLAGS} \
155 -r -d -o ${.TARGET} ${_firmw:C/\:.*$//}; \
156 else \
157 ln -s ${.ALLSRC:M*${_firmw:C/\:.*$//}} ${_firmw:C/\:.*$//}; \
158 ${LD} -b binary --no-warn-mismatch ${LDFLAGS} \
159 -r -d -o ${.TARGET} ${_firmw:C/\:.*$//}; \
160 rm ${_firmw:C/\:.*$//}; \
161 fi
162
163OBJS+= ${_firmw:C/\:.*$/.fwo/}
164.endfor
165.endif
166
145b818c 167OBJS+= ${SRCS:N*.h:N*.patch:R:S/$/.o/g}
984263bc
MD
168
169.if !defined(PROG)
170PROG= ${KMOD}.ko
171.endif
172
b2b3ffcd 173.if ${MACHINE_ARCH} != x86_64
43db70b8
SS
174${PROG}: ${KMOD}.kld
175 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld
984263bc
MD
176.endif
177
b2b3ffcd 178.if ${MACHINE_ARCH} != x86_64
984263bc
MD
179${KMOD}.kld: ${OBJS}
180 ${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS}
8d565796
MD
181.else
182${PROG}: ${OBJS}
99ab4213 183 ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS}
8d565796 184.endif
984263bc 185
a9295349
MD
186# links to platform and cpu architecture include files. If we are
187# building with a kernel these already exist in the kernel build dir.
188# '@' is a link to the system source.
189.if defined(BUILDING_WITH_KERNEL)
190_ILINKS=@
191.else
192_ILINKS=@ machine_base machine cpu_base cpu
193.endif
194
932f49b9
MD
195.if defined(ARCH)
196_ILINKS+=${ARCH}
197.endif
984263bc 198
82f3e8c4 199all: objwarn fwheaders ${PROG}
984263bc 200
82f3e8c4
SS
201beforedepend: fwheaders
202fwheaders: ${_ILINKS} ${FORWARD_HEADERS_COOKIE}
984263bc
MD
203# Ensure that the links exist without depending on it when it exists which
204# causes all the modules to be rebuilt when the directory pointed to changes.
205.for _link in ${_ILINKS}
206.if !exists(${.OBJDIR}/${_link})
207${OBJS}: ${_link}
208.endif
209.endfor
210
211# Search for kernel source tree in standard places.
932f49b9 212.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. ${.CURDIR}/../../../.. /sys /usr/src/sys
984263bc
MD
213.if !defined(SYSDIR) && exists(${_dir}/kern/)
214SYSDIR= ${_dir}
215.endif
216.endfor
217.if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
218.error "can't find kernel source tree"
219.endif
edbe133c 220S= ${SYSDIR}
984263bc 221
932f49b9
MD
222# path=`(cd $$path && /bin/pwd)` ;
223
984263bc
MD
224${_ILINKS}:
225 @case ${.TARGET} in \
226 machine) \
0955fd91 227 path=${SYSDIR}/platform/${MACHINE_PLATFORM}/include ;; \
a9295349 228 machine_base) \
0955fd91 229 path=${SYSDIR}/platform/${MACHINE_PLATFORM} ;; \
a9295349
MD
230 cpu) \
231 path=${SYSDIR}/cpu/${MACHINE_ARCH}/include ;; \
232 cpu_base) \
233 path=${SYSDIR}/cpu/${MACHINE_ARCH} ;; \
984263bc
MD
234 @) \
235 path=${SYSDIR} ;; \
932f49b9
MD
236 arch_*) \
237 path=${.CURDIR}/${MACHINE_ARCH} ;; \
984263bc 238 esac ; \
984263bc 239 ${ECHO} ${.TARGET} "->" $$path ; \
062db326 240 ${LN} -s $$path ${.TARGET}
984263bc
MD
241
242CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
243
244.if !target(install)
245
246_INSTALLFLAGS:= ${INSTALLFLAGS}
247.for ie in ${INSTALLFLAGS_EDIT}
248_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
249.endfor
250
251.if !target(realinstall)
252realinstall: _kmodinstall
253.ORDER: beforeinstall _kmodinstall
254_kmodinstall:
c2c83759 255.if defined(INSTALLSTRIPPEDMODULES)
984263bc
MD
256 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
257 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
c2c83759
MD
258 ${OBJCOPY} --strip-debug ${DESTDIR}${KMODDIR}/${PROG}
259.else
260 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
261 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
262.endif
905fbe6b 263.endif # !target(realinstall)
984263bc
MD
264
265.include <bsd.links.mk>
266
905fbe6b 267.endif # !target(install)
984263bc
MD
268
269.if !target(load)
270load: ${PROG}
271 ${KMODLOAD} -v ./${KMOD}.ko
272.endif
273
274.if !target(unload)
275unload:
276 ${KMODUNLOAD} -v ${KMOD}
277.endif
278
1b29ad66 279.for _src in ${SRCS:Mopt_*.h} ${SRCS:Muse_*.h}
984263bc
MD
280CLEANFILES+= ${_src}
281.if !target(${_src})
1b29ad66
SS
282.if defined(BUILDING_WITH_KERNEL) && exists(${BUILDING_WITH_KERNEL}/${_src})
283${_src}: ${BUILDING_WITH_KERNEL}/${_src}
a9295349
MD
284# we do not have to copy these files any more, the kernel build
285# directory is included in the path now.
286# cp ${BUILDING_WITH_KERNEL}/${_src} ${.TARGET}
1b29ad66 287.else
984263bc
MD
288${_src}:
289 touch ${.TARGET}
1b29ad66 290.endif # BUILDING_WITH_KERNEL
984263bc
MD
291.endif
292.endfor
293
1f2de5d4
MD
294MFILES?= kern/bus_if.m kern/device_if.m bus/iicbus/iicbb_if.m \
295 bus/iicbus/iicbus_if.m bus/isa/isa_if.m dev/netif/mii_layer/miibus_if.m \
666d2603
JS
296 bus/pccard/card_if.m bus/pccard/power_if.m bus/pci/pci_if.m \
297 bus/pci/pcib_if.m \
1f2de5d4 298 bus/ppbus/ppbus_if.m bus/smbus/smbus_if.m bus/usb/usb_if.m \
676159d4 299 dev/acpica5/acpi_if.m dev/disk/nata/ata_if.m \
984263bc
MD
300 dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
301 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \
d6644679
SW
302 libiconv/iconv_converter_if.m dev/agp/agp_if.m opencrypto/cryptodev_if.m \
303 bus/mmc/mmcbus_if.m bus/mmc/mmcbr_if.m
984263bc
MD
304
305.for _srcsrc in ${MFILES}
306.for _ext in c h
307.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
308CLEANFILES+= ${_src}
309.if !target(${_src})
310${_src}: @
311.if exists(@)
be59a52f 312${_src}: @/tools/makeobjops.awk @/${_srcsrc}
984263bc 313.endif
a9295349
MD
314
315.if defined(BUILDING_WITH_KERNEL) && \
316 exists(${BUILDING_WITH_KERNEL}/${_src})
317.else
145a9824 318 awk -f @/tools/makeobjops.awk -- -${_ext} @/${_srcsrc}
984263bc 319.endif
a9295349 320.endif
984263bc
MD
321.endfor # _src
322.endfor # _ext
323.endfor # _srcsrc
324
0961aa92
MD
325#.for _ext in c h
326#.if ${SRCS:Mvnode_if.${_ext}} != ""
327#CLEANFILES+= vnode_if.${_ext}
328#vnode_if.${_ext}: @
329#.if exists(@)
330#vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src
331#.endif
332# awk -f @/tools/vnode_if.awk -- -${_ext} @/kern/vnode_if.src
333#.endif
334#.endfor
984263bc
MD
335
336regress:
337
338.include <bsd.dep.mk>
339
340.if !exists(${DEPENDFILE})
341${OBJS}: ${SRCS:M*.h}
342.endif
343
344.include <bsd.obj.mk>
5e9c1061 345.include "bsd.kern.mk"
d4ef9227
JS
346
347# Behaves like MODULE_OVERRIDE
348.if defined(KLD_DEPS)
349all: _kdeps_all
350_kdeps_all: @
351.for _mdep in ${KLD_DEPS}
352 cd ${SYSDIR}/${_mdep} && make all
353.endfor
354depend: _kdeps_depend
355_kdeps_depend: @
356.for _mdep in ${KLD_DEPS}
357 cd ${SYSDIR}/${_mdep} && make depend
358.endfor
359install: _kdeps_install
360_kdeps_install: @
361.for _mdep in ${KLD_DEPS}
362 cd ${SYSDIR}/${_mdep} && make install
363.endfor
364clean: _kdeps_clean
365_kdeps_clean: @
366.for _mdep in ${KLD_DEPS}
367 cd ${SYSDIR}/${_mdep} && make clean
368.endfor
369.endif