1 # $NetBSD: Makefile.kern.inc,v 1.94.2.4 2007/02/10 14:42:03 tron 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 HOST_SH?= sh
25 DBSYM?= dbsym
26 MKDEP?= mkdep
27 STRIP?= strip
28 OBJCOPY?= objcopy
29 OBJDUMP?= objdump
30 CSCOPE?= cscope
31 MKID?= mkid
32 UUDECODE?= ${TOOL_UUDECODE:Uuudecode}
33 HEXDUMP?= ${TOOL_HEXDUMP:Uhexdump}
34 GENASSYM?= ${TOOL_GENASSYM:Ugenassym}
35 .MAKEOVERRIDES+=USETOOLS # make sure proper value is propagated
36
37 _MKMSG?= @\#
38 _MKSHMSG?= echo
39 _MKSHECHO?= echo
40 _MKMSG_CREATE?= :
41 _MKTARGET_COMPILE?= :
42 _MKTARGET_CREATE?= :
43
44 ##
45 ## (1) port independent source tree identification
46 ##
47 # source tree is located via $S relative to the compilation directory
48 .ifndef S
49 S!= cd ../../../..; pwd
50 .endif
51
52 ##
53 ## (2) compile settings
54 ##
55 ## CPPFLAGS, CFLAGS, and AFLAGS must be set in the port's Makefile
56 ##
57 INCLUDES?= -I. ${EXTRA_INCLUDES} -I${S}/../common/include -I$S/arch \
58 -I$S -nostdinc
59 CPPFLAGS+= ${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -D_KERNEL_OPT
60 DEFCOPTS?= -O2
61 COPTS?= ${DEFCOPTS}
62 DBG= # might contain unwanted -Ofoo
63 DEFWARNINGS?= yes
64 .if (${DEFWARNINGS} == "yes")
65 . if !defined(NOGCCERROR)
66 CWARNFLAGS+= -Werror
67 . endif
68 CWARNFLAGS+= -Wall -Wno-main -Wno-format-zero-length -Wpointer-arith
69 CWARNFLAGS+= -Wmissing-prototypes -Wstrict-prototypes
70 CWARNFLAGS+= -Wswitch -Wshadow
71 CWARNFLAGS+= -Wcast-qual -Wwrite-strings
72 # Add -Wno-sign-compare. -Wsign-compare is included in -Wall as of GCC 3.3,
73 # but our sources aren't up for it yet.
74 CWARNFLAGS+= -Wno-sign-compare
75 . if ${HAVE_GCC} > 3
76 CWARNFLAGS+= -Wno-pointer-sign -Wno-attributes
77 . if ${MACHINE} == "i386" || ${MACHINE_ARCH} == "sparc64" || ${MACHINE} == "prep"
78 CWARNFLAGS+= -Wextra -Wno-unused-parameter
79 . endif
80 . endif
81 .endif
82
83 CFLAGS+= -ffreestanding -fno-zero-initialized-in-bss
84 CFLAGS+= ${CPUFLAGS} ${DEBUG} ${COPTS} ${CWARNFLAGS}
85 AFLAGS+= ${CPUFLAGS} -D_LOCORE -Wa,-fatal-warnings
86
87 # XXX
88 .if ${HAVE_GCC} > 3
89 CFLAGS+= -fno-strict-aliasing
90 .endif
91
92 .if ${USE_SSP:Uno} == "yes"
93 CFLAGS+=-fstack-protector -Wstack-protector --param ssp-buffer-size=1
94 LDFLAGS+=-fstack-protector -Wstack-protector --param ssp-buffer-size=1
95 .endif
96
97 # If we want the bpendtsleep: label in kern_synch.c, we need to use
98 # -fno-reorder-blocks. Don't make this a config(1) defflag without
99 # making sure this fragment remains valid.
100 .if ${HAVE_GCC} > 3 && !empty(${CFLAGS:M-DKERN_SYNCH_BPENDTSLEEP_LABEL})
101 CFLAGS.kern_synch.c+= -fno-reorder-blocks
102 .endif
103
104 # Use the per-source COPTS variables to add -g to just those
105 # files that match the shell patterns given in ${DEBUGLIST}
106 #
107 .for i in ${DEBUGLIST}
108 . for j in ${CFILES:T:M$i.c}
109 COPTS.${j}+=-g
110 . endfor
111 .endfor
112
113 # compile rules: rules are named ${TYPE}_${SUFFIX} where TYPE is NORMAL or
114 # NOPROF and SUFFIX is the file suffix, capitalized (e.g. C for a .c file).
115 NORMAL_C?= @${_MKSHMSG} "compile ${.CURDIR:T}/${.TARGET}"; \
116 ${_MKSHECHO}\
117 ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<; \
118 ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<
119 NOPROF_C?= @${_MKSHMSG} "compile ${.CURDIR:T}/${.TARGET}"; \
120 ${_MKSHECHO}\
121 ${CC} ${CFLAGS} ${CPPFLAGS} -c $<; \
122 ${CC} ${CFLAGS} ${CPPFLAGS} -c $<
123 NORMAL_S?= @${_MKSHMSG} "compile ${.CURDIR:T}/${.TARGET}"; \
124 ${_MKSHECHO}\
125 ${CC} ${AFLAGS} ${CPPFLAGS} -c $<; \
126 ${CC} ${AFLAGS} ${CPPFLAGS} -c $<
127
128 ##
129 ## (3) libkern and compat
130 ##
131 ## Set KERN_AS in the port Makefile to "obj" or "library". The
132 ## default is "library", as documented in $S/lib/libkern/Makefile.inc.
133 ##
134
135 ### find out what to use for libkern
136 .include "$S/lib/libkern/Makefile.inc"
137 .ifndef PROF
138 LIBKERN?= ${KERNLIB}
139 .else
140 LIBKERN?= ${KERNLIB_PROF}
141 .endif
142
143 LIBKERNLN?= ${KERNLIBLN}
144
145 ### find out what to use for libcompat
146 .include "$S/compat/common/Makefile.inc"
147 .ifndef PROF
148 SYSLIBCOMPAT?= ${COMPATLIB}
149 .else
150 SYSLIBCOMPAT?= ${COMPATLIB_PROF}
151 .endif
152
153 SYSLIBCOMPATLN?= ${COMPATLIBLN}
154
155 ##
156 ## (4) local objects, compile rules, and dependencies
157 ##
158 ## Each port should have a corresponding section with settings for
159 ## MD_CFILES, MD_SFILES, and MD_OBJS, along with build rules for same.
160 ##
161 MI_CFILES=devsw.c ioconf.c param.c
162 # the need for a MI_SFILES variable is dubitable at best
163 MI_OBJS=${MI_CFILES:S/.c/.o/}
164
165 param.c: $S/conf/param.c
166 ${_MKTARGET_CREATE}
167 rm -f param.c
168 cp $S/conf/param.c .
169
170 param.o: Makefile
171
172 .for _cfile in ${MI_CFILES}
173 ${_cfile:T:R}.o: ${_cfile}
174 ${NORMAL_C}
175 .endfor
176
177 ##
178 ## (5) link settings
179 ##
180 ## TEXTADDR (or LOADADDRESS), LINKFORMAT, and any EXTRA_LINKFLAGS must
181 ## be set in the port's Makefile. The port specific definitions for
182 ## LINKFLAGS_NORMAL and LINKFLAGS_DEBUG will added to the LINKFLAGS
183 ## depending on the value of DEBUG.
184 ##
185 # load lines for config "xxx" will be emitted as:
186 # xxx: ${SYSTEM_DEP} swapxxx.o
187 # ${SYSTEM_LD_HEAD}
188 # ${SYSTEM_LD} swapxxx.o
189 # ${SYSTEM_LD_TAIL}
190 SYSTEM_OBJ?= ${MD_OBJS} ${MI_OBJS} ${OBJS} ${SYSLIBCOMPAT} ${LIBKERN}
191 SYSTEM_DEP?= Makefile ${SYSTEM_OBJ:O} .gdbinit
192 SYSTEM_LD_HEAD?=@rm -f $@
193 SYSTEM_LD?= @${_MKSHMSG} " link ${.CURDIR:T}/${.TARGET}"; \
194 ${_MKSHECHO}\
195 ${LD} -Map $@.map --cref ${LINKFLAGS} -o $@ '$${SYSTEM_OBJ}' '$${EXTRA_OBJ}' vers.o; \
196 ${LD} -Map $@.map --cref ${LINKFLAGS} -o $@ ${SYSTEM_OBJ} ${EXTRA_OBJ} vers.o
197 SYSTEM_LD_TAIL?=@${SIZE} $@; chmod 755 $@
198
199 TEXTADDR?= ${LOADADDRESS} # backwards compatibility
200 LINKTEXT?= ${TEXTADDR:C/.+/-Ttext &/}
201 LINKDATA?= ${DATAADDR:C/.+/-Tdata &/}
202 ENTRYPOINT?= start
203 LINKENTRY?= ${ENTRYPOINT:C/.+/-e &/}
204 LINKFLAGS?= ${LINKFORMAT} ${LINKTEXT} ${LINKDATA} ${LINKENTRY} \
205 ${EXTRA_LINKFLAGS}
206
207 LINKFLAGS_DEBUG?= -X
208 SYSTEM_LD_TAIL_DEBUG?=; \
209 echo mv -f $@ $@.gdb; mv -f $@ $@.gdb; \
210 echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \
211 ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb
212 LINKFLAGS_NORMAL?= -S
213 STRIPFLAGS?= -g
214
215 DEBUG?=
216 .if !empty(DEBUG:M-g*)
217 SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_DEBUG}
218 LINKFLAGS+= ${LINKFLAGS_DEBUG}
219 EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.gdb@}
220 .elifndef PROF
221 LINKFLAGS+= ${LINKFLAGS_NORMAL}
222 .endif
223
224 SYSTEM_LD_TAIL+=; \
225 if grep -q '^\#define.*SYMTAB_SPACE' opt_ddbparam.h; then \
226 echo "${DBSYM} $@"; \
227 ${DBSYM} $@; \
228 fi
229
230 SYSTEM_LD_HEAD+=${SYSTEM_LD_HEAD_EXTRA}
231 SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_EXTRA}
232
233 ##
234 ## (6) port independent targets and dependencies: assym.h, vers.o
235 ##
236 .if !target(assym.h)
237 assym.h: ${GENASSYM_CONF} ${GENASSYM_EXTRAS}
238 ${_MKTARGET_CREATE}
239 cat ${GENASSYM_CONF} ${GENASSYM_EXTRAS} | \
240 ${GENASSYM} -- ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} \
241 > assym.h.tmp && \
242 mv -f assym.h.tmp assym.h
243 ${MD_SFILES:C/\.[Ss]/.o/} ${SFILES:C/\.[Ss]/.o/}: assym.h
244 .endif
245
246 .if !target(vers.o)
247 newvers: vers.o
248 vers.o: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP} $S/conf/newvers.sh $S/conf/osrelease.sh
249 ${_MKMSG_CREATE} vers.c
250 ${HOST_SH} $S/conf/newvers.sh
251 ${_MKTARGET_COMPILE}
252 ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
253 .endif
254
255 .if !target(config_time.h)
256 EXTRA_CLEAN+= config_time.h
257 config_time.h: Makefile
258 ${_MKTARGET_CREATE}
259 cp config_time.src config_time.h
260 .endif
261
262 .if defined(MEMORY_DISK_IMAGE)
263 md_root_image.h: ${MEMORY_DISK_IMAGE}
264 ${_MKTARGET_CREATE}
265 ${TOOL_HEXDUMP} -v -e '"\t" 8/1 "0x%02x, " "\n"' ${.ALLSRC} > ${.TARGET}
266
267 # XXX This is only needed when building md_root.o
268 CPPFLAGS+= -DMEMORY_DISK_IMAGE
269 md_root.o: md_root_image.h
270 .endif
271
272 # depend on MEMORY_DISK_IMAGE configuration
273 md_root.o: Makefile
274
275 # depend on root or device configuration
276 autoconf.o conf.o: Makefile
277
278 # depend on network or filesystem configuration
279 uipc_proto.o vfs_conf.o: Makefile
280
281 # depend on maxusers and CPU configuration
282 assym.h machdep.o: Makefile
283
284 ##
285 ## (7) misc targets: install, clean(dir), depend(all), lint, links, tags,
286 ## cscope, mkid
287 ##
288 ## Any ports that have other stuff to be cleaned up should fill in
289 ## EXTRA_CLEAN. Some ports may want different settings for
290 ## KERNLINTFLAGS, MKDEP_CFLAGS, or MKDEP_AFLAGS.
291 ##
292 .if !target(__CLEANKERNEL)
293 __CLEANKERNEL: .USE
294 ${_MKMSG} "${.TARGET}ing the kernel objects"
295 rm -f ${KERNELS} eddep tags *.[io] *.ln [a-z]*.s vers.c \
296 [Ee]rrs linterrs makelinks assym.h.tmp assym.h \
297 ${EXTRA_KERNELS} ${EXTRA_CLEAN}
298 .endif
299
300 .if !target(kernelnames)
301 kernelnames:
302 @echo "${KERNELS} ${EXTRA_KERNELS}"
303 .endif
304
305 .if !target(__CLEANDEPEND)
306 __CLEANDEPEND: .USE
307 echo .depend ${DEPS} | xargs rm -f --
308 .endif
309
310 # do not !target these, the kern and compat Makefiles augment them
311 cleandir distclean: __CLEANKERNEL __CLEANDEPEND
312 clean: __CLEANKERNEL
313 depend: .depend
314 dependall: depend .WAIT all
315
316 .if !target(.depend)
317 MKDEP_AFLAGS?= ${AFLAGS}
318 MKDEP_CFLAGS?= ${CFLAGS}
319 SSRCS=${MD_SFILES} ${SFILES}
320 CSRCS=${MD_CFILES} ${MI_CFILES} ${CFILES}
321 SRCS=${SSRCS} ${CSRCS}
322 DEPS= ${SRCS:T:O:u:R:S/$/.d/g}
323
324 .for _s in ${SSRCS}
325 ${_s:T:R}.d: ${_s} assym.h config_time.h
326 ${_MKTARGET_CREATE}
327 ${MKDEP} -f ${.TARGET} -- ${MKDEP_AFLAGS} \
328 ${CPPFLAGS} ${CPPFLAGS.${_s:T}} ${_s}
329 .endfor
330 .for _s in ${CSRCS}
331 ${_s:T:R}.d: ${_s} config_time.h
332 ${_MKTARGET_CREATE}
333 ${MKDEP} -f ${.TARGET} -- ${MKDEP_CFLAGS} \
334 ${CPPFLAGS} ${CPPFLAGS.${_s:T}} ${_s}
335 .endfor
336
337 assym.d: assym.h config_time.h
338 ${_MKTARGET_CREATE}
339 cat ${GENASSYM_CONF} ${GENASSYM_EXTRAS} | \
340 ${GENASSYM} -- ${MKDEP} -f assym.dep -- \
341 ${CFLAGS} ${CPPFLAGS}
342 sed -e 's/.*\.o:.*\.c/assym.h:/' < assym.dep >${.TARGET}
343 rm -f assym.dep
344
345 .depend: ${DEPS} assym.d
346 ${_MKTARGET_CREATE}
347 echo "${.ALLSRC}" | ${MKDEP} -D
348 .endif
349
350 .if !target(lint)
351 ALLSFILES?= ${MD_SFILES} ${SFILES}
352 LINTSTUBS?= ${ALLSFILES:T:R:C/^.*$/LintStub_&.c/g}
353 KERNLINTFLAGS?= -bcehnxzFS
354 NORMAL_LN?= ${LINT} ${KERNLINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i $<
355
356 _lsrc=${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES}
357 LOBJS?= ${_lsrc:T:S/.c$/.ln/g} ${LIBKERNLN} ${SYSLIBCOMPATLN}
358
359 .for _sfile in ${ALLSFILES}
360 LintStub_${_sfile:T:R}.c: ${_sfile} assym.h
361 ${_MKTARGET_COMPILE}
362 ${CC} -E -C ${AFLAGS} ${CPPFLAGS} ${_sfile} | \
363 awk -f $S/kern/genlintstub.awk >${.TARGET}
364 .endfor
365
366 .for _cfile in ${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES}
367 ${_cfile:T:R}.ln: ${_cfile}
368 ${_MKTARGET_COMPILE}
369 ${NORMAL_LN}
370 .endfor
371
372 lint: ${LOBJS}
373 ${LINT} ${KERNLINTFLAGS} ${CPPFLAGS:M-[IDU]*} ${LOBJS}
374 .endif
375
376 .if !target(install)
377 # The install target can be redefined by putting a
378 # install-kernel-${MACHINE_NAME} target into /etc/mk.conf
379 MACHINE_NAME!= uname -n
380 install: install-kernel-${MACHINE_NAME}
381 .if !target(install-kernel-${MACHINE_NAME})
382 install-kernel-${MACHINE_NAME}:
383 rm -f ${DESTDIR}/onetbsd
384 ln ${DESTDIR}/netbsd ${DESTDIR}/onetbsd
385 cp netbsd ${DESTDIR}/nnetbsd
386 mv ${DESTDIR}/nnetbsd ${DESTDIR}/netbsd
387 .endif
388 .endif
389
390 .if !target(tags)
391 tags:
392 @echo "see $S/kern/Makefile for tags"
393 .endif
394
395 EXTRA_CLEAN+= cscope.out cscope.tmp
396 .if !target(cscope.out)
397 cscope.out: Makefile depend
398 ${_MKTARGET_CREATE}
399 @sed 's/[^:]*://;s/^ *//;s/ *\\ *$$//;' lib/kern/.depend | \
400 tr -s ' ' '\n' | sed 's|^\([^.\\]\)|lib/kern/\1|;s|^../../||;' > \
401 cscope.tmp
402 @sed 's/[^:]*://;s/^ *//;s/ *\\ *$$//;' lib/compat/.depend | \
403 tr -s ' ' '\n' | sed 's|^\([^.\\]\)|lib/compat/\1|;s|^../../||;' >> \
404 cscope.tmp
405 @echo ${SRCS} | cat - cscope.tmp | tr -s ' ' '\n' | sort -u | \
406 ${CSCOPE} -k -i - -b `echo ${INCLUDES} | sed s/-nostdinc//`
407 # cscope doesn't write cscope.out if it's uptodate, so ensure
408 # make doesn't keep calling cscope when not needed.
409 @rm -f cscope.tmp; touch cscope.out
410 .endif
411
412 .if !target(cscope)
413 cscope: cscope.out
414 @${CSCOPE} -d
415 .endif
416
417 EXTRA_CLEAN+= ID
418 .if !target(mkid)
419 .PHONY: mkid
420 mkid: ID
421
422 ID: Makefile depend
423 ${_MKTARGET_CREATE}
424 @${MKID} `sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' lib/kern/.depend \
425 lib/compat/.depend | tr ' ' '\n' | sed "s|^../../||" | sort -u` \
426 `sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' .depend | tr ' ' '\n' \
427 | sort -u`
428
429 .endif
430
431 .include "${S}/gdbscripts/Makefile.inc"
432
433 EXTRA_CLEAN+= .gdbinit
434 .gdbinit: Makefile ${S}/gdbscripts/Makefile.inc
435 ${_MKTARGET_CREATE}
436 rm -f .gdbinit
437 .for __gdbinit in ${SYS_GDBINIT}
438 echo "source ${S}/gdbscripts/${__gdbinit}" >> .gdbinit
439 .endfor
440 .if defined(GDBINIT) && !empty(GDBINIT)
441 .for __gdbinit in ${GDBINIT}
442 echo "source ${__gdbinit}" >> .gdbinit
443 .endfor
444 .endif
445
446 # The following files use alloca(3) or variable array allocations.
447 # Their full name is noted as documentation.
448 VARSTACK=dev/cgd.c kern/uipc_socket.c miscfs/genfs/genfs_vnops.c \
449 nfs/nfs_bio.c ufs/ufs/ufs_inode.c ufs/ufs/ufs_lookup.c uvm/uvm_bio.c \
450 uvm/uvm_pager.c dev/ic/aic7xxx.c dev/ic/aic79xx.c arch/xen/i386/gdt.c
451
452 .for __varstack in ${VARSTACK}
453 COPTS.${__varstack:T} += -Wno-stack-protector
454 .endfor
455
456 AFLAGS+= ${AOPTS.${.IMPSRC:T}}
457 CFLAGS+= ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}}
458 CPPFLAGS+= ${CPPFLAGS.${.IMPSRC:T}}
459 CWARNFLAGS+= ${CWARNFLAGS.${.IMPSRC:T}}
460
461 ##
462 ## the end
463 ##
Cache object: 0bc5a997caee6a7bf2b60ac62c79ce70
|