kern.pre.mk revision 239955
11556Srgrimes# $FreeBSD: head/sys/conf/kern.pre.mk 239955 2012-08-31 20:54:30Z jhb $
21556Srgrimes
31556Srgrimes# Part of a unified Makefile for building kernels.  This part contains all
41556Srgrimes# of the definitions that need to be before %BEFORE_DEPEND.
51556Srgrimes
61556Srgrimes.include <bsd.own.mk>
71556Srgrimes
81556Srgrimes# backwards compat option for older systems.
91556SrgrimesMACHINE_CPUARCH?=${MACHINE_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb)?/arm/:C/powerpc64/powerpc/}
101556Srgrimes
111556Srgrimes# Can be overridden by makeoptions or /etc/make.conf
121556SrgrimesKERNEL_KO?=	kernel
131556SrgrimesKERNEL?=	kernel
141556SrgrimesKODIR?=		/boot/${KERNEL}
151556SrgrimesLDSCRIPT_NAME?=	ldscript.$M
161556SrgrimesLDSCRIPT?=	$S/conf/${LDSCRIPT_NAME}
171556Srgrimes
181556SrgrimesM=		${MACHINE_CPUARCH}
191556Srgrimes
201556SrgrimesAWK?=		awk
211556SrgrimesLINT?=		lint
221556SrgrimesNM?=		nm
231556SrgrimesOBJCOPY?=	objcopy
241556SrgrimesSIZE?=		size
251556Srgrimes
261556Srgrimes.if defined(DEBUG)
271556Srgrimes_MINUS_O=	-O
281556SrgrimesCTFFLAGS+=	-g
291556Srgrimes.else
301556Srgrimes.if ${MACHINE_CPUARCH} == "powerpc"
3136152Scharnier_MINUS_O=	-O	# gcc miscompiles some code at -O2
3236152Scharnier.else
3336152Scharnier_MINUS_O=	-O2
341556Srgrimes.endif
3599110Sobrien.endif
3699110Sobrien.if ${MACHINE_CPUARCH} == "amd64"
371556Srgrimes.if ${MK_CLANG_IS_CC} == "no" && ${CC:T:Mclang} != "clang"
381556SrgrimesCOPTFLAGS?=-O2 -frename-registers -pipe
391556Srgrimes.else
401556SrgrimesCOPTFLAGS?=-O2 -pipe
411556Srgrimes.endif
421556Srgrimes.else
431556SrgrimesCOPTFLAGS?=${_MINUS_O} -pipe
441556Srgrimes.endif
451556Srgrimes.if !empty(COPTFLAGS:M-O[23s]) && empty(COPTFLAGS:M-fno-strict-aliasing)
461556SrgrimesCOPTFLAGS+= -fno-strict-aliasing
471556Srgrimes.endif
481556Srgrimes.if !defined(NO_CPU_COPTFLAGS)
491556SrgrimesCOPTFLAGS+= ${_CPUCFLAGS}
501556Srgrimes.endif
511556SrgrimesC_DIALECT= -std=c99
521556SrgrimesNOSTDINC= -nostdinc
531556Srgrimes
541556SrgrimesINCLUDES= ${NOSTDINC} ${INCLMAGIC} -I. -I$S
551556Srgrimes
5690111Simp# This hack lets us use the OpenBSD altq code without spamming a new
571556Srgrimes# include path into contrib'ed source files.
581556SrgrimesINCLUDES+= -I$S/contrib/altq
591556Srgrimes
601556Srgrimes.if make(depend) || make(kernel-depend)
611556Srgrimes
621556Srgrimes# ... and the same for ipfilter
639393SbdeINCLUDES+= -I$S/contrib/ipfilter
641556Srgrimes
65# ... and the same for pf
66INCLUDES+= -I$S/contrib/pf
67
68# ... and the same for ath
69INCLUDES+= -I$S/dev/ath -I$S/dev/ath/ath_hal
70
71# ... and the same for the NgATM stuff
72INCLUDES+= -I$S/contrib/ngatm
73
74# ... and the same for twa
75INCLUDES+= -I$S/dev/twa
76
77# ... and the same for XFS
78INCLUDES+= -I$S/gnu/fs/xfs/FreeBSD -I$S/gnu/fs/xfs/FreeBSD/support -I$S/gnu/fs/xfs
79
80# ... and the same for cxgb and cxgbe
81INCLUDES+= -I$S/dev/cxgb -I$S/dev/cxgbe
82
83.endif
84
85CFLAGS=	${COPTFLAGS} ${C_DIALECT} ${DEBUG} ${CWARNFLAGS}
86CFLAGS+= ${INCLUDES} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h
87.if ${MK_CLANG_IS_CC} == "no" && ${CC:T:Mclang} != "clang"
88CFLAGS+= -fno-common -finline-limit=${INLINE_LIMIT}
89.if ${MACHINE_CPUARCH} != "mips"
90CFLAGS+= --param inline-unit-growth=100
91CFLAGS+= --param large-function-growth=1000
92.else
93# XXX Actually a gross hack just for Octeon because of the Simple Executive.
94CFLAGS+= --param inline-unit-growth=10000
95CFLAGS+= --param large-function-growth=100000
96CFLAGS+= --param max-inline-insns-single=10000
97.endif
98.endif
99WERROR?= -Werror
100
101# XXX LOCORE means "don't declare C stuff" not "for locore.s".
102ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS}
103
104.if ${MK_CLANG_IS_CC} != "no" || ${CC:T:Mclang} == "clang"
105CLANG_NO_IAS= -no-integrated-as
106.endif
107
108.if defined(PROFLEVEL) && ${PROFLEVEL} >= 1
109CFLAGS+=	-DGPROF -falign-functions=16
110.if ${PROFLEVEL} >= 2
111CFLAGS+=	-DGPROF4 -DGUPROF
112PROF=	-pg -mprofiler-epilogue
113.else
114PROF=	-pg
115.endif
116.endif
117DEFINED_PROF=	${PROF}
118
119# Put configuration-specific C flags last (except for ${PROF}) so that they
120# can override the others.
121CFLAGS+=	${CONF_CFLAGS}
122
123# Optional linting. This can be overridden in /etc/make.conf.
124LINTFLAGS=	${LINTOBJKERNFLAGS}
125
126NORMAL_C= ${CC} -c ${CFLAGS} ${WERROR} ${PROF} ${.IMPSRC}
127NORMAL_S= ${CC} -c ${ASM_CFLAGS} ${WERROR} ${.IMPSRC}
128PROFILE_C= ${CC} -c ${CFLAGS} ${WERROR} ${.IMPSRC}
129NORMAL_C_NOWERROR= ${CC} -c ${CFLAGS} ${PROF} ${.IMPSRC}
130
131NORMAL_M= ${AWK} -f $S/tools/makeobjops.awk ${.IMPSRC} -c ; \
132	  ${CC} -c ${CFLAGS} ${WERROR} ${PROF} ${.PREFIX}.c
133
134NORMAL_FW= uudecode -o ${.TARGET} ${.IMPSRC}
135NORMAL_FWO= ${LD} -b binary -d -warn-common -r -d -o ${.TARGET} ${.IMPSRC}
136
137# Special flags for managing the compat compiles for ZFS
138ZFS_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
139ZFS_ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${ZFS_CFLAGS}
140ZFS_C=		${CC} -c ${ZFS_CFLAGS} ${WERROR} ${PROF} ${.IMPSRC}
141ZFS_S=		${CC} -c ${ZFS_ASM_CFLAGS} ${WERROR} ${.IMPSRC}
142
143.if ${MK_CTF} != "no"
144NORMAL_CTFCONVERT=	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
145.elif ${MAKE_VERSION} >= 5201111300
146NORMAL_CTFCONVERT=
147.else
148NORMAL_CTFCONVERT=	@:
149.endif
150
151NORMAL_LINT=	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC}
152
153# Infiniband C flags.  Correct include paths and omit errors that linux
154# does not honor.
155OFEDINCLUDES=	-I$S/ofed/include/
156OFEDNOERR=	-Wno-cast-qual -Wno-pointer-arith -fms-extensions
157OFEDCFLAGS=	${CFLAGS:N-I*} ${OFEDINCLUDES} ${CFLAGS:M-I*} ${OFEDNOERR}
158OFED_C_NOIMP=	${CC} -c -o ${.TARGET} ${OFEDCFLAGS} ${WERROR} ${PROF}
159OFED_C=		${OFED_C_NOIMP} ${.IMPSRC}
160
161GEN_CFILES= $S/$M/$M/genassym.c ${MFILES:T:S/.m$/.c/}
162SYSTEM_CFILES= config.c env.c hints.c vnode_if.c
163SYSTEM_DEP= Makefile ${SYSTEM_OBJS}
164SYSTEM_OBJS= locore.o ${MDOBJS} ${OBJS}
165SYSTEM_OBJS+= ${SYSTEM_CFILES:.c=.o}
166SYSTEM_OBJS+= hack.So
167SYSTEM_LD= @${LD} -Bdynamic -T ${LDSCRIPT} \
168	-warn-common -export-dynamic -dynamic-linker /red/herring \
169	-o ${.TARGET} -X ${SYSTEM_OBJS} vers.o
170SYSTEM_LD_TAIL= @${OBJCOPY} --strip-symbol gcc2_compiled. ${.TARGET} ; \
171	${SIZE} ${.TARGET} ; chmod 755 ${.TARGET}
172SYSTEM_DEP+= ${LDSCRIPT}
173
174# MKMODULESENV is set here so that port makefiles can augment
175# them.
176
177MKMODULESENV+=	MAKEOBJDIRPREFIX=${.OBJDIR}/modules KMODDIR=${KODIR}
178MKMODULESENV+=	MACHINE_CPUARCH=${MACHINE_CPUARCH}
179.if (${KERN_IDENT} == LINT)
180MKMODULESENV+=	ALL_MODULES=LINT
181.endif
182.if defined(MODULES_OVERRIDE)
183MKMODULESENV+=	MODULES_OVERRIDE="${MODULES_OVERRIDE}"
184.endif
185.if defined(WITHOUT_MODULES)
186MKMODULESENV+=	WITHOUT_MODULES="${WITHOUT_MODULES}"
187.endif
188.if defined(DEBUG)
189MKMODULESENV+=	DEBUG_FLAGS="${DEBUG}"
190.endif
191