kern.pre.mk revision 175886
1# $FreeBSD: head/sys/conf/kern.pre.mk 175886 2008-02-02 07:43:38Z imp $
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
6SRCCONF?=	/etc/src.conf
7.if exists(${SRCCONF})
8.include "${SRCCONF}"
9.endif
10
11# Can be overridden by makeoptions or /etc/make.conf
12KERNEL_KO?=	kernel
13KERNEL?=	kernel
14KODIR?=		/boot/${KERNEL}
15
16M=	${MACHINE_ARCH}
17
18AWK?=		awk
19LINT?=		lint
20NM?=		nm
21OBJCOPY?=	objcopy
22SIZE?=		size
23
24.if ${CC} == "icc"
25COPTFLAGS?=	-O
26.else
27. if defined(DEBUG)
28_MINUS_O=	-O
29. else
30_MINUS_O=	-O2
31. endif
32. if ${MACHINE_ARCH} == "amd64"
33COPTFLAGS?=-O2 -frename-registers -pipe
34. else
35COPTFLAGS?=${_MINUS_O} -pipe
36. endif
37. if !empty(COPTFLAGS:M-O[23s]) && empty(COPTFLAGS:M-fno-strict-aliasing)
38COPTFLAGS+= -fno-strict-aliasing
39. endif
40.endif
41.if !defined(NO_CPU_COPTFLAGS)
42. if ${CC} == "icc"
43COPTFLAGS+= ${_ICC_CPUCFLAGS:C/(-x[^M^K^W]+)[MKW]+|-x[MKW]+/\1/}
44. else
45COPTFLAGS+= ${_CPUCFLAGS}
46. endif
47.endif
48.if ${CC} == "icc"
49C_DIALECT=
50NOSTDINC= -X
51.else
52C_DIALECT= -std=c99
53NOSTDINC= -nostdinc
54.endif
55
56INCLUDES= ${NOSTDINC} ${INCLMAGIC} -I. -I$S
57
58# This hack lets us use the OpenBSD altq code without spamming a new
59# include path into contrib'ed source files.
60INCLUDES+= -I$S/contrib/altq
61
62.if make(depend) || make(kernel-depend)
63
64# ... and the same for ipfilter
65INCLUDES+= -I$S/contrib/ipfilter
66
67# ... and the same for pf
68INCLUDES+= -I$S/contrib/pf
69
70# ... and the same for Atheros HAL
71INCLUDES+= -I$S/dev/ath
72
73# ... and the same for the NgATM stuff
74INCLUDES+= -I$S/contrib/ngatm
75
76# .. and the same for twa
77INCLUDES+= -I$S/dev/twa
78
79# ...  and XFS
80INCLUDES+= -I$S/gnu/fs/xfs/FreeBSD -I$S/gnu/fs/xfs/FreeBSD/support -I$S/gnu/fs/xfs
81
82.endif
83
84CFLAGS=	${COPTFLAGS} ${C_DIALECT} ${DEBUG} ${CWARNFLAGS}
85CFLAGS+= ${INCLUDES} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h
86.if ${CC} != "icc"
87CFLAGS+= -fno-common -finline-limit=${INLINE_LIMIT}
88CFLAGS+= --param inline-unit-growth=100
89CFLAGS+= --param large-function-growth=1000
90.if ${MACHINE} != "pc98" && ${MACHINE_ARCH} != "arm" && ${MACHINE} != "sun4v"
91WERROR?= -Werror
92.endif
93.endif
94
95# XXX LOCORE means "don't declare C stuff" not "for locore.s".
96ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS}
97
98.if defined(PROFLEVEL) && ${PROFLEVEL} >= 1
99.if ${CC} == "icc"
100.error "Profiling doesn't work with icc yet"
101.endif
102CFLAGS+=	-DGPROF -falign-functions=16
103.if ${PROFLEVEL} >= 2
104CFLAGS+=	-DGPROF4 -DGUPROF
105PROF=	-pg -mprofiler-epilogue
106.else
107PROF=	-pg
108.endif
109.endif
110DEFINED_PROF=	${PROF}
111
112# Put configuration-specific C flags last (except for ${PROF}) so that they
113# can override the others.
114CFLAGS+=	${CONF_CFLAGS}
115
116# Optional linting. This can be overridden in /etc/make.conf.
117LINTFLAGS=	${LINTOBJKERNFLAGS}
118
119NORMAL_C= ${CC} -c ${CFLAGS} ${WERROR} ${PROF} ${.IMPSRC}
120NORMAL_S= ${CC} -c ${ASM_CFLAGS} ${WERROR} ${.IMPSRC}
121PROFILE_C= ${CC} -c ${CFLAGS} ${WERROR} ${.IMPSRC}
122NORMAL_C_NOWERROR= ${CC} -c ${CFLAGS} ${PROF} ${.IMPSRC}
123
124NORMAL_M= ${AWK} -f $S/tools/makeobjops.awk ${.IMPSRC} -c ; \
125	  ${CC} -c ${CFLAGS} ${WERROR} ${PROF} ${.PREFIX}.c
126
127NORMAL_LINT=	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC}
128
129GEN_CFILES= $S/$M/$M/genassym.c ${MFILES:T:S/.m$/.c/}
130SYSTEM_CFILES= config.c env.c hints.c vnode_if.c
131SYSTEM_DEP= Makefile ${SYSTEM_OBJS}
132SYSTEM_OBJS= locore.o ${MDOBJS} ${OBJS}
133SYSTEM_OBJS+= ${SYSTEM_CFILES:.c=.o}
134SYSTEM_OBJS+= hack.So
135SYSTEM_LD= @${LD} -Bdynamic -T $S/conf/ldscript.$M \
136	-warn-common -export-dynamic -dynamic-linker /red/herring \
137	-o ${.TARGET} -X ${SYSTEM_OBJS} vers.o
138SYSTEM_LD_TAIL= @${OBJCOPY} --strip-symbol gcc2_compiled. ${.TARGET} ; \
139	${SIZE} ${.TARGET} ; chmod 755 ${.TARGET}
140SYSTEM_DEP+= $S/conf/ldscript.$M
141
142# MKMODULESENV is set here so that port makefiles can augment
143# them.
144
145MKMODULESENV=	MAKEOBJDIRPREFIX=${.OBJDIR}/modules KMODDIR=${KODIR}
146.if (${KERN_IDENT} == LINT)
147MKMODULESENV+=	ALL_MODULES=LINT
148.endif
149.if defined(MODULES_OVERRIDE)
150MKMODULESENV+=	MODULES_OVERRIDE="${MODULES_OVERRIDE}"
151.endif
152.if defined(DEBUG)
153MKMODULESENV+=	DEBUG_FLAGS="${DEBUG}"
154.endif
155