build: do full flag handling for all compiler-type tools

This adds a full identification probe of CC, AS, LD and HOSTCC,
and sets up correct flags and dependency tracking for each.

Signed-off-by: Mans Rullgard <mans@mansr.com>
This commit is contained in:
Mans Rullgard 2012-07-20 13:43:07 +01:00
parent 02ac28229a
commit a758c5e259
2 changed files with 182 additions and 123 deletions

View File

@ -11,7 +11,7 @@ ifndef V
Q = @ Q = @
ECHO = printf "$(1)\t%s\n" $(2) ECHO = printf "$(1)\t%s\n" $(2)
BRIEF = CC AS YASM AR LD HOSTCC BRIEF = CC AS YASM AR LD HOSTCC
SILENT = DEPCC YASMDEP RM RANLIB SILENT = DEPCC DEPAS DEPHOSTCC YASMDEP RM RANLIB
MSG = $@ MSG = $@
M = @$(call ECHO,$(TAG),$@); M = @$(call ECHO,$(TAG),$@);
$(foreach VAR,$(BRIEF), \ $(foreach VAR,$(BRIEF), \
@ -25,14 +25,15 @@ ALLFFLIBS = avcodec avdevice avfilter avformat avresample avutil swscale
IFLAGS := -I. -I$(SRC_PATH) IFLAGS := -I. -I$(SRC_PATH)
CPPFLAGS := $(IFLAGS) $(CPPFLAGS) CPPFLAGS := $(IFLAGS) $(CPPFLAGS)
CFLAGS += $(ECFLAGS) CFLAGS += $(ECFLAGS)
CCFLAGS = $(CFLAGS) CCFLAGS = $(CPPFLAGS) $(CFLAGS)
ASFLAGS := $(CPPFLAGS) $(ASFLAGS)
YASMFLAGS += $(IFLAGS) -I$(SRC_PATH)/libavutil/x86/ -Pconfig.asm YASMFLAGS += $(IFLAGS) -I$(SRC_PATH)/libavutil/x86/ -Pconfig.asm
HOSTCFLAGS += $(IFLAGS) HOSTCFLAGS += $(IFLAGS)
LDFLAGS := $(ALLFFLIBS:%=-Llib%) $(LDFLAGS) LDFLAGS := $(ALLFFLIBS:%=-Llib%) $(LDFLAGS)
define COMPILE define COMPILE
$($(1)DEP) $(call $(1)DEP,$(1))
$($(1)) $(CPPFLAGS) $($(1)FLAGS) $($(1)_DEPFLAGS) -c $($(1)_O) $< $($(1)) $($(1)FLAGS) $($(1)_DEPFLAGS) -c $($(1)_O) $<
endef endef
COMPILE_C = $(call COMPILE,CC) COMPILE_C = $(call COMPILE,CC)

296
configure vendored
View File

@ -1731,6 +1731,8 @@ ldflags_filter=echo
AS_O='-o $@' AS_O='-o $@'
CC_O='-o $@' CC_O='-o $@'
LD_O='-o $@'
HOSTCC_O='-o $@'
host_cflags='-D_ISOC99_SOURCE -D_XOPEN_SOURCE=600 -O3 -g' host_cflags='-D_ISOC99_SOURCE -D_XOPEN_SOURCE=600 -O3 -g'
host_libs='-lm' host_libs='-lm'
@ -1741,8 +1743,8 @@ target_path='$(CURDIR)'
# since the object filename is not given with the -MM flag, the compiler # since the object filename is not given with the -MM flag, the compiler
# is only able to print the basename, and we must add the path ourselves # is only able to print the basename, and we must add the path ourselves
DEPEND_CMD='$(DEPCC) $(DEPFLAGS) $< | sed -e "/^\#.*/d" -e "s,^[[:space:]]*$(*F)\\.o,$(@D)/$(*F).o," > $(@:.o=.d)' DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< | sed -e "/^\#.*/d" -e "s,^[[:space:]]*$(*F)\\.o,$(@D)/$(*F).o," > $(@:.o=.d)'
DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -MM' DEPFLAGS='-MM'
# find source path # find source path
if test -f configure; then if test -f configure; then
@ -2042,120 +2044,150 @@ tms470_flags(){
done done
} }
if $cc -v 2>&1 | grep -q '^gcc.*LLVM'; then probe_cc(){
cc_type=llvm_gcc pfx=$1
gcc_extra_ver=$(expr "$($cc --version | head -n1)" : '.*\((.*)\)') _cc=$2
cc_ident="llvm-gcc $($cc -dumpversion) $gcc_extra_ver"
CC_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@' unset _type _ident _cc_o _flags _cflags _ldflags _depflags _DEPCMD _DEPFLAGS
AS_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@' _flags_filter=echo
cflags_speed='-O3'
cflags_size='-Os' if $_cc -v 2>&1 | grep -q '^gcc.*LLVM'; then
elif $cc -v 2>&1 | grep -qi ^gcc; then _type=llvm_gcc
cc_type=gcc gcc_extra_ver=$(expr "$($_cc --version | head -n1)" : '.*\((.*)\)')
gcc_version=$($cc --version | head -n1) _ident="llvm-gcc $($_cc -dumpversion) $gcc_extra_ver"
gcc_basever=$($cc -dumpversion) _depflags='-MMD -MF $(@:.o=.d) -MT $@'
gcc_pkg_ver=$(expr "$gcc_version" : '[^ ]* \(([^)]*)\)') _cflags_speed='-O3'
gcc_ext_ver=$(expr "$gcc_version" : ".*$gcc_pkg_ver $gcc_basever \\(.*\\)") _cflags_size='-Os'
cc_ident=$(cleanws "gcc $gcc_basever $gcc_pkg_ver $gcc_ext_ver") elif $_cc -v 2>&1 | grep -qi ^gcc; then
if ! $cc -dumpversion | grep -q '^2\.'; then _type=gcc
CC_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@' gcc_version=$($_cc --version | head -n1)
AS_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@' gcc_basever=$($_cc -dumpversion)
gcc_pkg_ver=$(expr "$gcc_version" : '[^ ]* \(([^)]*)\)')
gcc_ext_ver=$(expr "$gcc_version" : ".*$gcc_pkg_ver $gcc_basever \\(.*\\)")
_ident=$(cleanws "gcc $gcc_basever $gcc_pkg_ver $gcc_ext_ver")
if ! $_cc -dumpversion | grep -q '^2\.'; then
_depflags='-MMD -MF $(@:.o=.d) -MT $@'
fi
_cflags_speed='-O3'
_cflags_size='-Os'
elif $_cc --version 2>/dev/null | grep -q Intel; then
_type=icc
_ident=$($_cc --version | head -n1)
_depflags='-MMD'
_cflags_speed='-O3'
_cflags_size='-Os'
_cflags_noopt='-O1'
elif $_cc -v 2>&1 | grep -q xlc; then
_type=xlc
_ident=$($_cc -qversion 2>/dev/null | head -n1)
_cflags_speed='-O5'
_cflags_size='-O5 -qcompact'
elif $_cc -V 2>/dev/null | grep -q Compaq; then
_type=ccc
_ident=$($_cc -V | head -n1 | cut -d' ' -f1-3)
_DEPFLAGS='-M'
debuglevel=3
_ldflags='-Wl,-z,now' # calls to libots crash without this
_cflags_speed='-fast'
_cflags_size='-O1'
elif $_cc --vsn 2>/dev/null | grep -q "ARM C/C++ Compiler"; then
test -d "$sysroot" || die "No valid sysroot specified."
_type=armcc
_ident=$($_cc --vsn | head -n1)
armcc_conf="$PWD/armcc.conf"
$_cc --arm_linux_configure \
--arm_linux_config_file="$armcc_conf" \
--configure_sysroot="$sysroot" \
--configure_cpp_headers="$sysinclude" >>$logfile 2>&1 ||
die "Error creating armcc configuration file."
$_cc --vsn | grep -q RVCT && armcc_opt=rvct || armcc_opt=armcc
_flags="--arm_linux_config_file=$armcc_conf --translate_gcc"
as_default="${cross_prefix}gcc"
_depflags='-MMD'
_cflags_speed='-O3'
_cflags_size='-Os'
elif $_cc -version 2>/dev/null | grep -q TMS470; then
_type=tms470
_ident=$($_cc -version | head -n1 | tr -s ' ')
_flags='--gcc --abi=eabi -me'
_cflags='-D__gnuc_va_list=va_list -D__USER_LABEL_PREFIX__='
_cc_o='-fe=$@'
as_default="${cross_prefix}gcc"
ld_default="${cross_prefix}gcc"
_depflags='-ppa -ppd=$(@:.o=.d)'
_cflags_speed='-O3 -mf=5'
_cflags_size='-O3 -mf=2'
_flags_filter=tms470_flags
elif $_cc -v 2>&1 | grep -q clang; then
_type=clang
_ident=$($_cc --version | head -n1)
_depflags='-MMD'
_cflags_speed='-O3'
_cflags_size='-Os'
elif $_cc -V 2>&1 | grep -q Sun; then
_type=suncc
_ident=$($_cc -V 2>&1 | head -n1 | cut -d' ' -f 2-)
_DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< | sed -e "1s,^.*: ,$@: ," -e "\$$!s,\$$, \\\," -e "1!s,^.*: , ," > $(@:.o=.d)'
_DEPFLAGS='-xM1'
_ldflags='-std=c99'
_cflags_speed='-O5'
_cflags_size='-O5 -xspace'
_flags_filter=suncc_flags
elif $_cc -v 2>&1 | grep -q 'PathScale\|Path64'; then
_type=pathscale
_ident=$($_cc -v 2>&1 | head -n1 | tr -d :)
_depflags='-MMD -MF $(@:.o=.d) -MT $@'
_cflags_speed='-O2'
_cflags_size='-Os'
_flags_filter='filter_out -Wdisabled-optimization'
elif $_cc -v 2>&1 | grep -q Open64; then
_type=open64
_ident=$($_cc -v 2>&1 | head -n1 | tr -d :)
_depflags='-MMD -MF $(@:.o=.d) -MT $@'
_cflags_speed='-O2'
_cflags_size='-Os'
_flags_filter='filter_out -Wdisabled-optimization|-Wtype-limits|-fno-signed-zeros'
elif $_cc -V 2>&1 | grep -q Portland; then
_type=pgi
_ident="PGI $($_cc -V 2>&1 | awk '/^pgcc/ { print $2; exit }')"
opt_common='-alias=ansi -Mlre -Mpre'
_cflags_speed="-O3 -Mautoinline -Munroll=c:4 $opt_common"
_cflags_size="-O2 -Munroll=c:1 $opt_common"
_cflags_noopt="-O1"
_flags_filter=pgi_flags
fi fi
cflags_speed='-O3'
cflags_size='-Os' eval ${pfx}_type=\$_type
elif $cc --version 2>/dev/null | grep -q Intel; then eval ${pfx}_ident=\$_ident
cc_type=icc }
cc_ident=$($cc --version | head -n1)
CC_DEPFLAGS='-MMD' set_ccvars(){
AS_DEPFLAGS='-MMD' eval ${1}_O=\${_cc_o-\${${1}_O}}
cflags_speed='-O3'
cflags_size='-Os' if [ -n "$_depflags" ]; then
cflags_noopt='-O1' eval ${1}_DEPFLAGS=\$_depflags
elif $cc -v 2>&1 | grep -q xlc; then else
cc_type=xlc eval ${1}DEP=\${_DEPCMD:-\$DEPCMD}
cc_ident=$($cc -qversion 2>/dev/null | head -n1) eval ${1}DEP_FLAGS=\${_DEPFLAGS:-\$DEPFLAGS}
cflags_speed='-O5' eval DEP${1}FLAGS=\$_flags
cflags_size='-O5 -qcompact' fi
elif $cc -V 2>/dev/null | grep -q Compaq; then }
cc_type=ccc
cc_ident=$($cc -V | head -n1 | cut -d' ' -f1-3) probe_cc cc "$cc"
DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -M' cflags_filter=$_flags_filter
debuglevel=3 cflags_speed=$_cflags_speed
add_ldflags -Wl,-z,now # calls to libots crash without this cflags_size=$_cflags_size
cflags_speed='-fast' cflags_noopt=$_cflags_noopt
cflags_size='-O1' add_cflags $_flags $_cflags
elif $cc --vsn 2>/dev/null | grep -q "ARM C/C++ Compiler"; then cc_ldflags=$_ldflags
test -d "$sysroot" || die "No valid sysroot specified." set_ccvars CC
cc_type=armcc
cc_ident=$($cc --vsn | head -n1) probe_cc hostcc "$host_cc"
armcc_conf="$PWD/armcc.conf" host_cflags_filter=$_flags_filter
$cc --arm_linux_configure \ host_ldflags_filter=$_flags_filter
--arm_linux_config_file="$armcc_conf" \ add_host_cflags $_flags $_cflags
--configure_sysroot="$sysroot" \ add_host_ldflags $_flags $_ldflags
--configure_cpp_headers="$sysinclude" >>$logfile 2>&1 || set_ccvars HOSTCC
die "Error creating armcc configuration file."
$cc --vsn | grep -q RVCT && armcc_opt=rvct || armcc_opt=armcc
cc="$cc --arm_linux_config_file=$armcc_conf --translate_gcc"
as_default="${cross_prefix}gcc"
CC_DEPFLAGS='-MMD'
AS_DEPFLAGS='-MMD'
cflags_speed='-O3'
cflags_size='-Os'
asflags_filter="filter_out -W${armcc_opt}*"
elif $cc -version 2>/dev/null | grep -q TMS470; then
cc_type=tms470
cc_ident=$($cc -version | head -n1 | tr -s ' ')
cc="$cc --gcc --abi=eabi -me"
CC_O='-fe=$@'
as_default="${cross_prefix}gcc"
ld_default="${cross_prefix}gcc"
add_cflags -D__gnuc_va_list=va_list -D__USER_LABEL_PREFIX__=
CC_DEPFLAGS='-ppa -ppd=$(@:.o=.d)'
AS_DEPFLAGS='-MMD'
cflags_speed='-O3 -mf=5'
cflags_size='-O3 -mf=2'
cflags_filter=tms470_flags
elif $cc -v 2>&1 | grep -q clang; then
cc_type=clang
cc_ident=$($cc --version | head -n1)
CC_DEPFLAGS='-MMD'
AS_DEPFLAGS='-MMD'
cflags_speed='-O3'
cflags_size='-Os'
elif $cc -V 2>&1 | grep -q Sun; then
cc_type=suncc
cc_ident=$($cc -V 2>&1 | head -n1 | cut -d' ' -f 2-)
DEPEND_CMD='$(DEPCC) $(DEPFLAGS) $< | sed -e "1s,^.*: ,$@: ," -e "\$$!s,\$$, \\\," -e "1!s,^.*: , ," > $(@:.o=.d)'
DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -xM1'
add_ldflags -xc99
cflags_speed='-O5'
cflags_size='-O5 -xspace'
cflags_filter=suncc_flags
elif $cc -v 2>&1 | grep -q 'PathScale\|Path64'; then
cc_type=pathscale
cc_ident=$($cc -v 2>&1 | head -n1 | tr -d :)
CC_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@'
AS_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@'
cflags_speed='-O2'
cflags_size='-Os'
cflags_filter='filter_out -Wdisabled-optimization'
elif $cc -v 2>&1 | grep -q Open64; then
cc_type=open64
cc_ident=$($cc -v 2>&1 | head -n1 | tr -d :)
CC_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@'
AS_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@'
cflags_speed='-O2'
cflags_size='-Os'
cflags_filter='filter_out -Wdisabled-optimization|-Wtype-limits|-fno-signed-zeros'
elif $cc -V 2>&1 | grep -q Portland; then
cc_type=pgi
cc_ident="PGI $($cc -V 2>&1 | awk '/^pgcc/ { print $2; exit }')"
opt_common='-alias=ansi -Mlre -Mpre'
cflags_speed="-O3 -Mautoinline -Munroll=c:4 $opt_common"
cflags_size="-O2 -Munroll=c:1 $opt_common"
cflags_noopt="-O1"
cflags_filter=pgi_flags
fi
test -n "$cc_type" && enable $cc_type || test -n "$cc_type" && enable $cc_type ||
warn "Unknown C compiler $cc, unable to select optimal CFLAGS" warn "Unknown C compiler $cc, unable to select optimal CFLAGS"
@ -2165,8 +2197,23 @@ test -n "$cc_type" && enable $cc_type ||
: ${ld_default:=$cc} : ${ld_default:=$cc}
set_default ar as dep_cc ld set_default ar as dep_cc ld
test -n "$CC_DEPFLAGS" || CCDEP=$DEPEND_CMD probe_cc as "$as"
test -n "$AS_DEPFLAGS" || ASDEP=$DEPEND_CMD asflags_filter=$_flags_filter
add_asflags $_flags $_cflags
set_ccvars AS
probe_cc ld "$ld"
ldflags_filter=$_flags_filter
add_ldflags $_flags $_ldflags
test "$cc_type" != "$ld_type" && add_ldflags $cc_ldflags
LD_O=${_cc_o-$LD_O}
if [ -z "$CC_DEPFLAGS" ] && [ "$dep_cc" != "$cc" ]; then
probe_cc depcc "$dep_cc"
CCDEP=${_DEPCMD:-$DEPCMD}
CCDEP_FLAGS=${_DEPFLAGS:=$DEPFLAGS}
DEPCCFLAGS=$_flags
fi
add_cflags $extra_cflags add_cflags $extra_cflags
add_asflags $extra_cflags add_asflags $extra_cflags
@ -3355,6 +3402,9 @@ CC=$cc
AS=$as AS=$as
LD=$ld LD=$ld
DEPCC=$dep_cc DEPCC=$dep_cc
DEPCCFLAGS=$DEPCCFLAGS \$(CPPFLAGS)
DEPAS=$as
DEPASFLAGS=$DEPASFLAGS \$(CPPFLAGS)
YASM=$yasmexe YASM=$yasmexe
YASMDEP=$yasmexe YASMDEP=$yasmexe
AR=$ar AR=$ar
@ -3363,8 +3413,9 @@ LN_S=$ln_s
CPPFLAGS=$CPPFLAGS CPPFLAGS=$CPPFLAGS
CFLAGS=$CFLAGS CFLAGS=$CFLAGS
ASFLAGS=$ASFLAGS ASFLAGS=$ASFLAGS
AS_O=$CC_O AS_O=$AS_O
CC_O=$CC_O CC_O=$CC_O
LD_O=$LD_O
DLLTOOL=$dlltool DLLTOOL=$dlltool
LDFLAGS=$LDFLAGS LDFLAGS=$LDFLAGS
AVSERVERLDFLAGS=$AVSERVERLDFLAGS AVSERVERLDFLAGS=$AVSERVERLDFLAGS
@ -3379,9 +3430,10 @@ SLIBPREF=$SLIBPREF
SLIBSUF=$SLIBSUF SLIBSUF=$SLIBSUF
EXESUF=$EXESUF EXESUF=$EXESUF
EXTRA_VERSION=$extra_version EXTRA_VERSION=$extra_version
DEPFLAGS=$DEPFLAGS
CCDEP=$CCDEP CCDEP=$CCDEP
CCDEP_FLAGS=$CCDEP_FLAGS
ASDEP=$ASDEP ASDEP=$ASDEP
ASDEP_FLAGS=$ASDEP_FLAGS
CC_DEPFLAGS=$CC_DEPFLAGS CC_DEPFLAGS=$CC_DEPFLAGS
AS_DEPFLAGS=$AS_DEPFLAGS AS_DEPFLAGS=$AS_DEPFLAGS
HOSTCC=$host_cc HOSTCC=$host_cc
@ -3389,6 +3441,12 @@ HOSTCFLAGS=$host_cflags
HOSTEXESUF=$HOSTEXESUF HOSTEXESUF=$HOSTEXESUF
HOSTLDFLAGS=$host_ldflags HOSTLDFLAGS=$host_ldflags
HOSTLIBS=$host_libs HOSTLIBS=$host_libs
DEPHOSTCC=$host_cc
DEPHOSTCCFLAGS=$DEPHOSTCCFLAGS \$(HOSTCCFLAGS)
HOSTCCDEP=$HOSTCCDEP
HOSTCCDEP_FLAGS=$HOSTCCDEP_FLAGS
HOSTCC_DEPFLAGS=$HOSTCC_DEPFLAGS
HOSTCC_O=$HOSTCC_O
TARGET_EXEC=$target_exec TARGET_EXEC=$target_exec
TARGET_PATH=$target_path TARGET_PATH=$target_path
SDL_LIBS=$sdl_libs SDL_LIBS=$sdl_libs