]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/conf/kern.pre.mk
Introduce kern.opts.mk to hold all the options for kernel module
[FreeBSD/FreeBSD.git] / sys / conf / kern.pre.mk
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 <src.opts.mk>
7 .include <bsd.compiler.mk>
8 .include "kern.opts.mk"
9
10 # backwards compat option for older systems.
11 MACHINE_CPUARCH?=${MACHINE_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb)?/arm/:C/powerpc64/powerpc/}
12
13 # Can be overridden by makeoptions or /etc/make.conf
14 KERNEL_KO?=     kernel
15 KERNEL?=        kernel
16 KODIR?=         /boot/${KERNEL}
17 LDSCRIPT_NAME?= ldscript.$M
18 LDSCRIPT?=      $S/conf/${LDSCRIPT_NAME}
19
20 M=              ${MACHINE_CPUARCH}
21
22 AWK?=           awk
23 CP?=            cp
24 LINT?=          lint
25 NM?=            nm
26 OBJCOPY?=       objcopy
27 SIZE?=          size
28
29 .if defined(DEBUG)
30 _MINUS_O=       -O
31 CTFFLAGS+=      -g
32 .else
33 .if ${MACHINE_CPUARCH} == "powerpc"
34 _MINUS_O=       -O      # gcc miscompiles some code at -O2
35 .else
36 _MINUS_O=       -O2
37 .endif
38 .endif
39 .if ${MACHINE_CPUARCH} == "amd64"
40 .if ${COMPILER_TYPE} != "clang"
41 COPTFLAGS?=-O2 -frename-registers -pipe
42 .else
43 COPTFLAGS?=-O2 -pipe
44 .endif
45 .else
46 COPTFLAGS?=${_MINUS_O} -pipe
47 .endif
48 .if !empty(COPTFLAGS:M-O[23s]) && empty(COPTFLAGS:M-fno-strict-aliasing)
49 COPTFLAGS+= -fno-strict-aliasing
50 .endif
51 .if !defined(NO_CPU_COPTFLAGS)
52 COPTFLAGS+= ${_CPUCFLAGS}
53 .endif
54 C_DIALECT= -std=c99
55 NOSTDINC= -nostdinc
56
57 INCLUDES= ${NOSTDINC} ${INCLMAGIC} -I. -I$S
58
59 # This hack lets us use the OpenBSD altq code without spamming a new
60 # include path into contrib'ed source files.
61 INCLUDES+= -I$S/contrib/altq
62
63 .if make(depend) || make(kernel-depend)
64
65 # ... and the same for ipfilter
66 INCLUDES+= -I$S/contrib/ipfilter
67
68 # ... and the same for ath
69 INCLUDES+= -I$S/dev/ath -I$S/dev/ath/ath_hal -I$S/contrib/dev/ath/ath_hal
70
71 # ... and the same for the NgATM stuff
72 INCLUDES+= -I$S/contrib/ngatm
73
74 # ... and the same for twa
75 INCLUDES+= -I$S/dev/twa
76
77 # ... and the same for cxgb and cxgbe
78 INCLUDES+= -I$S/dev/cxgb -I$S/dev/cxgbe
79
80 .endif
81
82 CFLAGS= ${COPTFLAGS} ${C_DIALECT} ${DEBUG} ${CWARNFLAGS}
83 CFLAGS+= ${INCLUDES} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h
84 CFLAGS_PARAM_INLINE_UNIT_GROWTH?=100
85 CFLAGS_PARAM_LARGE_FUNCTION_GROWTH?=1000
86 .if ${MACHINE_CPUARCH} == "mips"
87 CFLAGS_ARCH_PARAMS?=--param max-inline-insns-single=1000
88 .endif
89 .if ${COMPILER_TYPE} != "clang"
90 CFLAGS+= -fno-common -finline-limit=${INLINE_LIMIT}
91 CFLAGS+= --param inline-unit-growth=${CFLAGS_PARAM_INLINE_UNIT_GROWTH}
92 CFLAGS+= --param large-function-growth=${CFLAGS_PARAM_LARGE_FUNCTION_GROWTH}
93 .if defined(CFLAGS_ARCH_PARAMS)
94 CFLAGS+=${CFLAGS_ARCH_PARAMS}
95 .endif
96 .endif
97 WERROR?= -Werror
98
99 # XXX LOCORE means "don't declare C stuff" not "for locore.s".
100 ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS}
101
102 .if ${COMPILER_TYPE} == "clang"
103 CLANG_NO_IAS= -no-integrated-as
104 .else
105 GCC_MS_EXTENSIONS= -fms-extensions
106 .endif
107
108 .if defined(PROFLEVEL) && ${PROFLEVEL} >= 1
109 CFLAGS+=        -DGPROF
110 .if ${COMPILER_TYPE} != "clang"
111 CFLAGS+=        -falign-functions=16
112 .endif
113 .if ${PROFLEVEL} >= 2
114 CFLAGS+=        -DGPROF4 -DGUPROF
115 PROF=           -pg
116 .if ${COMPILER_TYPE} != "clang"
117 PROF+=          -mprofiler-epilogue
118 .endif
119 .else
120 PROF=           -pg
121 .endif
122 .endif
123 DEFINED_PROF=   ${PROF}
124
125 # Put configuration-specific C flags last (except for ${PROF}) so that they
126 # can override the others.
127 CFLAGS+=        ${CONF_CFLAGS}
128
129 # Optional linting. This can be overridden in /etc/make.conf.
130 LINTFLAGS=      ${LINTOBJKERNFLAGS}
131
132 NORMAL_C= ${CC} -c ${CFLAGS} ${WERROR} ${PROF} ${.IMPSRC}
133 NORMAL_S= ${CC} -c ${ASM_CFLAGS} ${WERROR} ${.IMPSRC}
134 PROFILE_C= ${CC} -c ${CFLAGS} ${WERROR} ${.IMPSRC}
135 NORMAL_C_NOWERROR= ${CC} -c ${CFLAGS} ${PROF} ${.IMPSRC}
136
137 NORMAL_M= ${AWK} -f $S/tools/makeobjops.awk ${.IMPSRC} -c ; \
138           ${CC} -c ${CFLAGS} ${WERROR} ${PROF} ${.PREFIX}.c
139
140 NORMAL_FW= uudecode -o ${.TARGET} ${.ALLSRC}
141 NORMAL_FWO= ${LD} -b binary --no-warn-mismatch -d -warn-common -r \
142         -o ${.TARGET} ${.ALLSRC:M*.fw}
143
144 # Special flags for managing the compat compiles for ZFS
145 ZFS_CFLAGS=     -DFREEBSD_NAMECACHE -DBUILDING_ZFS -nostdinc -I$S/cddl/compat/opensolaris -I$S/cddl/contrib/opensolaris/uts/common/fs/zfs -I$S/cddl/contrib/opensolaris/uts/common/zmod -I$S/cddl/contrib/opensolaris/uts/common -I$S -I$S/cddl/contrib/opensolaris/common/zfs -I$S/cddl/contrib/opensolaris/common ${CFLAGS} -Wno-unknown-pragmas -Wno-missing-prototypes -Wno-undef -Wno-strict-prototypes -Wno-cast-qual -Wno-parentheses -Wno-redundant-decls -Wno-missing-braces -Wno-uninitialized -Wno-unused -Wno-inline -Wno-switch -Wno-pointer-arith -Wno-unknown-pragmas
146 ZFS_CFLAGS+=    -include $S/cddl/compat/opensolaris/sys/debug_compat.h
147 ZFS_ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${ZFS_CFLAGS}
148 ZFS_C=          ${CC} -c ${ZFS_CFLAGS} ${WERROR} ${PROF} ${.IMPSRC}
149 ZFS_S=          ${CC} -c ${ZFS_ASM_CFLAGS} ${WERROR} ${.IMPSRC}
150
151 .if ${MK_CTF} != "no"
152 NORMAL_CTFCONVERT=      ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
153 .elif ${MAKE_VERSION} >= 5201111300
154 NORMAL_CTFCONVERT=
155 .else
156 NORMAL_CTFCONVERT=      @:
157 .endif
158
159 NORMAL_LINT=    ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC}
160
161 # Infiniband C flags.  Correct include paths and omit errors that linux
162 # does not honor.
163 OFEDINCLUDES=   -I$S/ofed/include/
164 OFEDNOERR=      -Wno-cast-qual -Wno-pointer-arith ${GCC_MS_EXTENSIONS}
165 OFEDCFLAGS=     ${CFLAGS:N-I*} ${OFEDINCLUDES} ${CFLAGS:M-I*} ${OFEDNOERR}
166 OFED_C_NOIMP=   ${CC} -c -o ${.TARGET} ${OFEDCFLAGS} ${WERROR} ${PROF}
167 OFED_C=         ${OFED_C_NOIMP} ${.IMPSRC}
168
169 GEN_CFILES= $S/$M/$M/genassym.c ${MFILES:T:S/.m$/.c/}
170 SYSTEM_CFILES= config.c env.c hints.c vnode_if.c
171 SYSTEM_DEP= Makefile ${SYSTEM_OBJS}
172 SYSTEM_OBJS= locore.o ${MDOBJS} ${OBJS}
173 SYSTEM_OBJS+= ${SYSTEM_CFILES:.c=.o}
174 SYSTEM_OBJS+= hack.So
175 SYSTEM_LD= @${LD} -Bdynamic -T ${LDSCRIPT} ${LDFLAGS} --no-warn-mismatch \
176         -warn-common -export-dynamic -dynamic-linker /red/herring \
177         -o ${.TARGET} -X ${SYSTEM_OBJS} vers.o
178 SYSTEM_LD_TAIL= @${OBJCOPY} --strip-symbol gcc2_compiled. ${.TARGET} ; \
179         ${SIZE} ${.TARGET} ; chmod 755 ${.TARGET}
180 SYSTEM_DEP+= ${LDSCRIPT}
181
182 # MKMODULESENV is set here so that port makefiles can augment
183 # them.
184
185 MKMODULESENV+=  MAKEOBJDIRPREFIX=${.OBJDIR}/modules KMODDIR=${KODIR}
186 MKMODULESENV+=  MACHINE_CPUARCH=${MACHINE_CPUARCH}
187 MKMODULESENV+=  MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE_ARCH}
188 .if (${KERN_IDENT} == LINT)
189 MKMODULESENV+=  ALL_MODULES=LINT
190 .endif
191 .if defined(MODULES_OVERRIDE)
192 MKMODULESENV+=  MODULES_OVERRIDE="${MODULES_OVERRIDE}"
193 .endif
194 .if defined(WITHOUT_MODULES)
195 MKMODULESENV+=  WITHOUT_MODULES="${WITHOUT_MODULES}"
196 .endif
197 .if defined(DEBUG)
198 MKMODULESENV+=  DEBUG_FLAGS="${DEBUG}"
199 .endif
200
201 # Detect kernel config options that force stack frames to be turned on.
202 DDB_ENABLED!=   grep DDB opt_ddb.h || true ; echo
203 DTR_ENABLED!=   grep KDTRACE_FRAME opt_kdtrace.h || true ; echo
204 HWPMC_ENABLED!= grep HWPMC opt_hwpmc_hooks.h || true ; echo