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