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.35 2008/08/27 16:35:19 hasso Exp $
5 # The include file <bsd.kmod.mk> handles installing Kernel Loadable Device
11 # CLEANFILES Additional files to remove for the clean and cleandir targets.
13 # KMOD The name of the kernel module to build.
15 # KMODDIR Base path for kernel modules (see kld(4)).
16 # [${DESTKERNDIR}/${DESTMODULESNAME}]
18 # KMODOWN KLD owner. [${BINOWN}]
20 # KMODGRP KLD group. [${BINGRP}]
22 # KMODMODE KLD mode. [${BINMODE}]
24 # KMODLOAD Command to load a kernel module [/sbin/kldload]
26 # KMODUNLOAD Command to unload a kernel module [/sbin/kldunload]
28 # PROG The name of the kernel module to build.
29 # If not supplied, ${KMOD}.o is used.
31 # SRCS List of source files
33 # KMODDEPS List of modules which this one is dependant on
35 # DESTKERNDIR Change the tree where the kernel and the modules get
36 # installed. [/boot] ${DESTDIR} changes the root of the tree
37 # pointed to by ${DESTKERNDIR}.
39 # MFILES Optionally a list of interfaces used by the module.
40 # This file contains a default list of interfaces.
45 # install the kernel module and its manual pages; if the Makefile
46 # does not itself define the target install, the targets
47 # beforeinstall and afterinstall may also be used to cause
48 # actions immediately before and after the install target
57 # bsd.obj.mk: clean, cleandir and obj
58 # bsd.dep.mk: cleandepend, depend and tags
62 KMODLOAD?
= /sbin
/kldload
63 KMODUNLOAD?
= /sbin
/kldunload
65 KMODDIR?
= ${DESTKERNDIR}/${DESTMODULESNAME}
70 .
include <bsd.init.mk
>
72 .SUFFIXES
: .out .o .c .
cc .
cxx .C .y .l .s .S
74 CFLAGS
+= ${COPTS} -D_KERNEL
${CWARNFLAGS}
77 # Don't use any standard include directories.
78 # Since -nostdinc will annull any previous -I paths, we repeat all
79 # such paths after -nostdinc. It doesn't seem to be possible to
80 # add to the front of `make' variable.
82 # Don't use -I- anymore, source-relative includes are desireable.
83 _ICFLAGS
:= ${CFLAGS
:M-I
*}
84 CFLAGS
+= -nostdinc
${_ICFLAGS}
86 # Add -I paths for system headers. Individual KLD makefiles don't
87 # need any -I paths for this. Similar defaults for .PATH can't be
88 # set because there are no standard paths for non-headers.
90 # NOTE! Traditional architecture paths such as <i386/i386/blah.h>
91 # must run through the "machine_base" softlink using
92 # <machine_base/i386/blah.h>. An explicit cross-architecture path must
93 # operate relative to /usr/src/sys using e.g. <arch/i386/i386/blah.h>
97 # Add -I paths for headers in the kernel build directory
99 .if defined
(BUILDING_WITH_KERNEL
)
100 CFLAGS
+= -I
${BUILDING_WITH_KERNEL}
101 _MACHINE_FWD
= ${BUILDING_WITH_KERNEL}
103 .if defined
(MAKEOBJDIRPREFIX
)
104 _MACHINE_FWD
= ${MAKEOBJDIRPREFIX}/${SYSDIR}/forwarder_
${MACHINE_ARCH}
106 _MACHINE_FWD
= ${.OBJDIR
}/forwarder_
${MACHINE_ARCH}
107 CLEANDIRS
+= ${_MACHINE_FWD}
110 CFLAGS
+= -I
${_MACHINE_FWD}/include
111 .
include "kern.fwd.mk"
113 # Add a -I path to standard headers like <stddef.h>. Use a relative
114 # path to src/include if possible. If the @ symlink hasn't been built
115 # yet, then we can't tell if the relative path exists. Add both the
116 # potential relative path and an absolute path in that case.
118 .if exists
(@
/..
/include)
119 CFLAGS
+= -I@
/..
/include
121 CFLAGS
+= -I
${DESTDIR}/usr
/include
124 CFLAGS
+= -I@
/..
/include -I
${DESTDIR}/usr
/include
127 .if defined
(BUILDING_WITH_KERNEL
) && \
128 exists
(${BUILDING_WITH_KERNEL}/opt_global.h
)
129 CFLAGS
+= -include ${BUILDING_WITH_KERNEL}/opt_global.h
132 CFLAGS
+= ${DEBUG_FLAGS}
133 .if
${MACHINE_ARCH} == amd64
134 CFLAGS
+= -fno-omit-frame-pointer
137 .
include <bsd.patch.mk
>
139 OBJS
+= ${SRCS
:N
*.h
:N
*.patch
:R
:S
/$/.o
/g
}
145 .if
${MACHINE_ARCH} != amd64
146 ${PROG}: ${KMOD}.kld
${KMODDEPS}
147 ${LD} -Bshareable
${LDFLAGS} -o
${.TARGET
} ${KMOD}.kld
${KMODDEPS}
150 .if defined
(KMODDEPS
)
151 .for dep in
${KMODDEPS}
152 CLEANFILES
+= ${dep} __
${dep}_hack_dep.c
155 touch __
${dep}_hack_dep.c
156 ${CC} -shared
${CFLAGS} -o
${dep} __
${dep}_hack_dep.c
160 .if
${MACHINE_ARCH} != amd64
162 ${LD} ${LDFLAGS} -r
-o
${.TARGET
} ${OBJS}
165 ${LD} ${LDFLAGS} -r
-d
-o
${.TARGET
} ${OBJS}
168 # links to platform and cpu architecture include files. If we are
169 # building with a kernel these already exist in the kernel build dir.
170 # '@' is a link to the system source.
171 .if defined
(BUILDING_WITH_KERNEL
)
174 _ILINKS
=@ machine_base machine cpu_base cpu
181 all: objwarn fwheaders
${PROG}
183 beforedepend
: fwheaders
184 fwheaders
: ${_ILINKS} ${FORWARD_HEADERS_COOKIE}
185 # Ensure that the links exist without depending on it when it exists which
186 # causes all the modules to be rebuilt when the directory pointed to changes.
187 .for _link in
${_ILINKS}
188 .if
!exists
(${.OBJDIR
}/${_link})
193 # Search for kernel source tree in standard places.
194 .for _dir in
${.CURDIR
}/..
/..
${.CURDIR
}/..
/..
/..
${.CURDIR
}/..
/..
/..
/..
/sys
/usr
/src
/sys
195 .if
!defined
(SYSDIR
) && exists
(${_dir}/kern
/)
199 .if
!defined
(SYSDIR
) ||
!exists
(${SYSDIR}/kern
)
200 .error
"can't find kernel source tree"
204 # path=`(cd $$path && /bin/pwd)` ;
207 @case
${.TARGET
} in \
209 path
=${SYSDIR}/platform
/${MACHINE_PLATFORM}/include ;; \
211 path
=${SYSDIR}/platform
/${MACHINE_PLATFORM} ;; \
213 path
=${SYSDIR}/cpu
/${MACHINE_ARCH}/include ;; \
215 path
=${SYSDIR}/cpu
/${MACHINE_ARCH} ;; \
219 path
=${.CURDIR
}/${MACHINE_ARCH} ;; \
221 ${ECHO} ${.TARGET
} "->" $$path ; \
222 ${LN} -s
$$path ${.TARGET
}
224 CLEANFILES
+= ${PROG} ${KMOD}.kld
${OBJS} ${_ILINKS} symb.tmp tmp.o
228 _INSTALLFLAGS
:= ${INSTALLFLAGS}
229 .for ie in
${INSTALLFLAGS_EDIT}
230 _INSTALLFLAGS
:= ${_INSTALLFLAGS
${ie}}
233 .if
!target
(realinstall
)
234 realinstall
: _kmodinstall
235 .ORDER
: beforeinstall _kmodinstall
237 .if defined
(INSTALLSTRIPPEDMODULES
)
238 ${INSTALL} -o
${KMODOWN} -g
${KMODGRP} -m
${KMODMODE} \
239 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
240 ${OBJCOPY} --strip-debug
${DESTDIR}${KMODDIR}/${PROG}
242 ${INSTALL} -o
${KMODOWN} -g
${KMODGRP} -m
${KMODMODE} \
243 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
245 .
endif # !target(realinstall)
247 .
include <bsd.links.mk
>
249 .
endif # !target(install)
253 ${KMODLOAD} -v .
/${KMOD}.ko
258 ${KMODUNLOAD} -v
${KMOD}
261 .for _src in
${SRCS
:Mopt_
*.h
} ${SRCS
:Muse_
*.h
}
264 .if defined
(BUILDING_WITH_KERNEL
) && exists
(${BUILDING_WITH_KERNEL}/${_src})
265 ${_src}: ${BUILDING_WITH_KERNEL}/${_src}
266 # we do not have to copy these files any more, the kernel build
267 # directory is included in the path now.
268 # cp ${BUILDING_WITH_KERNEL}/${_src} ${.TARGET}
272 .
endif # BUILDING_WITH_KERNEL
276 MFILES?
= kern
/bus_if.m kern
/device_if.m bus
/iicbus
/iicbb_if.m \
277 bus
/iicbus
/iicbus_if.m bus
/isa
/isa_if.m dev
/netif
/mii_layer
/miibus_if.m \
278 bus
/pccard
/card_if.m bus
/pccard
/power_if.m bus
/pci
/pci_if.m \
280 bus
/ppbus
/ppbus_if.m bus
/smbus
/smbus_if.m bus
/usb
/usb_if.m \
281 dev
/acpica5
/acpi_if.m dev
/disk
/nata
/ata_if.m \
282 dev
/sound
/pcm
/ac97_if.m dev
/sound
/pcm
/channel_if.m \
283 dev
/sound
/pcm
/feeder_if.m dev
/sound
/pcm
/mixer_if.m \
284 libiconv
/iconv_converter_if.m dev
/agp
/agp_if.m opencrypto
/crypto_if.m
286 .for _srcsrc in
${MFILES}
288 .for _src in
${SRCS
:M
${_srcsrc
:T
:R
}.
${_ext}}
293 ${_src}: @
/tools
/makeobjops.awk @
/${_srcsrc}
296 .if defined
(BUILDING_WITH_KERNEL
) && \
297 exists
(${BUILDING_WITH_KERNEL}/${_src})
299 awk
-f @
/tools
/makeobjops.awk
-- -${_ext} @
/${_srcsrc}
307 #.if ${SRCS:Mvnode_if.${_ext}} != ""
308 #CLEANFILES+= vnode_if.${_ext}
311 #vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src
313 # awk -f @/tools/vnode_if.awk -- -${_ext} @/kern/vnode_if.src
319 .
include <bsd.dep.mk
>
321 .if
!exists
(${DEPENDFILE})
322 ${OBJS}: ${SRCS
:M
*.h
}
325 .
include <bsd.obj.mk
>
326 .
include "bsd.kern.mk"
328 # Behaves like MODULE_OVERRIDE
329 .if defined
(KLD_DEPS
)
332 .for _mdep in
${KLD_DEPS}
333 cd
${SYSDIR}/${_mdep} && make
all
335 depend
: _kdeps_depend
337 .for _mdep in
${KLD_DEPS}
338 cd
${SYSDIR}/${_mdep} && make depend
340 install: _kdeps_install
342 .for _mdep in
${KLD_DEPS}
343 cd
${SYSDIR}/${_mdep} && make
install
347 .for _mdep in
${KLD_DEPS}
348 cd
${SYSDIR}/${_mdep} && make
clean