kernel tree reorganization stage 1a: remove -I- for kmod build
[dragonfly.git] / sys / conf / kmod.mk
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.4 2003/08/08 03:57:35 dillon Exp $
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 #
15 # KMODDIR       Base path for kernel modules (see kld(4)). [/modules]
16 #
17 # KMODOWN       KLD owner. [${BINOWN}]
18 #
19 # KMODGRP       KLD group. [${BINGRP}]
20 #
21 # KMODMODE      KLD mode. [${BINMODE}]
22 #
23 # KMODLOAD      Command to load a kernel module [/sbin/kldload]
24 #
25 # KMODUNLOAD    Command to unload a kernel module [/sbin/kldunload]
26 #
27 # NOMAN         KLD does not have a manual page if set.
28 #
29 # PROG          The name of the kernel module to build.
30 #               If not supplied, ${KMOD}.o is used.
31 #
32 # SRCS          List of source files
33 #
34 # KMODDEPS      List of modules which this one is dependant on
35 #
36 # DESTDIR       Change the tree where the module gets installed. [not set]
37 #
38 # MFILES        Optionally a list of interfaces used by the module.
39 #               This file contains a default list of interfaces.
40 #
41 # +++ targets +++
42 #
43 #       install:
44 #               install the kernel module and its manual pages; if the Makefile
45 #               does not itself define the target install, the targets
46 #               beforeinstall and afterinstall may also be used to cause
47 #               actions immediately before and after the install target
48 #               is executed.
49 #
50 #       load:
51 #               Load KLD.
52 #
53 #       unload:
54 #               Unload KLD.
55 #
56 # bsd.obj.mk: clean, cleandir and obj
57 # bsd.dep.mk: cleandepend, depend and tags
58 # bsd.man.mk: maninstall
59 #
60
61 KMODLOAD?=      /sbin/kldload
62 KMODUNLOAD?=    /sbin/kldunload
63
64 .include <bsd.init.mk>
65
66 .SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
67
68 CFLAGS+=        ${COPTS} -D_KERNEL ${CWARNFLAGS}
69 CFLAGS+=        -DKLD_MODULE
70
71 # Don't use any standard include directories.
72 # Since -nostdinc will annull any previous -I paths, we repeat all
73 # such paths after -nostdinc.  It doesn't seem to be possible to
74 # add to the front of `make' variable.
75 #
76 # Don't use -I- anymore, source-relative includes are desireable.
77 _ICFLAGS:=      ${CFLAGS:M-I*}
78 CFLAGS+=        -nostdinc ${_ICFLAGS}
79
80 # Add -I paths for system headers.  Individual KLD makefiles don't
81 # need any -I paths for this.  Similar defaults for .PATH can't be
82 # set because there are no standard paths for non-headers.
83 CFLAGS+=        -I. -I@
84
85 # Add a -I path to standard headers like <stddef.h>.  Use a relative
86 # path to src/include if possible.  If the @ symlink hasn't been built
87 # yet, then we can't tell if the relative path exists.  Add both the
88 # potential relative path and an absolute path in that case.
89 .if exists(@)
90 .if exists(@/../include)
91 CFLAGS+=        -I@/../include
92 .else
93 CFLAGS+=        -I${DESTDIR}/usr/include
94 .endif
95 .else # !@
96 CFLAGS+=        -I@/../include -I${DESTDIR}/usr/include
97 .endif # @
98
99 CFLAGS+=        ${DEBUG_FLAGS}
100
101 .if ${OBJFORMAT} == elf
102 CLEANFILES+=    setdef0.c setdef1.c setdefs.h
103 CLEANFILES+=    setdef0.o setdef1.o
104 .endif
105
106 OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
107
108 .if !defined(PROG)
109 PROG=   ${KMOD}.ko
110 .endif
111
112 ${PROG}: ${KMOD}.kld ${KMODDEPS}
113 .if ${OBJFORMAT} == elf
114         gensetdefs ${KMOD}.kld
115         ${CC} ${CFLAGS} -c setdef0.c
116         ${CC} ${CFLAGS} -c setdef1.c
117         ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} setdef0.o ${KMOD}.kld setdef1.o ${KMODDEPS}
118 .else
119         ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld ${KMODDEPS}
120 .endif
121
122 .if defined(KMODDEPS)
123 .for dep in ${KMODDEPS}
124 CLEANFILES+=    ${dep} __${dep}_hack_dep.c
125
126 ${dep}:
127         touch __${dep}_hack_dep.c
128         ${CC} -shared ${CFLAGS} -o ${dep} __${dep}_hack_dep.c
129 .endfor
130 .endif
131
132 ${KMOD}.kld: ${OBJS}
133         ${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS}
134
135 .if !defined(NOMAN)
136 .include <bsd.man.mk>
137 .endif
138
139 _ILINKS=@ machine
140
141 all: objwarn ${PROG}
142 .if !defined(NOMAN)
143 all: _manpages
144 .endif
145
146 beforedepend: ${_ILINKS}
147 # Ensure that the links exist without depending on it when it exists which
148 # causes all the modules to be rebuilt when the directory pointed to changes.
149 .for _link in ${_ILINKS}
150 .if !exists(${.OBJDIR}/${_link})
151 ${OBJS}: ${_link}
152 .endif
153 .endfor
154
155 # Search for kernel source tree in standard places.
156 .for _dir in ${.CURDIR}/../.. ${.CURDIR}/../../.. /sys /usr/src/sys
157 .if !defined(SYSDIR) && exists(${_dir}/kern/)
158 SYSDIR= ${_dir}
159 .endif
160 .endfor
161 .if !defined(SYSDIR) || !exists(${SYSDIR}/kern)
162 .error "can't find kernel source tree"
163 .endif
164
165 ${_ILINKS}:
166         @case ${.TARGET} in \
167         machine) \
168                 path=${SYSDIR}/${MACHINE_ARCH}/include ;; \
169         @) \
170                 path=${SYSDIR} ;; \
171         esac ; \
172         path=`(cd $$path && /bin/pwd)` ; \
173         ${ECHO} ${.TARGET} "->" $$path ; \
174         ln -s $$path ${.TARGET}
175
176 CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS} ${_ILINKS} symb.tmp tmp.o
177
178 .if !target(install)
179
180 _INSTALLFLAGS:= ${INSTALLFLAGS}
181 .for ie in ${INSTALLFLAGS_EDIT}
182 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
183 .endfor
184
185 .if !target(realinstall)
186 realinstall: _kmodinstall
187 .ORDER: beforeinstall _kmodinstall
188 _kmodinstall:
189         ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
190             ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}
191 .endif !target(realinstall)
192
193 .include <bsd.links.mk>
194
195 .if !defined(NOMAN)
196 realinstall: _maninstall
197 .ORDER: beforeinstall _maninstall
198 .endif
199
200 .endif !target(install)
201
202 .if !target(load)
203 load:   ${PROG}
204         ${KMODLOAD} -v ./${KMOD}.ko
205 .endif
206
207 .if !target(unload)
208 unload:
209         ${KMODUNLOAD} -v ${KMOD}
210 .endif
211
212 .for _src in ${SRCS:Mopt_*.h}
213 CLEANFILES+=    ${_src}
214 .if !target(${_src})
215 ${_src}:
216         touch ${.TARGET}
217 .endif
218 .endfor
219
220 MFILES?= kern/bus_if.m kern/device_if.m bus/iicbus/iicbb_if.m \
221     bus/iicbus/iicbus_if.m bus/isa/isa_if.m dev/netif/mii_layer/miibus_if.m \
222     dev/misc/pccard/card_if.m dev/misc/pccard/power_if.m bus/pci/pci_if.m \
223     bus/ppbus/ppbus_if.m bus/smbus/smbus_if.m bus/usb/usb_if.m \
224     dev/sound/pcm/ac97_if.m dev/sound/pcm/channel_if.m \
225     dev/sound/pcm/feeder_if.m dev/sound/pcm/mixer_if.m \
226     libkern/iconv_converter_if.m dev/agp/agp_if.m opencrypto/crypto_if.m \
227     bus/canbus/canbus_if.m
228
229 .for _srcsrc in ${MFILES}
230 .for _ext in c h
231 .for _src in ${SRCS:M${_srcsrc:T:R}.${_ext}}
232 CLEANFILES+=    ${_src}
233 .if !target(${_src})
234 ${_src}: @
235 .if exists(@)
236 ${_src}: @/kern/makeops.pl @/${_srcsrc}
237 .endif
238         perl @/kern/makeops.pl -${_ext} @/${_srcsrc}
239 .endif
240 .endfor # _src
241 .endfor # _ext
242 .endfor # _srcsrc
243
244 .for _ext in c h
245 .if ${SRCS:Mvnode_if.${_ext}} != ""
246 CLEANFILES+=    vnode_if.${_ext}
247 vnode_if.${_ext}: @
248 .if exists(@)
249 vnode_if.${_ext}: @/kern/vnode_if.pl @/kern/vnode_if.src
250 .endif
251         perl @/kern/vnode_if.pl -${_ext} @/kern/vnode_if.src
252 .endif
253 .endfor
254
255 regress:
256
257 .include <bsd.dep.mk>
258
259 .if !exists(${DEPENDFILE})
260 ${OBJS}: ${SRCS:M*.h}
261 .endif
262
263 .include <bsd.obj.mk>
264 .include <bsd.kern.mk>