Introduce a new make variable COMPILER_TYPE that specifies what

type of compiler is being used (currently clang or gcc).  COMPILER_TYPE
is set in the new bsd.compiler.mk file based on the value of the CC
variable or, should it prove informative, by running ${CC} --version
and examining the output.

To avoid negative performance impacts in the default case and correct
value for COMPILER_TYPE type is determined and passed in the environment
of submake instances while building world.

Replace adhoc attempts at determining the compiler type by examining
CC or MK_CLANG_IS_CC with checks of COMPILER_TYPE.  This eliminates
bootstrapping complications when first setting WITH_CLANG_IS_CC.

Sponsored by:	DARPA, AFRL
Reviewed by:	Yamaya Takashi <yamayan@kbh.biglobe.ne.jp>, imp, linimon
		(with some modifications post review)
MFC after:	2 weeks
This commit is contained in:
brooks 2012-09-13 16:00:46 +00:00
parent 1e4174de1a
commit f17cb55447
7 changed files with 59 additions and 24 deletions

View File

@ -46,6 +46,7 @@ TARGET_ARCH=${TARGET}
.include <bsd.own.mk> .include <bsd.own.mk>
.include <bsd.arch.inc.mk> .include <bsd.arch.inc.mk>
.include <bsd.compiler.mk>
# We must do share/info early so that installation of info `dir' # We must do share/info early so that installation of info `dir'
# entries works correctly. Do it first since it is less likely to # entries works correctly. Do it first since it is less likely to
@ -235,7 +236,8 @@ BMAKEENV= INSTALL="sh ${.CURDIR}/tools/install.sh" \
PATH=${BPATH}:${PATH} \ PATH=${BPATH}:${PATH} \
WORLDTMP=${WORLDTMP} \ WORLDTMP=${WORLDTMP} \
VERSION="${VERSION}" \ VERSION="${VERSION}" \
MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}" MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}" \
COMPILER_TYPE=${COMPILER_TYPE}
BMAKE= MAKEOBJDIRPREFIX=${WORLDTMP} \ BMAKE= MAKEOBJDIRPREFIX=${WORLDTMP} \
${BMAKEENV} ${MAKE} -f Makefile.inc1 \ ${BMAKEENV} ${MAKE} -f Makefile.inc1 \
DESTDIR= \ DESTDIR= \
@ -270,6 +272,16 @@ WMAKEENV= ${CROSSENV} \
.if ${MK_CDDL} == "no" .if ${MK_CDDL} == "no"
WMAKEENV+= NO_CTF=1 WMAKEENV+= NO_CTF=1
.endif .endif
.if ${CC:T:Mgcc} == "gcc"
WMAKE_COMPILER_TYPE= gcc
.elif ${CC:T:Mclang} == "clang"
WMAKE_COMPILER_TYPE= clang
.elif ${MK_CLANG_IS_CC} == "no"
WMAKE_COMPILER_TYPE= gcc
.else
WMAKE_COMPILER_TYPE= clang
.endif
WMAKEENV+= COMPILER_TYPE=${WMAKE_COMPILER_TYPE}
WMAKE= ${WMAKEENV} ${MAKE} -f Makefile.inc1 DESTDIR=${WORLDTMP} WMAKE= ${WMAKEENV} ${MAKE} -f Makefile.inc1 DESTDIR=${WORLDTMP}
.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "powerpc64" .if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "powerpc64"
@ -313,7 +325,8 @@ LIB32WMAKEENV+= MAKEOBJDIRPREFIX=${OBJTREE}/lib32 \
CC="${CC} ${LIB32FLAGS}" \ CC="${CC} ${LIB32FLAGS}" \
CXX="${CXX} ${LIB32FLAGS}" \ CXX="${CXX} ${LIB32FLAGS}" \
LIBDIR=/usr/lib32 \ LIBDIR=/usr/lib32 \
SHLIBDIR=/usr/lib32 SHLIBDIR=/usr/lib32 \
COMPILER_TYPE=${WMAKE_COMPILER_TYPE}
LIB32WMAKE= ${LIB32WMAKEENV} ${MAKE} -DNO_CPU_CFLAGS -DCOMPAT_32BIT \ LIB32WMAKE= ${LIB32WMAKEENV} ${MAKE} -DNO_CPU_CFLAGS -DCOMPAT_32BIT \
-DWITHOUT_BIND -DWITHOUT_MAN -DWITHOUT_INFO \ -DWITHOUT_BIND -DWITHOUT_MAN -DWITHOUT_INFO \

View File

