kern.pre.mk revision 232263
1# $FreeBSD: head/sys/conf/kern.pre.mk 232263 2012-02-28 18:30:18Z dim $
2
3# Part of a unified Makefile for building kernels.  This part contains all
4# of the definitions that need to be before %BEFORE_DEPEND.
5
6.include <bsd.own.mk>
7
8# backwards compat option for older systems.
9MACHINE_CPUARCH?=${MACHINE_ARCH:C/mipse[lb]/mips/:C/armeb/arm/:C/powerpc64/powerpc/}
10
11# Can be overridden by makeoptions or /etc/make.conf
12KERNEL_KO?=	kernel
13KERNEL?=	kernel
14KODIR?=		/boot/${KERNEL}
15LDSCRIPT_NAME?=	ldscript.$M
16LDSCRIPT?=	$S/conf/${LDSCRIPT_NAME}
17
18M=		${MACHINE_CPUARCH}
19
20AWK?=		awk
21LINT?=		lint
22NM?=		nm
23OBJCOPY?=	objcopy
24SIZE?=		size
25
26.if defined(DEBUG)
27_MINUS_O=	-O
28CTFFLAGS+=	-g
29.else
30.if ${MACHINE_CPUARCH} == "powerpc"
31_MINUS_O=	-O	# gcc miscompiles some code at -O2
32.else
33_MINUS_O=	-O2
34.endif
35.endif
36.if ${MACHINE_CPUARCH} == "amd64"
37.if ${CC:T:Mclang} != "clang"
38COPTFLAGS?=-O2 -frename-registers -pipe
39.else
40COPTFLAGS?=-O2 -pipe
41.endif
42.else
43COPTFLAGS?=${_MINUS_O} -pipe
44.endif
45.if !empty(COPTFLAGS:M-O[23s]) && empty(COPTFLAGS:M-fno-strict-aliasing)
46COPTFLAGS+= -fno-strict-aliasing
47.endif
48.if !defined(NO_CPU_COPTFLAGS)
49COPTFLAGS+= ${_CPUCFLAGS}
50.endif
51C_DIALECT= -std=c99
52NOSTDINC= -nostdinc
53
54INCLUDES= ${NOSTDINC} ${INCLMAGIC} -I. -I$S
55
56# This hack lets us use the OpenBSD altq code without spamming a new
57# include path into contrib'ed source files.
58INCLUDES+= -I$S/contrib/altq
59
60.if make(depend) || make(kernel-depend)
61
62# ... and the same for ipfilter
63INCLUDES+= -I$S/contrib/ipfilter
64
65# ... and the same for pf
66INCLUDES+= -I$S/contrib/pf
67
68# ... and the same for ath
69INCLUDES+= -I$S/dev/ath -I$S/dev/ath/ath_hal
70
71# ... and the same for the NgATM stuff
72INCLUDES+= -I$S/contrib/ngatm
73
74# ... and the same for twa
75INCLUDES+= -I$S/dev/twa
76
77# ... and the same for XFS
78INCLUDES+= -I$S/gnu/fs/xfs/FreeBSD -I$S/gnu/fs/xfs/FreeBSD/support -I$S/gnu/fs/xfs
79
80# ... and the same for cxgb and cxgbe
81INCLUDES+= -I$S/dev/cxgb -I$S/dev/cxgbe
82
83.endif
84
85CFLAGS=	${COPTFLAGS} ${C_DIALECT} ${DEBUG} ${CWARNFLAGS}
86CFLAGS+= ${INCLUDES} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h
87.if ${CC:T:Mclang} != "clang"
88CFLAGS+= -fno-common -finline-limit=${INLINE_LIMIT}
89.if ${MACHINE_CPUARCH} != "mips"
90CFLAGS+= --param inline-unit-growth=100
91CFLAGS+= --param large-function-growth=1000
92.else
93# XXX Actually a gross hack just for Octeon because of the Simple Executive.
94CFLAGS+= --param inline-unit-growth=10000
95CFLAGS+= --param large-function-growth=100000
96CFLAGS+= --param max-inline-insns-single=10000
97.endif
98.endif
99WERROR?= -Werror
100
101# XXX LOCORE means "don't declare C stuff" not "for locore.s".
102ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS}
103
104.if ${CC:T:Mclang} == "clang"
105CLANG_NO_IAS= -no-integrated-as
106.endif
107
108.if defined(PROFLEVEL) && ${PROFLEVEL} >= 1
109CFLAGS+=	-DGPROF -falign-functions=16
110.if ${PROFLEVEL} >= 2
111CFLAGS+=	-DGPROF4 -DGUPROF
112PROF=	-pg -mprofiler-epilogue
113.else
114PROF=	-pg
115.endif
116.endif
117DEFINED_PROF=	${PROF}
118
119# Put configuration-specific C flags last (except for ${PROF}) so that they
120# can override the others.
121CFLAGS+=	${CONF_CFLAGS}
122
123# Optional linting. This can be overridden in /etc/make.conf.
124LINTFLAGS=	${LINTOBJKERNFLAGS}
125
126NORMAL_C= ${CC} -c ${CFLAGS} ${WERROR} ${PROF} ${.IMPSRC}
127NORMAL_S= ${CC} -c ${ASM_CFLAGS} ${WERROR} ${.IMPSRC}
128PROFILE_C= ${CC} -c ${CFLAGS} ${WERROR} ${.IMPSRC}
129NORMAL_C_NOWERROR= ${CC} -c ${CFLAGS} ${PROF} ${.IMPSRC}
130
131NORMAL_M= ${AWK} -f $S/tools/makeobjops.awk ${.IMPSRC} -c ; \
132	  ${CC} -c ${CFLAGS} ${WERROR} ${PROF} ${.PREFIX}.c
133
134.if ${MK_CTF} != "no"
135NORMAL_CTFCONVERT=	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
136.elif ${MAKE_VERSION} >= 5201111300
137NORMAL_CTFCONVERT=
138.else
139NORMAL_CTFCONVERT=	@:
140.endif
141
142NORMAL_LINT=	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC}
143
144# Infiniband C flags.  Correct include paths and omit errors that linux
145# does not honor.
146OFEDINCLUDES=	-I$S/ofed/include/
147OFEDNOERR=	-Wno-cast-qual -Wno-pointer-arith -fms-extensions
148OFEDCFLAGS=	${CFLAGS:N-I*} ${OFEDINCLUDES} ${CFLAGS:M-I*} ${OFEDNOERR}
149OFED_C_NOIMP=	${CC} -c -o ${.TARGET} ${OFEDCFLAGS} ${WERROR} ${PROF}
150OFED_C=		${OFED_C_NOIMP} ${.IMPSRC}
151
152GEN_CFILES= $S/$M/$M/genassym.c ${MFILES:T:S/.m$/.c/}
153SYSTEM_CFILES= config.c env.c hints.c vnode_if.c
154SYSTEM_DEP= Makefile ${SYSTEM_OBJS}
155SYSTEM_OBJS= locore.o ${MDOBJS} ${OBJS}
156SYSTEM_OBJS+= ${SYSTEM_CFILES:.c=.o}
157SYSTEM_OBJS+= hack.So
158SYSTEM_LD= @${LD} -Bdynamic -T ${LDSCRIPT} \
159	-warn-common -export-dynamic -dynamic-linker /red/herring \
160	-o ${.TARGET} -X ${SYSTEM_OBJS} vers.o
161SYSTEM_LD_TAIL= @${OBJCOPY} --strip-symbol gcc2_compiled. ${.TARGET} ; \
162	${SIZE} ${.TARGET} ; chmod 755 ${.TARGET}
163SYSTEM_DEP+= ${LDSCRIPT}
164
165# MKMODULESENV is set here so that port makefiles can augment
166# them.
167
168MKMODULESENV+=	MAKEOBJDIRPREFIX=${.OBJDIR}/modules KMODDIR=${KODIR}
169MKMODULESENV+=	MACHINE_CPUARCH=${MACHINE_CPUARCH}
170.if (${KERN_IDENT} == LINT)
171MKMODULESENV+=	ALL_MODULES=LINT
172.endif
173.if defined(MODULES_OVERRIDE)
174MKMODULESENV+=	MODULES_OVERRIDE="${MODULES_OVERRIDE}"
175.endif
176.if defined(WITHOUT_MODULES)
177MKMODULESENV+=	WITHOUT_MODULES="${WITHOUT_MODULES}"
178.endif
179.if defined(DEBUG)
180MKMODULESENV+=	DEBUG_FLAGS="${DEBUG}"
181.endif
182