]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/conf/kmod.mk
This commit was generated by cvs2svn to compensate for changes in r90019,
[FreeBSD/FreeBSD.git] / sys / conf / kmod.mk
1 #       From: @(#)bsd.prog.mk   5.26 (Berkeley) 6/25/91
2 # $FreeBSD$
3 #
4 # The include file <bsd.kmod.mk> handles installing Kernel Loadable Device
5 # drivers (KLD's).
6 #
7 #
8 # +++ variables +++
9 #
10 # CLEANFILES    Additional files to remove for the clean and cleandir targets.
11 #
12 # DISTRIBUTION  Name of distribution. [bin]
13 #
14 # KMOD          The name of the kernel module to build.
15 #
16 # KMODDIR       Base path for kernel modules (see kld(4)). [/boot/kernel]
17 #
18 # KMODOWN       KLD owner. [${BINOWN}]
19 #
20 # KMODGRP       KLD group. [${BINGRP}]
21 #
22 # KMODMODE      KLD mode. [${BINMODE}]
23 #
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:
28 #
29 #                       LINKS=  /modules/master /modules/meister
30 #
31 # KMODLOAD      Command to load a kernel module [/sbin/kldload]
32 #
33 # KMODUNLOAD    Command to unload a kernel module [/sbin/kldunload]
34 #
35 # PROG          The name of the kernel module to build.
36 #               If not supplied, ${KMOD}.o is used.
37 #
38 # SRCS          List of source files
39 #
40 # SUBDIR        A list of subdirectories that should be built as well.
41 #               Each of the targets will execute the same target in the
42 #               subdirectories.
43 #
44 # SYMLINKS      Same as LINKS, except it creates symlinks and the
45 #               linked-to pathname may be relative.
46 #
47 # DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk)
48 #
49 # MFILES        Optionally a list of interfaces used by the module.
50 #               This file contains a default list of interfaces.
51 #
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
55 #               exported.
56 #
57 # +++ targets +++
58 #
59 #       distribute:
60 #               This is a variant of install, which will
61 #               put the stuff into the right "distribution".
62 #
63 #       install:
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
68 #               is executed.
69 #
70 #       load:
71 #               Load KLD.
72 #
73 #       unload:
74 #               Unload KLD.
75 #
76 # bsd.obj.mk: clean, cleandir and obj
77 # bsd.dep.mk: cleandepend, depend and tags
78 #
79
80 KMODLOAD?=      /sbin/kldload
81 KMODUNLOAD?=    /sbin/kldunload
82 OBJCOPY?=       objcopy
83
84 TARGET_ARCH?=   ${MACHINE_ARCH}
85
86 .if !target(__initialized__)
87 __initialized__:
88 .if exists(${.CURDIR}/../Makefile.inc)
89 .include "${.CURDIR}/../Makefile.inc"
90 .endif
91 .endif
92
93 .SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
94
95 CFLAGS+=        ${COPTS} -D_KERNEL ${CWARNFLAGS}
96 CFLAGS+=        -DKLD_MODULE
97
98 # Don't use any standard or source-relative include directories.
99 # Since -nostdinc will annull any previous -I paths, we repeat all
100 # such paths after -nostdinc.  It doesn't seem to be possible to
101 # add to the front of `make' variable.
102 _ICFLAGS:=      ${CFLAGS:M-I*}
103 CFLAGS+=        -nostdinc -I- ${INCLMAGIC} ${_ICFLAGS}
104
105 # Add -I paths for system headers.  Individual KLD makefiles don't
106 # need any -I paths for this.  Similar defaults for .PATH can't be
107 # set because there are no standard paths for non-headers.
108 CFLAGS+=        -I. -I@ -I@/dev
109
110 # Add a -I path to standard headers like <stddef.h>.  Use a relative
111 # path to src/include if possible.  If the @ symlink hasn't been built
112 # yet, then we can't tell if the relative path exists.  Add both the
113 # potential relative path and an absolute path in that case.
114 .if exists(@)
115 .if exists(@/../include)
116 CFLAGS+=        -I@/../include
117 .else
118 CFLAGS+=        -I${DESTDIR}/usr/include
119 .endif
120 .else # !@
121 CFLAGS+=        -I@/../include -I${DESTDIR}/usr/include
122 .endif # @
123
124 # Disallow common variables, and if we end up with commons from
125 # somewhere unexpected, allocate storage for them in the module itself.
126 CFLAGS+=        -fno-common
127 LDFLAGS+=       -d -warn-common
128
129 CFLAGS+=        ${DEBUG_FLAGS}
130
131 .if ${OBJFORMAT} == elf
132 CLEANFILES+=    setdef0.c setdef1.c setdefs.h
133 CLEANFILES+=    setdef0.o setdef1.o
134 .endif
135
136 OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
137
138 .if !defined(PROG)
139 PROG=   ${KMOD}.ko
140 .endif
141
142 .if !defined(DEBUG)
143 FULLPROG=       ${PROG}
144 .else
145 FULLPROG=       ${PROG}.debug
146 ${PROG}: ${FULLPROG}
147         ${OBJCOPY} --strip-debug ${FULLPROG} ${PROG}
148 .endif
149
150 ${FULLPROG}: ${KMOD}.kld
151         ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld
152
153 EXPORT_SYMS?=   NO
154 .if ${EXPORT_SYMS} != YES
155 CLEANFILES+=    ${.OBJDIR}/export_syms
156 .endif
157
158 ${KMOD}.kld: ${OBJS}
159         ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS}
160 .if defined(EXPORT_SYMS)
161 .if ${EXPORT_SYMS} != YES
162 .if ${EXPORT_SYMS} == NO
163         touch ${.OBJDIR}/export_syms
164 .elif !exists(${.CURDIR}/${EXPORT_SYMS})
165         echo ${EXPORT_SYMS} > ${.OBJDIR}/export_syms
166 .else
167         grep -v '^#' < ${EXPORT_SYMS} >  ${.OBJDIR}/export_syms
168 .endif
169         awk -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \
170                 ${.OBJDIR}/export_syms | \
171         xargs -J% ${OBJCOPY} % ${.TARGET}
172 .endif
173 .endif
174
175
176 .if !target(all-man)
177 all-man: _SUBDIR
178 .endif
179 .if !target(maninstall)
180 maninstall: _SUBDIR
181 .endif
182
183 _ILINKS=@ machine
184
185 .MAIN: all
186 all: objwarn ${PROG} _SUBDIR
187
188 beforedepend: ${_ILINKS}
189         @rm -f .depend
190
191 # Ensure that the links exist without depending on it when it exists which
192 # causes all the modules to be rebuilt when the directory pointed to changes.
193 .for _link in ${_ILINKS}
194 .if !exists(${.OBJDIR}/${_link})
195 ${OBJS}: ${_link}
196 .endif
197 .endfor
198
199 # Search for kernel source tree in standard places.
200 .for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys
201 .if !defined(SYSDIR) && exists(${_dir}/kern/)
202 SYSDIR= ${_dir}
203 .endif
204 .endfor
205 .if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
206 .error "can't find kernel source tree"
207 .endif
208
209 ${_ILINKS}:
210         @case ${.TARGET} in \
211         machine) \
212                 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \
213         @) \
214                 path=${SYSDIR} ;; \
215         esac ; \
216         path=`(cd $$path && /bin/pwd)` ; \
217         ${ECHO} ${.TARGET} "->" $$path ; \
218         ln -s $$path ${.TARGET}
219
220 CLEANFILES+= ${PROG} ${FULLPROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
221
222 .if !target(install)
223 .if !target(beforeinstall)
224 beforeinstall:
225 .endif
226 .if !target(afterinstall)
227 afterinstall:
228 .endif
229
230 _INSTALLFLAGS:= ${INSTALLFLAGS}
231 .for ie in ${INSTALLFLAGS_EDIT}
232 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
233 .endfor
234
235 install.debug: _SUBDIR
236         ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
237             ${_INSTALLFLAGS} ${FULLPROG} ${DESTDIR}${KMODDIR}/
238
239 realinstall: _SUBDIR
240         ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
241             ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}/
242 .if defined(LINKS) && !empty(LINKS)
243         @set ${LINKS}; \
244         while test $$# -ge 2; do \
245                 l=${DESTDIR}$$1; \
246                 shift; \
247                 t=${DESTDIR}$$1; \
248                 shift; \
249                 ${ECHO} $$t -\> $$l; \
250                 ln -f $$l $$t; \
251         done; true
252 .endif
253 .if defined(SYMLINKS) && !empty(SYMLINKS)
254         @set ${SYMLINKS}; \
255         while test $$# -ge 2; do \
256                 l=$$1; \
257                 shift; \
258                 t=${DESTDIR}$$1; \
259                 shift; \
260                 ${ECHO} $$t -\> $$l; \
261                 ln -fs $$l $$t; \
262         done; true
263 .endif
264 .if !defined(NO_XREF)
265         -kldxref ${DESTDIR}${KMODDIR}
266 .endif
267
268 install: afterinstall _SUBDIR
269 afterinstall: realinstall
270 realinstall: beforeinstall
271 .endif
272
273 DISTRIBUTION?=  bin
274 .if !target(distribute)
275 distribute: _SUBDIR
276 .for dist in ${DISTRIBUTION}
277         cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
278 .endfor
279 .endif
280
281 .if !target(load)
282 load:   ${PROG}
283         ${KMODLOAD} -v ${.CURDIR}/${KMOD}.ko
284 .endif
285
286 .if !target(unload)
287 unload:
288         ${KMODUNLOAD} -v ${KMOD}
289 .endif
290
291 .for _src in ${SRCS:Mopt_*.h}
292 CLEANFILES+=    ${_src}
293 .if !target(${_src})
294 ${_src}:
295         touch ${.TARGET}
296 .endif
297 .endfor
298
299 MFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \
300     dev/iicbus/iicbus_if.m isa/isa_if.m \
301     libkern/iconv_converter_if.m \
302     dev/mii/miibus_if.m \
303     dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \
304     dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \
305     dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
306     dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m pci/agp_if.m
307
308 .for _srcsrc in ${MFILES}
309 .for _ext in c h
310 .for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
311 CLEANFILES+=    ${_src}
312 .if !target(${_src})
313 .if !exists(@)
314 ${_src}: @
315 .endif
316 .if exists(@)
317 ${_src}: @/kern/makeobjops.pl @/${_srcsrc}
318 .endif
319         perl @/kern/makeobjops.pl -${_ext} @/${_srcsrc}
320 .endif
321 .endfor # _src
322 .endfor # _ext
323 .endfor # _srcsrc
324
325 .for _ext in c h
326 .if ${SRCS:Mvnode_if.${_ext}} != ""
327 CLEANFILES+=    vnode_if.${_ext}
328 .if !exists(@)
329 vnode_if.${_ext}: @
330 .endif
331 .if exists(@)
332 vnode_if.${_ext}: @/kern/vnode_if.pl @/kern/vnode_if.src
333 .endif
334         perl @/kern/vnode_if.pl -${_ext} @/kern/vnode_if.src
335 .endif
336 .endfor
337
338 regress:
339
340 .include <bsd.dep.mk>
341
342 .if !exists(${DEPENDFILE})
343 ${OBJS}: ${SRCS:M*.h}
344 .endif
345
346 .include <bsd.obj.mk>
347
348 .include <bsd.kern.mk>