@ -3,7 +3,8 @@
FILES= bsd.README FILES= bsd.README
FILES+= bsd.arch.inc.mk FILES+= bsd.arch.inc.mk
FILES+= bsd.compat.mk bsd.cpu.mk bsd.dep.mk bsd.doc.mk bsd.dtrace.mk FILES+= bsd.compat.mk bsd.compiler.mk bsd.cpu.mk
FILES+= bsd.dep.mk bsd.doc.mk bsd.dtrace.mk
FILES+= bsd.endian.mk FILES+= bsd.endian.mk
FILES+= bsd.files.mk bsd.crunchgen.mk bsd.incs.mk bsd.info.mk bsd.init.mk FILES+= bsd.files.mk bsd.crunchgen.mk bsd.incs.mk bsd.info.mk bsd.init.mk
FILES+= bsd.kmod.mk FILES+= bsd.kmod.mk

21
share/mk/bsd.compiler.mk Normal file
View File

@ -0,0 +1,21 @@
# $FreeBSD$
.if !defined(COMPILER_TYPE)
. if ${CC:T:Mgcc} == "gcc"
COMPILER_TYPE:= gcc
. elif ${CC:T:Mclang} == "clang"
COMPILER_TYPE:= clang
. else
_COMPILER_VERSION!= ${CC} --version
. if ${_COMPILER_VERSION:Mgcc} == "gcc"
COMPILER_TYPE:= gcc
. elif ${_COMPILER_VERSION:M\(GCC\)} == "(GCC)"
COMPILER_TYPE:= gcc
. elif ${_COMPILER_VERSION:Mclang} == "clang"
COMPILER_TYPE:= clang
. else
.error Unable to determing compiler type for ${CC}
. endif
. undef _COMPILER_VERSION
. endif
.endif

View File

