ecc/e3: Split it into two drivers, coremctl(4) and ecc(4)
[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
b399af11 80.if !defined(NO_WERROR) && (${CCVER} == "gcc47" || ${CCVER} == "gcc50")
197d4943
SW
81WERROR=-Werror
82.endif
83
84CFLAGS+= ${COPTS} -D_KERNEL ${CWARNFLAGS} ${WERROR}
984263bc
MD
85CFLAGS+= -DKLD_MODULE
86
e5d18209 87# Don't use any standard include directories.
984263bc
MD
88# Since -nostdinc will annull any previous -I paths, we repeat all
89# such paths after -nostdinc. It doesn't seem to be possible to
90# add to the front of `make' variable.
e5d18209
MD
91#
92# Don't use -I- anymore, source-relative includes are desireable.
984263bc 93_ICFLAGS:= ${CFLAGS:M-I*}
e5d18209 94CFLAGS+= -nostdinc ${_ICFLAGS}
984263bc
MD
95
96# Add -I paths for system headers. Individual KLD makefiles don't
97# need any -I paths for this. Similar defaults for .PATH can't be
98# set because there are no standard paths for non-headers.
39619464 99#
f8334305 100# NOTE! Traditional architecture paths such as <i386/i386/blah.h>
a9295349
MD
101# must run through the "machine_base" softlink using
102# <machine_base/i386/blah.h>. An explicit cross-architecture path must
103# operate relative to /usr/src/sys using e.g. <arch/i386/i386/blah.h>
39619464 104#
f8334305 105CFLAGS+= -I. -I@
984263bc 106
a9295349
MD
107# Add -I paths for headers in the kernel build directory
108#
109.if defined(BUILDING_WITH_KERNEL)
110CFLAGS+= -I${BUILDING_WITH_KERNEL}
a7f2f51f
SZ
111_MACHINE_FWD= ${BUILDING_WITH_KERNEL}
112.else
113.if defined(MAKEOBJDIRPREFIX)
114_MACHINE_FWD= ${MAKEOBJDIRPREFIX}/${SYSDIR}/forwarder_${MACHINE_ARCH}
115.else
116_MACHINE_FWD= ${.OBJDIR}/forwarder_${MACHINE_ARCH}
117CLEANDIRS+= ${_MACHINE_FWD}
118.endif
a9295349 119.endif
a7f2f51f
SZ
120CFLAGS+= -I${_MACHINE_FWD}/include
121.include "kern.fwd.mk"
a9295349 122
984263bc
MD
123# Add a -I path to standard headers like <stddef.h>. Use a relative
124# path to src/include if possible. If the @ symlink hasn't been built
125# yet, then we can't tell if the relative path exists. Add both the
126# potential relative path and an absolute path in that case.
127.if exists(@)
128.if exists(@/../include)
129CFLAGS+= -I@/../include
130.else
131CFLAGS+= -I${DESTDIR}/usr/include
132.endif
133.else # !@
134CFLAGS+= -I@/../include -I${DESTDIR}/usr/include
135.endif # @
136
deee08c4
SS
137.if defined(BUILDING_WITH_KERNEL) && \
138 exists(${BUILDING_WITH_KERNEL}/opt_global.h)
faba9d16 139CFLAGS+= -DHAVE_KERNEL_OPTION_HEADERS -include ${BUILDING_WITH_KERNEL}/opt_global.h
deee08c4
SS
140.endif
141
984263bc 142CFLAGS+= ${DEBUG_FLAGS}
f0919f25 143.if ${MACHINE_ARCH} == "x86_64"
982b0507
MD
144CFLAGS+= -fno-omit-frame-pointer
145.endif
984263bc 146
285638ea
SS
147.include <bsd.patch.mk>
148
32e913d7
JT
149.if defined(FIRMWS)
150AWK=/usr/bin/awk
151.if !exists(@)
152${KMOD:S/$/.c/}: @
153.else
154${KMOD:S/$/.c/}: @/tools/fw_stub.awk
155.endif
156 ${AWK} -f @/tools/fw_stub.awk ${FIRMWS} -m${KMOD} -c${KMOD:S/$/.c/g} \
157 ${FIRMWARE_LICENSE:C/.+/-l/}${FIRMWARE_LICENSE}
158
159SRCS+= ${KMOD:S/$/.c/}
160CLEANFILES+= ${KMOD:S/$/.c/}
161
162.for _firmw in ${FIRMWS}
163${_firmw:C/\:.*$/.fwo/}: ${_firmw:C/\:.*$//}
164 @${ECHO} ${_firmw:C/\:.*$//} ${.ALLSRC:M*${_firmw:C/\:.*$//}}
165 @if [ -e ${_firmw:C/\:.*$//} ]; then \
166 ${LD} -b binary --no-warn-mismatch ${LDFLAGS} \
167 -r -d -o ${.TARGET} ${_firmw:C/\:.*$//}; \
168 else \
169 ln -s ${.ALLSRC:M*${_firmw:C/\:.*$//}} ${_firmw:C/\:.*$//}; \
170 ${LD} -b binary --no-warn-mismatch ${LDFLAGS} \
171 -r -d -o ${.TARGET} ${_firmw:C/\:.*$//}; \
172 rm ${_firmw:C/\:.*$//}; \
173 fi
174
175OBJS+= ${_firmw:C/\:.*$/.fwo/}
176.endfor
177.endif
178
145b818c 179OBJS+= ${SRCS:N*.h:N*.patch:R:S/$/.o/g}
984263bc
MD
180
181.if !defined(PROG)
182PROG= ${KMOD}.ko
183.endif
184
b2b3ffcd 185.if ${MACHINE_ARCH} != x86_64
43db70b8
SS
186${PROG}: ${KMOD}.kld
187 ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld
984263bc
MD
188.endif
189
b2b3ffcd 190.if ${MACHINE_ARCH} != x86_64
984263bc
MD
191${KMOD}.kld: ${OBJS}
192 ${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS}
8d565796
MD
193.else
194${PROG}: ${OBJS}
99ab4213 195 ${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS}
8d565796 196.endif
984263bc 197
a9295349
MD
198# links to platform and cpu architecture include files. If we are
199# building with a kernel these already exist in the kernel build dir.
200# '@' is a link to the system source.
201.if defined(BUILDING_WITH_KERNEL)
202_ILINKS=@
203.else
204_ILINKS=@ machine_base machine cpu_base cpu
205.endif
206
932f49b9
MD
207.if defined(ARCH)
208_ILINKS+=${ARCH}
209.endif
984263bc 210
82f3e8c4 211all: objwarn fwheaders ${PROG}
984263bc 212
82f3e8c4
SS
213beforedepend: fwheaders
214fwheaders: ${_ILINKS} ${FORWARD_HEADERS_COOKIE}
984263bc
MD
215# Ensure that the links exist without depending on it when it exists which
216# causes all the modules to be rebuilt when the directory pointed to changes.
217.for _link in ${_ILINKS}
218.if !exists(${.OBJDIR}/${_link})
219${OBJS}: ${_link}
220.endif
221.endfor
222
223# Search for kernel source tree in standard places.
932f49b9 224.for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. ${.CURDIR}/../../../.. /sys /usr/src/sys
984263bc
MD
225.if !defined(SYSDIR) && exists(${_dir}/kern/)
226SYSDIR= ${_dir}
227.endif
228.endfor
229.if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
230.error "can't find kernel source tree"
231.endif
edbe133c 232S= ${SYSDIR}
984263bc 233
932f49b9
MD
234# path=`(cd $$path && /bin/pwd)` ;
235
984263bc
MD
236${_ILINKS}:
237 @case ${.TARGET} in \
238 machine) \
0955fd91 239 path=${SYSDIR}/platform/${MACHINE_PLATFORM}/include ;; \
a9295349 240 machine_base) \
0955fd91 241 path=${SYSDIR}/platform/${MACHINE_PLATFORM} ;; \
a9295349
MD
242 cpu) \
243 path=${SYSDIR}/cpu/${MACHINE_ARCH}/include ;; \
244 cpu_base) \
245 path=${SYSDIR}/cpu/${MACHINE_ARCH} ;; \
984263bc
MD
246 @) \
247 path=${SYSDIR} ;; \
932f49b9
MD
248 arch_*) \
249 path=${.CURDIR}/${MACHINE_ARCH} ;; \
984263bc 250 esac ; \
984263bc 251 ${ECHO} ${.TARGET} "->" $$path ; \
062db326 252 ${LN} -s $$path ${.TARGET}
984263bc
MD
253
254CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
255
256.if !target(install)
257
258_INSTALLFLAGS:= ${INSTALLFLAGS}
259.for ie in ${INSTALLFLAGS_EDIT}
260_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
261.endfor
262
263.if !target(realinstall)
264realinstall: _kmodinstall
265.ORDER: beforeinstall _kmodinstall
266_kmodinstall:
c2c83759 267.if defined(INSTALLSTRIPPEDMODULES)
984263bc
MD
268 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
269 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
c2c83759
MD
270 ${OBJCOPY} --strip-debug ${DESTDIR}${KMODDIR}/${PROG}
271.else
272 ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
273 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
274.endif
905fbe6b 275.endif # !target(realinstall)
984263bc
MD
276
277.include <bsd.links.mk>
278
905fbe6b 279.endif # !target(install)
984263bc
MD
280
281.if !target(load)
282load: ${PROG}
283 ${KMODLOAD} -v ./${KMOD}.ko
284.endif
285
286.if !target(unload)
287unload:
288 ${KMODUNLOAD} -v ${KMOD}
289.endif
290
1b29ad66 291.for _src in ${SRCS:Mopt_*.h} ${SRCS:Muse_*.h}
984263bc
MD
292CLEANFILES+= ${_src}
293.if !target(${_src})
1b29ad66
SS
294.if defined(BUILDING_WITH_KERNEL) && exists(${BUILDING_WITH_KERNEL}/${_src})
295${_src}: ${BUILDING_WITH_KERNEL}/${_src}
a9295349
MD
296# we do not have to copy these files any more, the kernel build
297# directory is included in the path now.
298# cp ${BUILDING_WITH_KERNEL}/${_src} ${.TARGET}
1b29ad66 299.else
984263bc
MD
300${_src}:
301 touch ${.TARGET}
1b29ad66 302.endif # BUILDING_WITH_KERNEL
984263bc
MD
303.endif
304.endfor
305
1f2de5d4
MD
306MFILES?= kern/bus_if.m kern/device_if.m bus/iicbus/iicbb_if.m \
307 bus/iicbus/iicbus_if.m bus/isa/isa_if.m dev/netif/mii_layer/miibus_if.m \
666d2603
JS
308 bus/pccard/card_if.m bus/pccard/power_if.m bus/pci/pci_if.m \
309 bus/pci/pcib_if.m \
2a617999 310 bus/ppbus/ppbus_if.m bus/smbus/smbus_if.m bus/u4b/usb_if.m \
5db2f26e 311 dev/acpica/acpi_if.m dev/acpica/acpi_wmi_if.m dev/disk/nata/ata_if.m \
5cecf125 312 dev/disk/sdhci/sdhci_if.m \
2a1ad637 313 dev/sound/pci/hda/hdac_if.m \
984263bc
MD
314 dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
315 dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \
d6644679 316 libiconv/iconv_converter_if.m dev/agp/agp_if.m opencrypto/cryptodev_if.m \
9aa0ab36
SW
317 bus/mmc/mmcbus_if.m bus/mmc/mmcbr_if.m \
318 dev/virtual/virtio/virtio/virtio_bus_if.m \
f7409137
SZ
319 dev/virtual/virtio/virtio/virtio_if.m \
320 dev/misc/coremctl/coremctl_if.m
984263bc
MD
321
322.for _srcsrc in ${MFILES}
323.for _ext in c h
324.for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
325CLEANFILES+= ${_src}
326.if !target(${_src})
327${_src}: @
328.if exists(@)
be59a52f 329${_src}: @/tools/makeobjops.awk @/${_srcsrc}
984263bc 330.endif
a9295349
MD
331
332.if defined(BUILDING_WITH_KERNEL) && \
333 exists(${BUILDING_WITH_KERNEL}/${_src})
334.else
145a9824 335 awk -f @/tools/makeobjops.awk -- -${_ext} @/${_srcsrc}
984263bc 336.endif
a9295349 337.endif
984263bc
MD
338.endfor # _src
339.endfor # _ext
340.endfor # _srcsrc
341
0961aa92
MD
342#.for _ext in c h
343#.if ${SRCS:Mvnode_if.${_ext}} != ""
344#CLEANFILES+= vnode_if.${_ext}
345#vnode_if.${_ext}: @
346#.if exists(@)
347#vnode_if.${_ext}: @/tools/vnode_if.awk @/kern/vnode_if.src
348#.endif
349# awk -f @/tools/vnode_if.awk -- -${_ext} @/kern/vnode_if.src
350#.endif
351#.endfor
984263bc 352
dcb4b80d
SW
353.if !empty(SRCS:Mmiidevs.h)
354CLEANFILES+= miidevs.h
355.if !exists(@)
356miidevs.h: @
357.else
358miidevs.h: @/tools/miidevs2h.awk @/dev/netif/mii_layer/miidevs
359.endif
360 ${AWK} -f @/tools/miidevs2h.awk @/dev/netif/mii_layer/miidevs
361.endif
362
363.if !empty(SRCS:Mpccarddevs.h)
364CLEANFILES+= pccarddevs.h
365.if !exists(@)
366pccarddevs.h: @
367.else
368pccarddevs.h: @/tools/pccarddevs2h.awk @/bus/pccard/pccarddevs
369.endif
370 ${AWK} -f @/tools/pccarddevs2h.awk @/bus/pccard/pccarddevs
371.endif
372
373.if !empty(SRCS:Mpcidevs.h)
374CLEANFILES+= pcidevs.h
375.if !exists(@)
376pcidevs.h: @
377.else
378pcidevs.h: @/tools/pcidevs2h.awk @/bus/pci/pcidevs
379.endif
380 ${AWK} -f @/tools/pcidevs2h.awk @/bus/pci/pcidevs
381.endif
382
ef4aa9ff
SW
383.if !empty(SRCS:Musbdevs.h)
384CLEANFILES+= usbdevs.h
385.if !exists(@)
386usbdevs.h: @
387.else
388usbdevs.h: @/tools/usbdevs2h.awk @/bus/u4b/usbdevs
389.endif
390 ${AWK} -f @/tools/usbdevs2h.awk @/bus/u4b/usbdevs -h
391.endif
392
393.if !empty(SRCS:Musbdevs_data.h)
394CLEANFILES+= usbdevs_data.h
395.if !exists(@)
396usbdevs_data.h: @
397.else
398usbdevs_data.h: @/tools/usbdevs2h.awk @/bus/u4b/usbdevs
399.endif
400 ${AWK} -f @/tools/usbdevs2h.awk @/bus/u4b/usbdevs -d
401.endif
402
d2fa5f95
SW
403.if !empty(SRCS:Macpi_quirks.h)
404CLEANFILES+= acpi_quirks.h
405.if !exists(@)
406acpi_quirks.h: @
407.else
408acpi_quirks.h: @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks
409.endif
410 ${AWK} -f @/tools/acpi_quirks2h.awk @/dev/acpica/acpi_quirks
411.endif
412
fd35368d
AH
413.if !empty(SRCS:Massym.s)
414CLEANFILES+= assym.s genassym.o
415assym.s: genassym.o
416.if defined(BUILDING_WITH_KERNEL)
417genassym.o: opt_global.h
418.endif
419.if !exists(@)
420assym.s: @
421.else
422assym.s: @/kern/genassym.sh
423.endif
424 sh @/kern/genassym.sh genassym.o > ${.TARGET}
425.if exists(@)
426genassym.o: @/platform/${MACHINE_PLATFORM}/${MACHINE_ARCH}/genassym.c
427.endif
fa7add71 428genassym.o: @ ${SRCS:Mopt_*.h}
fd35368d
AH
429 ${CC} -c ${CFLAGS:N-fno-common:N-mcmodel=small} ${WERROR} \
430 @/platform/${MACHINE_PLATFORM}/${MACHINE_ARCH}/genassym.c
431.endif
432
984263bc
MD
433regress:
434
435.include <bsd.dep.mk>
436
437.if !exists(${DEPENDFILE})
438${OBJS}: ${SRCS:M*.h}
439.endif
440
441.include <bsd.obj.mk>
5e9c1061 442.include "bsd.kern.mk"
d4ef9227
JS
443
444# Behaves like MODULE_OVERRIDE
445.if defined(KLD_DEPS)
446all: _kdeps_all
447_kdeps_all: @
448.for _mdep in ${KLD_DEPS}
449 cd ${SYSDIR}/${_mdep} && make all
450.endfor
451depend: _kdeps_depend
452_kdeps_depend: @
453.for _mdep in ${KLD_DEPS}
454 cd ${SYSDIR}/${_mdep} && make depend
455.endfor
456install: _kdeps_install
457_kdeps_install: @
458.for _mdep in ${KLD_DEPS}
459 cd ${SYSDIR}/${_mdep} && make install
460.endfor
461clean: _kdeps_clean
462_kdeps_clean: @
463.for _mdep in ${KLD_DEPS}
464 cd ${SYSDIR}/${_mdep} && make clean
465.endfor
466.endif