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 $
4 # The include file <bsd.kmod.mk> handles installing Kernel Loadable Device
9 # CLEANFILES Additional files to remove for the clean and cleandir targets.
11 # KMOD The name of the kernel module to build.
13 # KMODDIR Base path for kernel modules (see kld(4)).
16 # KMODOWN KLD owner. [${BINOWN}]
18 # KMODGRP KLD group. [${BINGRP}]
20 # KMODMODE KLD mode. [${BINMODE}]
22 # KMODLOAD Command to load a kernel module [/sbin/kldload]
24 # KMODUNLOAD Command to unload a kernel module [/sbin/kldunload]
26 # PROG The name of the kernel module to build.
27 # If not supplied, ${KMOD}.o is used.
29 # SRCS List of source files
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}.
35 # MFILES Optionally a list of interfaces used by the module.
36 # This file contains a default list of interfaces.
38 # FIRMWS Firmware module in the form filename:shortname:version
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
55 # bsd.obj.mk: clean, cleandir and obj
56 # bsd.dep.mk: cleandepend, depend and tags
60 KMODLOAD?
= /sbin
/kldload
61 KMODUNLOAD?
= /sbin
/kldunload
63 # KERNEL is needed when running make install directly from
67 KMODDIR?
= ${DESTKERNDIR}
72 .
include <bsd.init.mk
>
74 .SUFFIXES
: .out .o .c .
cc .
cxx .C .y .l .s .S
76 CFLAGS
+= ${COPTS} -D_KERNEL
${CWARNFLAGS}
79 # Don't use any standard include directories.
80 # Since -nostdinc will annull any previous -I paths, we repeat all
81 # such paths after -nostdinc. It doesn't seem to be possible to
82 # add to the front of `make' variable.
84 # Don't use -I- anymore, source-relative includes are desireable.
85 _ICFLAGS
:= ${CFLAGS
:M-I
*}
86 CFLAGS
+= -nostdinc
${_ICFLAGS}
88 # Add -I paths for system headers. Individual KLD makefiles don't
89 # need any -I paths for this. Similar defaults for .PATH can't be
90 # set because there are no standard paths for non-headers.
92 # NOTE! Traditional architecture paths such as <i386/i386/blah.h>
93 # must run through the "machine_base" softlink using
94 # <machine_base/i386/blah.h>. An explicit cross-architecture path must
95 # operate relative to /usr/src/sys using e.g. <arch/i386/i386/blah.h>
99 # Add -I paths for headers in the kernel build directory
101 .if defined
(BUILDING_WITH_KERNEL
)
102 CFLAGS
+= -I
${BUILDING_WITH_KERNEL}
103 _MACHINE_FWD
= ${BUILDING_WITH_KERNEL}
105 .if defined
(MAKEOBJDIRPREFIX
)
106 _MACHINE_FWD
= ${MAKEOBJDIRPREFIX}/${SYSDIR}/forwarder_
${MACHINE_ARCH}
108 _MACHINE_FWD
= ${.OBJDIR
}/forwarder_
${MACHINE_ARCH}
109 CLEANDIRS
+= ${_MACHINE_FWD}
112 CFLAGS
+= -I
${_MACHINE_FWD}/include
113 .
include "kern.fwd.mk"
115 # Add a -I path to standard headers like <stddef.h>. Use a relative
116 # path to src/include if possible. If the @ symlink hasn't been built
117 # yet, then we can't tell if the relative path exists. Add both the
118 # potential relative path and an absolute path in that case.
120 .if exists
(@
/..
/include)
121 CFLAGS
+= -I@
/..
/include
123 CFLAGS
+= -I
${DESTDIR}/usr
/include
126 CFLAGS
+= -I@
/..
/include -I
${DESTDIR}/usr
/include
129 .if defined
(BUILDING_WITH_KERNEL
) && \
130 exists
(${BUILDING_WITH_KERNEL}/opt_global.h
)
131 CFLAGS
+= -include ${BUILDING_WITH_KERNEL}/opt_global.h
134 CFLAGS
+= ${DEBUG_FLAGS}
135 .if
${MACHINE_ARCH} == x86_64
136 CFLAGS
+= -fno-omit-frame-pointer
139 .
include <bsd.patch.mk
>
146 ${KMOD
:S
/$/.c
/}: @
/tools
/fw_stub.awk
148 ${AWK} -f @
/tools
/fw_stub.awk
${FIRMWS} -m
${KMOD} -c
${KMOD
:S
/$/.c
/g
} \
149 ${FIRMWARE_LICENSE
:C
/.
+/-l
/}${FIRMWARE_LICENSE}
151 SRCS
+= ${KMOD
:S
/$/.c
/}
152 CLEANFILES
+= ${KMOD
:S
/$/.c
/}
154 .for _firmw in
${FIRMWS}
155 ${_firmw
:C
/\
:.
*$/.fwo
/}: ${_firmw
:C
/\
:.
*$//}
156 @
${ECHO} ${_firmw
:C
/\
:.
*$//} ${.ALLSRC
:M
*${_firmw
:C
/\
:.
*$//}}
157 @if
[ -e
${_firmw
:C
/\
:.
*$//} ]; then \
158 ${LD} -b binary
--no-warn-mismatch
${LDFLAGS} \
159 -r
-d
-o
${.TARGET
} ${_firmw
:C
/\
:.
*$//}; \
161 ln
-s
${.ALLSRC
:M
*${_firmw
:C
/\
:.
*$//}} ${_firmw
:C
/\
:.
*$//}; \
162 ${LD} -b binary
--no-warn-mismatch
${LDFLAGS} \
163 -r
-d
-o
${.TARGET
} ${_firmw
:C
/\
:.
*$//}; \
164 rm ${_firmw
:C
/\
:.
*$//}; \
167 OBJS
+= ${_firmw
:C
/\
:.
*$/.fwo
/}
171 OBJS
+= ${SRCS
:N
*.h
:N
*.patch
:R
:S
/$/.o
/g
}
177 .if
${MACHINE_ARCH} != x86_64
179 ${LD} -Bshareable
${LDFLAGS} -o
${.TARGET
} ${KMOD}.kld
182 .if
${MACHINE_ARCH} != x86_64
184 ${LD} ${LDFLAGS} -r
-o
${.TARGET
} ${OBJS}
187 ${LD} ${LDFLAGS} -r
-d
-o
${.TARGET
} ${OBJS}
190 # links to platform and cpu architecture include files. If we are
191 # building with a kernel these already exist in the kernel build dir.
192 # '@' is a link to the system source.
193 .if defined
(BUILDING_WITH_KERNEL
)
196 _ILINKS
=@ machine_base machine cpu_base cpu
203 all: objwarn fwheaders
${PROG}
205 beforedepend
: fwheaders
206 fwheaders
: ${_ILINKS} ${FORWARD_HEADERS_COOKIE}
207 # Ensure that the links exist without depending on it when it exists which
208 # causes all the modules to be rebuilt when the directory pointed to changes.
209 .for _link in
${_ILINKS}
210 .if
!exists
(${.OBJDIR
}/${_link})
215 # Search for kernel source tree in standard places.
216 .for _dir in
${.CURDIR
}/..
/..
${.CURDIR
}/..
/..
/..
${.CURDIR
}/..
/..
/..
/..
/sys
/usr
/src
/sys
217 .if
!defined
(SYSDIR
) && exists
(${_dir}/kern
/)
221 .if
!defined
(SYSDIR
) ||
!exists
(${SYSDIR}/kern
)
222 .error
"can't find kernel source tree"
226 # path=`(cd $$path && /bin/pwd)` ;
229 @case
${.TARGET
} in \
231 path
=${SYSDIR}/platform
/${MACHINE_PLATFORM}/include ;; \
233 path
=${SYSDIR}/platform
/${MACHINE_PLATFORM} ;; \
235 path
=${SYSDIR}/cpu
/${MACHINE_ARCH}/include ;; \
237 path
=${SYSDIR}/cpu
/${MACHINE_ARCH} ;; \
241 path
=${.CURDIR
}/${MACHINE_ARCH} ;; \
243 ${ECHO} ${.TARGET
} "->" $$path ; \
244 ${LN} -s
$$path ${.TARGET
}
246 CLEANFILES
+= ${PROG} ${KMOD}.kld
${OBJS} ${_ILINKS} symb.tmp tmp.o
250 _INSTALLFLAGS
:= ${INSTALLFLAGS}
251 .for ie in
${INSTALLFLAGS_EDIT}
252 _INSTALLFLAGS
:= ${_INSTALLFLAGS
${ie}}
255 .if
!target
(realinstall
)
256 realinstall
: _kmodinstall
257 .ORDER
: beforeinstall _kmodinstall
259 .if defined
(INSTALLSTRIPPEDMODULES
)
260 ${INSTALL} -o
${KMODOWN} -g
${KMODGRP} -m
${KMODMODE} \
261 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
262 ${OBJCOPY} --strip-debug
${DESTDIR}${KMODDIR}/${PROG}
264 ${INSTALL} -o
${KMODOWN} -g
${KMODGRP} -m
${KMODMODE} \
265 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
267 .
endif # !target(realinstall)
269 .
include <bsd.links.mk
>
271 .
endif # !target(install)
275 ${KMODLOAD} -v .
/${KMOD}.ko
280 ${KMODUNLOAD} -v
${KMOD}
283 .for _src in
${SRCS
:Mopt_
*.h
} ${SRCS
:Muse_
*.h
}
286 .if defined
(BUILDING_WITH_KERNEL
) && exists
(${BUILDING_WITH_KERNEL}/${_src})
287 ${_src}: ${BUILDING_WITH_KERNEL}/${_src}
288 # we do not have to copy these files any more, the kernel build
289 # directory is included in the path now.
290 # cp ${BUILDING_WITH_KERNEL}/${_src} ${.TARGET}
294 .
endif # BUILDING_WITH_KERNEL
298 MFILES?
= kern
/bus_if.m kern
/device_if.m bus
/iicbus
/iicbb_if.m \
299 bus
/iicbus
/iicbus_if.m bus
/isa
/isa_if.m dev
/netif
/mii_layer
/miibus_if.m \
300 bus
/pccard
/card_if.m bus
/pccard
/power_if.m bus
/pci
/pci_if.m \
302 bus
/ppbus
/ppbus_if.m bus
/smbus
/smbus_if.m bus
/usb
/usb_if.m \
303 dev
/acpica5
/acpi_if.m dev
/disk
/nata
/ata_if.m \
304 dev
/sound
/pcm
/ac97_if.m dev
/sound
/pcm
/channel_if.m \
305 dev
/sound
/pcm
/feeder_if.m dev
/sound
/pcm
/mixer_if.m \
306 libiconv
/iconv_converter_if.m dev
/agp
/agp_if.m opencrypto
/cryptodev_if.m \
307 bus
/mmc
/mmcbus_if.m bus
/mmc
/mmcbr_if.m
309 .for _srcsrc in
${MFILES}
311 .for _src in
${SRCS
:M
${_srcsrc
:T
:R
}.
${_ext}}
316 ${_src}: @
/tools
/makeobjops.awk @
/${_srcsrc}
319 .if defined
(BUILDING_WITH_KERNEL
) && \
320 exists
(${BUILDING_WITH_KERNEL}/${_src})
322 awk
-f @
/tools
/makeobjops.awk
-- -${_ext} @
/${_srcsrc}
330 #.if ${SRCS:Mvnode_if.${_ext}} != ""
331 #CLEANFILES+= vnode_if.${_ext}
334 #vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src
336 # awk -f @/tools/vnode_if.awk -- -${_ext} @/kern/vnode_if.src
340 .if
!empty
(SRCS
:Massym.s
)
341 CLEANFILES
+= assym.s genassym.o
343 .if defined
(BUILDING_WITH_KERNEL
)
344 genassym.o
: opt_global.h
349 assym.s
: @
/kern
/genassym.sh
351 sh @
/kern
/genassym.sh genassym.o
> ${.TARGET
}
353 genassym.o
: @
/platform
/${MACHINE_PLATFORM}/${MACHINE_ARCH}/genassym.c
355 genassym.o
: @
${SRCS
:Mopt_
*.h
}
356 ${CC} -c
${CFLAGS
:N-fno-common
:N-mcmodel
=small
} ${WERROR} \
357 @
/platform
/${MACHINE_PLATFORM}/${MACHINE_ARCH}/genassym.c
362 .
include <bsd.dep.mk
>
364 .if
!exists
(${DEPENDFILE})
365 ${OBJS}: ${SRCS
:M
*.h
}
368 .
include <bsd.obj.mk
>
369 .
include "bsd.kern.mk"
371 # Behaves like MODULE_OVERRIDE
372 .if defined
(KLD_DEPS
)
375 .for _mdep in
${KLD_DEPS}
376 cd
${SYSDIR}/${_mdep} && make
all
378 depend
: _kdeps_depend
380 .for _mdep in
${KLD_DEPS}
381 cd
${SYSDIR}/${_mdep} && make depend
383 install: _kdeps_install
385 .for _mdep in
${KLD_DEPS}
386 cd
${SYSDIR}/${_mdep} && make
install
390 .for _mdep in
${KLD_DEPS}
391 cd
${SYSDIR}/${_mdep} && make
clean