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