kern.pre.mk revision 210311
1295263Sgjb# $FreeBSD: head/sys/conf/kern.pre.mk 210311 2010-07-20 19:25:11Z jmallett $
2295263Sgjb
3295263Sgjb# Part of a unified Makefile for building kernels.  This part contains all
4295263Sgjb# of the definitions that need to be before %BEFORE_DEPEND.
5294517Sgjb
6294517Sgjb.include <bsd.own.mk>
7294517Sgjb
8295262Sgjb# backwards compat option for older systems.
9294517SgjbMACHINE_CPUARCH?=${MACHINE_ARCH:C/mipse[lb]/mips/:C/armeb/arm/:C/powerpc64/powerpc/}
10294517Sgjb
11294517Sgjb# Can be overridden by makeoptions or /etc/make.conf
12294517SgjbKERNEL_KO?=	kernel
13294517SgjbKERNEL?=	kernel
14294517SgjbKODIR?=		/boot/${KERNEL}
15294517SgjbLDSCRIPT_NAME?=	ldscript.$M
16294517SgjbLDSCRIPT?=	$S/conf/${LDSCRIPT_NAME}
17294517Sgjb
18295225SgjbM=	${MACHINE_CPUARCH}
19295262Sgjb
20295225SgjbAWK?=		awk
21295225SgjbLINT?=		lint
22295225SgjbNM?=		nm
23295225SgjbOBJCOPY?=	objcopy
24295225SgjbSIZE?=		size
25
26.if ${CC} == "icc"
27COPTFLAGS?=	-O
28.else
29. if defined(DEBUG)
30_MINUS_O=	-O
31CTFFLAGS+=	-g
32. else
33_MINUS_O=	-O2
34. endif
35. if ${MACHINE_ARCH} == "amd64"
36COPTFLAGS?=-O2 -frename-registers -pipe
37. else
38COPTFLAGS?=${_MINUS_O} -pipe
39. endif
40. if !empty(COPTFLAGS:M-O[23s]) && empty(COPTFLAGS:M-fno-strict-aliasing)
41COPTFLAGS+= -fno-strict-aliasing
42. endif
43.endif
44.if !defined(NO_CPU_COPTFLAGS)
45. if ${CC} == "icc"
46COPTFLAGS+= ${_ICC_CPUCFLAGS:C/(-x[^M^K^W]+)[MKW]+|-x[MKW]+/\1/}
47. else
48COPTFLAGS+= ${_CPUCFLAGS}
49. endif
50.endif
51.if ${CC} == "icc"
52C_DIALECT=
53NOSTDINC= -X
54.else
55C_DIALECT= -std=c99
56NOSTDINC= -nostdinc
57.endif
58
59INCLUDES= ${NOSTDINC} ${INCLMAGIC} -I. -I$S
60
61# This hack lets us use the OpenBSD altq code without spamming a new
62# include path into contrib'ed source files.
63INCLUDES+= -I$S/contrib/altq
64
65.if make(depend) || make(kernel-depend)
66
67# ... and the same for ipfilter
68INCLUDES+= -I$S/contrib/ipfilter
69
70# ... and the same for pf
71INCLUDES+= -I$S/contrib/pf
72
73# ... and the same for ath
74INCLUDES+= -I$S/dev/ath -I$S/dev/ath/ath_hal
75
76# ... and the same for the NgATM stuff
77INCLUDES+= -I$S/contrib/ngatm
78
79# .. and the same for twa
80INCLUDES+= -I$S/dev/twa
81
82# ...  and XFS
83INCLUDES+= -I$S/gnu/fs/xfs/FreeBSD -I$S/gnu/fs/xfs/FreeBSD/support -I$S/gnu/fs/xfs
84
85# ...  and OpenSolaris
86INCLUDES+= -I$S/contrib/opensolaris/compat
87
88# ... and the same for cxgb
89INCLUDES+= -I$S/dev/cxgb
90
91.endif
92
93CFLAGS=	${COPTFLAGS} ${C_DIALECT} ${DEBUG} ${CWARNFLAGS}
94CFLAGS+= ${INCLUDES} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h
95.if ${CC} != "icc"
96CFLAGS+= -fno-common -finline-limit=${INLINE_LIMIT}
97.if ${MACHINE_CPUARCH} != "mips"
98CFLAGS+= --param inline-unit-growth=100
99CFLAGS+= --param large-function-growth=1000
100.else
101# XXX Actually a gross hack just for Octeon because of the Simple Executive.
102CFLAGS+= --param inline-unit-growth=1000
103CFLAGS+= --param large-function-growth=100000
104.endif
105WERROR?= -Werror
106.endif
107
108# XXX LOCORE means "don't declare C stuff" not "for locore.s".
109ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS}
110
111.if defined(PROFLEVEL) && ${PROFLEVEL} >= 1
112.if ${CC} == "icc"
113.error "Profiling doesn't work with icc yet"
114.endif
115CFLAGS+=	-DGPROF -falign-functions=16
116.if ${PROFLEVEL} >= 2
117CFLAGS+=	-DGPROF4 -DGUPROF
118PROF=	-pg -mprofiler-epilogue
119.else
120PROF=	-pg
121.endif
122.endif
123DEFINED_PROF=	${PROF}
124
125# Put configuration-specific C flags last (except for ${PROF}) so that they
126# can override the others.
127CFLAGS+=	${CONF_CFLAGS}
128
129# Optional linting. This can be overridden in /etc/make.conf.
130LINTFLAGS=	${LINTOBJKERNFLAGS}
131
132NORMAL_C= ${CC} -c ${CFLAGS} ${WERROR} ${PROF} ${.IMPSRC}
133NORMAL_S= ${CC} -c ${ASM_CFLAGS} ${WERROR} ${.IMPSRC}
134PROFILE_C= ${CC} -c ${CFLAGS} ${WERROR} ${.IMPSRC}
135NORMAL_C_NOWERROR= ${CC} -c ${CFLAGS} ${PROF} ${.IMPSRC}
136
137NORMAL_M= ${AWK} -f $S/tools/makeobjops.awk ${.IMPSRC} -c ; \
138	  ${CC} -c ${CFLAGS} ${WERROR} ${PROF} ${.PREFIX}.c
139
140NORMAL_CTFCONVERT= [ -z "${CTFCONVERT}" -o -n "${NO_CTF}" ] || \
141		   ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
142
143NORMAL_LINT=	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC}
144
145GEN_CFILES= $S/$M/$M/genassym.c ${MFILES:T:S/.m$/.c/}
146SYSTEM_CFILES= config.c env.c hints.c vnode_if.c
147SYSTEM_DEP= Makefile ${SYSTEM_OBJS}
148SYSTEM_OBJS= locore.o ${MDOBJS} ${OBJS}
149SYSTEM_OBJS+= ${SYSTEM_CFILES:.c=.o}
150SYSTEM_OBJS+= hack.So
151SYSTEM_CTFMERGE= [ -z "${CTFMERGE}" -o -n "${NO_CTF}" ] || ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SYSTEM_OBJS} vers.o
152SYSTEM_LD= @${LD} -Bdynamic -T ${LDSCRIPT} \
153	-warn-common -export-dynamic -dynamic-linker /red/herring \
154	-o ${.TARGET} -X ${SYSTEM_OBJS} vers.o
155SYSTEM_LD_TAIL= @${OBJCOPY} --strip-symbol gcc2_compiled. ${.TARGET} ; \
156	${SIZE} ${.TARGET} ; chmod 755 ${.TARGET}
157SYSTEM_DEP+= ${LDSCRIPT}
158
159# MKMODULESENV is set here so that port makefiles can augment
160# them.
161
162MKMODULESENV=	MAKEOBJDIRPREFIX=${.OBJDIR}/modules KMODDIR=${KODIR}
163MKMODULESENV+=	MACHINE_CPUARCH=${MACHINE_CPUARCH}
164.if (${KERN_IDENT} == LINT)
165MKMODULESENV+=	ALL_MODULES=LINT
166.endif
167.if defined(MODULES_OVERRIDE)
168MKMODULESENV+=	MODULES_OVERRIDE="${MODULES_OVERRIDE}"
169.endif
170.if defined(DEBUG)
171MKMODULESENV+=	DEBUG_FLAGS="${DEBUG}"
172.endif
173