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