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