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