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