1 # From: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91
4 # The include file <bsd.kmod.mk> handles installing Kernel Loadable Device
10 # CLEANFILES Additional files to remove for the clean and cleandir targets.
12 # DISTRIBUTION Name of distribution. [bin]
14 # KMOD The name of the kernel module to build.
16 # KMODDIR Base path for kernel modules (see kld(4)). [/boot/kernel]
18 # KMODOWN KLD owner. [${BINOWN}]
20 # KMODGRP KLD group. [${BINGRP}]
22 # KMODMODE KLD mode. [${BINMODE}]
24 # LINKS The list of KLD links; should be full pathnames, the
25 # linked-to file coming first, followed by the linked
26 # file. The files are hard-linked. For example, to link
27 # /modules/master and /modules/meister, use:
29 # LINKS= /modules/master /modules/meister
31 # KMODLOAD Command to load a kernel module [/sbin/kldload]
33 # KMODUNLOAD Command to unload a kernel module [/sbin/kldunload]
35 # PROG The name of the kernel module to build.
36 # If not supplied, ${KMOD}.o is used.
38 # SRCS List of source files
40 # SUBDIR A list of subdirectories that should be built as well.
41 # Each of the targets will execute the same target in the
44 # SYMLINKS Same as LINKS, except it creates symlinks and the
45 # linked-to pathname may be relative.
47 # DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk)
49 # MFILES Optionally a list of interfaces used by the module.
50 # This file contains a default list of interfaces.
52 # EXPORT_SYMS A list of symbols that should be exported from the module,
53 # or the name of a file containing a list of symbols, or YES
54 # to export all symbols. If not defined, no symbols are
60 # This is a variant of install, which will
61 # put the stuff into the right "distribution".
64 # install the kernel module; if the Makefile
65 # does not itself define the target install, the targets
66 # beforeinstall and afterinstall may also be used to cause
67 # actions immediately before and after the install target
76 # bsd.obj.mk: clean, cleandir and obj
77 # bsd.dep.mk: cleandepend, depend and tags
81 KMODLOAD?= /sbin/kldload
82 KMODUNLOAD?= /sbin/kldunload
86 .error "Do not use KMODDEPS on 5.0+, use MODULE_VERSION/MODULE_DEPEND"
89 .include <bsd.init.mk>
91 .SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
93 CFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS}
96 # Don't use any standard or source-relative include directories.
97 # Since -nostdinc will annull any previous -I paths, we repeat all
98 # such paths after -nostdinc. It doesn't seem to be possible to
99 # add to the front of `make' variable.
100 _ICFLAGS:= ${CFLAGS:M-I*}
101 CFLAGS+= -nostdinc -I- ${INCLMAGIC} ${_ICFLAGS}
103 # Add -I paths for system headers. Individual KLD makefiles don't
104 # need any -I paths for this. Similar defaults for .PATH can't be
105 # set because there are no standard paths for non-headers.
106 CFLAGS+= -I. -I@ -I@/dev
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.
113 .if exists(@/../include)
114 CFLAGS+= -I@/../include
116 CFLAGS+= -I${DESTDIR}/usr/include
119 CFLAGS+= -I@/../include -I${DESTDIR}/usr/include
122 # Disallow common variables, and if we end up with commons from
123 # somewhere unexpected, allocate storage for them in the module itself.
125 LDFLAGS+= -d -warn-common
127 CFLAGS+= ${DEBUG_FLAGS}
129 .if ${OBJFORMAT} == elf
130 CLEANFILES+= setdef0.c setdef1.c setdefs.h
131 CLEANFILES+= setdef0.o setdef1.o
134 OBJS+= ${SRCS:N*.h:R:S/$/.o/g}
143 FULLPROG= ${PROG}.debug
145 ${OBJCOPY} --strip-debug ${FULLPROG} ${PROG}
148 ${FULLPROG}: ${KMOD}.kld
149 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld
152 .if ${EXPORT_SYMS} != YES
153 CLEANFILES+= ${.OBJDIR}/export_syms
157 ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS}
158 .if defined(EXPORT_SYMS)
159 .if ${EXPORT_SYMS} != YES
160 .if ${EXPORT_SYMS} == NO
161 touch ${.OBJDIR}/export_syms
162 .elif !exists(${.CURDIR}/${EXPORT_SYMS})
163 echo ${EXPORT_SYMS} > ${.OBJDIR}/export_syms
165 grep -v '^#' < ${EXPORT_SYMS} > ${.OBJDIR}/export_syms
167 awk -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \
168 ${.OBJDIR}/export_syms | \
169 xargs -J% ${OBJCOPY} % ${.TARGET}
178 beforedepend: ${_ILINKS}
181 # Ensure that the links exist without depending on it when it exists which
182 # causes all the modules to be rebuilt when the directory pointed to changes.
183 .for _link in ${_ILINKS}
184 .if !exists(${.OBJDIR}/${_link})
189 # Search for kernel source tree in standard places.
190 .for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys
191 .if !defined(SYSDIR) && exists(${_dir}/kern/)
195 .if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
196 .error "can't find kernel source tree"
200 @case ${.TARGET} in \
202 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \
206 path=`(cd $$path && /bin/pwd)` ; \
207 ${ECHO} ${.TARGET} "->" $$path ; \
208 ln -s $$path ${.TARGET}
210 CLEANFILES+= ${PROG} ${FULLPROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
213 .if !target(beforeinstall)
216 .if !target(afterinstall)
220 _INSTALLFLAGS:= ${INSTALLFLAGS}
221 .for ie in ${INSTALLFLAGS_EDIT}
222 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
227 cd ${.CURDIR}; ${MAKE} -DINSTALL_DEBUG install
231 .if defined(DEBUG) && defined(INSTALL_DEBUG)
232 ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
233 ${_INSTALLFLAGS} ${FULLPROG} ${DESTDIR}${KMODDIR}/
235 ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
236 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}/
237 .if defined(LINKS) && !empty(LINKS)
239 while test $$# -ge 2; do \
244 ${ECHO} $$t -\> $$l; \
248 .if defined(SYMLINKS) && !empty(SYMLINKS)
250 while test $$# -ge 2; do \
255 ${ECHO} $$t -\> $$l; \
259 .if !defined(NO_XREF)
260 @echo "FAILURES HERE ARE OK"
261 -kldxref ${DESTDIR}${KMODDIR}
262 @echo "END OF SECTION WHERE FAILURES ARE OK"
266 install: afterinstall
267 afterinstall: realinstall
268 realinstall: beforeinstall
272 .if !target(distribute)
274 .for dist in ${DISTRIBUTION}
275 cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
281 ${KMODLOAD} -v ${.CURDIR}/${KMOD}.ko
286 ${KMODUNLOAD} -v ${KMOD}
289 .for _src in ${SRCS:Mopt_*.h}
297 MFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \
298 dev/iicbus/iicbus_if.m isa/isa_if.m \
299 libkern/iconv_converter_if.m \
300 dev/mii/miibus_if.m \
301 dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \
302 dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \
303 dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
304 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m pci/agp_if.m
306 .for _srcsrc in ${MFILES}
308 .for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
315 ${_src}: @/tools/makeobjops.awk @/${_srcsrc}
317 ${AWK} -f @/tools/makeobjops.awk @/${_srcsrc} -${_ext}
324 .if ${SRCS:Mvnode_if.${_ext}} != ""
325 CLEANFILES+= vnode_if.${_ext}
330 vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src
332 ${AWK} -f @/tools/vnode_if.awk @/kern/vnode_if.src -${_ext}
339 ${LINT} ${LINTKERNFLAGS} ${CFLAGS:M-[DILU]*} ${.ALLSRC:M*.c}
341 .include <bsd.dep.mk>
343 .if !exists(${DEPENDFILE})
344 ${OBJS}: ${SRCS:M*.h}
347 .include <bsd.obj.mk>
349 .include <bsd.kern.mk>