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