xref: /freebsd/sys/conf/kern.pre.mk (revision 3157ba21)
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
6.include <bsd.own.mk>
7
8# Can be overridden by makeoptions or /etc/make.conf
9KERNEL_KO?=	kernel
10KERNEL?=	kernel
11KODIR?=		/boot/${KERNEL}
12LDSCRIPT_NAME?=	ldscript.$M
13LDSCRIPT?=	$S/conf/${LDSCRIPT_NAME}
14
15M=	${MACHINE_ARCH}
16
17AWK?=		awk
18LINT?=		lint
19NM?=		nm
20OBJCOPY?=	objcopy
21SIZE?=		size
22
23.if ${CC} == "icc"
24COPTFLAGS?=	-O
25.else
26. if defined(DEBUG)
27_MINUS_O=	-O
28CTFFLAGS+=	-g
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 ath
71INCLUDES+= -I$S/dev/ath -I$S/dev/ath/ath_hal
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# ...  and OpenSolaris
83INCLUDES+= -I$S/contrib/opensolaris/compat
84
85# ... and the same for cxgb
86INCLUDES+= -I$S/dev/cxgb
87
88.endif
89
90CFLAGS=	${COPTFLAGS} ${C_DIALECT} ${DEBUG} ${CWARNFLAGS}
91CFLAGS+= ${INCLUDES} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h
92.if ${CC} != "icc"
93CFLAGS+= -fno-common -finline-limit=${INLINE_LIMIT}
94CFLAGS+= --param inline-unit-growth=100
95CFLAGS+= --param large-function-growth=1000
96WERROR?= -Werror
97.endif
98
99# XXX LOCORE means "don't declare C stuff" not "for locore.s".
100ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS}
101
102.if defined(PROFLEVEL) && ${PROFLEVEL} >= 1
103.if ${CC} == "icc"
104.error "Profiling doesn't work with icc yet"
105.endif
106CFLAGS+=	-DGPROF -falign-functions=16
107.if ${PROFLEVEL} >= 2
108CFLAGS+=	-DGPROF4 -DGUPROF
109PROF=	-pg -mprofiler-epilogue
110.else
111PROF=	-pg
112.endif
113.endif
114DEFINED_PROF=	${PROF}
115
116# Put configuration-specific C flags last (except for ${PROF}) so that they
117# can override the others.
118CFLAGS+=	${CONF_CFLAGS}
119
120# Optional linting. This can be overridden in /etc/make.conf.
121LINTFLAGS=	${LINTOBJKERNFLAGS}
122
123NORMAL_C= ${CC} -c ${CFLAGS} ${WERROR} ${PROF} ${.IMPSRC}
124NORMAL_S= ${CC} -c ${ASM_CFLAGS} ${WERROR} ${.IMPSRC}
125PROFILE_C= ${CC} -c ${CFLAGS} ${WERROR} ${.IMPSRC}
126NORMAL_C_NOWERROR= ${CC} -c ${CFLAGS} ${PROF} ${.IMPSRC}
127
128NORMAL_M= ${AWK} -f $S/tools/makeobjops.awk ${.IMPSRC} -c ; \
129	  ${CC} -c ${CFLAGS} ${WERROR} ${PROF} ${.PREFIX}.c
130
131NORMAL_CTFCONVERT= [ -z "${CTFCONVERT}" -o -n "${NO_CTF}" ] || \
132		   ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
133
134NORMAL_LINT=	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC}
135
136GEN_CFILES= $S/$M/$M/genassym.c ${MFILES:T:S/.m$/.c/}
137SYSTEM_CFILES= config.c env.c hints.c vnode_if.c
138SYSTEM_DEP= Makefile ${SYSTEM_OBJS}
139SYSTEM_OBJS= locore.o ${MDOBJS} ${OBJS}
140SYSTEM_OBJS+= ${SYSTEM_CFILES:.c=.o}
141SYSTEM_OBJS+= hack.So
142SYSTEM_CTFMERGE= [ -z "${CTFMERGE}" -o -n "${NO_CTF}" ] || ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SYSTEM_OBJS} vers.o
143SYSTEM_LD= @${LD} -Bdynamic -T ${LDSCRIPT} \
144	-warn-common -export-dynamic -dynamic-linker /red/herring \
145	-o ${.TARGET} -X ${SYSTEM_OBJS} vers.o
146SYSTEM_LD_TAIL= @${OBJCOPY} --strip-symbol gcc2_compiled. ${.TARGET} ; \
147	${SIZE} ${.TARGET} ; chmod 755 ${.TARGET}
148SYSTEM_DEP+= ${LDSCRIPT}
149
150# MKMODULESENV is set here so that port makefiles can augment
151# them.
152
153MKMODULESENV=	MAKEOBJDIRPREFIX=${.OBJDIR}/modules KMODDIR=${KODIR}
154.if (${KERN_IDENT} == LINT)
155MKMODULESENV+=	ALL_MODULES=LINT
156.endif
157.if defined(MODULES_OVERRIDE)
158MKMODULESENV+=	MODULES_OVERRIDE="${MODULES_OVERRIDE}"
159.endif
160.if defined(DEBUG)
161MKMODULESENV+=	DEBUG_FLAGS="${DEBUG}"
162.endif
163