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