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