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