ソースを参照

GCC: Link libstdc++ and libgcc statically

Bryan Drewery 11 年 前
コミット
9f291c9aca
3 ファイル変更119 行追加0 行削除
  1. 2 0
      build/autotools/configure.ac
  2. 114 0
      configure
  3. 3 0
      doc/UPDATES

+ 2 - 0
build/autotools/configure.ac

@@ -42,6 +42,8 @@ if [[ "${ax_cv_prog_cc_Og}" = "no" ]]; then
   DEBCXXFLAGS="${DEBCXXFLAGS} -O0"
 fi
 CXX_FLAG_CHECK([DEBCXXFLAGS], [-fstack-protector-all], [stackprotectorall])
+CXX_FLAG_CHECK([LDFLAGS], [-static-libstdc++], [static_libstdcxx])
+CXX_FLAG_CHECK([LDFLAGS], [-static-libgcc], [static_libgcc])
 
 EGG_CHECK_DEPMODE
 

+ 114 - 0
configure

@@ -3616,6 +3616,120 @@ EOF
   fi
 
 
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler understands -static-libstdc++" >&5
+$as_echo_n "checking whether the compiler understands -static-libstdc++... " >&6; }
+if ${ax_cv_prog_cc_static_libstdcxx+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+    ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+    ac_saved_flags="$CXXFLAGS"
+    CXXFLAGS="-Werror -static-libstdc++"
+    cat build/confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end build/confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  ax_cv_prog_cc_static_libstdcxx="yes"
+else
+  ax_cv_prog_cc_static_libstdcxx="no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+    CXXFLAGS="$ac_saved_flags"
+    ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_prog_cc_static_libstdcxx" >&5
+$as_echo "$ax_cv_prog_cc_static_libstdcxx" >&6; }
+
+  if [ "$ax_cv_prog_cc_static_libstdcxx" = "yes" ]; then
+    LDFLAGS="$LDFLAGS -static-libstdc++"
+  elif [ -n "" ]; then
+      cat << 'EOF' >&2
+configure: error:
+
+  Your OS or C++ compiler does not support -static-libstdc++.
+  This compile flag is required.
+
+EOF
+    exit 1
+  fi
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler understands -static-libgcc" >&5
+$as_echo_n "checking whether the compiler understands -static-libgcc... " >&6; }
+if ${ax_cv_prog_cc_static_libgcc+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+    ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+    ac_saved_flags="$CXXFLAGS"
+    CXXFLAGS="-Werror -static-libgcc"
+    cat build/confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end build/confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  ax_cv_prog_cc_static_libgcc="yes"
+else
+  ax_cv_prog_cc_static_libgcc="no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+    CXXFLAGS="$ac_saved_flags"
+    ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_prog_cc_static_libgcc" >&5
+$as_echo "$ax_cv_prog_cc_static_libgcc" >&6; }
+
+  if [ "$ax_cv_prog_cc_static_libgcc" = "yes" ]; then
+    LDFLAGS="$LDFLAGS -static-libgcc"
+  elif [ -n "" ]; then
+      cat << 'EOF' >&2
+configure: error:
+
+  Your OS or C++ compiler does not support -static-libgcc.
+  This compile flag is required.
+
+EOF
+    exit 1
+  fi
+
+
 
 CCDEPMODE=gcc
 num=`$CXX -dumpversion | sed "s/^\\\(.\\\).*/\\\1/"`

+ 3 - 0
doc/UPDATES

@@ -10,6 +10,9 @@ maint
     bolds being backwards (#86).
   * Fix TCL warnings during build if TCL is not being used.
   * Rework the build to parallelize better and rebuild some things less often.
+  * GCC: Always link libstdc++ and libgcc statically. This avoids distributing
+    a binary that would rely on having a specific compiler version installed
+    and avoids issues when updating the local compiler.
 
 1.4.5
   * Remove ahbl as it now positively identifies all hosts as abusive