xref: /freebsd/sys/conf/kern.pre.mk (revision e4e9813eb92cd7c4d4b819a8fbed5cbd3d92f5d8)
1# $FreeBSD$
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"
49NOSTDINC= -X
50.else
51C_DIALECT= -std=c99
52NOSTDINC= -nostdinc
53.endif
54
55INCLUDES= ${NOSTDINC} -I- ${INCLMAGIC} -I. -I$S
56
57# This hack lets us use the OpenBSD altq code without spamming a new
58# include path into contrib'ed source files.
59INCLUDES+= -I$S/contrib/altq
60
61# ... and the same for Atheros HAL when the author builds it from
62#     non-distributable sources.
63.if defined(ATH_BUILDING_FROM_SOURCE)
64INCLUDES+= -I$S/contrib/dev/ath
65.endif
66
67.if make(depend) || make(kernel-depend)
68
69# ... and the same for ipfilter
70INCLUDES+= -I$S/contrib/ipfilter
71
72# ... and the same for pf
73INCLUDES+= -I$S/contrib/pf
74
75# ... and the same for Atheros HAL
76INCLUDES+= -I$S/contrib/dev/ath/freebsd
77
78# ... and the same for the NgATM stuff
79INCLUDES+= -I$S/contrib/ngatm
80
81# .. and the same for twa
82INCLUDES+= -I$S/dev/twa
83
84# ...  and XFS
85INCLUDES+= -I$S/gnu/fs/xfs/FreeBSD -I$S/gnu/fs/xfs/FreeBSD/support -I$S/gnu/fs/xfs
86
87.endif
88
89CFLAGS=	${COPTFLAGS} ${C_DIALECT} ${DEBUG} ${CWARNFLAGS}
90CFLAGS+= ${INCLUDES} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h
91.if ${CC} != "icc"
92CFLAGS+= -fno-common -finline-limit=${INLINE_LIMIT}
93CFLAGS+= --param inline-unit-growth=100
94CFLAGS+= --param large-function-growth=1000
95WERROR?= -Werror
96.endif
97
98# XXX LOCORE means "don't declare C stuff" not "for locore.s".
99ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS}
100
101.if defined(PROFLEVEL) && ${PROFLEVEL} >= 1
102.if ${CC} == "icc"
103.error Profiling doesn't work with ICC yet.
104.else
105CFLAGS+=	-DGPROF -falign-functions=16
106.endif
107.if ${PROFLEVEL} >= 2
108CFLAGS+=	-DGPROF4 -DGUPROF
109. if ${CC} == "icc"
110# XXX doesn't work yet
111#PROF=	-prof_gen
112. else
113PROF=	-finstrument-functions -Wno-inline
114. endif
115.else
116. if ${CC} == "icc"
117PROF=	-p
118. else
119PROF=	-pg
120. endif
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_LINT=	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC}
141
142GEN_CFILES= $S/$M/$M/genassym.c ${MFILES:T:S/.m$/.c/}
143SYSTEM_CFILES= config.c env.c hints.c vnode_if.c
144SYSTEM_DEP= Makefile ${SYSTEM_OBJS}
145SYSTEM_OBJS= locore.o ${MDOBJS} ${OBJS}
146SYSTEM_OBJS+= ${SYSTEM_CFILES:.c=.o}
147SYSTEM_OBJS+= hack.So
148SYSTEM_LD= @${LD} -Bdynamic -T $S/conf/ldscript.$M \
149	-warn-common -export-dynamic -dynamic-linker /red/herring \
150	-o ${.TARGET} -X ${SYSTEM_OBJS} vers.o
151SYSTEM_LD_TAIL= @${OBJCOPY} --strip-symbol gcc2_compiled. ${.TARGET} ; \
152	${SIZE} ${.TARGET} ; chmod 755 ${.TARGET}
153SYSTEM_DEP+= $S/conf/ldscript.$M
154
155# MKMODULESENV is set here so that port makefiles can augment
156# them.
157
158MKMODULESENV=	MAKEOBJDIRPREFIX=${.OBJDIR}/modules KMODDIR=${KODIR}
159.if (${KERN_IDENT} == LINT)
160MKMODULESENV+=	ALL_MODULES=LINT
161.endif
162.if defined(MODULES_OVERRIDE)
163MKMODULESENV+=	MODULES_OVERRIDE="${MODULES_OVERRIDE}"
164.endif
165.if defined(DEBUG)
166MKMODULESENV+=	DEBUG_FLAGS="${DEBUG}"
167.endif
168