xref: /netbsd/sys/conf/Makefile.kern.inc (revision c4a72b64)
1#	$NetBSD: Makefile.kern.inc,v 1.30 2002/11/25 01:37:11 thorpej 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##
25DBSYM?=		dbsym
26MKDEP?=		mkdep
27STRIP?=		strip
28OBJCOPY?=	objcopy
29OBJDUMP?=	objdump
30CSCOPE?=	cscope
31MKID?=		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
39S!=	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##
47INCLUDES?=	-I. ${EXTRA_INCLUDES} -I$S/arch -I$S -nostdinc
48CPPFLAGS+=	${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -D_KERNEL_OPT
49DEFCOPTS?=	-O2
50COPTS?=		${DEFCOPTS}
51DBG=		# might contain unwanted -Ofoo
52DEFWARNINGS?=	yes
53.if (${DEFWARNINGS} == "yes")
54CWARNFLAGS+=	-Werror -Wall -Wno-main -Wno-format-zero-length -Wpointer-arith
55CWARNFLAGS+=	-Wmissing-prototypes -Wstrict-prototypes
56# Add -Wno-sign-compare.  -Wsign-compare is included in -Wall as of GCC 3.3,
57# but our sources aren't up for it yet.
58CWARNFLAGS+=	-Wno-sign-compare
59# XXX Delete -Wuninitialized for now, since the compiler doesn't
60# XXX always get it right.  --thorpej
61CWARNFLAGS+=	-Wno-uninitialized
62.endif
63CFLAGS+=	-ffreestanding ${DEBUG} ${COPTS} ${CWARNFLAGS}
64AFLAGS+=	-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).
77NORMAL_C?=	${CC} ${CFLAGS} ${CPPFLAGS} ${${<:T:R}_G} ${PROF} -c $<
78NOPROF_C?=	${CC} ${CFLAGS} ${CPPFLAGS} ${${<:T:R}_G} -c $<
79NORMAL_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
91LIBKERN?=	${KERNLIB}
92.else
93LIBKERN?=	${KERNLIB_PROF}
94.endif
95
96LIBKERNLN?=	${KERNLIBLN}
97
98### find out what to use for libcompat
99.include "$S/compat/common/Makefile.inc"
100.ifndef PROF
101LIBCOMPAT?=	${COMPATLIB}
102.else
103LIBCOMPAT?=	${COMPATLIB_PROF}
104.endif
105
106LIBCOMPATLN?=	${COMPATLIBLN}
107
108##
109## (4) local objects, compile rules, and dependencies
110##
111## Each port should have a corresponding section with settings for
112## MD_CFILES, MD_SFILES, and MD_OBJS, along with build rules for same.
113##
114MI_CFILES=devsw.c ioconf.c param.c
115# the need for a MI_SFILES variable is dubitable at best
116MI_OBJS=${MI_CFILES:S/.c/.o/}
117
118param.c: $S/conf/param.c
119	rm -f param.c
120	cp $S/conf/param.c .
121
122param.o: Makefile
123
124.for _cfile in ${MI_CFILES}
125${_cfile:T:R}.o: ${_cfile}
126	${NORMAL_C}
127.endfor
128
129##
130## (5) link settings
131##
132## TEXTADDR (or LOADADDRESS), LINKFORMAT, and any EXTRA_LINKFLAGS must
133## be set in the port's Makefile.  The port specific definitions for
134## LINKFLAGS_NORMAL and LINKFLAGS_DEBUG will added to the LINKFLAGS
135## depending on the value of DEBUG.
136##
137# load lines for config "xxx" will be emitted as:
138# xxx: ${SYSTEM_DEP} swapxxx.o
139#	${SYSTEM_LD_HEAD}
140#	${SYSTEM_LD} swapxxx.o
141#	${SYSTEM_LD_TAIL}
142SYSTEM_OBJ?=	${MD_OBJS} ${MI_OBJS} ${OBJS} ${LIBCOMPAT} ${LIBKERN}
143SYSTEM_DEP?=	Makefile ${SYSTEM_OBJ} .gdbinit
144SYSTEM_LD_HEAD?=	@rm -f $@
145SYSTEM_LD?=	@echo ${LD} ${LINKFLAGS} -o $@ '$${SYSTEM_OBJ}' vers.o; \
146		${LD} ${LINKFLAGS} -o $@ ${SYSTEM_OBJ} vers.o
147SYSTEM_LD_TAIL?=	@${SIZE} $@; chmod 755 $@
148
149TEXTADDR?=	${LOADADDRESS}			# backwards compatibility
150LINKTEXT?=	${TEXTADDR:C/.+/-Ttext &/}
151LINKDATA?=	${DATAADDR:C/.+/-Tdata &/}
152ENTRYPOINT?=	start
153LINKENTRY?=	${ENTRYPOINT:C/.+/-e &/}
154LINKFLAGS?=	${LINKFORMAT} ${LINKTEXT} ${LINKDATA} ${LINKENTRY} \
155		${EXTRA_LINKFLAGS}
156
157LINKFLAGS_DEBUG?=	-X
158SYSTEM_LD_TAIL_DEBUG?=; \
159		echo mv -f $@ $@.gdb; mv -f $@ $@.gdb; \
160		echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \
161		${STRIP} ${STRIPFLAGS} -o $@ $@.gdb
162LINKFLAGS_NORMAL?=	-S
163STRIPFLAGS?=	-g
164
165DEBUG?=
166.if ${DEBUG} == "-g"
167SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_DEBUG}
168LINKFLAGS+=	${LINKFLAGS_DEBUG}
169EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.gdb@}
170.elifndef PROF
171LINKFLAGS+=	${LINKFLAGS_NORMAL}
172.endif
173
174SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_EXTRA}
175
176##
177## (6) port independent targets and dependencies: assym.h, vers.o
178##
179.if !target(assym.h)
180assym.h: $S/kern/genassym.sh ${GENASSYM} ${GENASSYM_EXTRAS}
181	cat ${GENASSYM} ${GENASSYM_EXTRAS} | \
182	    sh $S/kern/genassym.sh ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} \
183	    > assym.h.tmp && \
184	mv -f assym.h.tmp assym.h
185${MD_SFILES:C/\.[Ss]/.o/} ${SFILES:C/\.[Ss]/.o/}: assym.h
186.endif
187
188.if !target(vers.o)
189newvers: vers.o
190vers.o: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP} $S/conf/newvers.sh $S/conf/osrelease.sh
191	sh $S/conf/newvers.sh
192	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
193.endif
194
195.if !target(config_time.h)
196EXTRA_CLEAN+= config_time.h
197config_time.h: Makefile
198	cp config_time.src config_time.h
199.endif
200
201# depend on root or device configuration
202autoconf.o conf.o: Makefile
203
204# depend on network or filesystem configuration
205uipc_proto.o vfs_conf.o: Makefile
206
207# depend on maxusers and CPU configuration
208assym.h machdep.o: Makefile
209
210##
211## (7) misc targets: install, clean(dir), depend(all), lint, links, tags,
212##                   cscope, mkid
213##
214## Any ports that have other stuff to be cleaned up should fill in
215## EXTRA_CLEAN.  Some ports may want different settings for
216## KERNLINTFLAGS, MKDEP_CFLAGS, or MKDEP_AFLAGS.
217##
218.if !target(__CLEANKERNEL)
219__CLEANKERNEL: .USE
220	@echo "${.TARGET}ing the kernel objects"
221	rm -f ${KERNELS} eddep tags *.[io] *.ln [a-z]*.s vers.c \
222	    [Ee]rrs linterrs makelinks assym.h.tmp assym.h \
223	    ${EXTRA_KERNELS} ${EXTRA_CLEAN}
224.endif
225
226.if !target(kernelnames)
227kernelnames:
228	@echo "${KERNELS} ${EXTRA_KERNELS}"
229.endif
230
231.if !target(__CLEANDEPEND)
232__CLEANDEPEND: .USE
233	rm -f .depend
234.endif
235
236# do not !target these, the kern and compat Makefiles augment them
237cleandir distclean: __CLEANKERNEL __CLEANDEPEND
238clean: __CLEANKERNEL
239depend: .depend
240
241.if !target(.depend)
242SRCS?=		${MD_SFILES} ${MD_CFILES} ${MI_CFILES} ${CFILES} ${SFILES}
243MKDEP_AFLAGS?=	${AFLAGS}
244MKDEP_CFLAGS?=	${CFLAGS}
245.depend: ${SRCS} assym.h
246	${MKDEP} ${MKDEP_AFLAGS} ${CPPFLAGS} ${MD_SFILES} ${SFILES}
247	${MKDEP} -a ${MKDEP_CFLAGS} ${CPPFLAGS} ${MD_CFILES} ${MI_CFILES} \
248	    ${CFILES}
249	cat ${GENASSYM} ${GENASSYM_EXTRAS} | \
250	    sh $S/kern/genassym.sh ${MKDEP} -f assym.dep ${CFLAGS} ${CPPFLAGS}
251	@sed -e 's/.*\.o:.*\.c/assym.h:/' < assym.dep >> .depend
252	@rm -f assym.dep
253.endif
254
255.if !target(dependall)
256dependall: depend all
257.endif
258
259.if !target(lint)
260ALLSFILES?=	${MD_SFILES} ${SFILES}
261LINTSTUBS?=	${ALLSFILES:T:R:C/^.*$/LintStub_&.c/g}
262KERNLINTFLAGS?=	-bcehnxzFS
263NORMAL_LN?=	${LINT} ${KERNLINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i $<
264
265_lsrc=${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES}
266LOBJS?= ${_lsrc:T:S/.c$/.ln/g} ${LIBKERNLN} ${LIBCOMPATLN}
267
268.for _sfile in ${ALLSFILES}
269LintStub_${_sfile:T:R}.c: ${_sfile} assym.h
270	${CC} -E -C ${AFLAGS} ${CPPFLAGS} ${_sfile} | \
271	      awk -f $S/kern/genlintstub.awk >${.TARGET}
272.endfor
273
274.for _cfile in ${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES}
275${_cfile:T:R}.ln: ${_cfile}
276	${NORMAL_LN}
277.endfor
278
279lint: ${LOBJS}
280	${LINT} ${KERNLINTFLAGS} ${CPPFLAGS:M-[IDU]*} ${LOBJS}
281.endif
282
283.if !target(install)
284# The install target can be redefined by putting a
285# install-kernel-${MACHINE_NAME} target into /etc/mk.conf
286MACHINE_NAME!=  uname -n
287install: install-kernel-${MACHINE_NAME}
288.if !target(install-kernel-${MACHINE_NAME})
289install-kernel-${MACHINE_NAME}:
290	rm -f ${DESTDIR}/onetbsd
291	ln ${DESTDIR}/netbsd ${DESTDIR}/onetbsd
292	cp netbsd ${DESTDIR}/nnetbsd
293	mv ${DESTDIR}/nnetbsd ${DESTDIR}/netbsd
294.endif
295.endif
296
297.if !target(tags)
298tags:
299	@echo "see $S/kern/Makefile for tags"
300.endif
301
302EXTRA_CLEAN+= cscope.out
303.if !target(cscope.out)
304cscope.out: Makefile depend
305	@echo Building cscope.out source database
306	@echo ${SRCS} `sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' \
307	lib/kern/.depend lib/compat/.depend | tr ' ' '\n' | \
308	sed "s|^../../||" | sort -u` \
309	| ${CSCOPE} -k -i - -b `echo ${INCLUDES} | sed s/-nostdinc//`
310#	cscope doesn't write cscope.out if it's uptodate, so ensure
311#	make doesn't keep calling cscope when not needed.
312	@touch cscope.out
313.endif
314
315.if !target(cscope)
316cscope: cscope.out
317	@${CSCOPE} -d
318.endif
319
320EXTRA_CLEAN+= ID
321.if !target(mkid)
322.PHONY: mkid
323mkid: ID
324
325ID: Makefile depend
326	@echo Building mkid database
327	@${MKID} `sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' lib/kern/.depend \
328	lib/compat/.depend | tr ' ' '\n' | sed "s|^../../||" | sort -u` \
329	`sed 's/[^:]*://;s/^ *//;s/ *\\\\ *$$//;' .depend | tr ' ' '\n' \
330	| sort -u`
331
332.endif
333
334.include "${S}/gdbscripts/Makefile.inc"
335
336EXTRA_CLEAN+= .gdbinit
337.gdbinit: Makefile ${S}/gdbscripts/Makefile.inc
338	@echo building GDB initialization file
339	rm -f .gdbinit
340.for __gdbinit in ${SYS_GDBINIT}
341	echo "source ${S}/gdbscripts/${__gdbinit}" >> .gdbinit
342.endfor
343.if defined(GDBINIT) && !empty(GDBINIT)
344.for __gdbinit in ${GDBINIT}
345	echo "source ${__gdbinit}" >> .gdbinit
346.endfor
347.endif
348
349##
350## the end
351##
352