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 # NOMAN KLD does not have a manual page if set.
37 # PROG The name of the kernel module to build.
38 # If not supplied, ${KMOD}.o is used.
40 # SRCS List of source files
42 # SUBDIR A list of subdirectories that should be built as well.
43 # Each of the targets will execute the same target in the
46 # SYMLINKS Same as LINKS, except it creates symlinks and the
47 # linked-to pathname may be relative.
49 # DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk)
51 # MFILES Optionally a list of interfaces used by the module.
52 # This file contains a default list of interfaces.
57 # This is a variant of install, which will
58 # put the stuff into the right "distribution".
61 # install the program and its manual pages; if the Makefile
62 # does not itself define the target install, the targets
63 # beforeinstall and afterinstall may also be used to cause
64 # actions immediately before and after the install target
73 # bsd.obj.mk: clean, cleandir and obj
74 # bsd.dep.mk: cleandepend, depend and tags
75 # bsd.man.mk: maninstall
78 KMODLOAD?= /sbin/kldload
79 KMODUNLOAD?= /sbin/kldunload
81 TARGET_ARCH?= ${MACHINE_ARCH}
83 .if !target(__initialized__)
85 .if exists(${.CURDIR}/../Makefile.inc)
86 .include "${.CURDIR}/../Makefile.inc"
90 .SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
92 CFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS}
95 # Don't use any standard or source-relative include directories.
96 # Since -nostdinc will annull any previous -I paths, we repeat all
97 # such paths after -nostdinc. It doesn't seem to be possible to
98 # add to the front of `make' variable.
99 _ICFLAGS:= ${CFLAGS:M-I*}
100 CFLAGS+= -nostdinc -I- ${INCLMAGIC} ${_ICFLAGS}
102 # Add -I paths for system headers. Individual KLD makefiles don't
103 # need any -I paths for this. Similar defaults for .PATH can't be
104 # set because there are no standard paths for non-headers.
105 CFLAGS+= -I. -I@ -I@/dev
107 # Add a -I path to standard headers like <stddef.h>. Use a relative
108 # path to src/include if possible. If the @ symlink hasn't been built
109 # yet, then we can't tell if the relative path exists. Add both the
110 # potential relative path and an absolute path in that case.
112 .if exists(@/../include)
113 CFLAGS+= -I@/../include
115 CFLAGS+= -I${DESTDIR}/usr/include
118 CFLAGS+= -I@/../include -I${DESTDIR}/usr/include
121 CFLAGS+= ${DEBUG_FLAGS}
123 .if ${OBJFORMAT} == elf
124 CLEANFILES+= setdef0.c setdef1.c setdefs.h
125 CLEANFILES+= setdef0.o setdef1.o
128 OBJS+= ${SRCS:N*.h:R:S/$/.o/g}
135 .if ${OBJFORMAT} == elf
136 perl5 @/kern/gensetdefs.pl ${KMOD}.kld
137 ${CC} ${CFLAGS} -c setdef0.c
138 ${CC} ${CFLAGS} -c setdef1.c
139 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} setdef0.o ${KMOD}.kld setdef1.o
141 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld
145 ${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS}
151 .include <bsd.man.mk>
156 .if !target(maninstall)
164 all: objwarn ${PROG} all-man _SUBDIR
166 beforedepend: ${_ILINKS}
169 # Ensure that the links exist without depending on it when it exists which
170 # causes all the modules to be rebuilt when the directory pointed to changes.
171 .for _link in ${_ILINKS}
172 .if !exists(${.OBJDIR}/${_link})
177 # Search for kernel source tree in standard places.
178 .for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys
179 .if !defined(SYSDIR) && exists(${_dir}/kern/)
183 .if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
184 .error "can't find kernel source tree"
188 @case ${.TARGET} in \
190 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \
194 path=`(cd $$path && /bin/pwd)` ; \
195 ${ECHO} ${.TARGET} "->" $$path ; \
196 ln -s $$path ${.TARGET}
198 CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
201 .if !target(beforeinstall)
204 .if !target(afterinstall)
208 _INSTALLFLAGS:= -fschg ${INSTALLFLAGS}
209 .for ie in ${INSTALLFLAGS_EDIT}
210 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
214 ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
215 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
216 .if defined(LINKS) && !empty(LINKS)
218 while test $$# -ge 2; do \
223 ${ECHO} $$t -\> $$l; \
227 .if defined(SYMLINKS) && !empty(SYMLINKS)
229 while test $$# -ge 2; do \
234 ${ECHO} $$t -\> $$l; \
239 install: afterinstall _SUBDIR
241 afterinstall: realinstall maninstall
243 afterinstall: realinstall
245 realinstall: beforeinstall
249 .if !target(distribute)
251 .for dist in ${DISTRIBUTION}
252 cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
258 ${KMODLOAD} -v ./${KMOD}.ko
263 ${KMODUNLOAD} -v ${KMOD}
266 .for _src in ${SRCS:Mopt_*.h}
274 MFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \
275 dev/iicbus/iicbus_if.m isa/isa_if.m dev/mii/miibus_if.m \
276 dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \
277 dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \
278 dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
279 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m pci/agp_if.m
281 .for _srcsrc in ${MFILES}
283 .for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
290 ${_src}: @/kern/makeobjops.pl @/${_srcsrc}
292 perl @/kern/makeobjops.pl -${_ext} @/${_srcsrc}
299 .if ${SRCS:Mvnode_if.${_ext}} != ""
300 CLEANFILES+= vnode_if.${_ext}
305 vnode_if.${_ext}: @/kern/vnode_if.pl @/kern/vnode_if.src
307 perl @/kern/vnode_if.pl -${_ext} @/kern/vnode_if.src
313 .include <bsd.dep.mk>
315 .if !exists(${DEPENDFILE})
316 ${OBJS}: ${SRCS:M*.h}
319 .include <bsd.obj.mk>
321 .include <bsd.kern.mk>