Makefile.kern.inc revision 1.24 1 # $NetBSD: Makefile.kern.inc,v 1.24 2002/10/05 17:17:48 chs 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}. There are
5 # many `MI' definitions that should end up in here, but they are not yet.
6 #
7 # Each target in this file should be protected with `if !target(target)'
8 # or `if !commands(target)' and each variable should only be conditionally
9 # assigned `VAR ?= VALUE', so that everything can be overriden.
10 #
11 # DEBUG is set to -g if debugging.
12 # PROF is set to -pg if profiling.
13 #
14 # To specify debugging, add the config line: makeoptions DEBUG="-g"
15 # A better way is to specify -g only for a few files.
16 #
17 # makeoptions DEBUGLIST="uvm* trap if_*"
18 #
19 # all ports are expected to include bsd.own.mk for toolchain settings
20
21 ##
22 ## (0) toolchain settings for things that aren't part of the standard
23 ## toolchain
24 ##
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 ##
35 ## (1) port independent source tree identification
36 ##
37 # source tree is located via $S relative to the compilation directory
38 .ifndef S
39 S!= cd ../../../..; pwd
40 .endif
41
42 ##
43 ## (2) compile settings
44 ##
45 ## CPPFLAGS, CFLAGS, and AFLAGS must be set in the port's Makefile
46 ##
47 INCLUDES?= -I. ${EXTRA_INCLUDES} -I$S/arch -I$S -nostdinc
48 CPPFLAGS+= ${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -D_KERNEL_OPT
49 DEFCOPTS?= -O2
50 COPTS+= ${DEFCOPTS}
51 DBG= # might contain unwanted -Ofoo
52 DEFWARNINGS?= yes
53 .if (${DEFWARNINGS} == "yes")
54 CWARNFLAGS+= -Werror -Wall -Wno-main -Wno-format-zero-length -Wpointer-arith
55 CWARNFLAGS+= -Wmissing-prototypes -Wstrict-prototypes
56 # XXX Delete -Wuninitialized for now, since the compiler doesn't
57 # XXX always get it right. --thorpej
58 CWARNFLAGS+= -Wno-uninitialized
59 .endif
60 CFLAGS+= -ffreestanding ${DEBUG} ${COPTS} ${CWARNFLAGS}
61 AFLAGS+= -D_LOCORE
62
63 # Define a set of xxx_G variables that will add -g to just those
64 # files that match the shell patterns given in ${DEBUGLIST}
65 #
66 .for i in ${DEBUGLIST}
67 .for j in ${CFILES:T:M$i.c}
68 ${j:R}_G?= -g
69 .endfor
70 .endfor
71
72 # compile rules: rules are named ${TYPE}_${SUFFIX} where TYPE is NORMAL or
73 # NOPROF and SUFFIX is the file suffix, capitalized (e.g. C for a .c file).
74 NORMAL_C?= ${CC} ${CFLAGS} ${CPPFLAGS} ${${<:T:R}_G} ${PROF} -c $<
75 NOPROF_C?= ${CC} ${CFLAGS} ${CPPFLAGS} ${${<:T:R}_G} -c $<
76 NORMAL_S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c $<
77
78 ##
79 ## (3) libkern and compat
80 ##
81 ## Set KERN_AS in the port Makefile to "obj" or "library". The
82 ## default is "library", as documented in $S/lib/libkern/Makefile.inc.
83 ##
84
85 ### find out what to use for libkern
86 .include "$S/lib/libkern/Makefile.inc"
87 .ifndef PROF
88 LIBKERN?= ${KERNLIB}
89 .else
90 LIBKERN?= ${KERNLIB_PROF}
91 .endif
92
93 ### find out what to use for libcompat
94 .include "$S/compat/common/Makefile.inc"
95 .ifndef PROF
96 LIBCOMPAT?= ${COMPATLIB}
97 .else
98 LIBCOMPAT?= ${COMPATLIB_PROF}
99 .endif
100
101 ##
102 ## (4) local objects, compile rules, and dependencies
103 ##
104 ## Each port should have a corresponding section with settings for
105 ## MD_CFILES, MD_SFILES, and MD_OBJS, along with build rules for same.
106 ##
107 MI_CFILES=devsw.c ioconf.c param.c
108 # the need for a MI_SFILES variable is dubitable at best
109 MI_OBJS=${MI_CFILES:S/.c/.o/}
110
111 param.c: $S/conf/param.c
112 rm -f param.c
113 cp $S/conf/param.c .
114
115 param.o: Makefile
116
117 .for _cfile in ${MI_CFILES}
118 ${_cfile:T:R}.o: ${_cfile}
119 ${NORMAL_C}
120 .endfor
121
122 ##
123 ## (5) link settings
124 ##
125 ## TEXTADDR (or LOADADDRESS), LINKFORMAT, and any EXTRA_LINKFLAGS must
126 ## be set in the port's Makefile. The port specific definitions for
127 ## LINKFLAGS_NORMAL and LINKFLAGS_DEBUG will added to the LINKFLAGS
128 ## depending on the value of DEBUG.
129 ##
130 # load lines for config "xxx" will be emitted as:
131 # xxx: ${SYSTEM_DEP} swapxxx.o
132 # ${SYSTEM_LD_HEAD}
133 # ${SYSTEM_LD} swapxxx.o
134 # ${SYSTEM_LD_TAIL}
135 SYSTEM_OBJ?= ${MD_OBJS} ${MI_OBJS} ${OBJS} ${LIBCOMPAT} ${LIBKERN}
136 SYSTEM_DEP?= Makefile ${SYSTEM_OBJ} .gdbinit
137 SYSTEM_LD_HEAD?= @rm -f $@
138 SYSTEM_LD?= @echo ${LD} ${LINKFLAGS} -o $@ '$${SYSTEM_OBJ}' vers.o; \
139 ${LD} ${LINKFLAGS} -o $@ ${SYSTEM_OBJ} vers.o
140 SYSTEM_LD_TAIL?= @${SIZE} $@; chmod 755 $@
141
142 TEXTADDR?= ${LOADADDRESS} # backwards compatibility
143 LINKTEXT?= ${TEXTADDR:C/.+/-Ttext &/}
144 LINKDATA?= ${DATAADDR:C/.+/-Tdata &/}
145 ENTRYPOINT?= start
146 LINKENTRY?= ${ENTRYPOINT:C/.+/-e &/}
147 LINKFLAGS?= ${LINKFORMAT} ${LINKTEXT} ${LINKDATA} ${LINKENTRY} \
148 ${EXTRA_LINKFLAGS}
149
150 LINKFLAGS_DEBUG?= -X
151 SYSTEM_LD_TAIL_DEBUG?=; \
152 echo mv -f $@ $@.gdb; mv -f $@ $@.gdb; \
153 echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \
154 ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb
155 LINKFLAGS_NORMAL?= -S
156 STRIPFLAGS?= -g
157
158 DEBUG?=
159 .if ${DEBUG} == "-g"
160 SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_DEBUG}
161 LINKFLAGS+= ${LINKFLAGS_DEBUG}
162 EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.gdb@}
163 .elifndef PROF
164 LINKFLAGS+= ${LINKFLAGS_NORMAL}
165 .endif
166
167 SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_EXTRA}
168
169 ##
170 ## (6) port independent targets and dependencies: assym.h, vers.o
171 ##
172 .if !target(assym.h)
173 assym.h: $S/kern/genassym.sh ${GENASSYM} ${GENASSYM_EXTRAS}
174 cat ${GENASSYM} ${GENASSYM_EXTRAS} | \
175 sh $S/kern/genassym.sh ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} \
176 > assym.h.tmp && \
177 mv -f assym.h.tmp assym.h
178 ${MD_SFILES:C/\.[Ss]/.o/} ${SFILES:C/\.[Ss]/.o/}: assym.h
179 .endif
180
181 .if !target(vers.o)
182 newvers: vers.o
183 vers.o: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP} $S/conf/newvers.sh $S/conf/osrelease.sh
184 sh $S/conf/newvers.sh
185 ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
186 .endif
187
188 # depend on root or device configuration
189 autoconf.o conf.o: Makefile
190
191 # depend on network or filesystem configuration
192 uipc_proto.o vfs_conf.o: Makefile
193
194 # depend on maxusers and CPU configuration
195 assym.h machdep.o: Makefile
196
197 ##
198 ## (7) misc targets: install, clean(dir), depend(all), lint, links, tags,
199 ## cscope, mkid
200 ##
201 ## Any ports that have other stuff to be cleaned up should fill in
202 ## EXTRA_CLEAN. Some ports may want different settings for
203 ## KERNLINTFLAGS, MKDEP_CFLAGS, or MKDEP_AFLAGS.
204 ##
205 .if !target(__CLEANKERNEL)
206 __CLEANKERNEL: .USE
207 @echo "${.TARGET}ing the kernel objects"
208 rm -f ${KERNELS} eddep tags *.[io] [a-z]*.s vers.c \
209 [Ee]rrs linterrs makelinks assym.h.tmp assym.h \
210 ${EXTRA_KERNELS} ${EXTRA_CLEAN}
211 .endif
212
213 .if !target(kernelnames)
214 kernelnames:
215 @echo "${KERNELS} ${EXTRA_KERNELS}"
216 .endif
217
218 .if !target(__CLEANDEPEND)
219 __CLEANDEPEND: .USE
220 rm -f .depend
221 .endif
222
223 # do not !target these, the kern and compat Makefiles augment them
224 cleandir distclean: __CLEANKERNEL __CLEANDEPEND
225 clean: __CLEANKERNEL
226 depend: .depend
227
228 .if !target(.depend)
229 SRCS?= ${MD_SFILES} ${MD_CFILES} ${MI_CFILES} ${CFILES} ${SFILES}
230 MKDEP_AFLAGS?= ${AFLAGS}
231 MKDEP_CFLAGS?= ${CFLAGS}
232 .depend: ${SRCS} assym.h
233 ${MKDEP} ${MKDEP_AFLAGS} ${CPPFLAGS} ${MD_SFILES} ${SFILES}
234 ${MKDEP} -a ${MKDEP_CFLAGS} ${CPPFLAGS} ${MD_CFILES} ${MI_CFILES} \
235 ${CFILES}
236 cat ${GENASSYM} ${GENASSYM_EXTRAS} | \
237 sh $S/kern/genassym.sh ${MKDEP} -f assym.dep ${CFLAGS} ${CPPFLAGS}
238 @sed -e 's/.*\.o:.*\.c/assym.h:/' < assym.dep >> .depend
239 @rm -f assym.dep
240 .endif
241
242 .if !target(dependall)
243 dependall: depend all
244 .endif
245
246 .if !target(lint)
247 ALLSFILES?= ${MD_SFILES} ${SFILES}
248 LINTSTUBS?= ${ALLSFILES:T:R:C/^.*$/LintStub_&.c/g}
249 KERNLINTFLAGS?= -hbxncez -Dvolatile=
250 .for _sfile in ${ALLSFILES}
251 LintStub_${_sfile:T:R}.c: ${_sfile} assym.h
252 ${CC} -E -C ${AFLAGS} ${CPPFLAGS} ${_sfile} | \
253 awk -f $S/kern/genlintstub.awk >${.TARGET}
254 .endfor
255 lint: ${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES}
256 @${LINT} ${KERNLINTFLAGS} ${CPPFLAGS} -UKGDB \
257 ${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES} | \
258 grep -v 'static function .* unused'
259 .endif
260
261 .if !target(install)
262 # The install target can be redefined by putting a
263 # install-kernel-${MACHINE_NAME} target into /etc/mk.conf
264 MACHINE_NAME!= uname -n
265 install: install-kernel-${MACHINE_NAME}
266 .if !target(install-kernel-${MACHINE_NAME}})
267 install-kernel-${MACHINE_NAME}:
268 rm -f ${DESTDIR}/onetbsd
269 ln ${DESTDIR}/netbsd ${DESTDIR}/onetbsd
270 cp netbsd ${DESTDIR}/nnetbsd
271 mv ${DESTDIR}/nnetbsd ${DESTDIR}/netbsd
272 .endif
273 .endif
274
275 .if !target(tags)
276 tags:
277 @echo "see $S/kern/Makefile for tags"
278 .endif
279
280 EXTRA_CLEAN+= cscope.out
281 .if !target(cscope.out)
282 cscope.out: Makefile depend
283 @echo Building cscope.out source database
284 @echo ${SRCS} `sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' \
285 lib/kern/.depend lib/compat/.depend | tr ' ' '\n' | \
286 sed "s|^../../||" | sort -u` \
287 | ${CSCOPE} -k -i - -b `echo ${INCLUDES} | sed s/-nostdinc//`
288 # cscope doesn't write cscope.out if it's uptodate, so ensure
289 # make doesn't keep calling cscope when not needed.
290 @touch cscope.out
291 .endif
292
293 .if !target(cscope)
294 cscope: cscope.out
295 @${CSCOPE} -d
296 .endif
297
298 EXTRA_CLEAN+= ID
299 .if !target(mkid)
300 .PHONY: mkid
301 mkid: ID
302
303 ID: Makefile depend
304 @echo Building mkid database
305 @${MKID} `sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' lib/kern/.depend \
306 lib/compat/.depend | tr ' ' '\n' | sed "s|^../../||" | sort -u` \
307 `sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' .depend | tr ' ' '\n' \
308 | sort -u`
309
310 .endif
311
312 .include "${S}/gdbscripts/Makefile.inc"
313
314 EXTRA_CLEAN+= .gdbinit
315 .gdbinit: Makefile ${S}/gdbscripts/Makefile.inc
316 @echo building GDB initialization file
317 rm -f .gdbinit
318 .for __gdbinit in ${SYS_GDBINIT}
319 echo "source ${S}/gdbscripts/${__gdbinit}" >> .gdbinit
320 .endfor
321 .if defined(GDBINIT) && !empty(GDBINIT)
322 .for __gdbinit in ${GDBINIT}
323 echo "source ${__gdbinit}" >> .gdbinit
324 .endfor
325 .endif
326
327 ##
328 ## the end
329 ##
330