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