]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/conf/kmod.mk
Reorg vm_page.c into vm_page.c, vm_pageq.c, and vm_contig.c (for contigmalloc).
[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 # NOMAN         KLD does not have a manual page if set.
36 #
37 # PROG          The name of the kernel module to build.
38 #               If not supplied, ${KMOD}.o is used.
39 #
40 # SRCS          List of source files
41 #
42 # SUBDIR        A list of subdirectories that should be built as well.
43 #               Each of the targets will execute the same target in the
44 #               subdirectories.
45 #
46 # SYMLINKS      Same as LINKS, except it creates symlinks and the
47 #               linked-to pathname may be relative.
48 #
49 # DESTDIR, DISTDIR are set by other Makefiles (e.g. bsd.own.mk)
50 #
51 # MFILES        Optionally a list of interfaces used by the module.
52 #               This file contains a default list of interfaces.
53 #
54 # +++ targets +++
55 #
56 #       distribute:
57 #               This is a variant of install, which will
58 #               put the stuff into the right "distribution".
59 #
60 #       install:
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
65 #               is executed.
66 #
67 #       load:
68 #               Load KLD.
69 #
70 #       unload:
71 #               Unload KLD.
72 #
73 # bsd.obj.mk: clean, cleandir and obj
74 # bsd.dep.mk: cleandepend, depend and tags
75 # bsd.man.mk: maninstall
76 #
77
78 KMODLOAD?=      /sbin/kldload
79 KMODUNLOAD?=    /sbin/kldunload
80
81 TARGET_ARCH?=   ${MACHINE_ARCH}
82
83 .if !target(__initialized__)
84 __initialized__:
85 .if exists(${.CURDIR}/../Makefile.inc)
86 .include "${.CURDIR}/../Makefile.inc"
87 .endif
88 .endif
89
90 .SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
91
92 CFLAGS+=        ${COPTS} -D_KERNEL ${CWARNFLAGS}
93 CFLAGS+=        -DKLD_MODULE
94
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}
101
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
106
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.
111 .if exists(@)
112 .if exists(@/../include)
113 CFLAGS+=        -I@/../include
114 .else
115 CFLAGS+=        -I${DESTDIR}/usr/include
116 .endif
117 .else # !@
118 CFLAGS+=        -I@/../include -I${DESTDIR}/usr/include
119 .endif # @
120
121 CFLAGS+=        ${DEBUG_FLAGS}
122
123 .if ${OBJFORMAT} == elf
124 CLEANFILES+=    setdef0.c setdef1.c setdefs.h
125 CLEANFILES+=    setdef0.o setdef1.o
126 .endif
127
128 OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
129
130 .if !defined(PROG)
131 PROG=   ${KMOD}.ko
132 .endif
133
134 ${PROG}: ${KMOD}.kld
135         ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld
136
137 ${KMOD}.kld: ${OBJS}
138         ${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS}
139
140 .if !defined(NOMAN)
141 .if 0
142 MAN?=   ${KMOD}.4
143 .endif
144 .include <bsd.man.mk>
145 .else
146 .if !target(all-man)
147 all-man: _SUBDIR
148 .endif
149 .if !target(maninstall)
150 maninstall: _SUBDIR
151 .endif
152 .endif
153
154 _ILINKS=@ machine
155
156 .MAIN: all
157 all: objwarn ${PROG} all-man _SUBDIR
158
159 beforedepend: ${_ILINKS}
160         @rm -f .depend
161
162 # Ensure that the links exist without depending on it when it exists which
163 # causes all the modules to be rebuilt when the directory pointed to changes.
164 .for _link in ${_ILINKS}
165 .if !exists(${.OBJDIR}/${_link})
166 ${OBJS}: ${_link}
167 .endif
168 .endfor
169
170 # Search for kernel source tree in standard places.
171 .for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys
172 .if !defined(SYSDIR) && exists(${_dir}/kern/)
173 SYSDIR= ${_dir}
174 .endif
175 .endfor
176 .if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
177 .error "can't find kernel source tree"
178 .endif
179
180 ${_ILINKS}:
181         @case ${.TARGET} in \
182         machine) \
183                 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \
184         @) \
185                 path=${SYSDIR} ;; \
186         esac ; \
187         path=`(cd $$path && /bin/pwd)` ; \
188         ${ECHO} ${.TARGET} "->" $$path ; \
189         ln -s $$path ${.TARGET}
190
191 CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
192
193 .if !target(install)
194 .if !target(beforeinstall)
195 beforeinstall:
196 .endif
197 .if !target(afterinstall)
198 afterinstall:
199 .endif
200
201 _INSTALLFLAGS:= ${INSTALLFLAGS}
202 .for ie in ${INSTALLFLAGS_EDIT}
203 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
204 .endfor
205
206 realinstall: _SUBDIR
207         ${INSTALL} ${COPY} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
208             ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
209 .if defined(LINKS) && !empty(LINKS)
210         @set ${LINKS}; \
211         while test $$# -ge 2; do \
212                 l=${DESTDIR}$$1; \
213                 shift; \
214                 t=${DESTDIR}$$1; \
215                 shift; \
216                 ${ECHO} $$t -\> $$l; \
217                 ln -f $$l $$t; \
218         done; true
219 .endif
220 .if defined(SYMLINKS) && !empty(SYMLINKS)
221         @set ${SYMLINKS}; \
222         while test $$# -ge 2; do \
223                 l=$$1; \
224                 shift; \
225                 t=${DESTDIR}$$1; \
226                 shift; \
227                 ${ECHO} $$t -\> $$l; \
228                 ln -fs $$l $$t; \
229         done; true
230 .endif
231
232 install: afterinstall _SUBDIR
233 .if !defined(NOMAN)
234 afterinstall: realinstall maninstall
235 .else
236 afterinstall: realinstall
237 .endif
238 realinstall: beforeinstall
239 .endif
240
241 DISTRIBUTION?=  bin
242 .if !target(distribute)
243 distribute: _SUBDIR
244 .for dist in ${DISTRIBUTION}
245         cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
246 .endfor
247 .endif
248
249 .if !target(load)
250 load:   ${PROG}
251         ${KMODLOAD} -v ./${KMOD}.ko
252 .endif
253
254 .if !target(unload)
255 unload:
256         ${KMODUNLOAD} -v ${KMOD}
257 .endif
258
259 .for _src in ${SRCS:Mopt_*.h}
260 CLEANFILES+=    ${_src}
261 .if !target(${_src})
262 ${_src}:
263         touch ${.TARGET}
264 .endif
265 .endfor
266
267 MFILES?= kern/bus_if.m kern/device_if.m dev/iicbus/iicbb_if.m \
268     dev/iicbus/iicbus_if.m isa/isa_if.m \
269     libkern/iconv_converter_if.m \
270     dev/mii/miibus_if.m \
271     dev/pccard/card_if.m dev/pccard/power_if.m dev/pci/pci_if.m \
272     dev/pci/pcib_if.m dev/ppbus/ppbus_if.m dev/smbus/smbus_if.m \
273     dev/usb/usb_if.m dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
274     dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m pci/agp_if.m
275
276 .for _srcsrc in ${MFILES}
277 .for _ext in c h
278 .for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
279 CLEANFILES+=    ${_src}
280 .if !target(${_src})
281 .if !exists(@)
282 ${_src}: @
283 .endif
284 .if exists(@)
285 ${_src}: @/kern/makeobjops.pl @/${_srcsrc}
286 .endif
287         perl @/kern/makeobjops.pl -${_ext} @/${_srcsrc}
288 .endif
289 .endfor # _src
290 .endfor # _ext
291 .endfor # _srcsrc
292
293 .for _ext in c h
294 .if ${SRCS:Mvnode_if.${_ext}} != ""
295 CLEANFILES+=    vnode_if.${_ext}
296 .if !exists(@)
297 vnode_if.${_ext}: @
298 .endif
299 .if exists(@)
300 vnode_if.${_ext}: @/kern/vnode_if.pl @/kern/vnode_if.src
301 .endif
302         perl @/kern/vnode_if.pl -${_ext} @/kern/vnode_if.src
303 .endif
304 .endfor
305
306 regress:
307
308 .include <bsd.dep.mk>
309
310 .if !exists(${DEPENDFILE})
311 ${OBJS}: ${SRCS:M*.h}
312 .endif
313
314 .include <bsd.obj.mk>
315
316 .include <bsd.kern.mk>