kern.pre.mk revision 149978
11573Srgrimes# $FreeBSD: head/sys/conf/kern.pre.mk 149978 2005-09-11 07:33:43Z obrien $
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# Can be overridden by makeoptions or /etc/make.conf
71573SrgrimesKERNEL_KO?=	kernel
81573SrgrimesKERNEL?=	kernel
91573SrgrimesKODIR?=		/boot/${KERNEL}
101573Srgrimes
111573SrgrimesM=	${MACHINE_ARCH}
121573Srgrimes
131573SrgrimesAWK?=		awk
141573SrgrimesLINT?=		lint
151573SrgrimesNM?=		nm
161573SrgrimesOBJCOPY?=	objcopy
171573SrgrimesSIZE?=		size
181573Srgrimes
191573Srgrimes.if ${CC} == "icc"
201573SrgrimesCOPTFLAGS?=	-O
211573Srgrimes.else
221573Srgrimes. if defined(DEBUG)
231573Srgrimes_MINUS_O=	-O
241573Srgrimes. else
251573Srgrimes_MINUS_O=	-O2
261573Srgrimes. endif
271573Srgrimes. if ${MACHINE_ARCH} == "amd64"
281573SrgrimesCOPTFLAGS?=-O2 -frename-registers -pipe
291573Srgrimes. else
301573SrgrimesCOPTFLAGS?=${_MINUS_O} -pipe
311573Srgrimes. endif
321573Srgrimes. if !empty(COPTFLAGS:M-O[23s]) && empty(COPTFLAGS:M-fno-strict-aliasing)
331573SrgrimesCOPTFLAGS+= -fno-strict-aliasing
341573Srgrimes. endif
351573Srgrimes.endif
361573Srgrimes.if !defined(NO_CPU_COPTFLAGS)
371573Srgrimes. if ${CC} == "icc"
3862232SdcsCOPTFLAGS+= ${_ICC_CPUCFLAGS:C/(-x[^M^K^W]+)[MKW]+|-x[MKW]+/\1/}
3962232Sdcs. else
401573SrgrimesCOPTFLAGS+= ${_CPUCFLAGS}
411573Srgrimes. endif
421573Srgrimes.endif
431573Srgrimes.if ${CC} == "icc"
441573SrgrimesNOSTDINC= -X
451573Srgrimes.else
461573SrgrimesNOSTDINC= -nostdinc
471573Srgrimes.endif
481573Srgrimes
491573SrgrimesINCLUDES= ${NOSTDINC} -I- ${INCLMAGIC} -I. -I$S
501573Srgrimes
511573Srgrimes# This hack lets us use the Intel ACPICA code without spamming a new
521573Srgrimes# include path into 100+ source files.
531573SrgrimesINCLUDES+= -I$S/contrib/dev/acpica
541573Srgrimes
551573Srgrimes# ... and the same for altq
561573SrgrimesINCLUDES+= -I$S/contrib/altq
571573Srgrimes
581573Srgrimes# ... and the same for Atheros HAL when the author builds it from
591573Srgrimes#     non-distributable sources.
601573Srgrimes.if defined(ATH_BUILDING_FROM_SOURCE)
611573SrgrimesINCLUDES+= -I$S/contrib/dev/ath
621573Srgrimes.endif
631573Srgrimes
641573Srgrimes.if make(depend) || make(kernel-depend)
651573Srgrimes
661573Srgrimes# ... and the same for ipfilter
671573SrgrimesINCLUDES+= -I$S/contrib/ipfilter
681573Srgrimes
691573Srgrimes# ... and the same for pf
701573SrgrimesINCLUDES+= -I$S/contrib/pf
711573Srgrimes
721573Srgrimes# ... and the same for Atheros HAL
731573SrgrimesINCLUDES+= -I$S/contrib/dev/ath/freebsd
741573Srgrimes
751573Srgrimes# ... and the same for the NgATM stuff
761573SrgrimesINCLUDES+= -I$S/contrib/ngatm
771573Srgrimes
781573Srgrimes# .. and the same for twa
791573SrgrimesINCLUDES+= -I$S/dev/twa
801573Srgrimes
811573Srgrimes.endif
821573Srgrimes
831573SrgrimesCFLAGS=	${COPTFLAGS} ${CWARNFLAGS} ${DEBUG}
841573SrgrimesCFLAGS+= ${INCLUDES} -D_KERNEL -include opt_global.h
851573Srgrimes.if ${CC} != "icc"
861573SrgrimesCFLAGS+= -fno-common -finline-limit=${INLINE_LIMIT}
871573SrgrimesCFLAGS+= --param inline-unit-growth=100
881573SrgrimesCFLAGS+= --param large-function-growth=1000
891573SrgrimesWERROR?= -Werror
901573Srgrimes.endif
911573Srgrimes
921573Srgrimes# XXX LOCORE means "don't declare C stuff" not "for locore.s".
931573SrgrimesASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS}
941573Srgrimes
951573Srgrimes.if defined(PROFLEVEL) && ${PROFLEVEL} >= 1
961573Srgrimes.if ${CC} == "icc"
971573Srgrimes.error Profiling doesn't work with ICC yet.
981573Srgrimes.else
991573SrgrimesCFLAGS+=	-DGPROF -falign-functions=16
1001573Srgrimes.endif
1011573Srgrimes.if ${PROFLEVEL} >= 2
1021573SrgrimesCFLAGS+=	-DGPROF4 -DGUPROF
1031573Srgrimes. if ${CC} == "icc"
1041573Srgrimes# XXX doesn't work yet
1051573Srgrimes#PROF=	-prof_gen
1061573Srgrimes. else
1071573SrgrimesPROF=	-finstrument-functions -Wno-inline
1081573Srgrimes. endif
1091573Srgrimes.else
1101573Srgrimes. if ${CC} == "icc"
1111573SrgrimesPROF=	-p
1121573Srgrimes. else
1131573SrgrimesPROF=	-pg
1141573Srgrimes. endif
1151573Srgrimes.endif
1161573Srgrimes.endif
1171573SrgrimesDEFINED_PROF=	${PROF}
1181573Srgrimes
1191573Srgrimes# Put configuration-specific C flags last (except for ${PROF}) so that they
1201573Srgrimes# can override the others.
1211573SrgrimesCFLAGS+=	${CONF_CFLAGS}
1221573Srgrimes
1231573Srgrimes# Optional linting. This can be overridden in /etc/make.conf.
1241573SrgrimesLINTFLAGS=	${LINTOBJKERNFLAGS}
1251573Srgrimes
1261573SrgrimesNORMAL_C= ${CC} -c ${CFLAGS} ${WERROR} ${PROF} ${.IMPSRC}
1271573SrgrimesNORMAL_S= ${CC} -c ${ASM_CFLAGS} ${WERROR} ${.IMPSRC}
1281573SrgrimesPROFILE_C= ${CC} -c ${CFLAGS} ${WERROR} ${.IMPSRC}
1291573SrgrimesNORMAL_C_NOWERROR= ${CC} -c ${CFLAGS} ${PROF} ${.IMPSRC}
1301573Srgrimes
1311573SrgrimesNORMAL_M= ${AWK} -f $S/tools/makeobjops.awk ${.IMPSRC} -c ; \
1321573Srgrimes	  ${CC} -c ${CFLAGS} ${WERROR} ${PROF} ${.PREFIX}.c
1331573Srgrimes
1341573SrgrimesNORMAL_LINT=	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC}
1351573Srgrimes
1361573SrgrimesGEN_CFILES= $S/$M/$M/genassym.c ${MFILES:T:S/.m$/.c/}
1371573SrgrimesSYSTEM_CFILES= config.c env.c hints.c vnode_if.c
1381573SrgrimesSYSTEM_DEP= Makefile ${SYSTEM_OBJS}
1391573SrgrimesSYSTEM_OBJS= locore.o ${MDOBJS} ${OBJS}
1401573SrgrimesSYSTEM_OBJS+= ${SYSTEM_CFILES:.c=.o}
1411573SrgrimesSYSTEM_OBJS+= hack.So
1421573SrgrimesSYSTEM_LD= @${LD} -Bdynamic -T $S/conf/ldscript.$M \
1431573Srgrimes	-warn-common -export-dynamic -dynamic-linker /red/herring \
1441573Srgrimes	-o ${.TARGET} -X ${SYSTEM_OBJS} vers.o
1451573SrgrimesSYSTEM_LD_TAIL= @${OBJCOPY} --strip-symbol gcc2_compiled. ${.TARGET} ; \
1461573Srgrimes	${SIZE} ${.TARGET} ; chmod 755 ${.TARGET}
1471573SrgrimesSYSTEM_DEP+= $S/conf/ldscript.$M
1481573Srgrimes
1491573Srgrimes# MKMODULESENV is set here so that port makefiles can augment
1501573Srgrimes# them.
1511573Srgrimes
1521573SrgrimesMKMODULESENV=	MAKEOBJDIRPREFIX=${.OBJDIR}/modules KMODDIR=${KODIR}
15317141Sjkh.if (${KERN_IDENT} == LINT)
15417141SjkhMKMODULESENV+=	ALL_MODULES=LINT
1551573Srgrimes.endif
1561573Srgrimes.if defined(MODULES_OVERRIDE)
15762232SdcsMKMODULESENV+=	MODULES_OVERRIDE="${MODULES_OVERRIDE}"
15862232Sdcs.endif
15962232Sdcs.if defined(DEBUG)
16062232SdcsMKMODULESENV+=	DEBUG_FLAGS="${DEBUG}"
16162232Sdcs.endif
16262232Sdcs