xref: /freebsd/sys/conf/kern.pre.mk (revision c4f6a2a9e1b1879b618c436ab4f56ff75c73a0f5)
1# kern.pre.mk
2#
3# Unified Makefile for building kernels.  This includes all the definitions
4# that need to be included before %BEFORE_DEPEND
5#
6# $FreeBSD$
7#
8
9# Can be overridden by makeoptions or /etc/make.conf
10KERNEL_KO?=	kernel
11KERNEL?=	kernel
12KODIR?=		/boot/${KERNEL}
13
14M=	${MACHINE_ARCH}
15
16AWK?=		awk
17NM?=		nm
18OBJCOPY?=	objcopy
19SIZE?=		size
20
21COPTFLAGS?=-O -pipe
22.if !defined(NO_CPU_COPTFLAGS)
23COPTFLAGS+= ${_CPUCFLAGS}
24.endif
25INCLUDES= -nostdinc -I- ${INCLMAGIC} -I. -I$S -I$S/dev
26
27# This hack lets us use the Intel ACPICA code without spamming a new
28# include path into 100+ source files.
29INCLUDES+= -I$S/contrib/dev/acpica
30
31# ... and the same for ipfilter
32INCLUDES+= -I$S/contrib/ipfilter
33
34# This hack is to allow kernel compiles to succeed on machines w/out srcdist
35.if exists($S/../include)
36INCLUDES+= -I$S/../include
37.else
38INCLUDES+= -I/usr/include
39.endif
40
41COPTS=	${INCLUDES} -D_KERNEL -include opt_global.h
42CFLAGS=	${COPTFLAGS} ${CWARNFLAGS} ${DEBUG} ${COPTS} -fno-common
43
44# XXX LOCORE means "don't declare C stuff" not "for locore.s".
45ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS}
46
47# Select the correct set of tools. Can't set OBJFORMAT here because it
48# doesn't get exported into the environment, and if it were exported
49# then it might break building of utilities.
50CFLAGS+=	${FMT}
51
52.if defined(PROFLEVEL) && ${PROFLEVEL} >= 1
53CFLAGS+=	-DGPROF -falign-functions=16
54.if ${PROFLEVEL} >= 2
55CFLAGS+=	-DGPROF4 -DGUPROF
56# XXX -Wno-inline is to break some warnings.
57PROF=	-finstrument-functions -Wno-inline
58.else
59PROF=	-pg
60.endif
61.endif
62DEFINED_PROF=	${PROF}
63WERROR?=	-Werror
64
65# Put configuration-specific C flags last (except for ${PROF}) so that they
66# can override the others.
67CFLAGS+=	${CONF_CFLAGS}
68
69NORMAL_C= ${CC} -c ${CFLAGS} ${WERROR} ${PROF} ${.IMPSRC}
70NORMAL_S= ${CC} -c ${ASM_CFLAGS} ${WERROR} ${.IMPSRC}
71PROFILE_C= ${CC} -c ${CFLAGS} ${WERROR} ${.IMPSRC}
72NORMAL_C_NOWERROR= ${CC} -c ${CFLAGS} ${PROF} ${.IMPSRC}
73
74NORMAL_M= ${AWK} -f $S/tools/makeobjops.awk $< -c ; \
75	  ${CC} -c ${CFLAGS} ${PROF} ${.PREFIX}.c
76
77GEN_CFILES= $S/$M/$M/genassym.c
78SYSTEM_CFILES= vnode_if.c hints.c env.c config.c
79SYSTEM_SFILES= $S/$M/$M/locore.s
80SYSTEM_DEP= Makefile ${SYSTEM_OBJS}
81SYSTEM_OBJS= locore.o vnode_if.o ${OBJS} hints.o env.o config.o hack.So
82SYSTEM_LD= @${LD} ${FMT} -Bdynamic -T $S/conf/ldscript.$M \
83	-warn-common -export-dynamic -dynamic-linker /red/herring \
84	-o ${.TARGET} -X ${SYSTEM_OBJS} vers.o
85SYSTEM_LD_TAIL= @${OBJCOPY} --strip-symbol gcc2_compiled. ${.TARGET} ; \
86	${SIZE} ${FMT} ${.TARGET} ; chmod 755 ${.TARGET}
87SYSTEM_DEP+= $S/conf/ldscript.$M
88
89# MKMODULESENV is set here so that port makefiles can augment
90# them.
91
92MKMODULESENV=	MAKEOBJDIRPREFIX=${.OBJDIR}/modules KMODDIR=${KODIR}
93.if (${KERN_IDENT} == LINT)
94MKMODULESENV+=	ALL_MODULES=LINT
95.endif
96.if defined(MODULES_OVERRIDE)
97MKMODULESENV+=	MODULES_OVERRIDE="${MODULES_OVERRIDE}"
98.endif
99.if defined(DEBUG)
100MKMODULESENV+=	DEBUG="${DEBUG}" DEBUG_FLAGS="${DEBUG}"
101.endif
102
103all:	${KERNEL_KO}
104