Makefile.kern.inc revision 1.70 1 # $NetBSD: Makefile.kern.inc,v 1.70 2005/11/24 12:54:29 dbj 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+= ${CPUFLAGS} -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 rm -f .depend
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 SRCS?= ${MD_SFILES} ${MD_CFILES} ${MI_CFILES} ${CFILES} ${SFILES}
305 MKDEP_AFLAGS?= ${AFLAGS}
306 MKDEP_CFLAGS?= ${CFLAGS}
307 # We have to assume that we'll eventually run out of command line.
308 # We already hit that on non-NetBSD hosts.
309 _SFILES=${MD_SFILES} ${SFILES}
310 _CFILES=${MD_CFILES} ${MI_CFILES} ${CFILES}
311 .if ${MAKEVERBOSE} == 2
312 _T=-t
313 .else
314 _T=
315 .endif
316 _XargsMKDEP=${MKDEP:M*=*} xargs ${_T} ${MKDEP:N*=*}
317 _SubMake=${.MAKE} -f ${MAKEFILE} -DnoBEGIN
318
319 # This dance is necessary to avoid long command lines.
320 ${SRCS:S,^,list-,}:
321 @echo ${.TARGET:S,^list-,,}
322
323 _sfiles: ${_SFILES:S,^,list-,}
324 _cfiles: ${_CFILES:S,^,list-,}
325
326 .depend: ${SRCS} assym.h config_time.h
327 ${_MKTARGET_CREATE}
328 @> $@
329 @${_SubMake} _sfiles | ${_XargsMKDEP} -a -- ${MKDEP_AFLAGS} ${CPPFLAGS}
330 @${_SubMake} _cfiles | ${_XargsMKDEP} -a -- ${MKDEP_CFLAGS} ${CPPFLAGS}
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 >> .depend
335 @rm -f assym.dep
336 .endif
337
338 .if !target(lint)
339 ALLSFILES?= ${MD_SFILES} ${SFILES}
340 LINTSTUBS?= ${ALLSFILES:T:R:C/^.*$/LintStub_&.c/g}
341 KERNLINTFLAGS?= -bcehnxzFS
342 NORMAL_LN?= ${LINT} ${KERNLINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i $<
343
344 _lsrc=${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES}
345 LOBJS?= ${_lsrc:T:S/.c$/.ln/g} ${LIBKERNLN} ${SYSLIBCOMPATLN}
346
347 .for _sfile in ${ALLSFILES}
348 LintStub_${_sfile:T:R}.c: ${_sfile} assym.h
349 ${_MKTARGET_COMPILE}
350 ${CC} -E -C ${AFLAGS} ${CPPFLAGS} ${_sfile} | \
351 awk -f $S/kern/genlintstub.awk >${.TARGET}
352 .endfor
353
354 .for _cfile in ${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES}
355 ${_cfile:T:R}.ln: ${_cfile}
356 ${_MKTARGET_COMPILE}
357 ${NORMAL_LN}
358 .endfor
359
360 lint: ${LOBJS}
361 ${LINT} ${KERNLINTFLAGS} ${CPPFLAGS:M-[IDU]*} ${LOBJS}
362 .endif
363
364 .if !target(install)
365 # The install target can be redefined by putting a
366 # install-kernel-${MACHINE_NAME} target into /etc/mk.conf
367 MACHINE_NAME!= uname -n
368 install: install-kernel-${MACHINE_NAME}
369 .if !target(install-kernel-${MACHINE_NAME})
370 install-kernel-${MACHINE_NAME}:
371 rm -f ${DESTDIR}/onetbsd
372 ln ${DESTDIR}/netbsd ${DESTDIR}/onetbsd
373 cp netbsd ${DESTDIR}/nnetbsd
374 mv ${DESTDIR}/nnetbsd ${DESTDIR}/netbsd
375 .endif
376 .endif
377
378 .if !target(tags)
379 tags:
380 @echo "see $S/kern/Makefile for tags"
381 .endif
382
383 EXTRA_CLEAN+= cscope.out cscope.tmp
384 .if !target(cscope.out)
385 cscope.out: Makefile depend
386 ${_MKTARGET_CREATE}
387 @sed 's/[^:]*://;s/^ *//;s/ *\\ *$$//;' lib/kern/.depend | \
388 tr -s ' ' '\n' | sed 's|^\([^.\\]\)|lib/kern/\1|;s|^../../||;' > \
389 cscope.tmp
390 @sed 's/[^:]*://;s/^ *//;s/ *\\ *$$//;' lib/compat/.depend | \
391 tr -s ' ' '\n' | sed 's|^\([^.\\]\)|lib/compat/\1|;s|^../../||;' >> \
392 cscope.tmp
393 @echo ${SRCS} | cat - cscope.tmp | tr -s ' ' '\n' | sort -u | \
394 ${CSCOPE} -k -i - -b `echo ${INCLUDES} | sed s/-nostdinc//`
395 # cscope doesn't write cscope.out if it's uptodate, so ensure
396 # make doesn't keep calling cscope when not needed.
397 @rm -f cscope.tmp; touch cscope.out
398 .endif
399
400 .if !target(cscope)
401 cscope: cscope.out
402 @${CSCOPE} -d
403 .endif
404
405 EXTRA_CLEAN+= ID
406 .if !target(mkid)
407 .PHONY: mkid
408 mkid: ID
409
410 ID: Makefile depend
411 ${_MKTARGET_CREATE}
412 @${MKID} `sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' lib/kern/.depend \
413 lib/compat/.depend | tr ' ' '\n' | sed "s|^../../||" | sort -u` \
414 `sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' .depend | tr ' ' '\n' \
415 | sort -u`
416
417 .endif
418
419 .include "${S}/gdbscripts/Makefile.inc"
420
421 EXTRA_CLEAN+= .gdbinit
422 .gdbinit: Makefile ${S}/gdbscripts/Makefile.inc
423 ${_MKTARGET_CREATE}
424 rm -f .gdbinit
425 .for __gdbinit in ${SYS_GDBINIT}
426 echo "source ${S}/gdbscripts/${__gdbinit}" >> .gdbinit
427 .endfor
428 .if defined(GDBINIT) && !empty(GDBINIT)
429 .for __gdbinit in ${GDBINIT}
430 echo "source ${__gdbinit}" >> .gdbinit
431 .endfor
432 .endif
433
434 CFLAGS+= ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}}
435 CPPFLAGS+= ${CPPFLAGS.${.IMPSRC:T}}
436 CWARNFLAGS+= ${CWARNFLAGS.${.IMPSRC:T}}
437
438 ##
439 ## the end
440 ##
441