@ -8,6 +8,8 @@
# for GCC: http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Warning-Options.html # for GCC: http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Warning-Options.html
.include <bsd.compiler.mk>
# the default is gnu99 for now # the default is gnu99 for now
CSTD?= gnu99 CSTD?= gnu99
@ -28,8 +30,8 @@ CFLAGS+= -std=${CSTD}
.if defined(WARNS) .if defined(WARNS)
.if ${WARNS} >= 1 .if ${WARNS} >= 1
CWARNFLAGS+= -Wsystem-headers CWARNFLAGS+= -Wsystem-headers
.if !defined(NO_WERROR) && ((${MK_CLANG_IS_CC} == "no" && \ .if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \
${CC:T:Mclang} != "clang") || !defined(NO_WERROR.clang)) || !defined(NO_WERROR.clang))
CWARNFLAGS+= -Werror CWARNFLAGS+= -Werror
.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang) .endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang)
.endif # WARNS >= 1 .endif # WARNS >= 1
@ -43,8 +45,8 @@ CWARNFLAGS+= -W -Wno-unused-parameter -Wstrict-prototypes\
.if ${WARNS} >= 4 .if ${WARNS} >= 4
CWARNFLAGS+= -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow\ CWARNFLAGS+= -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow\
-Wunused-parameter -Wunused-parameter
.if !defined(NO_WCAST_ALIGN) && ((${MK_CLANG_IS_CC} == "no" && \ .if !defined(NO_WCAST_ALIGN) && (${COMPILER_TYPE} != "clang" \
${CC:T:Mclang} != "clang") || !defined(NO_WCAST_ALIGN.clang)) || !defined(NO_WCAST_ALIGN.clang))
CWARNFLAGS+= -Wcast-align CWARNFLAGS+= -Wcast-align
.endif # !NO_WCAST_ALIGN && (!CLANG || !NO_WCAST_ALIGN.clang) .endif # !NO_WCAST_ALIGN && (!CLANG || !NO_WCAST_ALIGN.clang)
.endif # WARNS >= 4 .endif # WARNS >= 4
@ -61,8 +63,7 @@ CWARNFLAGS+= -Wno-uninitialized
CWARNFLAGS+= -Wno-pointer-sign CWARNFLAGS+= -Wno-pointer-sign
# Clang has more warnings enabled by default, and when using -Wall, so if WARNS # Clang has more warnings enabled by default, and when using -Wall, so if WARNS
# is set to low values, these have to be disabled explicitly. # is set to low values, these have to be disabled explicitly.
.if (${MK_CLANG_IS_CC} != "no" || ${CC:T:Mclang} == "clang") && \ .if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD)
!defined(EARLY_BUILD)
.if ${WARNS} <= 6 .if ${WARNS} <= 6
CWARNFLAGS+= -Wno-empty-body -Wno-string-plus-int CWARNFLAGS+= -Wno-empty-body -Wno-string-plus-int
.endif # WARNS <= 6 .endif # WARNS <= 6
@ -89,20 +90,18 @@ WFORMAT= 1
.if ${WFORMAT} > 0 .if ${WFORMAT} > 0
#CWARNFLAGS+= -Wformat-nonliteral -Wformat-security -Wno-format-extra-args #CWARNFLAGS+= -Wformat-nonliteral -Wformat-security -Wno-format-extra-args
CWARNFLAGS+= -Wformat=2 -Wno-format-extra-args CWARNFLAGS+= -Wformat=2 -Wno-format-extra-args
.if (${MK_CLANG_IS_CC} != "no" || ${CC:T:Mclang} == "clang") && \ .if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD)
!defined(EARLY_BUILD)
.if ${WARNS} <= 3 .if ${WARNS} <= 3
CWARNFLAGS+= -Wno-format-nonliteral CWARNFLAGS+= -Wno-format-nonliteral
.endif # WARNS <= 3 .endif # WARNS <= 3
.endif # CLANG .endif # CLANG
.if !defined(NO_WERROR) && ((${MK_CLANG_IS_CC} == "no" && \ .if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \
${CC:T:Mclang} != "clang") || !defined(NO_WERROR.clang)) || !defined(NO_WERROR.clang))
CWARNFLAGS+= -Werror CWARNFLAGS+= -Werror
.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang) .endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang)
.endif # WFORMAT > 0 .endif # WFORMAT > 0
.endif # WFORMAT .endif # WFORMAT
.if defined(NO_WFORMAT) || ((${MK_CLANG_IS_CC} != "no" || \ .if defined(NO_WFORMAT) || (${COMPILER_TYPE} == "clang" && defined(NO_WFORMAT.clang))
${CC:T:Mclang} == "clang") && defined(NO_WFORMAT.clang))
CWARNFLAGS+= -Wno-format CWARNFLAGS+= -Wno-format
.endif # NO_WFORMAT || (CLANG && NO_WFORMAT.clang) .endif # NO_WFORMAT || (CLANG && NO_WFORMAT.clang)
.endif # !NO_WARNS .endif # !NO_WARNS
@ -111,8 +110,7 @@ CWARNFLAGS+= -Wno-format
CWARNFLAGS+= -Wno-unknown-pragmas CWARNFLAGS+= -Wno-unknown-pragmas
.endif # IGNORE_PRAGMA .endif # IGNORE_PRAGMA
.if (${MK_CLANG_IS_CC} != "no" || ${CC:T:Mclang} == "clang") && \ .if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD)
!defined(EARLY_BUILD)
CLANG_NO_IAS= -no-integrated-as CLANG_NO_IAS= -no-integrated-as
CLANG_OPT_SMALL= -mstack-alignment=8 -mllvm -inline-threshold=3\ CLANG_OPT_SMALL= -mstack-alignment=8 -mllvm -inline-threshold=3\
-mllvm -enable-load-pre=false -mllvm -simplifycfg-dup-ret -mllvm -enable-load-pre=false -mllvm -simplifycfg-dup-ret

View File

@ -15,7 +15,7 @@ CWARNFLAGS?= -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes \
# Disable a few warnings for clang, since there are several places in the # Disable a few warnings for clang, since there are several places in the
# kernel where fixing them is more trouble than it is worth, or where there is # kernel where fixing them is more trouble than it is worth, or where there is
# a false positive. # a false positive.
.if ${MK_CLANG_IS_CC} != "no" || ${CC:T:Mclang} == "clang" .if ${COMPILER_TYPE} == "clang"
NO_WCONSTANT_CONVERSION= -Wno-constant-conversion NO_WCONSTANT_CONVERSION= -Wno-constant-conversion
NO_WARRAY_BOUNDS= -Wno-array-bounds NO_WARRAY_BOUNDS= -Wno-array-bounds
NO_WSHIFT_COUNT_NEGATIVE= -Wno-shift-count-negative NO_WSHIFT_COUNT_NEGATIVE= -Wno-shift-count-negative
@ -52,7 +52,7 @@ CWARNEXTRA?= -Wno-error-tautological-compare -Wno-error-empty-body \
# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42
# #
.if ${MACHINE_CPUARCH} == "i386" .if ${MACHINE_CPUARCH} == "i386"
.if ${MK_CLANG_IS_CC} == "no" && ${CC:T:Mclang} != "clang" .if ${COMPILER_TYPE} != "clang"
CFLAGS+= -mno-align-long-strings -mpreferred-stack-boundary=2 CFLAGS+= -mno-align-long-strings -mpreferred-stack-boundary=2
.else .else
CFLAGS+= -mno-aes -mno-avx CFLAGS+= -mno-aes -mno-avx
@ -100,7 +100,7 @@ INLINE_LIMIT?= 15000
# (-mfpmath= is not supported) # (-mfpmath= is not supported)
# #
.if ${MACHINE_CPUARCH} == "amd64" .if ${MACHINE_CPUARCH} == "amd64"
.if ${MK_CLANG_IS_CC} != "no" || ${CC:T:Mclang} == "clang" .if ${COMPILER_TYPE} == "clang"
CFLAGS+= -mno-aes -mno-avx CFLAGS+= -mno-aes -mno-avx
.endif .endif
CFLAGS+= -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float \ CFLAGS+= -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float \

