Makefile.kern.inc revision 1.104.6.1 1 # $NetBSD: Makefile.kern.inc,v 1.104.6.1 2008/01/19 12:15:01 bouyer Exp $
2 #
3 # This file contains common `MI' targets and definitions and it is included
4 # at the bottom of each `MD' ${MACHINE}/conf/Makefile.${MACHINE}.
5 #
6 # Each target in this file should be protected with `if !target(target)'
7 # or `if !commands(target)' and each variable should only be conditionally
8 # assigned `VAR ?= VALUE', so that everything can be overriden.
9 #
10 # DEBUG is set to -g if debugging.
11 # PROF is set to -pg if profiling.
12 #
13 # To specify debugging, add the config line: makeoptions DEBUG="-g"
14 # A better way is to specify -g only for a few files.
15 #
16 # makeoptions DEBUGLIST="uvm* trap if_*"
17 #
18 # all ports are expected to include bsd.own.mk for toolchain settings
19
20 ##
21 ## (0) toolchain settings for things that aren't part of the standard
22 ## toolchain
23 ##
24 HOST_SH?= sh
25 DBSYM?= dbsym
26 MKDEP?= mkdep
27 STRIP?= strip
28 OBJCOPY?= objcopy
29 OBJDUMP?= objdump
30 CSCOPE?= cscope
31 MKID?= mkid
32 UUDECODE?= ${TOOL_UUDECODE:Uuudecode}
33 HEXDUMP?= ${TOOL_HEXDUMP:Uhexdump}
34 GENASSYM?= ${TOOL_GENASSYM:Ugenassym}
35 .MAKEOVERRIDES+=USETOOLS # make sure proper value is propagated
36
37 _MKMSG?= @\#
38 _MKSHMSG?= echo
39 _MKSHECHO?= echo
40 _MKMSG_CREATE?= :
41 _MKTARGET_COMPILE?= :
42 _MKTARGET_CREATE?= :
43
44 ##
45 ## (1) port independent source tree identification
46 ##
47 # source tree is located via $S relative to the compilation directory
48 .ifndef S
49 S!= cd ../../../..; pwd
50 .endif
51
52 ##
53 ## (2) compile settings
54 ##
55 ## CPPFLAGS, CFLAGS, and AFLAGS must be set in the port's Makefile
56 ##
57 INCLUDES?= -I. ${EXTRA_INCLUDES} -I${S}/../common/include -I$S/arch \
58 -I$S -nostdinc
59 CPPFLAGS+= ${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -D_KERNEL_OPT
60 DEFCOPTS?= -O2
61 COPTS?= ${DEFCOPTS}
62 DBG= # might contain unwanted -Ofoo
63 DEFWARNINGS?= yes
64 .if (${DEFWARNINGS} == "yes")
65 . if !defined(NOGCCERROR)
66 CWARNFLAGS+= -Werror
67 . endif
68 CWARNFLAGS+= -Wall -Wno-main -Wno-format-zero-length -Wpointer-arith
69 CWARNFLAGS+= -Wmissing-prototypes -Wstrict-prototypes
70 CWARNFLAGS+= -Wswitch -Wshadow
71 CWARNFLAGS+= -Wcast-qual -Wwrite-strings
72 # Add -Wno-sign-compare. -Wsign-compare is included in -Wall as of GCC 3.3,
73 # but our sources aren't up for it yet.
74 CWARNFLAGS+= -Wno-sign-compare
75 . if ${HAVE_GCC} > 3
76 CWARNFLAGS+= -Wno-pointer-sign -Wno-attributes
77 . if ${MACHINE} == "i386" || ${MACHINE_ARCH} == "sparc64" || ${MACHINE} == "prep"
78 CWARNFLAGS+= -Wextra -Wno-unused-parameter
79 . endif
80 . endif
81 .endif
82
83 CFLAGS+= -ffreestanding -fno-zero-initialized-in-bss
84 CFLAGS+= ${CPUFLAGS} ${DEBUG} ${COPTS} ${CWARNFLAGS}
85 AFLAGS+= ${CPUFLAGS} -D_LOCORE -Wa,-fatal-warnings
86
87 # XXX
88 .if ${HAVE_GCC} > 3
89 CFLAGS+= -fno-strict-aliasing
90 .endif
91
92 .if ${USE_SSP:Uno} == "yes"
93 CFLAGS+=-fstack-protector -Wstack-protector --param ssp-buffer-size=1
94 LDFLAGS+=-fstack-protector -Wstack-protector --param ssp-buffer-size=1
95 .endif
96
97 # If we want the bpendtsleep: label in kern_synch.c, we need to use
98 # -fno-reorder-blocks. Don't make this a config(1) defflag without
99 # making sure this fragment remains valid.
100 .if ${HAVE_GCC} > 3 && !empty(${CFLAGS:M-DKERN_SYNCH_BPENDTSLEEP_LABEL})
101 CFLAGS.kern_synch.c+= -fno-reorder-blocks
102 .endif
103
104 # Use the per-source COPTS variables to add -g to just those
105 # files that match the shell patterns given in ${DEBUGLIST}
106 #
107 .for i in ${DEBUGLIST}
108 . for j in ${CFILES:T:M$i.c}
109 COPTS.${j}+=-g
110 . endfor
111 .endfor
112
113 # Always compile subr_debug_info.c with debug informations.
114 # This allows gdb to use type informations.
115 #
116 COPTS.debugsyms.c+= -g
117
118 # compile rules: rules are named ${TYPE}_${SUFFIX} where TYPE is NORMAL or
119 # NOPROF and SUFFIX is the file suffix, capitalized (e.g. C for a .c file).
120 NORMAL_C?= @${_MKSHMSG} "compile ${.CURDIR:T}/${.TARGET}"; \
121 ${_MKSHECHO}\
122 ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<; \
123 ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<
124 NOPROF_C?= @${_MKSHMSG} "compile ${.CURDIR:T}/${.TARGET}"; \
125 ${_MKSHECHO}\
126 ${CC} ${CFLAGS} ${CPPFLAGS} -c $<; \
127 ${CC} ${CFLAGS} ${CPPFLAGS} -c $<
128 NORMAL_S?= @${_MKSHMSG} "compile ${.CURDIR:T}/${.TARGET}"; \
129 ${_MKSHECHO}\
130 ${CC} ${AFLAGS} ${CPPFLAGS} -c $<; \
131 ${CC} ${AFLAGS} ${CPPFLAGS} -c $<
132
133 ##
134 ## (3) libkern and compat
135 ##
136 ## Set KERN_AS in the port Makefile to "obj" or "library". The
137 ## default is "library", as documented in $S/lib/libkern/Makefile.inc.
138 ##
139
140 ### find out what to use for libkern
141 .include "$S/lib/libkern/Makefile.inc"
142 .ifndef PROF
143 LIBKERN?= ${KERNLIB}
144 .else
145 LIBKERN?= ${KERNLIB_PROF}
146 .endif
147
148 LIBKERNLN?= ${KERNLIBLN}
149
150 ### find out what to use for libcompat
151 .include "$S/compat/common/Makefile.inc"
152 .ifndef PROF
153 SYSLIBCOMPAT?= ${COMPATLIB}
154 .else
155 SYSLIBCOMPAT?= ${COMPATLIB_PROF}
156 .endif
157
158 SYSLIBCOMPATLN?= ${COMPATLIBLN}
159
160 ##
161 ## (4) local objects, compile rules, and dependencies
162 ##
163 ## Each port should have a corresponding section with settings for
164 ## MD_CFILES, MD_SFILES, and MD_OBJS, along with build rules for same.
165 ##
166 MI_CFILES=devsw.c ioconf.c param.c
167 # the need for a MI_SFILES variable is dubitable at best
168 MI_OBJS=${MI_CFILES:S/.c/.o/}
169
170 param.c: $S/conf/param.c
171 ${_MKTARGET_CREATE}
172 rm -f param.c
173 cp $S/conf/param.c .
174
175 param.o: Makefile
176
177 .for _cfile in ${MI_CFILES}
178 ${_cfile:T:R}.o: ${_cfile}
179 ${NORMAL_C}
180 .endfor
181
182 ##
183 ## (5) link settings
184 ##
185 ## TEXTADDR (or LOADADDRESS), LINKFORMAT, and any EXTRA_LINKFLAGS must
186 ## be set in the port's Makefile. The port specific definitions for
187 ## LINKFLAGS_NORMAL and LINKFLAGS_DEBUG will added to the LINKFLAGS
188 ## depending on the value of DEBUG.
189 ##
190 # load lines for config "xxx" will be emitted as:
191 # xxx: ${SYSTEM_DEP} swapxxx.o
192 # ${SYSTEM_LD_HEAD}
193 # ${SYSTEM_LD} swapxxx.o
194 # ${SYSTEM_LD_TAIL}
195 SYSTEM_OBJ?= ${MD_OBJS} ${MI_OBJS} ${OBJS} ${SYSLIBCOMPAT} ${LIBKERN}
196 SYSTEM_DEP?= Makefile ${SYSTEM_OBJ:O} .gdbinit
197 SYSTEM_LD_HEAD?=@rm -f $@
198 SYSTEM_LD?= @${_MKSHMSG} " link ${.CURDIR:T}/${.TARGET}"; \
199 ${_MKSHECHO}\
200 ${LD} -Map $@.map --cref ${LINKFLAGS} -o $@ '$${SYSTEM_OBJ}' '$${EXTRA_OBJ}' vers.o; \
201 ${LD} -Map $@.map --cref ${LINKFLAGS} -o $@ ${SYSTEM_OBJ} ${EXTRA_OBJ} vers.o
202 SYSTEM_LD_TAIL?=@${SIZE} $@; chmod 755 $@
203
204 TEXTADDR?= ${LOADADDRESS} # backwards compatibility
205 LINKTEXT?= ${TEXTADDR:C/.+/-Ttext &/}
206 LINKDATA?= ${DATAADDR:C/.+/-Tdata &/}
207 ENTRYPOINT?= start
208 LINKENTRY?= ${ENTRYPOINT:C/.+/-e &/}
209 LINKFLAGS?= ${LINKFORMAT} ${LINKTEXT} ${LINKDATA} ${LINKENTRY} \
210 ${EXTRA_LINKFLAGS}
211
212 LINKFLAGS_DEBUG?= -X
213 SYSTEM_LD_TAIL_DEBUG?=; \
214 echo mv -f $@ $@.gdb; mv -f $@ $@.gdb; \
215 echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \
216 ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb
217 LINKFLAGS_NORMAL?= -S
218 STRIPFLAGS?= -g
219
220 DEBUG?=
221 .if !empty(DEBUG:M-g*)
222 SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_DEBUG}
223 LINKFLAGS+= ${LINKFLAGS_DEBUG}
224 EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.gdb@}
225 .elifndef PROF
226 LINKFLAGS+= ${LINKFLAGS_NORMAL}
227 .endif
228
229 SYSTEM_LD_TAIL+=; \
230 if grep -q '^\#define.*SYMTAB_SPACE' opt_ddbparam.h; then \
231 echo "${DBSYM} $@"; \
232 ${DBSYM} $@; \
233 fi
234
235 SYSTEM_LD_HEAD+=${SYSTEM_LD_HEAD_EXTRA}
236 SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_EXTRA}
237
238 ##
239 ## (6) port independent targets and dependencies: assym.h, vers.o
240 ##
241 .if !target(assym.h)
242 assym.h: ${GENASSYM_CONF} ${GENASSYM_EXTRAS}
243 ${_MKTARGET_CREATE}
244 cat ${GENASSYM_CONF} ${GENASSYM_EXTRAS} | \
245 ${GENASSYM} -- ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} \
246 > assym.h.tmp && \
247 mv -f assym.h.tmp assym.h
248 ${MD_SFILES:C/\.[Ss]/.o/} ${SFILES:C/\.[Ss]/.o/}: assym.h
249 .endif
250
251 .if !target(vers.o)
252 newvers: vers.o
253 vers.o: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP} $S/conf/newvers.sh $S/conf/osrelease.sh
254 ${_MKMSG_CREATE} vers.c
255 ${HOST_SH} $S/conf/newvers.sh
256 ${_MKTARGET_COMPILE}
257 ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
258 .endif
259
260 .if !target(config_time.h)
261 BUILDSYMLINKS+= config_time.src config_time.h
262 .endif
263
264 .if defined(MEMORY_DISK_IMAGE)
265 md_root_image.h: ${MEMORY_DISK_IMAGE}
266 ${_MKTARGET_CREATE}
267 ${TOOL_HEXDUMP} -v -e '"\t" 8/1 "0x%02x, " "\n"' ${.ALLSRC} > ${.TARGET}
268
269 # XXX This is only needed when building md_root.o
270 CPPFLAGS+= -DMEMORY_DISK_IMAGE
271 md_root.o: md_root_image.h
272 .endif
273
274 # depend on MEMORY_DISK_IMAGE configuration
275 md_root.o: Makefile
276
277 # depend on root or device configuration
278 autoconf.o conf.o: Makefile
279
280 # depend on network or filesystem configuration
281 uipc_proto.o vfs_conf.o: Makefile
282
283 # depend on maxusers and CPU configuration
284 assym.h machdep.o: Makefile
285
286 ##
287 ## (7) misc targets: install, clean(dir), depend(all), lint, links, tags,
288 ## cscope, mkid
289 ##
290 ## Any ports that have other stuff to be cleaned up should fill in
291 ## EXTRA_CLEAN. Some ports may want different settings for
292 ## KERNLINTFLAGS, MKDEP_CFLAGS, or MKDEP_AFLAGS.
293 ##
294 .if !target(__CLEANKERNEL)
295 __CLEANKERNEL: .USE
296 ${_MKMSG} "${.TARGET}ing the kernel objects"
297 rm -f ${KERNELS} eddep tags *.[io] *.ln [a-z]*.s vers.c \
298 [Ee]rrs linterrs makelinks assym.h.tmp assym.h \
299 ${EXTRA_KERNELS} ${EXTRA_CLEAN}
300 .endif
301
302 .if !target(kernelnames)
303 kernelnames:
304 @echo "${KERNELS} ${EXTRA_KERNELS}"
305 .endif
306
307 .if !target(__CLEANDEPEND)
308 __CLEANDEPEND: .USE
309 echo .depend ${DEPS} | xargs rm -f --
310 .endif
311
312 # do not !target these, the kern and compat Makefiles augment them
313 cleandir distclean: __CLEANKERNEL __CLEANDEPEND
314 clean: __CLEANKERNEL
315 depend: .depend
316 dependall: depend .WAIT all
317
318 .if !target(.depend)
319 MKDEP_AFLAGS?= ${AFLAGS}
320 MKDEP_CFLAGS?= ${CFLAGS}
321 SSRCS=${MD_SFILES} ${SFILES}
322 CSRCS=${MD_CFILES} ${MI_CFILES} ${CFILES}
323 SRCS=${SSRCS} ${CSRCS}
324 DEPS= ${SRCS:T:O:u:R:S/$/.d/g}
325
326 .for _s in ${SSRCS}
327 ${_s:T:R}.d: ${_s} assym.h
328 ${_MKTARGET_CREATE}
329 ${MKDEP} -f ${.TARGET} -- ${MKDEP_AFLAGS} \
330 ${CPPFLAGS} ${CPPFLAGS.${_s:T}} ${_s}
331 .endfor
332 .for _s in ${CSRCS}
333 ${_s:T:R}.d: ${_s}
334 ${_MKTARGET_CREATE}
335 ${MKDEP} -f ${.TARGET} -- ${MKDEP_CFLAGS} \
336 ${CPPFLAGS} ${CPPFLAGS.${_s:T}} ${_s}
337 .endfor
338
339 assym.d: assym.h
340 ${_MKTARGET_CREATE}
341 cat ${GENASSYM_CONF} ${GENASSYM_EXTRAS} | \
342 ${GENASSYM} -- ${MKDEP} -f assym.dep -- \
343 ${CFLAGS} ${CPPFLAGS}
344 sed -e 's/.*\.o:.*\.c/assym.h:/' < assym.dep >${.TARGET}
345 rm -f assym.dep
346
347 .depend: ${DEPS} assym.d
348 ${_MKTARGET_CREATE}
349 echo "${.ALLSRC}" | ${MKDEP} -D
350 .endif
351
352 .if !target(lint)
353 ALLSFILES?= ${MD_SFILES} ${SFILES}
354 LINTSTUBS?= ${ALLSFILES:T:R:C/^.*$/LintStub_&.c/g}
355 KERNLINTFLAGS?= -bcehnxzFS
356 NORMAL_LN?= ${LINT} ${KERNLINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i $<
357
358 _lsrc=${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES}
359 LOBJS?= ${_lsrc:T:S/.c$/.ln/g} ${LIBKERNLN} ${SYSLIBCOMPATLN}
360
361 .for _sfile in ${ALLSFILES}
362 LintStub_${_sfile:T:R}.c: ${_sfile} assym.h
363 ${_MKTARGET_COMPILE}
364 ${CC} -E -C ${AFLAGS} ${CPPFLAGS} ${_sfile} | \
365 awk -f $S/kern/genlintstub.awk >${.TARGET}
366 .endfor
367
368 .for _cfile in ${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES}
369 ${_cfile:T:R}.ln: ${_cfile}
370 ${_MKTARGET_COMPILE}
371 ${NORMAL_LN}
372 .endfor
373
374 lint: ${LOBJS}
375 ${LINT} ${KERNLINTFLAGS} ${CPPFLAGS:M-[IDU]*} ${LOBJS}
376 .endif
377
378 # List of kernel images that will be installed into the root file system.
379 # Some platforms may need to install more than one (e.g. a netbsd.aout file
380 # to be loaded directly by the firmware), so this can be overriden by them.
381 KERNIMAGES?= netbsd
382
383 .if !target(install)
384 # The install target can be redefined by putting a
385 # install-kernel-${MACHINE_NAME} target into /etc/mk.conf
386 MACHINE_NAME!= uname -n
387 install: install-kernel-${MACHINE_NAME}
388 .if !target(install-kernel-${MACHINE_NAME})
389 install-kernel-${MACHINE_NAME}:
390 .for _K in ${KERNIMAGES}
391 rm -f ${DESTDIR}/o${_K}
392 ln ${DESTDIR}/${_K} ${DESTDIR}/o${_K}
393 cp ${_K} ${DESTDIR}/n${_K}
394 mv ${DESTDIR}/n${_K} ${DESTDIR}/${_K}
395 .endfor
396 .endif
397 .endif
398
399 .if !target(tags)
400 tags:
401 @echo "see $S/kern/Makefile for tags"
402 .endif
403
404 EXTRA_CLEAN+= cscope.out cscope.tmp
405 .if !target(cscope.out)
406 cscope.out: Makefile depend
407 ${_MKTARGET_CREATE}
408 @sed 's/[^:]*://;s/^ *//;s/ *\\ *$$//;' lib/kern/.depend | \
409 tr -s ' ' '\n' | sed 's|^\([^.\\]\)|lib/kern/\1|;s|^../../||;' > \
410 cscope.tmp
411 @sed 's/[^:]*://;s/^ *//;s/ *\\ *$$//;' lib/compat/.depend | \
412 tr -s ' ' '\n' | sed 's|^\([^.\\]\)|lib/compat/\1|;s|^../../||;' >> \
413 cscope.tmp
414 @echo ${SRCS} | cat - cscope.tmp | tr -s ' ' '\n' | sort -u | \
415 ${CSCOPE} -k -i - -b `echo ${INCLUDES} | sed s/-nostdinc//`
416 # cscope doesn't write cscope.out if it's uptodate, so ensure
417 # make doesn't keep calling cscope when not needed.
418 @rm -f cscope.tmp; touch cscope.out
419 .endif
420
421 .if !target(cscope)
422 cscope: cscope.out
423 @${CSCOPE} -d
424 .endif
425
426 EXTRA_CLEAN+= ID
427 .if !target(mkid)
428 .PHONY: mkid
429 mkid: ID
430
431 ID: Makefile depend
432 ${_MKTARGET_CREATE}
433 @${MKID} `sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' lib/kern/.depend \
434 lib/compat/.depend | tr ' ' '\n' | sed "s|^../../||" | sort -u` \
435 `sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' .depend | tr ' ' '\n' \
436 | sort -u`
437
438 .endif
439
440 .include "${S}/gdbscripts/Makefile.inc"
441
442 EXTRA_CLEAN+= .gdbinit
443 .gdbinit: Makefile ${S}/gdbscripts/Makefile.inc
444 ${_MKTARGET_CREATE}
445 rm -f .gdbinit
446 .for __gdbinit in ${SYS_GDBINIT}
447 echo "source ${S}/gdbscripts/${__gdbinit}" >> .gdbinit
448 .endfor
449 .if defined(GDBINIT) && !empty(GDBINIT)
450 .for __gdbinit in ${GDBINIT}
451 echo "source ${__gdbinit}" >> .gdbinit
452 .endfor
453 .endif
454
455 # The following files use alloca(3) or variable array allocations.
456 # Their full name is noted as documentation.
457 VARSTACK=dev/cgd.c kern/uipc_socket.c miscfs/genfs/genfs_vnops.c \
458 nfs/nfs_bio.c uvm/uvm_bio.c \
459 uvm/uvm_pager.c dev/ic/aic7xxx.c dev/ic/aic79xx.c arch/xen/i386/gdt.c \
460 dev/ofw/ofw_subr.c
461
462 . if ${HAVE_GCC} > 3
463 .for __varstack in ${VARSTACK}
464 COPTS.${__varstack:T} += -Wno-stack-protector
465 .endfor
466 .endif
467
468 AFLAGS+= ${AOPTS.${.IMPSRC:T}}
469 CFLAGS+= ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}}
470 CPPFLAGS+= ${CPPFLAGS.${.IMPSRC:T}}
471 CWARNFLAGS+= ${CWARNFLAGS.${.IMPSRC:T}}
472
473 .include <bsd.files.mk>
474
475 ##
476 ## the end
477 ##
478