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