View File

@ -4,6 +4,7 @@
# of the definitions that need to be before %BEFORE_DEPEND. # of the definitions that need to be before %BEFORE_DEPEND.
.include <bsd.own.mk> .include <bsd.own.mk>
.include <bsd.compiler.mk>
# backwards compat option for older systems. # backwards compat option for older systems.
MACHINE_CPUARCH?=${MACHINE_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb)?/arm/:C/powerpc64/powerpc/} MACHINE_CPUARCH?=${MACHINE_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb)?/arm/:C/powerpc64/powerpc/}
@ -35,7 +36,7 @@ _MINUS_O= -O2
.endif .endif
.endif .endif
.if ${MACHINE_CPUARCH} == "amd64" .if ${MACHINE_CPUARCH} == "amd64"
.if ${MK_CLANG_IS_CC} == "no" && ${CC:T:Mclang} != "clang" .if ${COMPILER_TYPE} != "clang"
COPTFLAGS?=-O2 -frename-registers -pipe COPTFLAGS?=-O2 -frename-registers -pipe
.else .else
COPTFLAGS?=-O2 -pipe COPTFLAGS?=-O2 -pipe
@ -85,7 +86,7 @@ INCLUDES+= -I$S/dev/cxgb -I$S/dev/cxgbe
CFLAGS= ${COPTFLAGS} ${C_DIALECT} ${DEBUG} ${CWARNFLAGS} CFLAGS= ${COPTFLAGS} ${C_DIALECT} ${DEBUG} ${CWARNFLAGS}
CFLAGS+= ${INCLUDES} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h CFLAGS+= ${INCLUDES} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h
.if ${MK_CLANG_IS_CC} == "no" && ${CC:T:Mclang} != "clang" .if ${COMPILER_TYPE} != "clang"
CFLAGS+= -fno-common -finline-limit=${INLINE_LIMIT} CFLAGS+= -fno-common -finline-limit=${INLINE_LIMIT}
.if ${MACHINE_CPUARCH} != "mips" .if ${MACHINE_CPUARCH} != "mips"
CFLAGS+= --param inline-unit-growth=100 CFLAGS+= --param inline-unit-growth=100
@ -102,7 +103,7 @@ WERROR?= -Werror
# XXX LOCORE means "don't declare C stuff" not "for locore.s". # XXX LOCORE means "don't declare C stuff" not "for locore.s".
ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS} ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS}
.if ${MK_CLANG_IS_CC} != "no" || ${CC:T:Mclang} == "clang" .if ${COMPILER_TYPE} == "clang"
CLANG_NO_IAS= -no-integrated-as CLANG_NO_IAS= -no-integrated-as
.endif .endif

View File

@ -73,6 +73,7 @@ OBJCOPY?= objcopy
.endif .endif
.include <bsd.init.mk> .include <bsd.init.mk>
.include <bsd.compiler.mk>
.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S .SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
@ -108,7 +109,7 @@ CFLAGS+= -I. -I@
# for example. # for example.
CFLAGS+= -I@/contrib/altq CFLAGS+= -I@/contrib/altq
.if ${MK_CLANG_IS_CC} == "no" && ${CC:T:Mclang} != "clang" .if ${COMPILER_TYPE} != "clang"
CFLAGS+= -finline-limit=${INLINE_LIMIT} CFLAGS+= -finline-limit=${INLINE_LIMIT}
CFLAGS+= --param inline-unit-growth=100 CFLAGS+= --param inline-unit-growth=100
CFLAGS+= --param large-function-growth=1000 CFLAGS+= --param large-function-growth=1000