changeset 16031:17a1c60434a8 draft

(svn r20724) -Fix: debug builds with LTO enabled didn't have debug information and were not optimised at all, causing many compile-time warnings
author smatz <smatz@openttd.org>
date Fri, 03 Sep 2010 13:23:29 +0000
parents 82202f09efc4
children e49b9efeb530
files config.lib
diffstat 1 files changed, 36 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/config.lib
+++ b/config.lib
@@ -1116,10 +1116,12 @@
 	# $5 - variable to finally write cxxflags to
 	# $6 - the current ldflags
 	# $7 - variable to finally write ldflags to
+	# $8 - variable to finally write features to
 
 	flags="$2"
 	cxxflags="$4"
 	ldflags="$6"
+	features=""
 
 	if [ `basename $1 | cut -c 1-3` = "icc" ]; then
 		# Enable some things only for certain ICC versions
@@ -1141,11 +1143,13 @@
 			cxxflags="$cxxflags -std=c++0x"
 		fi
 
-		has_ipo=`$1 -help ipo | grep '\-ipo'`
-		if [ "$enable_lto" != "0" ] && [ -n "$has_ipo" ]; then
-			# Use IPO (only if we see IPO exists and is requested)
-			flags="$flags -ipo"
-			ldflags="$ldflags -ipo $CFLAGS"
+		if [ "$enable_lto" != "0" ]; then
+			has_ipo=`$1 -help ipo | grep '\-ipo'`
+			if [ -n "$has_ipo" ]; then
+				# Use IPO (only if we see IPO exists and is requested)
+				flags="$flags -ipo"
+				features="$features lto"
+			fi
 		fi
 	else
 		# Enable some things only for certain GCC versions
@@ -1177,7 +1181,6 @@
 			#  break anything. So disable strict-aliasing to make the
 			#  compiler all happy.
 			flags="$flags -fno-strict-aliasing"
-			ldflags="$ldflags -fno-strict-aliasing"
 			# Warn about casting-out 'const' with regular C-style cast.
 			#  The preferred way is const_cast<>() which doesn't warn.
 			flags="$flags -Wcast-qual"
@@ -1189,7 +1192,6 @@
 			# sure that they will not happen. It furthermore complains
 			# about its own optimized code in some places.
 			flags="$flags -fno-strict-overflow"
-			ldflags="$ldflags -fno-strict-overflow"
 		fi
 
 		if [ $cc_version -ge 43 ]; then
@@ -1198,13 +1200,12 @@
 			cxxflags="$cxxflags -std=gnu++0x"
 		fi
 
-		if [ $cc_version -ge 45 ]; then
-			# Only GCC 4.5+ has (possibly) LTO
+		if [ "$enable_lto" != "0" ]; then
 			has_lto=`$1 -dumpspecs | grep '\%{flto}'`
-			if [ "$enable_lto" != "0" ] && [ -n "$has_lto" ]; then
+			if [ -n "$has_lto" ]; then
 				# Use LTO only if we see LTO exists and is requested
 				flags="$flags -flto"
-				ldflags="$ldflags -flto $2"
+				features="$features lto"
 			fi
 		fi
 
@@ -1219,6 +1220,7 @@
 	eval "$3=\"$flags\""
 	eval "$5=\"$cxxflags\""
 	eval "$7=\"$ldflags\""
+	eval "$8=\"$features\""
 }
 
 make_cflags_and_ldflags() {
@@ -1228,6 +1230,8 @@
 	CXXFLAGS_BUILD=""
 	# LDFLAGS for BUILD
 	LDFLAGS_BUILD=""
+	# FEATURES for BUILD (lto)
+	FEATURES_BUILD=""
 	# General CFlags for HOST
 	CFLAGS="$CFLAGS"
 	# Special CXXFlags for HOST
@@ -1236,13 +1240,15 @@
 	LIBS="-lstdc++"
 	# LDFLAGS used for HOST
 	LDFLAGS="$LDFLAGS"
-
-	make_compiler_cflags "$cc_build" "$CFLAGS_BUILD" "CFLAGS_BUILD" "$CXXFLAGS_BUILD" "CXXFLAGS_BUILD" "$LDFLAGS_BUILD" "LDFLAGS_BUILD"
-	make_compiler_cflags "$cc_host" "$CFLAGS" "CFLAGS" "$CXXFLAGS" "CXXFLAGS" "$LDFLAGS" "LDFLAGS"
+	# FEATURES for HOST (lto)
+	FEATURES=""
+
+	make_compiler_cflags "$cc_build" "$CFLAGS_BUILD" "CFLAGS_BUILD" "$CXXFLAGS_BUILD" "CXXFLAGS_BUILD" "$LDFLAGS_BUILD" "LDFLAGS_BUILD" "FEATURES_BUILD"
+	make_compiler_cflags "$cc_host" "$CFLAGS" "CFLAGS" "$CXXFLAGS" "CXXFLAGS" "$LDFLAGS" "LDFLAGS" "FEATURES"
 
 	CFLAGS="$CFLAGS -D$os"
 
-	if [ $enable_debug = 0 ]; then
+	if [ "$enable_debug" = "0" ]; then
 		# No debug, add default stuff
 		OBJS_SUBDIR="release"
 		if [ "$os" = "OSX" ]; then
@@ -1255,7 +1261,6 @@
 			fi
 
 			CFLAGS="-O2 -fomit-frame-pointer $CFLAGS"
-			LDFLAGS="-O2 -fomit-frame-pointer $LDFLAGS"
 		fi
 	else
 		OBJS_SUBDIR="debug"
@@ -1275,7 +1280,6 @@
 		fi
 		if [ $enable_debug -ge 2 ]; then
 			CFLAGS="$CFLAGS -fno-inline"
-			LDFLAGS="$LDFLAGS -fno-inline"
 		fi
 		if [ $enable_debug -ge 3 ]; then
 			CFLAGS="$CFLAGS -O0"
@@ -1609,6 +1613,21 @@
 
 	CFLAGS="$CFLAGS -DGLOBAL_DATA_DIR=\\\\\"$prefix_dir/$data_dir\\\\\""
 
+	if [ "$enable_lto" != "0" ]; then
+		lto_build=`echo "$FEATURES_BUILD" | grep "lto"`
+		lto_host=`echo "$FEATURES" | grep "lto"`
+		if [ -z "$lto_build$lto_host" ]; then
+			log 1 "WARNING: you enabled LTO/IPO, but neither build nor host compiler supports it"
+			log 1 "WARNING: LTO/IPO has been disabled"
+		fi
+		if [ -n "$lto_build" ]; then
+			LDFLAGS_BUILD="$LDFLAGS_BUILD $CFLAGS_BUILD $CXXFLAGS_BUILD"
+		fi
+		if [ -n "$lto_host" ]; then
+			LDFLAGS="$LDFLAGS $CFLAGS $CXXFLAGS"
+		fi
+	fi
+
 	log 1 "using CFLAGS... $CFLAGS"
 	log 1 "using CXXFLAGS... $CXXFLAGS"
 	log 1 "using LDFLAGS... $LIBS $LDFLAGS"