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