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