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