kernel/virtio: Some cleanup (Makefiles and gcc47 warnings).
[dragonfly.git] / sys / conf / kmod.mk
CommitLineData
984263bc
MD
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#
4# The include file <bsd.kmod.mk> handles installing Kernel Loadable Device
5# drivers (KLD's).
6#
7#
8# +++ variables +++
984263bc
MD
9# CLEANFILES Additional files to remove for the clean and cleandir targets.
10#
11# KMOD The name of the kernel module to build.
12#
3b25fbd4 13# KMODDIR Base path for kernel modules (see kld(4)).
116b7e3c 14# [${DESTKERNDIR}]
984263bc
MD
15#
16# KMODOWN KLD owner. [${BINOWN}]
17#
18# KMODGRP KLD group. [${BINGRP}]
19#
20# KMODMODE KLD mode. [${BINMODE}]
21#
22# KMODLOAD Command to load a kernel module [/sbin/kldload]
23#
24# KMODUNLOAD Command to unload a kernel module [/sbin/kldunload]
25#
984263bc
MD
26# PROG The name of the kernel module to build.
27# If not supplied, ${KMOD}.o is used.
28#
29# SRCS List of source files
30#
3b25fbd4
YT
31# DESTKERNDIR Change the tree where the kernel and the modules get
32# installed. [/boot] ${DESTDIR} changes the root of the tree
33# pointed to by ${DESTKERNDIR}.
984263bc
MD
34#
35# MFILES Optionally a list of interfaces used by the module.
36# This file contains a default list of interfaces.
37#
000e5405
SW
38# FIRMWS List of firmware images in format filename:shortname:version
39#
40# FIRMWARE_LICENSE
41# Set to the name of the license the user has to agree on in
42# order to use this firmware. See /usr/share/doc/legal
32e913d7 43#
984263bc
MD
44# +++ targets +++
45#
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.
52#
53# load:
54# Load KLD.
55#
56# unload:
57# Unload KLD.
58#
59# bsd.obj.mk: clean, cleandir and obj
60# bsd.dep.mk: cleandepend, depend and tags
984263bc
MD
61#
62
c2c83759 63OBJCOPY?= objcopy
984263bc
MD
64KMODLOAD?= /sbin/kldload
65KMODUNLOAD?= /sbin/kldunload
66
7a84d2a7
MD
67# KERNEL is needed when running make install directly from
68# the obj directory.
69KERNEL?= kernel
70
116b7e3c 71KMODDIR?= ${DESTKERNDIR}
3b25fbd4
YT
72KMODOWN?= ${BINOWN}
73KMODGRP?= ${BINGRP}
74KMODMODE?= ${BINMODE}
75
984263bc
MD
76.include <bsd.init.mk>
77
78.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
79
80CFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS}
81CFLAGS+= -DKLD_MODULE
82
e5d18209 83# Don't use any standard include directories.
984263bc
MD
84# Since -nostdinc will annull any previous -I paths, we repeat all
85# such paths after -nostdinc. It doesn't seem to be possible to
86# add to the front of `make' variable.
e5d18209
MD
87#
88# Don't use -I- anymore, source-relative includes are desireable.
984263bc 89_ICFLAGS:= ${CFLAGS:M-I*}
e5d18209 90CFLAGS+= -nostdinc ${_ICFLAGS}
984263bc
MD
91
92# Add -I paths for system headers. Individual KLD makefiles don't
93# need any -I paths for this. Similar defaults for .PATH can't be
94# set because there are no standard paths for non-headers.
39619464 95#
f8334305 96# NOTE! Traditional architecture paths such as <i386/i386/blah.h>
a9295349
MD
97# must run through the "machine_base" softlink using
98# <machine_base/i386/blah.h>. An explicit cross-architecture path must
99# operate relative to /usr/src/sys using e.g. <arch/i386/i386/blah.h>
39619464 100#
f8334305 101CFLAGS+= -I. -I@
984263bc 102
a9295349
MD
103# Add -I paths for headers in the kernel build directory
104#
105.if defined(BUILDING_WITH_KERNEL)
106CFLAGS+= -I${BUILDING_WITH_KERNEL}
a7f2f51f
SZ
107_MACHINE_FWD= ${BUILDING_WITH_KERNEL}
108.else
109.if defined(MAKEOBJDIRPREFIX)
110_MACHINE_FWD= ${MAKEOBJDIRPREFIX}/${SYSDIR}/forwarder_${MACHINE_ARCH}
111.else
112_MACHINE_FWD= ${.OBJDIR}/forwarder_${MACHINE_ARCH}
113CLEANDIRS+= ${_MACHINE_FWD}
114.endif
a9295349 115.endif
a7f2f51f
SZ
116CFLAGS+= -I${_MACHINE_FWD}/include
117.include "kern.fwd.mk"
a9295349 118
984263bc
MD
119# Add a -I path to standard headers like <stddef.h>. Use a relative
120# path to src/include if possible. If the @ symlink hasn't been built
121# yet, then we can't tell if the relative path exists. Add both the
122# potential relative path and an absolute path in that case.
123.if exists(@)
124.if exists(@/../include)
125CFLAGS+= -I@/../include
126.else
127CFLAGS+= -I${DESTDIR}/usr/include
128.endif
129.else # !@
130CFLAGS+= -I@/../include -I${DESTDIR}/usr/include
131.endif # @
132
deee08c4
SS
133.if defined(BUILDING_WITH_KERNEL) && \
134 exists(${BUILDING_WITH_KERNEL}/opt_global.h)
135CFLAGS+= -include ${BUILDING_WITH_KERNEL}/opt_global.h
136.endif
137
984263bc 138CFLAGS+= ${DEBUG_FLAGS}
b2b3ffcd 139.if ${MACHINE_ARCH} == x86_64
982b0507
MD
140CFLAGS+= -fno-omit-frame-pointer
141.endif
984263bc 142
285638ea
SS
143.include <bsd.patch.mk>
144
32e913d7
JT
145.if defined(FIRMWS)
146AWK=/usr/bin/awk
147.if !exists(@)
148${KMOD:S/$/.c/}: @
149.else
150${KMOD:S/$/.c/}: @/tools/fw_stub.awk
151.endif
152 ${AWK} -f @/tools/fw_stub.awk ${FIRMWS} -m${KMOD} -c${KMOD:S/$/.c/g} \
153 ${FIRMWARE_LICENSE:C/.+/-l/}${FIRMWARE_LICENSE}
154
155SRCS+= ${KMOD:S/$/.c/}
156CLEANFILES+= ${KMOD:S/$/.c/}
157
158.for _firmw in ${FIRMWS}
159${_firmw:C/\:.*$/.fwo/}: ${_firmw:C/\:.*$//}
160 @${ECHO} ${_firmw:C/\:.*$//} ${.ALLSRC:M*${_firmw:C/\:.*$//}}
161 @if [ -e ${_firmw:C/\:.*$//} ]; then \
162 ${LD} -b binary --no-warn-mismatch ${LDFLAGS} \
163 -r -d -o ${.TARGET} ${_firmw:C/\:.*$//}; \
164 else \
165 ln -s ${.ALLSRC:M*${_firmw:C/\:.*$//}} ${_firmw:C/\:.*$//}; \
166 ${LD} -b binary --no-warn-mismatch ${LDFLAGS} \
167 -r -d -o ${.TARGET} ${_firmw:C/\:.*$//}; \
168 rm ${_firmw:C/\:.*$//}; \
169 fi
170
171OBJS+= ${_firmw:C/\:.*$/.fwo/}
172.endfor
173.endif
174
145b818c 175OBJS+= ${SRCS:N*.h:N*.patch:R:S/$/.o/g}
984263bc
MD
176
177.if !defined(PROG)
178PROG= ${KMOD}.ko
179.endif
180
b2b3ffcd 181.if ${MACHINE_ARCH} != x86_64
43db70b8
SS
182${PROG}: ${KMOD}.kld
183 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld
984263bc
MD
184.endif
185
b2b3ffcd 186.if ${MACHINE_ARCH} != x86_64
984263bc
MD
187${KMOD}.kld: ${OBJS}
188 ${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS}
8d565796
MD
189.else
190${PROG}: ${OBJS}
99ab4213 191 ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS}
8d565796 192.endif
984263bc 193
a9295349
MD
194# links to platform and cpu architecture include files. If we are
195# building with a kernel these already exist in the kernel build dir.
196# '@' is a link to the system source.
197.if defined(BUILDING_WITH_KERNEL)
198_ILINKS=@
199.else
200_ILINKS=@ machine_base machine cpu_base cpu
201.endif
202
932f49b9
MD
203.if defined(ARCH)
204_ILINKS+=${ARCH}
205.endif
984263bc 206
82f3e8c4 207all: objwarn fwheaders ${PROG}
984263bc 208
82f3e8c4
SS
209beforedepend: fwheaders
210fwheaders: ${_ILINKS} ${FORWARD_HEADERS_COOKIE}
984263bc
MD
211# Ensure that the links exist without depending on it when it exists which
212# causes all the modules to be rebuilt when the directory pointed to changes.
213.for _link in ${_ILINKS}
214.if !exists(${.OBJDIR}/${_link})
215${OBJS}: ${_link}
216.endif
217.endfor
218
219# Search for kernel source tree in standard places.
932f49b9 220.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. ${.CURDIR}/../../../.. /sys /usr/src/sys
984263bc
MD
221.if !defined(SYSDIR) && exists(${_dir}/kern/)
222SYSDIR= ${_dir}
223.endif
224.endfor
225.if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
226.error "can't find kernel source tree"
227.endif
edbe133c 228S= ${SYSDIR}
984263bc 229
932f49b9
MD
230# path=`(cd $$path && /bin/pwd)` ;
231
984263bc
MD
232${_ILINKS}:
233 @case ${.TARGET} in \
234 machine) \
0955fd91 235 path=${SYSDIR}/platform/${MACHINE_PLATFORM}/include ;; \
a9295349 236 machine_base) \
0955fd91 237 path=${SYSDIR}/platform/${MACHINE_PLATFORM} ;; \
a9295349
MD
238 cpu) \
239 path=${SYSDIR}/cpu/${MACHINE_ARCH}/include ;; \
240 cpu_base) \
241 path=${SYSDIR}/cpu/${MACHINE_ARCH} ;; \
984263bc
MD
242 @) \
243 path=${SYSDIR} ;; \
932f49b9
MD
244 arch_*) \
245 path=${.CURDIR}/${MACHINE_ARCH} ;; \
984263bc 246 esac ; \
984263bc 247 ${ECHO} ${.TARGET} "->" $$path ; \
062db326 248 ${LN} -s $$path ${.TARGET}
984263bc
MD
249
250CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
251
252.if !target(install)
253
254_INSTALLFLAGS:= ${INSTALLFLAGS}
255.for ie in ${INSTALLFLAGS_EDIT}
256_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
257.endfor
258
259.if !target(realinstall)
260realinstall: _kmodinstall
261.ORDER: beforeinstall _kmodinstall
262_kmodinstall:
c2c83759 263.if defined(INSTALLSTRIPPEDMODULES)
984263bc
MD
264 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
265 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
c2c83759
MD
266 ${OBJCOPY} --strip-debug ${DESTDIR}${KMODDIR}/${PROG}
267.else
268 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
269 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
270.endif
905fbe6b 271.endif # !target(realinstall)
984263bc
MD
272
273.include <bsd.links.mk>
274
905fbe6b 275.endif # !target(install)
984263bc
MD
276
277.if !target(load)
278load: ${PROG}
279 ${KMODLOAD} -v ./${KMOD}.ko
280.endif
281
282.if !target(unload)
283unload:
284 ${KMODUNLOAD} -v ${KMOD}
285.endif
286
1b29ad66 287.for _src in ${SRCS:Mopt_*.h} ${SRCS:Muse_*.h}
984263bc
MD
288CLEANFILES+= ${_src}
289.if !target(${_src})
1b29ad66
SS
290.if defined(BUILDING_WITH_KERNEL) && exists(${BUILDING_WITH_KERNEL}/${_src})
291${_src}: ${BUILDING_WITH_KERNEL}/${_src}
a9295349
MD
292# we do not have to copy these files any more, the kernel build
293# directory is included in the path now.
294# cp ${BUILDING_WITH_KERNEL}/${_src} ${.TARGET}
1b29ad66 295.else
984263bc
MD
296${_src}:
297 touch ${.TARGET}
1b29ad66 298.endif # BUILDING_WITH_KERNEL
984263bc
MD
299.endif
300.endfor
301
1f2de5d4
MD
302MFILES?= kern/bus_if.m kern/device_if.m bus/iicbus/iicbb_if.m \
303 bus/iicbus/iicbus_if.m bus/isa/isa_if.m dev/netif/mii_layer/miibus_if.m \
666d2603
JS
304 bus/pccard/card_if.m bus/pccard/power_if.m bus/pci/pci_if.m \
305 bus/pci/pcib_if.m \
8b9caf33 306 bus/ppbus/ppbus_if.m bus/smbus/smbus_if.m \
5db2f26e 307 dev/acpica/acpi_if.m dev/acpica/acpi_wmi_if.m dev/disk/nata/ata_if.m \
984263bc
MD
308 dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
309 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \
d6644679 310 libiconv/iconv_converter_if.m dev/agp/agp_if.m opencrypto/cryptodev_if.m \
9aa0ab36
SW
311 bus/mmc/mmcbus_if.m bus/mmc/mmcbr_if.m \
312 dev/virtual/virtio/virtio/virtio_bus_if.m \
313 dev/virtual/virtio/virtio/virtio_if.m
984263bc 314
8b9caf33
SW
315.if defined(WANT_USB4BSD)
316MFILES+=bus/u4b/usb_if.m
317.else
318MFILES+=bus/usb/usb_if.m
319.endif
320
984263bc
MD
321.for _srcsrc in ${MFILES}
322.for _ext in c h
323.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
324CLEANFILES+= ${_src}
325.if !target(${_src})
326${_src}: @
327.if exists(@)
be59a52f 328${_src}: @/tools/makeobjops.awk @/${_srcsrc}
984263bc 329.endif
a9295349
MD
330
331.if defined(BUILDING_WITH_KERNEL) && \
332 exists(${BUILDING_WITH_KERNEL}/${_src})
333.else
145a9824 334 awk -f @/tools/makeobjops.awk -- -${_ext} @/${_srcsrc}
984263bc 335.endif
a9295349 336.endif
984263bc
MD
337.endfor # _src
338.endfor # _ext
339.endfor # _srcsrc
340
0961aa92
MD
341#.for _ext in c h
342#.if ${SRCS:Mvnode_if.${_ext}} != ""
343#CLEANFILES+= vnode_if.${_ext}
344#vnode_if.${_ext}: @
345#.if exists(@)
346#vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src
347#.endif
348# awk -f @/tools/vnode_if.awk -- -${_ext} @/kern/vnode_if.src
349#.endif
350#.endfor
984263bc 351
fd35368d
AH
352.if !empty(SRCS:Massym.s)
353CLEANFILES+= assym.s genassym.o
354assym.s: genassym.o
355.if defined(BUILDING_WITH_KERNEL)
356genassym.o: opt_global.h
357.endif
358.if !exists(@)
359assym.s: @
360.else
361assym.s: @/kern/genassym.sh
362.endif
363 sh @/kern/genassym.sh genassym.o > ${.TARGET}
364.if exists(@)
365genassym.o: @/platform/${MACHINE_PLATFORM}/${MACHINE_ARCH}/genassym.c
366.endif
fa7add71 367genassym.o: @ ${SRCS:Mopt_*.h}
fd35368d
AH
368 ${CC} -c ${CFLAGS:N-fno-common:N-mcmodel=small} ${WERROR} \
369 @/platform/${MACHINE_PLATFORM}/${MACHINE_ARCH}/genassym.c
370.endif
371
984263bc
MD
372regress:
373
374.include <bsd.dep.mk>
375
376.if !exists(${DEPENDFILE})
377${OBJS}: ${SRCS:M*.h}
378.endif
379
380.include <bsd.obj.mk>
5e9c1061 381.include "bsd.kern.mk"
d4ef9227
JS
382
383# Behaves like MODULE_OVERRIDE
384.if defined(KLD_DEPS)
385all: _kdeps_all
386_kdeps_all: @
387.for _mdep in ${KLD_DEPS}
388 cd ${SYSDIR}/${_mdep} && make all
389.endfor
390depend: _kdeps_depend
391_kdeps_depend: @
392.for _mdep in ${KLD_DEPS}
393 cd ${SYSDIR}/${_mdep} && make depend
394.endfor
395install: _kdeps_install
396_kdeps_install: @
397.for _mdep in ${KLD_DEPS}
398 cd ${SYSDIR}/${_mdep} && make install
399.endfor
400clean: _kdeps_clean
401_kdeps_clean: @
402.for _mdep in ${KLD_DEPS}
403 cd ${SYSDIR}/${_mdep} && make clean
404.endfor
405.endif