kern.pre.mk revision 183292
11573Srgrimes# $FreeBSD: head/sys/conf/kern.pre.mk 183292 2008-09-23 03:16:54Z kmacy $
21573Srgrimes
31573Srgrimes# Part of a unified Makefile for building kernels.  This part contains all
41573Srgrimes# of the definitions that need to be before %BEFORE_DEPEND.
51573Srgrimes
61573Srgrimes.include <bsd.own.mk>
71573Srgrimes
81573Srgrimes# Can be overridden by makeoptions or /etc/make.conf
91573SrgrimesKERNEL_KO?=	kernel
101573SrgrimesKERNEL?=	kernel
111573SrgrimesKODIR?=		/boot/${KERNEL}
121573SrgrimesLDSCRIPT_NAME?=	ldscript.$M
131573SrgrimesLDSCRIPT?=	$S/conf/${LDSCRIPT_NAME}
141573Srgrimes
151573SrgrimesM=	${MACHINE_ARCH}
161573Srgrimes
171573SrgrimesAWK?=		awk
181573SrgrimesLINT?=		lint
191573SrgrimesNM?=		nm
201573SrgrimesOBJCOPY?=	objcopy
211573SrgrimesSIZE?=		size
221573Srgrimes
231573Srgrimes.if ${CC} == "icc"
241573SrgrimesCOPTFLAGS?=	-O
251573Srgrimes.else
261573Srgrimes. if defined(DEBUG)
271573Srgrimes_MINUS_O=	-O
281573Srgrimes. else
2950476Speter_MINUS_O=	-O2
301573Srgrimes. endif
3126826Ssteve. if ${MACHINE_ARCH} == "amd64"
321573SrgrimesCOPTFLAGS?=-O2 -frename-registers -pipe
331573Srgrimes. else
341573SrgrimesCOPTFLAGS?=${_MINUS_O} -pipe
351573Srgrimes. endif
361573Srgrimes. if !empty(COPTFLAGS:M-O[23s]) && empty(COPTFLAGS:M-fno-strict-aliasing)
371573SrgrimesCOPTFLAGS+= -fno-strict-aliasing
381573Srgrimes. endif
391573Srgrimes.endif
4059460Sphantom.if !defined(NO_CPU_COPTFLAGS)
4159460Sphantom. if ${CC} == "icc"
421573SrgrimesCOPTFLAGS+= ${_ICC_CPUCFLAGS:C/(-x[^M^K^W]+)[MKW]+|-x[MKW]+/\1/}
4384306Sru. else
441573SrgrimesCOPTFLAGS+= ${_CPUCFLAGS}
451573Srgrimes. endif
461573Srgrimes.endif
471573Srgrimes.if ${CC} == "icc"
481573SrgrimesC_DIALECT=
491573SrgrimesNOSTDINC= -X
501573Srgrimes.else
511573SrgrimesC_DIALECT= -std=c99
521573SrgrimesNOSTDINC= -nostdinc
531573Srgrimes.endif
5417780Smpp
551573SrgrimesINCLUDES= ${NOSTDINC} ${INCLMAGIC} -I. -I$S
561573Srgrimes
571573Srgrimes# This hack lets us use the OpenBSD altq code without spamming a new
581573Srgrimes# include path into contrib'ed source files.
591573SrgrimesINCLUDES+= -I$S/contrib/altq
6017780Smpp
611573Srgrimes.if make(depend) || make(kernel-depend)
621573Srgrimes
631573Srgrimes# ... and the same for ipfilter
641573SrgrimesINCLUDES+= -I$S/contrib/ipfilter
651573Srgrimes
661573Srgrimes# ... and the same for pf
671573SrgrimesINCLUDES+= -I$S/contrib/pf
681573Srgrimes
691573Srgrimes# ... and the same for Atheros HAL
701573SrgrimesINCLUDES+= -I$S/dev/ath
711573Srgrimes
721573Srgrimes# ... and the same for the NgATM stuff
731573SrgrimesINCLUDES+= -I$S/contrib/ngatm
741573Srgrimes
751573Srgrimes# .. and the same for twa
761573SrgrimesINCLUDES+= -I$S/dev/twa
771573Srgrimes
781573Srgrimes# ...  and XFS
791573SrgrimesINCLUDES+= -I$S/gnu/fs/xfs/FreeBSD -I$S/gnu/fs/xfs/FreeBSD/support -I$S/gnu/fs/xfs
8071097Sru
811573Srgrimes# ...  and OpenSolaris
821573SrgrimesINCLUDES+= -I$S/contrib/opensolaris/compat
831573Srgrimes
841573Srgrimes# ... and the same for cxgb
851573SrgrimesINCLUDES+= -I$S/dev/cxgb
861573Srgrimes
8771097Sru.endif
881573Srgrimes
891573SrgrimesCFLAGS=	${COPTFLAGS} ${C_DIALECT} ${DEBUG} ${CWARNFLAGS}
901573SrgrimesCFLAGS+= ${INCLUDES} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h
9117780Smpp.if ${CC} != "icc"
921573SrgrimesCFLAGS+= -fno-common -finline-limit=${INLINE_LIMIT}
931573SrgrimesCFLAGS+= --param inline-unit-growth=100
941573SrgrimesCFLAGS+= --param large-function-growth=1000
951573SrgrimesWERROR?= -Werror
961573Srgrimes.endif
971573Srgrimes
981573Srgrimes# XXX LOCORE means "don't declare C stuff" not "for locore.s".
991573SrgrimesASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS}
1001573Srgrimes
1011573Srgrimes.if defined(PROFLEVEL) && ${PROFLEVEL} >= 1
1021573Srgrimes.if ${CC} == "icc"
1031573Srgrimes.error "Profiling doesn't work with icc yet"
1041573Srgrimes.endif
1051573SrgrimesCFLAGS+=	-DGPROF -falign-functions=16
1061573Srgrimes.if ${PROFLEVEL} >= 2
1071573SrgrimesCFLAGS+=	-DGPROF4 -DGUPROF
1081573SrgrimesPROF=	-pg -mprofiler-epilogue
1091573Srgrimes.else
11017780SmppPROF=	-pg
1111573Srgrimes.endif
1121573Srgrimes.endif
1131573SrgrimesDEFINED_PROF=	${PROF}
1141573Srgrimes
1151573Srgrimes# Put configuration-specific C flags last (except for ${PROF}) so that they
116108087Sru# can override the others.
1171573SrgrimesCFLAGS+=	${CONF_CFLAGS}
1181573Srgrimes
1191573Srgrimes# Optional linting. This can be overridden in /etc/make.conf.
1201573SrgrimesLINTFLAGS=	${LINTOBJKERNFLAGS}
1211573Srgrimes
1221573SrgrimesNORMAL_C= ${CC} -c ${CFLAGS} ${WERROR} ${PROF} ${.IMPSRC}
1231573SrgrimesNORMAL_S= ${CC} -c ${ASM_CFLAGS} ${WERROR} ${.IMPSRC}
1241573SrgrimesPROFILE_C= ${CC} -c ${CFLAGS} ${WERROR} ${.IMPSRC}
1251573SrgrimesNORMAL_C_NOWERROR= ${CC} -c ${CFLAGS} ${PROF} ${.IMPSRC}
1261573Srgrimes
1271573SrgrimesNORMAL_M= ${AWK} -f $S/tools/makeobjops.awk ${.IMPSRC} -c ; \
1281573Srgrimes	  ${CC} -c ${CFLAGS} ${WERROR} ${PROF} ${.PREFIX}.c
1291573Srgrimes
1301573Srgrimes.if defined(CTFCONVERT)
1311573SrgrimesNORMAL_CTFCONVERT= ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
1321573Srgrimes.else
1331573SrgrimesNORMAL_CTFCONVERT=
1341573Srgrimes.endif
1351573Srgrimes
1361573SrgrimesNORMAL_LINT=	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC}
1371573Srgrimes
13817780SmppGEN_CFILES= $S/$M/$M/genassym.c ${MFILES:T:S/.m$/.c/}
1391573SrgrimesSYSTEM_CFILES= config.c env.c hints.c vnode_if.c
1401573SrgrimesSYSTEM_DEP= Makefile ${SYSTEM_OBJS}
1411573SrgrimesSYSTEM_OBJS= locore.o ${MDOBJS} ${OBJS}
1421573SrgrimesSYSTEM_OBJS+= ${SYSTEM_CFILES:.c=.o}
1431573SrgrimesSYSTEM_OBJS+= hack.So
1441573Srgrimes.if defined(CTFMERGE)
1451573SrgrimesSYSTEM_CTFMERGE= ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SYSTEM_OBJS} vers.o
14617780SmppLD+= -g
14717780Smpp.endif
14817780SmppSYSTEM_LD= @${LD} -Bdynamic -T ${LDSCRIPT} \
1491573Srgrimes	-warn-common -export-dynamic -dynamic-linker /red/herring \
15017780Smpp	-o ${.TARGET} -X ${SYSTEM_OBJS} vers.o
1511573SrgrimesSYSTEM_LD_TAIL= @${OBJCOPY} --strip-symbol gcc2_compiled. ${.TARGET} ; \
1521573Srgrimes	${SIZE} ${.TARGET} ; chmod 755 ${.TARGET}
1531573SrgrimesSYSTEM_DEP+= ${LDSCRIPT}
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