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 List of firmware images in format filename:shortname:version
41 # Set to the name of the license the user has to agree on in
42 # order to use this firmware. See /usr/share/doc/legal
44 # KERNBUILDDIR Set to the location of the kernel build directory where
45 # the opt_*.h files, .o's and kernel wind up.
50 # install the kernel module and its manual pages; if the Makefile
51 # does not itself define the target install, the targets
52 # beforeinstall and afterinstall may also be used to cause
53 # actions immediately before and after the install target
62 # bsd.obj.mk: clean, cleandir and obj
63 # bsd.dep.mk: cleandepend, depend and tags
67 KMODLOAD?
= /sbin
/kldload
68 KMODUNLOAD?
= /sbin
/kldunload
70 # KERNEL is needed when running make install directly from
74 KMODDIR?
= ${DESTKERNDIR}
79 .
include <bsd.init.mk
>
81 .SUFFIXES
: .out .o .c .
cc .
cxx .C .y .l .s .S
83 .if
!defined
(NO_WERROR
) && (${CCVER} == "gcc47" ||
${CCVER} == "gcc80")
89 # always use external as(1)
91 COPTFLAGS
+= -no-integrated-as
94 # useful for debugging
95 #.warning "KMOD-PREFILTER ${CFLAGS}"
97 WORLD_CCOPTLEVEL
= # XXX prevent world opt level affecting kernel modules
98 CFLAGS
= ${COPTFLAGS} ${KCFLAGS} ${COPTS} -D_KERNEL
99 CFLAGS
+= ${CWARNFLAGS} -std
=${CSTD} ${WERROR}
100 CFLAGS
+= -DKLD_MODULE
102 # Don't use any standard include directories.
103 # Since -nostdinc will annull any previous -I paths, we repeat all
104 # such paths after -nostdinc. It doesn't seem to be possible to
105 # add to the front of `make' variable.
107 # Don't use -I- anymore, source-relative includes are desireable.
108 _ICFLAGS
:= ${CFLAGS
:M-I
*}
109 CFLAGS
+= -nostdinc
${_ICFLAGS}
111 # Add -I paths for system headers. Individual KLD makefiles don't
112 # need any -I paths for this. Similar defaults for .PATH can't be
113 # set because there are no standard paths for non-headers.
115 # NOTE! Traditional platform paths such as <platform/pc64/blah.h>
116 # must run through the "machine_base" softlink using
117 # <machine_base/blah.h>. An explicit cross-platform path must
118 # operate relative to /usr/src/sys using e.g. <platform/pc64/isa/blah.h>
121 .if defined
(FREEBSD_COMPAT
)
122 CFLAGS
+= -Idragonfly
/freebsd_compat
123 CFLAGS
+= -DFREEBSD_COMPAT
=1
127 # Add -I paths for headers in the kernel build directory
129 .if defined
(KERNBUILDDIR
)
130 CFLAGS
+= -I
${KERNBUILDDIR}
131 _MACHINE_FWD
= ${KERNBUILDDIR}
133 .if defined
(MAKEOBJDIRPREFIX
)
134 _MACHINE_FWD
= ${MAKEOBJDIRPREFIX}/${SYSDIR}/forwarder_
${MACHINE_ARCH}
136 _MACHINE_FWD
= ${.OBJDIR
}/forwarder_
${MACHINE_ARCH}
137 CLEANDIRS
+= ${_MACHINE_FWD}
140 CFLAGS
+= -I
${_MACHINE_FWD}/include
142 .
include "kern.fwd.mk"
144 # Add a -I path to standard headers like <stddef.h>. Use a relative
145 # path to src/include if possible. If the dragonfly symlink hasn't been
146 # built yet, then we can't tell if the relative path exists. Add both the
147 # potential relative path and an absolute path in that case.
148 .if exists
(dragonfly
)
149 .if exists
(dragonfly
/..
/include)
150 CFLAGS
+= -Idragonfly
/..
/include
152 CFLAGS
+= -I
${DESTDIR}/usr
/include
155 CFLAGS
+= -Idragonfly
/..
/include -I
${DESTDIR}/usr
/include
158 .if defined
(KERNBUILDDIR
) && \
159 exists
(${KERNBUILDDIR}/opt_global.h
)
160 CFLAGS
+= -DHAVE_KERNEL_OPTION_HEADERS
-include ${KERNBUILDDIR}/opt_global.h
163 CFLAGS
+= ${DEBUG_FLAGS}
164 .if
${MACHINE_ARCH} == "x86_64"
165 CFLAGS
+= -fno-omit-frame-pointer
170 .if
!exists
(dragonfly
)
171 ${KMOD
:S
/$/.c
/}: dragonfly
173 ${KMOD
:S
/$/.c
/}: dragonfly
/tools
/fw_stub.awk
175 ${AWK} -f dragonfly
/tools
/fw_stub.awk
${FIRMWS} -m
${KMOD} -c
${KMOD
:S
/$/.c
/g
} \
176 ${FIRMWARE_LICENSE
:C
/.
+/-l
/}${FIRMWARE_LICENSE}
178 SRCS
+= ${KMOD
:S
/$/.c
/}
179 CLEANFILES
+= ${KMOD
:S
/$/.c
/}
181 .for _firmw in
${FIRMWS}
182 ${_firmw
:C
/\
:.
*$/.fwo
/}: ${_firmw
:C
/\
:.
*$//}
183 @
${ECHO} ${_firmw
:C
/\
:.
*$//} ${.ALLSRC
:M
*${_firmw
:C
/\
:.
*$//}}
184 @if
[ -e
${_firmw
:C
/\
:.
*$//} ]; then \
185 ${LD} -b binary
--no-warn-mismatch
${LDFLAGS} \
186 -r
-d
-o
${.TARGET
} ${_firmw
:C
/\
:.
*$//}; \
188 ln
-s
${.ALLSRC
:M
*${_firmw
:C
/\
:.
*$//}} ${_firmw
:C
/\
:.
*$//}; \
189 ${LD} -b binary
--no-warn-mismatch
${LDFLAGS} \
190 -r
-d
-o
${.TARGET
} ${_firmw
:C
/\
:.
*$//}; \
191 rm ${_firmw
:C
/\
:.
*$//}; \
194 OBJS
+= ${_firmw
:C
/\
:.
*$/.fwo
/}
198 OBJS
+= ${SRCS
:N
*.h
:R
:S
/$/.o
/g
}
204 # In case of LTO provide all standard CFLAGS!
209 .if
${MACHINE_ARCH} != x86_64
211 ${CC} ${ELDFLAGS} -nostdlib
-Wl
,--hash-style
=sysv \
212 -Wl
,-Bshareable
${LDFLAGS} -o
${.TARGET
} ${KMOD}.kld
215 .if
${MACHINE_ARCH} != x86_64
217 ${CC} ${ELDFLAGS} -nostdlib
-Wl
,--hash-style
=sysv \
218 ${LDFLAGS} -r
-o
${.TARGET
} ${OBJS}
221 ${CC} ${ELDFLAGS} -nostdlib
-Wl
,--hash-style
=sysv \
222 ${LDFLAGS} -r
-Wl
,-d
-o
${.TARGET
} ${OBJS}
225 # links to platform and cpu architecture include files. If we are
226 # building with a kernel most of these already exist in the kernel build
229 # 'dragonfly' is a link to system sources.
231 # Note that 'dragonfly', 'machine_base', and 'cpu_base' primarily exist
232 # when source files need to reference sources in the dragonfly codebase or
233 # when header files need to differentiate between compat headers and base
234 # system headers (e.g. when forwarding headers)
236 .if defined
(KERNBUILDDIR
)
239 _ILINKS
=dragonfly machine_base machine cpu_base cpu
246 all: objwarn fwheaders
${PROG}
248 beforedepend
: fwheaders
249 fwheaders
: ${_ILINKS} ${FORWARD_HEADERS_COOKIE}
250 # Ensure that the links exist without depending on it when it exists which
251 # causes all the modules to be rebuilt when the directory pointed to changes.
252 .for _link in
${_ILINKS}
253 .if
!exists
(${.OBJDIR
}/${_link})
258 # Search for kernel source tree in standard places.
259 .for _dir in
${.CURDIR
}/..
/..
${.CURDIR
}/..
/..
/..
${.CURDIR
}/..
/..
/..
/..
/sys
/usr
/src
/sys
260 .if
!defined
(SYSDIR
) && exists
(${_dir}/kern
/)
264 .if
!defined
(SYSDIR
) ||
!exists
(${SYSDIR}/kern
)
265 .error
"can't find kernel source tree"
269 # path=`(cd $$path && /bin/pwd)` ;
272 @case
${.TARGET
} in \
274 path
=${SYSDIR}/platform
/${MACHINE_PLATFORM}/include ;; \
276 path
=${SYSDIR}/platform
/${MACHINE_PLATFORM} ;; \
278 path
=${SYSDIR}/cpu
/${MACHINE_ARCH}/include ;; \
280 path
=${SYSDIR}/cpu
/${MACHINE_ARCH} ;; \
284 path
=${.CURDIR
}/${MACHINE_ARCH} ;; \
286 ${ECHO} ${.TARGET
} "->" $$path ; \
287 ${LN} -s
$$path ${.TARGET
}
289 CLEANFILES
+= ${PROG} ${KMOD}.kld
${OBJS} ${_ILINKS} symb.tmp tmp.o
293 _INSTALLFLAGS
:= ${INSTALLFLAGS}
294 .for ie in
${INSTALLFLAGS_EDIT}
295 _INSTALLFLAGS
:= ${_INSTALLFLAGS
${ie}}
298 .if
!target
(realinstall
)
299 realinstall
: _kmodinstall
300 .ORDER
: beforeinstall _kmodinstall
302 .if defined
(INSTALLSTRIPPEDMODULES
)
303 ${INSTALL} -o
${KMODOWN} -g
${KMODGRP} -m
${KMODMODE} \
304 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
305 ${OBJCOPY} --strip-debug
${DESTDIR}${KMODDIR}/${PROG}
307 ${INSTALL} -o
${KMODOWN} -g
${KMODGRP} -m
${KMODMODE} \
308 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
310 .
endif # !target(realinstall)
312 .
include <bsd.links.mk
>
314 .
endif # !target(install)
318 ${KMODLOAD} -v .
/${KMOD}.ko
323 ${KMODUNLOAD} -v
${KMOD}
326 .for _src in
${SRCS
:Mopt_
*.h
} ${SRCS
:Muse_
*.h
}
329 .if defined
(KERNBUILDDIR
) && exists
(${KERNBUILDDIR}/${_src})
330 ${_src}: ${KERNBUILDDIR}/${_src}
331 # we do not have to copy these files any more, the kernel build
332 # directory is included in the path now.
333 # cp ${KERNBUILDDIR}/${_src} ${.TARGET}
337 .
endif # KERNBUILDDIR
341 MFILES?
= kern
/bus_if.m kern
/device_if.m bus
/iicbus
/iicbb_if.m \
342 bus
/iicbus
/iicbus_if.m bus
/isa
/isa_if.m dev
/netif
/mii_layer
/miibus_if.m \
343 bus
/pccard
/card_if.m bus
/pccard
/power_if.m bus
/pci
/pci_if.m \
345 bus
/ppbus
/ppbus_if.m bus
/smbus
/smbus_if.m bus
/u4b
/usb_if.m \
346 dev
/acpica
/acpi_if.m dev
/acpica
/acpi_wmi_if.m dev
/disk
/nata
/ata_if.m \
347 dev
/disk
/sdhci
/sdhci_if.m \
348 dev
/sound
/pci
/hda
/hdac_if.m \
349 dev
/sound
/pcm
/ac97_if.m dev
/sound
/pcm
/channel_if.m \
350 dev
/sound
/pcm
/feeder_if.m dev
/sound
/pcm
/mixer_if.m \
351 dev
/sound
/midi
/mpu_if.m dev
/sound
/midi
/mpufoi_if.m \
352 dev
/sound
/midi
/synth_if.m \
353 libiconv
/iconv_converter_if.m dev
/agp
/agp_if.m opencrypto
/cryptodev_if.m \
354 bus
/mmc
/mmcbus_if.m bus
/mmc
/mmcbr_if.m \
355 dev
/virtual
/virtio
/virtio
/virtio_bus_if.m \
356 dev
/misc
/backlight
/backlight_if.m dev
/misc
/coremctl
/coremctl_if.m kern
/cpu_if.m \
358 freebsd
/net
/ifdi_if.m
360 .for _srcsrc in
${MFILES}
362 .for _src in
${SRCS
:M
${_srcsrc
:T
:R
}.
${_ext}}
366 .if exists
(dragonfly
)
367 ${_src}: dragonfly
/tools
/makeobjops.awk dragonfly
/${_srcsrc}
370 .if defined
(KERNBUILDDIR
) && \
371 exists
(${KERNBUILDDIR}/${_src})
373 awk
-f dragonfly
/tools
/makeobjops.awk
-- -${_ext} dragonfly
/${_srcsrc}
380 .if
!empty
(SRCS
:Mmiidevs.h
)
381 CLEANFILES
+= miidevs.h
382 .if
!exists
(dragonfly
)
385 miidevs.h
: dragonfly
/tools
/miidevs2h.awk dragonfly
/dev
/netif
/mii_layer
/miidevs
387 ${AWK} -f dragonfly
/tools
/miidevs2h.awk dragonfly
/dev
/netif
/mii_layer
/miidevs
390 .if
!empty
(SRCS
:Mpccarddevs.h
)
391 CLEANFILES
+= pccarddevs.h
392 .if
!exists
(dragonfly
)
393 pccarddevs.h
: dragonfly
395 pccarddevs.h
: dragonfly
/tools
/pccarddevs2h.awk dragonfly
/bus
/pccard
/pccarddevs
397 ${AWK} -f dragonfly
/tools
/pccarddevs2h.awk dragonfly
/bus
/pccard
/pccarddevs
400 .if
!empty
(SRCS
:Mpcidevs.h
)
401 CLEANFILES
+= pcidevs.h
402 .if
!exists
(dragonfly
)
405 pcidevs.h
: dragonfly
/tools
/pcidevs2h.awk dragonfly
/bus
/pci
/pcidevs
407 ${AWK} -f dragonfly
/tools
/pcidevs2h.awk dragonfly
/bus
/pci
/pcidevs
410 .if
!empty
(SRCS
:Musbdevs.h
)
411 CLEANFILES
+= usbdevs.h
412 .if
!exists
(dragonfly
)
415 usbdevs.h
: dragonfly
/tools
/usbdevs2h.awk dragonfly
/bus
/u4b
/usbdevs
417 ${AWK} -f dragonfly
/tools
/usbdevs2h.awk dragonfly
/bus
/u4b
/usbdevs
-h
420 .if
!empty
(SRCS
:Musbdevs_data.h
)
421 CLEANFILES
+= usbdevs_data.h
422 .if
!exists
(dragonfly
)
423 usbdevs_data.h
: dragonfly
425 usbdevs_data.h
: dragonfly
/tools
/usbdevs2h.awk dragonfly
/bus
/u4b
/usbdevs
427 ${AWK} -f dragonfly
/tools
/usbdevs2h.awk dragonfly
/bus
/u4b
/usbdevs
-d
430 .if
!empty
(SRCS
:Macpi_quirks.h
)
431 CLEANFILES
+= acpi_quirks.h
432 .if
!exists
(dragonfly
)
433 acpi_quirks.h
: dragonfly
435 acpi_quirks.h
: dragonfly
/tools
/acpi_quirks2h.awk dragonfly
/dev
/acpica
/acpi_quirks
437 ${AWK} -f dragonfly
/tools
/acpi_quirks2h.awk dragonfly
/dev
/acpica
/acpi_quirks
440 .if
!empty
(SRCS
:Massym.s
)
441 CLEANFILES
+= assym.s genassym.o
443 .if defined
(KERNBUILDDIR
)
444 genassym.o
: opt_global.h
446 .if
!exists
(dragonfly
)
449 assym.s
: dragonfly
/kern
/genassym.sh
451 sh dragonfly
/kern
/genassym.sh genassym.o
> ${.TARGET
}
452 .if exists
(dragonfly
)
453 genassym.o
: dragonfly
/platform
/${MACHINE_PLATFORM}/${MACHINE_ARCH}/genassym.c
455 genassym.o
: dragonfly
${SRCS
:Mopt_
*.h
}
456 ${CC} -c
${CFLAGS
:N-fno-common
:N-flto
:N-mcmodel
=small
} -fcommon \
457 ${WERROR} dragonfly
/platform
/${MACHINE_PLATFORM}/${MACHINE_ARCH}/genassym.c
462 .
include <bsd.dep.mk
>
464 .if
!exists
(${DEPENDFILE})
465 ${OBJS}: ${SRCS
:M
*.h
}
468 .
include <bsd.obj.mk
>
469 .
include "bsd.kern.mk"
471 # Behaves like MODULE_OVERRIDE
472 .if defined
(KLD_DEPS
)
474 _kdeps_all
: dragonfly
475 .for _mdep in
${KLD_DEPS}
476 cd
${SYSDIR}/${_mdep} && make
all
478 depend
: _kdeps_depend
479 _kdeps_depend
: dragonfly
480 .for _mdep in
${KLD_DEPS}
481 cd
${SYSDIR}/${_mdep} && make depend
483 install: _kdeps_install
484 _kdeps_install
: dragonfly
485 .for _mdep in
${KLD_DEPS}
486 cd
${SYSDIR}/${_mdep} && make
install
489 _kdeps_clean
: dragonfly
490 .for _mdep in
${KLD_DEPS}
491 cd
${SYSDIR}/${_mdep} && make
clean