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