Makefile.kern.inc revision 1.11 1 # $NetBSD: Makefile.kern.inc,v 1.11 2002/02/11 03:43:53 mrg 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 MKDEP?= mkdep
26 STRIP?= strip
27 OBJCOPY?= objcopy
28 OBJDUMP?= objdump
29
30 ##
31 ## (1) port independent source tree identification
32 ##
33 # source tree is located via $S relative to the compilation directory
34 .ifndef S
35 S!= cd ../../../..; pwd
36 .endif
37
38 ##
39 ## (2) compile settings
40 ##
41 ## CPPFLAGS, CFLAGS, and AFLAGS must be set in the port's Makefile
42 ##
43 INCLUDES?= -I. ${EXTRA_INCLUDES} -I$S/arch -I$S -nostdinc
44 CPPFLAGS+= ${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -D_KERNEL_OPT
45 DEFCOPTS?= -O2
46 COPTS?= ${DEFCOPTS}
47 DBG= # might contain unwanted -Ofoo
48 DEFWARNINGS?= yes
49 .if (${DEFWARNINGS} == "yes")
50 CWARNFLAGS+= -Werror -Wall -Wno-main
51 WEAK_POINTERS?= no
52 .if !(${WEAK_POINTERS} == "yes")
53 CWARNFLAGS+= -Wpointer-arith
54 .endif
55 LOOSE_PROTOTYPES?= no
56 .if !(${LOOSE_PROTOTYPES} == "yes")
57 CWARNFLAGS+= -Wmissing-prototypes -Wstrict-prototypes
58 .endif
59 # XXX Delete -Wuninitialized for now, since the compiler doesn't
60 # XXX always get it right. --thorpej
61 CWARNFLAGS+= -Wno-uninitialized
62 .endif
63 CFLAGS+= -ffreestanding ${DEBUG} ${COPTS} ${CWARNFLAGS}
64 AFLAGS+= -D_LOCORE
65
66 # Define a set of xxx_G variables that will add -g to just those
67 # files that match the shell patterns given in ${DEBUGLIST}
68 #
69 .for i in ${DEBUGLIST}
70 .for j in ${CFILES:T:M$i.c}
71 ${j:R}_G?= -g
72 .endfor
73 .endfor
74
75 # compile rules: rules are named ${TYPE}_${SUFFIX} where TYPE is NORMAL or
76 # NOPROF and SUFFIX is the file suffix, capitalized (e.g. C for a .c file).
77 NORMAL_C?= ${CC} ${CFLAGS} ${CPPFLAGS} ${${<:T:R}_G} ${PROF} -c $<
78 NOPROF_C?= ${CC} ${CFLAGS} ${CPPFLAGS} ${${<:T:R}_G} -c $<
79 NORMAL_S?= ${CC} ${AFLAGS} ${CPPFLAGS} -c $<
80
81 ##
82 ## (3) libkern and compat
83 ##
84 ## Set KERN_AS in the port Makefile to "obj" or "library". The
85 ## default is "library", as documented in $S/lib/libkern/Makefile.inc.
86 ##
87
88 ### find out what to use for libkern
89 .include "$S/lib/libkern/Makefile.inc"
90 .ifndef PROF
91 LIBKERN?= ${KERNLIB}
92 .else
93 LIBKERN?= ${KERNLIB_PROF}
94 .endif
95
96 ### find out what to use for libcompat
97 .include "$S/compat/common/Makefile.inc"
98 .ifndef PROF
99 LIBCOMPAT?= ${COMPATLIB}
100 .else
101 LIBCOMPAT?= ${COMPATLIB_PROF}
102 .endif
103
104 ##
105 ## (4) local objects, compile rules, and dependencies
106 ##
107 ## Each port should have a corresponding section with settings for
108 ## MD_CFILES, MD_SFILES, and MD_OBJS, along with build rules for same.
109 ##
110 MI_CFILES=ioconf.c param.c
111 # the need for a MI_SFILES variable is dubitable at best
112 MI_OBJS=${MI_CFILES:S/.c/.o/}
113
114 param.c: $S/conf/param.c
115 rm -f param.c
116 cp $S/conf/param.c .
117
118 param.o: Makefile
119
120 .for _cfile in ${MI_CFILES}
121 ${_cfile:T:R}.o: ${_cfile}
122 ${NORMAL_C}
123 .endfor
124
125 ##
126 ## (5) link settings
127 ##
128 ## TEXTADDR (or LOADADDRESS), LINKFORMAT, and any EXTRA_LINKFLAGS must
129 ## be set in the port's Makefile. The port specific definitions for
130 ## LINKFLAGS_NORMAL and LINKFLAGS_DEBUG will added to the LINKFLAGS
131 ## depending on the value of DEBUG.
132 ##
133 # load lines for config "xxx" will be emitted as:
134 # xxx: ${SYSTEM_DEP} swapxxx.o
135 # ${SYSTEM_LD_HEAD}
136 # ${SYSTEM_LD} swapxxx.o
137 # ${SYSTEM_LD_TAIL}
138 SYSTEM_OBJ?= ${MD_OBJS} ${MI_OBJS} ${OBJS} ${LIBCOMPAT} ${LIBKERN}
139 SYSTEM_DEP?= Makefile ${SYSTEM_OBJ}
140 SYSTEM_LD_HEAD?= @rm -f $@
141 SYSTEM_LD?= @echo ${LD} ${LINKFLAGS} -o $@ '$${SYSTEM_OBJ}' vers.o; \
142 ${LD} ${LINKFLAGS} -o $@ ${SYSTEM_OBJ} vers.o
143 SYSTEM_LD_TAIL?= @${SIZE} $@; chmod 755 $@
144
145 TEXTADDR?= ${LOADADDRESS} # backwards compatibility
146 LINKTEXT?= ${TEXTADDR:C/.+/-Ttext &/}
147 LINKDATA?= ${DATAADDR:C/.+/-Tdata &/}
148 ENTRYPOINT?= start
149 LINKENTRY?= ${ENTRYPOINT:C/.+/-e &/}
150 LINKFLAGS?= ${LINKFORMAT} ${LINKTEXT} ${LINKDATA} ${LINKENTRY} \
151 ${EXTRA_LINKFLAGS}
152
153 LINKFLAGS_DEBUG?= -X
154 SYSTEM_LD_TAIL_DEBUG?=; \
155 echo mv -f $@ $@.gdb; mv -f $@ $@.gdb; \
156 echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \
157 ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb
158 LINKFLAGS_NORMAL?= -S
159 STRIPFLAGS?= -g
160
161 DEBUG?=
162 .if ${DEBUG} == "-g"
163 SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_DEBUG}
164 LINKFLAGS+= ${LINKFLAGS_DEBUG}
165 EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.gdb@}
166 .elifndef PROF
167 LINKFLAGS+= ${LINKFLAGS_NORMAL}
168 .endif
169
170 SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_EXTRA}
171
172 ##
173 ## (6) port independent targets and dependencies: assym.h, vers.o
174 ##
175 .if !target(assym.h)
176 assym.h: $S/kern/genassym.sh ${GENASSYM} ${GENASSYM_EXTRAS}
177 cat ${GENASSYM} ${GENASSYM_EXTRAS} | \
178 sh $S/kern/genassym.sh ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} \
179 > assym.h.tmp && \
180 mv -f assym.h.tmp assym.h
181 ${MD_SFILES:C/\.[Ss]/.o/} ${SFILES:C/\.[Ss]/.o/}: assym.h
182 .endif
183
184 .if !target(vers.o)
185 newvers: vers.o
186 vers.o: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP}
187 sh $S/conf/newvers.sh
188 ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
189 .endif
190
191 # depend on root or device configuration
192 autoconf.o conf.o: Makefile
193
194 # depend on network or filesystem configuration
195 uipc_proto.o vfs_conf.o: Makefile
196
197 # depend on maxusers and CPU configuration
198 assym.h machdep.o: Makefile
199
200 ##
201 ## (7) misc targets: install, clean(dir), depend(all), lint, links, tags
202 ##
203 ## Any ports that have other stuff to be cleaned up should fill in
204 ## EXTRA_CLEAN. Some ports may want different settings for
205 ## KERNLINTFLAGS, MKDEP_CFLAGS, or MKDEP_AFLAGS.
206 ##
207 .if !target(__CLEANKERNEL)
208 __CLEANKERNEL: .USE
209 @echo "${.TARGET}ing the kernel objects"
210 rm -f ${KERNELS} eddep tags *.[io] [a-z]*.s vers.c \
211 [Ee]rrs linterrs makelinks assym.h.tmp assym.h \
212 ${EXTRA_KERNELS} ${EXTRA_CLEAN}
213 .endif
214
215 .if !target(kernelnames)
216 kernelnames:
217 @echo "${KERNELS} ${EXTRA_KERNELS}"
218 .endif
219
220 .if !target(__CLEANDEPEND)
221 __CLEANDEPEND: .USE
222 rm -f .depend
223 .endif
224
225 # do not !target these, the kern and compat Makefiles augment them
226 cleandir distclean: __CLEANKERNEL __CLEANDEPEND
227 clean: __CLEANKERNEL
228 depend: .depend
229
230 .if !target(.depend)
231 SRCS?= ${MD_SFILES} ${MD_CFILES} ${MI_CFILES} ${CFILES} ${SFILES}
232 MKDEP_AFLAGS?= ${AFLAGS}
233 MKDEP_CFLAGS?= ${CFLAGS}
234 .depend: ${SRCS} assym.h
235 ${MKDEP} ${MKDEP_AFLAGS} ${CPPFLAGS} ${MD_SFILES} ${SFILES}
236 ${MKDEP} -a ${MKDEP_CFLAGS} ${CPPFLAGS} ${MD_CFILES} ${MI_CFILES} \
237 ${CFILES}
238 cat ${GENASSYM} ${GENASSYM_EXTRAS} | \
239 sh $S/kern/genassym.sh ${MKDEP} -f assym.dep ${CFLAGS} ${CPPFLAGS}
240 @sed -e 's/.*\.o:.*\.c/assym.h:/' < assym.dep >> .depend
241 @rm -f assym.dep
242 .endif
243
244 .if !target(dependall)
245 dependall: depend all
246 .endif
247
248 .if !target(lint)
249 ALLSFILES?= ${MD_SFILES} ${SFILES}
250 LINTSTUBS?= ${ALLSFILES:T:R:C/^.*$/LintStub_&.c/g}
251 KERNLINTFLAGS?= -hbxncez -Dvolatile=
252 .for _sfile in ${ALLSFILES}
253 LintStub_${_sfile:T:R}.c: ${_sfile} assym.h
254 ${CC} -E -C ${AFLAGS} ${CPPFLAGS} ${_sfile} | \
255 awk -f $S/kern/genlintstub.awk >${.TARGET}
256 .endfor
257 lint: ${CFILES} ${KERNLINTSTUBS} ${MI_CFILES} ${MD_CFILES}
258 @${LINT} ${KERNLINTFLAGS} ${CPPFLAGS} -UKGDB \
259 ${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES} | \
260 grep -v 'static function .* unused'
261 .endif
262
263 .if !target(install)
264 # The install target can be redefined by putting a
265 # install-kernel-${MACHINE_NAME} target into /etc/mk.conf
266 MACHINE_NAME!= uname -n
267 install: install-kernel-${MACHINE_NAME}
268 .if !target(install-kernel-${MACHINE_NAME}})
269 install-kernel-${MACHINE_NAME}:
270 rm -f ${DESTDIR}/onetbsd
271 ln ${DESTDIR}/netbsd ${DESTDIR}/onetbsd
272 cp netbsd ${DESTDIR}/nnetbsd
273 mv ${DESTDIR}/nnetbsd ${DESTDIR}/netbsd
274 .endif
275 .endif
276
277 .if !target(tags)
278 tags:
279 @echo "see $S/kern/Makefile for tags"
280 .endif
281
282 ##
283 ## the end
284 ##
285