xref: /netbsd/sys/conf/Makefile.kern.inc (revision bf9ec67e)
1#	$NetBSD: Makefile.kern.inc,v 1.14 2002/05/26 00:15:25 fvdl 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##
25MKDEP?=		mkdep
26STRIP?=		strip
27OBJCOPY?=	objcopy
28OBJDUMP?=	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
36S!=	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##
44INCLUDES?=	-I. ${EXTRA_INCLUDES} -I$S/arch -I$S -nostdinc
45CPPFLAGS+=	${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -D_KERNEL_OPT
46DEFCOPTS?=	-O2
47COPTS?=		${DEFCOPTS}
48DBG=		# might contain unwanted -Ofoo
49DEFWARNINGS?=	yes
50.if (${DEFWARNINGS} == "yes")
51CWARNFLAGS+=	-Werror -Wall -Wno-main -Wno-format-zero-length
52WEAK_POINTERS?=	no
53.if !(${WEAK_POINTERS} == "yes")
54CWARNFLAGS+=	-Wpointer-arith
55.endif
56LOOSE_PROTOTYPES?= no
57.if !(${LOOSE_PROTOTYPES} == "yes")
58CWARNFLAGS+=	-Wmissing-prototypes -Wstrict-prototypes
59.endif
60# XXX Delete -Wuninitialized for now, since the compiler doesn't
61# XXX always get it right.  --thorpej
62CWARNFLAGS+=	-Wno-uninitialized
63.endif
64CFLAGS+=	-ffreestanding ${DEBUG} ${COPTS} ${CWARNFLAGS}
65AFLAGS+=	-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).
78NORMAL_C?=	${CC} ${CFLAGS} ${CPPFLAGS} ${${<:T:R}_G} ${PROF} -c $<
79NOPROF_C?=	${CC} ${CFLAGS} ${CPPFLAGS} ${${<:T:R}_G} -c $<
80NORMAL_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
92LIBKERN?=	${KERNLIB}
93.else
94LIBKERN?=	${KERNLIB_PROF}
95.endif
96
97### find out what to use for libcompat
98.include "$S/compat/common/Makefile.inc"
99.ifndef PROF
100LIBCOMPAT?=	${COMPATLIB}
101.else
102LIBCOMPAT?=	${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##
111MI_CFILES=ioconf.c param.c
112# the need for a MI_SFILES variable is dubitable at best
113MI_OBJS=${MI_CFILES:S/.c/.o/}
114
115param.c: $S/conf/param.c
116	rm -f param.c
117	cp $S/conf/param.c .
118
119param.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}
139SYSTEM_OBJ?=	${MD_OBJS} ${MI_OBJS} ${OBJS} ${LIBCOMPAT} ${LIBKERN}
140SYSTEM_DEP?=	Makefile ${SYSTEM_OBJ}
141SYSTEM_LD_HEAD?=	@rm -f $@
142SYSTEM_LD?=	@echo ${LD} ${LINKFLAGS} -o $@ '$${SYSTEM_OBJ}' vers.o; \
143		${LD} ${LINKFLAGS} -o $@ ${SYSTEM_OBJ} vers.o
144SYSTEM_LD_TAIL?=	@${SIZE} $@; chmod 755 $@
145
146TEXTADDR?=	${LOADADDRESS}			# backwards compatibility
147LINKTEXT?=	${TEXTADDR:C/.+/-Ttext &/}
148LINKDATA?=	${DATAADDR:C/.+/-Tdata &/}
149ENTRYPOINT?=	start
150LINKENTRY?=	${ENTRYPOINT:C/.+/-e &/}
151LINKFLAGS?=	${LINKFORMAT} ${LINKTEXT} ${LINKDATA} ${LINKENTRY} \
152		${EXTRA_LINKFLAGS}
153
154LINKFLAGS_DEBUG?=	-X
155SYSTEM_LD_TAIL_DEBUG?=; \
156		echo mv -f $@ $@.gdb; mv -f $@ $@.gdb; \
157		echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \
158		${STRIP} ${STRIPFLAGS} -o $@ $@.gdb
159LINKFLAGS_NORMAL?=	-S
160STRIPFLAGS?=	-g
161
162DEBUG?=
163.if ${DEBUG} == "-g"
164SYSTEM_LD_TAIL+=${SYSTEM_LD_TAIL_DEBUG}
165LINKFLAGS+=	${LINKFLAGS_DEBUG}
166EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.gdb@}
167.elifndef PROF
168LINKFLAGS+=	${LINKFLAGS_NORMAL}
169.endif
170
171SYSTEM_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)
177assym.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)
186newvers: vers.o
187vers.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
193autoconf.o conf.o: Makefile
194
195# depend on network or filesystem configuration
196uipc_proto.o vfs_conf.o: Makefile
197
198# depend on maxusers and CPU configuration
199assym.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)
217kernelnames:
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
227cleandir distclean: __CLEANKERNEL __CLEANDEPEND
228clean: __CLEANKERNEL
229depend: .depend
230
231.if !target(.depend)
232SRCS?=		${MD_SFILES} ${MD_CFILES} ${MI_CFILES} ${CFILES} ${SFILES}
233MKDEP_AFLAGS?=	${AFLAGS}
234MKDEP_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)
246dependall: depend all
247.endif
248
249.if !target(lint)
250ALLSFILES?=	${MD_SFILES} ${SFILES}
251LINTSTUBS?=	${ALLSFILES:T:R:C/^.*$/LintStub_&.c/g}
252KERNLINTFLAGS?=	-hbxncez -Dvolatile=
253.for _sfile in ${ALLSFILES}
254LintStub_${_sfile:T:R}.c: ${_sfile} assym.h
255	${CC} -E -C ${AFLAGS} ${CPPFLAGS} ${_sfile} | \
256	      awk -f $S/kern/genlintstub.awk >${.TARGET}
257.endfor
258lint: ${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
267MACHINE_NAME!=  uname -n
268install: install-kernel-${MACHINE_NAME}
269.if !target(install-kernel-${MACHINE_NAME}})
270install-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)
279tags:
280	@echo "see $S/kern/Makefile for tags"
281.endif
282
283##
284## the end
285##
286