Add MD, optimized versions of string functions for amd64.
[dragonfly.git] / sys / conf / kmod.mk
blob25c46ba44b8f809538dce5eaf1fb87c3563f03f9
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 $
3 # $DragonFly: src/sys/conf/kmod.mk,v 1.35 2008/08/27 16:35:19 hasso Exp $
5 # The include file <bsd.kmod.mk> handles installing Kernel Loadable Device
6 # drivers (KLD's).
9 # +++ variables +++
11 # CLEANFILES Additional files to remove for the clean and cleandir targets.
13 # KMOD The name of the kernel module to build.
15 # KMODDIR Base path for kernel modules (see kld(4)).
16 # [${DESTKERNDIR}/${DESTMODULESNAME}]
18 # KMODOWN KLD owner. [${BINOWN}]
20 # KMODGRP KLD group. [${BINGRP}]
22 # KMODMODE KLD mode. [${BINMODE}]
24 # KMODLOAD Command to load a kernel module [/sbin/kldload]
26 # KMODUNLOAD Command to unload a kernel module [/sbin/kldunload]
28 # NOMAN KLD does not have a manual page if set.
30 # PROG The name of the kernel module to build.
31 # If not supplied, ${KMOD}.o is used.
33 # SRCS List of source files
35 # KMODDEPS List of modules which this one is dependant on
37 # DESTKERNDIR Change the tree where the kernel and the modules get
38 # installed. [/boot] ${DESTDIR} changes the root of the tree
39 # pointed to by ${DESTKERNDIR}.
41 # MFILES Optionally a list of interfaces used by the module.
42 # This file contains a default list of interfaces.
44 # +++ targets +++
46 # install:
47 # install the kernel module and its manual pages; if the Makefile
48 # does not itself define the target install, the targets
49 # beforeinstall and afterinstall may also be used to cause
50 # actions immediately before and after the install target
51 # is executed.
53 # load:
54 # Load KLD.
56 # unload:
57 # Unload KLD.
59 # bsd.obj.mk: clean, cleandir and obj
60 # bsd.dep.mk: cleandepend, depend and tags
61 # bsd.man.mk: maninstall
64 OBJCOPY?= objcopy
65 KMODLOAD?= /sbin/kldload
66 KMODUNLOAD?= /sbin/kldunload
68 KMODDIR?= ${DESTKERNDIR}/${DESTMODULESNAME}
69 KMODOWN?= ${BINOWN}
70 KMODGRP?= ${BINGRP}
71 KMODMODE?= ${BINMODE}
73 .include <bsd.init.mk>
75 .SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
77 CFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS}
78 CFLAGS+= -DKLD_MODULE
80 # Don't use any standard include directories.
81 # Since -nostdinc will annull any previous -I paths, we repeat all
82 # such paths after -nostdinc. It doesn't seem to be possible to
83 # add to the front of `make' variable.
85 # Don't use -I- anymore, source-relative includes are desireable.
86 _ICFLAGS:= ${CFLAGS:M-I*}
87 CFLAGS+= -nostdinc ${_ICFLAGS}
89 # Add -I paths for system headers. Individual KLD makefiles don't
90 # need any -I paths for this. Similar defaults for .PATH can't be
91 # set because there are no standard paths for non-headers.
93 # NOTE! Traditional architecture paths such as <i386/i386/blah.h>
94 # must run through the "machine_base" softlink using
95 # <machine_base/i386/blah.h>. An explicit cross-architecture path must
96 # operate relative to /usr/src/sys using e.g. <arch/i386/i386/blah.h>
98 CFLAGS+= -I. -I@
100 # Add -I paths for headers in the kernel build directory
102 .if defined(BUILDING_WITH_KERNEL)
103 CFLAGS+= -I${BUILDING_WITH_KERNEL}
104 _MACHINE_FWD= ${BUILDING_WITH_KERNEL}
105 .else
106 .if defined(MAKEOBJDIRPREFIX)
107 _MACHINE_FWD= ${MAKEOBJDIRPREFIX}/${SYSDIR}/forwarder_${MACHINE_ARCH}
108 .else
109 _MACHINE_FWD= ${.OBJDIR}/forwarder_${MACHINE_ARCH}
110 CLEANDIRS+= ${_MACHINE_FWD}
111 .endif
112 .endif
113 CFLAGS+= -I${_MACHINE_FWD}/include
114 .include "kern.fwd.mk"
116 # Add a -I path to standard headers like <stddef.h>. Use a relative
117 # path to src/include if possible. If the @ symlink hasn't been built
118 # yet, then we can't tell if the relative path exists. Add both the
119 # potential relative path and an absolute path in that case.
120 .if exists(@)
121 .if exists(@/../include)
122 CFLAGS+= -I@/../include
123 .else
124 CFLAGS+= -I${DESTDIR}/usr/include
125 .endif
126 .else # !@
127 CFLAGS+= -I@/../include -I${DESTDIR}/usr/include
128 .endif # @
130 .if defined(BUILDING_WITH_KERNEL) && \
131 exists(${BUILDING_WITH_KERNEL}/opt_global.h)
132 CFLAGS+= -include ${BUILDING_WITH_KERNEL}/opt_global.h
133 .endif
135 CFLAGS+= ${DEBUG_FLAGS}
136 .if ${MACHINE_ARCH} == amd64
137 CFLAGS+= -fno-omit-frame-pointer
138 .endif
140 .include <bsd.patch.mk>
142 OBJS+= ${SRCS:N*.h:N*.patch:R:S/$/.o/g}
144 .if !defined(PROG)
145 PROG= ${KMOD}.ko
146 .endif
148 .if ${MACHINE_ARCH} != amd64
149 ${PROG}: ${KMOD}.kld ${KMODDEPS}
150 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld ${KMODDEPS}
151 .endif
153 .if defined(KMODDEPS)
154 .for dep in ${KMODDEPS}
155 CLEANFILES+= ${dep} __${dep}_hack_dep.c
157 ${dep}:
158 touch __${dep}_hack_dep.c
159 ${CC} -shared ${CFLAGS} -o ${dep} __${dep}_hack_dep.c
160 .endfor
161 .endif
163 .if ${MACHINE_ARCH} != amd64
164 ${KMOD}.kld: ${OBJS}
165 ${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS}
166 .else
167 ${PROG}: ${OBJS}
168 .endif
170 .if !defined(NOMAN)
171 .include <bsd.man.mk>
172 .endif
174 # links to platform and cpu architecture include files. If we are
175 # building with a kernel these already exist in the kernel build dir.
176 # '@' is a link to the system source.
177 .if defined(BUILDING_WITH_KERNEL)
178 _ILINKS=@
179 .else
180 _ILINKS=@ machine_base machine cpu_base cpu
181 .endif
183 .if defined(ARCH)
184 _ILINKS+=${ARCH}
185 .endif
187 all: objwarn fwheaders ${PROG}
188 .if !defined(NOMAN)
189 all: _manpages
190 .endif
192 beforedepend: fwheaders
193 fwheaders: ${_ILINKS} ${FORWARD_HEADERS_COOKIE}
194 # Ensure that the links exist without depending on it when it exists which
195 # causes all the modules to be rebuilt when the directory pointed to changes.
196 .for _link in ${_ILINKS}
197 .if !exists(${.OBJDIR}/${_link})
198 ${OBJS}: ${_link}
199 .endif
200 .endfor
202 # Search for kernel source tree in standard places.
203 .for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. ${.CURDIR}/../../../.. /sys /usr/src/sys
204 .if !defined(SYSDIR) && exists(${_dir}/kern/)
205 SYSDIR= ${_dir}
206 .endif
207 .endfor
208 .if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
209 .error "can't find kernel source tree"
210 .endif
211 S= ${SYSDIR}
213 # path=`(cd $$path && /bin/pwd)` ;
215 ${_ILINKS}:
216 @case ${.TARGET} in \
217 machine) \
218 path=${SYSDIR}/platform/${MACHINE_PLATFORM}/include ;; \
219 machine_base) \
220 path=${SYSDIR}/platform/${MACHINE_PLATFORM} ;; \
221 cpu) \
222 path=${SYSDIR}/cpu/${MACHINE_ARCH}/include ;; \
223 cpu_base) \
224 path=${SYSDIR}/cpu/${MACHINE_ARCH} ;; \
225 @) \
226 path=${SYSDIR} ;; \
227 arch_*) \
228 path=${.CURDIR}/${MACHINE_ARCH} ;; \
229 esac ; \
230 ${ECHO} ${.TARGET} "->" $$path ; \
231 ${LN} -s $$path ${.TARGET}
233 CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
235 .if !target(install)
237 _INSTALLFLAGS:= ${INSTALLFLAGS}
238 .for ie in ${INSTALLFLAGS_EDIT}
239 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
240 .endfor
242 .if !target(realinstall)
243 realinstall: _kmodinstall
244 .ORDER: beforeinstall _kmodinstall
245 _kmodinstall:
246 .if defined(INSTALLSTRIPPEDMODULES)
247 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
248 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
249 ${OBJCOPY} --strip-debug ${DESTDIR}${KMODDIR}/${PROG}
250 .else
251 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
252 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
253 .endif
254 .endif # !target(realinstall)
256 .include <bsd.links.mk>
258 .if !defined(NOMAN)
259 realinstall: _maninstall
260 .ORDER: beforeinstall _maninstall
261 .endif
263 .endif # !target(install)
265 .if !target(load)
266 load: ${PROG}
267 ${KMODLOAD} -v ./${KMOD}.ko
268 .endif
270 .if !target(unload)
271 unload:
272 ${KMODUNLOAD} -v ${KMOD}
273 .endif
275 .for _src in ${SRCS:Mopt_*.h} ${SRCS:Muse_*.h}
276 CLEANFILES+= ${_src}
277 .if !target(${_src})
278 .if defined(BUILDING_WITH_KERNEL) && exists(${BUILDING_WITH_KERNEL}/${_src})
279 ${_src}: ${BUILDING_WITH_KERNEL}/${_src}
280 # we do not have to copy these files any more, the kernel build
281 # directory is included in the path now.
282 # cp ${BUILDING_WITH_KERNEL}/${_src} ${.TARGET}
283 .else
284 ${_src}:
285 touch ${.TARGET}
286 .endif # BUILDING_WITH_KERNEL
287 .endif
288 .endfor
290 MFILES?= kern/bus_if.m kern/device_if.m bus/iicbus/iicbb_if.m \
291 bus/iicbus/iicbus_if.m bus/isa/isa_if.m dev/netif/mii_layer/miibus_if.m \
292 bus/pccard/card_if.m bus/pccard/power_if.m bus/pci/pci_if.m \
293 bus/pci/pcib_if.m \
294 bus/ppbus/ppbus_if.m bus/smbus/smbus_if.m bus/usb/usb_if.m \
295 dev/acpica5/acpi_if.m dev/disk/nata/ata_if.m \
296 dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
297 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \
298 libiconv/iconv_converter_if.m dev/agp/agp_if.m opencrypto/crypto_if.m
300 .for _srcsrc in ${MFILES}
301 .for _ext in c h
302 .for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
303 CLEANFILES+= ${_src}
304 .if !target(${_src})
305 ${_src}: @
306 .if exists(@)
307 ${_src}: @/tools/makeobjops.awk @/${_srcsrc}
308 .endif
310 .if defined(BUILDING_WITH_KERNEL) && \
311 exists(${BUILDING_WITH_KERNEL}/${_src})
312 .else
313 awk -f @/tools/makeobjops.awk -- -${_ext} @/${_srcsrc}
314 .endif
315 .endif
316 .endfor # _src
317 .endfor # _ext
318 .endfor # _srcsrc
320 #.for _ext in c h
321 #.if ${SRCS:Mvnode_if.${_ext}} != ""
322 #CLEANFILES+= vnode_if.${_ext}
323 #vnode_if.${_ext}: @
324 #.if exists(@)
325 #vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src
326 #.endif
327 # awk -f @/tools/vnode_if.awk -- -${_ext} @/kern/vnode_if.src
328 #.endif
329 #.endfor
331 regress:
333 .include <bsd.dep.mk>
335 .if !exists(${DEPENDFILE})
336 ${OBJS}: ${SRCS:M*.h}
337 .endif
339 .include <bsd.obj.mk>
340 .include "bsd.kern.mk"
342 # Behaves like MODULE_OVERRIDE
343 .if defined(KLD_DEPS)
344 all: _kdeps_all
345 _kdeps_all: @
346 .for _mdep in ${KLD_DEPS}
347 cd ${SYSDIR}/${_mdep} && make all
348 .endfor
349 depend: _kdeps_depend
350 _kdeps_depend: @
351 .for _mdep in ${KLD_DEPS}
352 cd ${SYSDIR}/${_mdep} && make depend
353 .endfor
354 install: _kdeps_install
355 _kdeps_install: @
356 .for _mdep in ${KLD_DEPS}
357 cd ${SYSDIR}/${_mdep} && make install
358 .endfor
359 clean: _kdeps_clean
360 _kdeps_clean: @
361 .for _mdep in ${KLD_DEPS}
362 cd ${SYSDIR}/${_mdep} && make clean
363 .endfor
364 .endif