[vlc-devel] [PATCH] configure: restrict from applying gcc only flags to other compilers.
Francois Cartegnie
fcvlcdev at free.fr
Fri Mar 2 02:21:24 CET 2012
Applying gcc's optimizations to other compilers lead to undefined
behavior.
In the suncc case, the build will fail later because of default
propagation of unknown flags to the linker.
---
configure.ac | 112 ++++++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 81 insertions(+), 31 deletions(-)
diff --git a/configure.ac b/configure.ac
index 2a74fe6..03d58f5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -858,6 +858,13 @@ AS_IF([test "${enable_debug}" != "no"], [
AC_DEFINE(NDEBUG)
])
+dnl Set up version & compiler variables for various hacks
+if test "$GCC" != "yes"; then
+ AC_CHECK_DECL([__SUNPRO_C], [COMPILER="suncc"], [COMPILER=""])
+else
+ COMPILER="gcc"
+fi
+
dnl
dnl Profiling
dnl
@@ -895,11 +902,19 @@ AS_IF([test "${enable_coverage}" != "no"], [
])
AS_IF([test "${SYS}" != "mingw32" -a "${SYS}" != "mingwce"], [
+ case "${COMPILER}" in
+ "suncc")
+ SYMBOLSVISIBILITY="-xldscope=symbolic"
+ ;;
+ *)
+ SYMBOLSVISIBILITY="-fvisibility=hidden"
+ ;;
+ esac
VLC_SAVE_FLAGS
- CFLAGS="${CFLAGS} -fvisibility=hidden"
- CXXFLAGS="${CXXFLAGS} -fvisibility=hidden"
- OBJCFLAGS="${OBJCFLAGS} -fvisibility=hidden"
- AC_CACHE_CHECK([if $CC accepts -fvisibility=hidden],
+ CFLAGS="${CFLAGS} ${SYMBOLSVISIBILITY}"
+ CXXFLAGS="${CXXFLAGS} ${SYMBOLSVISIBILITY}"
+ OBJCFLAGS="${OBJCFLAGS} ${SYMBOLSVISIBILITY}"
+ AC_CACHE_CHECK([if $CC accepts $SYMBOLSVISIBILITY],
[ac_cv_c_visibility_hidden], [
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [
ac_cv_c_visibility_hidden=yes
@@ -910,7 +925,6 @@ AS_IF([test "${SYS}" != "mingw32" -a "${SYS}" != "mingwce"], [
AS_IF([test "${ac_cv_c_visibility_hidden}" = "no"], [VLC_RESTORE_FLAGS])
])
-
dnl
dnl Enable/disable optimizations
dnl
@@ -922,13 +936,30 @@ AC_ARG_ENABLE(optimizations,
dnl Check for various optimization flags
AS_IF([test "${enable_optimizations}" != "no"], [
+ case "${COMPILER}" in
+ "suncc")
+ OPTIMIZATION_LEVEL4="-xO5"
+ OPTIMIZATION_LEVEL3="-xO4"
+ OPTIMIZATION_MATH="-fsimple=2"
+ OPTIMIZATION_UNROLL="-xunroll"
+ OPTIMIZATION_OMITFRAMEPTR="-xregs=frameptr"
+ ;;
+ *)
+ OPTIMIZATION_LEVEL4="-O4"
+ OPTIMIZATION_LEVEL3="-O3"
+ OPTIMIZATION_MATH="-ffast-math"
+ OPTIMIZATION_UNROLL="-funroll-loops"
+ OPTIMIZATION_OMITFRAMEPTR="-fomit-frame-pointer"
+ ;;
+ esac
+
dnl -O4 and -O3 only in production builds
AS_IF([test "{enable_debug}" = "no"], [
VLC_SAVE_FLAGS
- CFLAGS="${CFLAGS} -O4"
- CXXFLAGS="${CXXFLAGS} -O4"
- OBJCFLAGS="${OBJCFLAGS} -O4"
- AC_CACHE_CHECK([if $CC accepts -O4], [ac_cv_c_o4], [
+ CFLAGS="${CFLAGS} ${OPTIMIZATION_LEVEL4}"
+ CXXFLAGS="${CXXFLAGS} ${OPTIMIZATION_LEVEL4}"
+ OBJCFLAGS="${OBJCFLAGS} ${OPTIMIZATION_LEVEL4}"
+ AC_CACHE_CHECK([if $CC accepts $OPTIMIZATION_LEVEL4], [ac_cv_c_o4], [
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [
ac_cv_c_o4=yes
], [
@@ -937,10 +968,10 @@ AS_IF([test "${enable_optimizations}" != "no"], [
])
AS_IF([test "${ac_cv_c_o4}" = "no"], [
VLC_RESTORE_FLAGS
- CFLAGS="${CFLAGS} -O3"
- CXXFLAGS="${CXXFLAGS} -O3"
- OBJCFLAGS="${OBJCFLAGS} -O3"
- AC_CACHE_CHECK([if $CC accepts -O3], [ac_cv_c_o3], [
+ CFLAGS="${CFLAGS} ${OPTIMIZATION_LEVEL3}"
+ CXXFLAGS="${CXXFLAGS} ${OPTIMIZATION_LEVEL3}"
+ OBJCFLAGS="${OBJCFLAGS} ${OPTIMIZATION_LEVEL3}"
+ AC_CACHE_CHECK([if $CC accepts $OPTIMIZATION_LEVEL3], [ac_cv_c_o3], [
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [
ac_cv_c_o3=yes
], [
@@ -953,10 +984,10 @@ AS_IF([test "${enable_optimizations}" != "no"], [
dnl Check for -ffast-math
VLC_SAVE_FLAGS
- CFLAGS="${CFLAGS} -ffast-math"
- CXXFLAGS="${CXXFLAGS} -ffast-math"
- OBJCFLAGS="${OBJCFLAGS} -ffast-math"
- AC_CACHE_CHECK([if $CC accepts -ffast-math], [ac_cv_c_fast_math], [
+ CFLAGS="${CFLAGS} ${OPTIMIZATION_MATH}"
+ CXXFLAGS="${CXXFLAGS} ${OPTIMIZATION_MATH}"
+ OBJCFLAGS="${OBJCFLAGS} ${OPTIMIZATION_MATH}"
+ AC_CACHE_CHECK([if $CC accepts $OPTIMIZATION_MATH], [ac_cv_c_fast_math], [
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [
ac_cv_c_fast_math=yes
], [
@@ -967,10 +998,10 @@ AS_IF([test "${enable_optimizations}" != "no"], [
dnl Check for -funroll-loops
VLC_SAVE_FLAGS
- CFLAGS="${CFLAGS} -funroll-loops"
- CXXFLAGS="${CXXFLAGS} -funroll-loops"
- OBJCFLAGS="${OBJCFLAGS} -funroll-loops"
- AC_CACHE_CHECK([if $CC accepts -funroll-loops], [ac_cv_c_unroll_loops], [
+ CFLAGS="${CFLAGS} ${OPTIMIZATION_UNROLL}"
+ CXXFLAGS="${CXXFLAGS} ${OPTIMIZATION_UNROLL}"
+ OBJCFLAGS="${OBJCFLAGS} ${OPTIMIZATION_UNROLL}"
+ AC_CACHE_CHECK([if $CC accepts $OPTIMIZATION_UNROLL], [ac_cv_c_unroll_loops], [
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [
ac_cv_c_unroll_loops=yes
], [
@@ -982,10 +1013,10 @@ AS_IF([test "${enable_optimizations}" != "no"], [
AS_IF([test "$enable_debug" = "no"], [
dnl Check for -fomit-frame-pointer
VLC_SAVE_FLAGS
- CFLAGS="${CFLAGS} -fomit-frame-pointer"
- CXXFLAGS="${CXXFLAGS} -fomit-frame-pointer"
- OBJCFLAGS="${OBJCFLAGS} -fomit-frame-pointer"
- AC_CACHE_CHECK([if $CC accepts -fomit-frame-pointer],
+ CFLAGS="${CFLAGS} ${OPTIMIZATION_OMITFRAMEPTR}"
+ CXXFLAGS="${CXXFLAGS} ${OPTIMIZATION_OMITFRAMEPTR}"
+ OBJCFLAGS="${OBJCFLAGS} ${OPTIMIZATION_OMITFRAMEPTR}"
+ AC_CACHE_CHECK([if $CC accepts $OPTIMIZATION_OMITFRAMEPTR],
[ac_cv_c_omit_frame_pointer], [
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [
ac_cv_c_omit_frame_pointer=yes
@@ -995,6 +1026,7 @@ AS_IF([test "${enable_optimizations}" != "no"], [
])
AS_IF([test "${ac_cv_c_omit_frame_pointer}" = "no"], [VLC_RESTORE_FLAGS])
])
+
])
dnl Check for Darwin plugin linking flags
@@ -1489,21 +1521,39 @@ dnl
AC_ARG_WITH(tuning,
[AS_HELP_STRING([--with-tuning=ARCH],
[tune compilation for an architecture (default varies)])])
+case "${COMPILER}" in
+"suncc")
+ TUNING_KEYWORD="-xtarget="
+ TUNING_DARWINi686="-xtarget=generic"
+ TUNING_DARWINx8664="-xtarget=generic"
+ TUNING_i686="-xtarget=generic"
+ TUNING_x8664="-xtarget=generic"
+ TUNING_POWERPC="-xarch=ppc"
+;;
+*)
+ TUNING_KEYWORD="-mtune="
+ TUNING_DARWINi686="-march=prescott -mtune=generic"
+ TUNING_DARWINx8664="-march=core2 -mtune=core2"
+ TUNING_i686="-mtune=pentium2"
+ TUNING_x8664="-mtune=athlon64"
+ TUNING_POWERPC="-mtune=G4"
+;;
+esac
if test -n "${with_tuning}"; then
if test "${with_tuning}" != "no"; then
- CFLAGS_TUNING="-mtune=${with_tuning}"
+ CFLAGS_TUNING="${TUNING_KEYWORD}${with_tuning}"
fi
else
if test "${SYS}" = "darwin" -a "${host_cpu}" = "i686"; then
- CFLAGS_TUNING="-march=prescott -mtune=generic"
+ CFLAGS_TUNING="${TUNING_DARWINi686}"
elif test "${SYS}" = "darwin" -a "${host_cpu}" = "x86_64"; then
- CFLAGS_TUNING="-march=core2 -mtune=core2"
+ CFLAGS_TUNING="${TUNING_DARWINx8664}"
elif test "${host_cpu}" = "i686" -o "${host_cpu}" = "i586" -o "${host_cpu}" = "i486" -o "${host_cpu}" = "i386"; then
- CFLAGS_TUNING="-mtune=pentium2"
+ CFLAGS_TUNING="${TUNING_i686}"
elif test "${host_cpu}" = "x86_64"; then
- CFLAGS_TUNING="-mtune=athlon64"
+ CFLAGS_TUNING="${TUNING_x8664}"
elif test "${host_cpu}" = "powerpc"; then
- CFLAGS_TUNING="-mtune=G4";
+ CFLAGS_TUNING="${TUNING_POWERPC}"
fi
fi
--
1.7.6
More information about the vlc-devel
mailing list