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