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