This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[libstdc++] Add --disable-hosted-libstdcxx, clean up conditionals
- From: Phil Edwards <phil at jaj dot com>
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Wed, 27 Aug 2003 15:06:55 -0400
- Subject: [libstdc++] Add --disable-hosted-libstdcxx, clean up conditionals
The main point of this patch is --disable-hosted-libstdcxx, which will
build and install only the parts needed by a freestanding implementation.
In practice, that means a few headers and libsupc++.
The patch is functional, but suboptimal in that all the configury tests
are still performed, even though most of them will be unused. Also, no
libstdc++.* is actually created, so an end user needs to use "gcc ...
-lsupc++" or the equivalent. Future iterations can build a libstdc++
containing only the libsup parts, and skip unneeded tests, etc. I wanted
to keep this simple.
While doing that, I ran into problems with the way in which we
do AM_CONDITIONAL tests. Excrutiating details on request; basically,
instead of set-then-test, we were trying to do set-then-test-then-reset,
which of course doesn't change the test. M4 to the rescue again: we now
use GLIBCXX_CONDITIONAL instead of AM_CONDITIONAL, which does the exact
same thing, except that it does all the work towards the end of configure,
when all the shell variables have reached their final state.
(I haven't included the 'configure' or Makefile.in's diffs here, but
looking at them is educational.)
Running the testsuite with a freestanding build is largely pointless, but
I verified that the default hosted build hasn't changed. Also, including
each of the freestanding headers by itself works. Applied to trunk.
2003-08-27 Phil Edwards <pme@gcc.gnu.org>
* acinclude.m4 (GLIBCXX_CONDITIONAL): New macro. Wrap
AM_CONDITIONAL. Replace all calls to AM_CONDITIONAL with this one.
(GLIBCXX_ENABLE_HOSTED): New macro, sets new variable is_hosted,
used elsewhere in this file.
(GLIBCXX_EVALUATE_CONDITIONALS): New macro...
* configure.ac: ...called here to expand all conditionals.
* Makefile.am: Conditionalize SUBDIRS on GLIBCXX_HOSTED.
* include/Makefile.am: Remove redundant gxx_include_dir assignment.
(install-freestanding-headers): New target, a subset of
install-headers. Conditionalize install-data-local on GLIBCXX_HOSTED.
* aclocal.m4, configure, Makefile.in, include/Makefile.in,
libmath/Makefile.in, libsupc++/Makefile.in, po/Makefile.in,
src/Makefile.in, testsuite/Makefile.in: Regenerated.
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/Makefile.am,v
retrieving revision 1.46
diff -u -3 -p -r1.46 Makefile.am
--- Makefile.am 27 Aug 2003 00:38:16 -0000 1.46
+++ Makefile.am 27 Aug 2003 18:58:10 -0000
@@ -24,8 +24,12 @@
include $(top_srcdir)/fragment.am
+if GLIBCXX_HOSTED
+ # Possibly libmath as well...
+ hosted_source = src po
+endif
## Keep this list sync'd with acinclude.m4:GLIBCXX_CONFIGURE.
-SUBDIRS = include libmath libsupc++ src po testsuite
+SUBDIRS = include libmath libsupc++ $(hosted_source) testsuite
# These rules are messy, but are hella worth it.
doxygen:
Index: acinclude.m4
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/acinclude.m4,v
retrieving revision 1.264
diff -u -3 -p -r1.264 acinclude.m4
--- acinclude.m4 27 Aug 2003 00:38:16 -0000 1.264
+++ acinclude.m4 27 Aug 2003 18:58:11 -0000
@@ -1,5 +1,22 @@
dnl
+dnl GLIBCXX_CONDITIONAL (NAME, SHELL-TEST)
+dnl
+dnl Exactly like AM_CONDITIONAL, but delays evaluation of the test until the
+dnl end of configure. This lets tested variables be reassigned, and the
+dnl conditional will depend on the final state of the variable. For a simple
+dnl example of why this is needed, see GLIBCXX_ENABLE_HOSTED.
+dnl
+m4_define([_m4_divert(glibcxx_diversion)], 8000)dnl
+AC_DEFUN(GLIBCXX_CONDITIONAL, [dnl
+ m4_divert_text([glibcxx_diversion],dnl
+ AM_CONDITIONAL([$1],[$2])
+ )dnl
+])dnl
+AC_DEFUN(GLIBCXX_EVALUATE_CONDITIONALS, [m4_undivert([glibcxx_diversion])])dnl
+
+
+dnl
dnl Check to see what architecture and operating system we are compiling
dnl for. Also, if architecture- or OS-specific flags are required for
dnl compilation, pick them up here.
@@ -143,7 +160,10 @@ AC_DEFUN(GLIBCXX_CONFIGURE, [
AM_MAINTAINER_MODE
- # Set up safe default values for all subsequent AM_CONDITIONAL tests.
+ # Set up safe default values for all subsequent AM_CONDITIONAL tests
+ # which are themselves conditionally expanded.
+ ## (Right now, this only matters for enable_wchar_t, but nothing prevents
+ ## other macros from doing the same. This should be automated.) -pme
need_libmath=no
enable_wchar_t=no
#enable_libstdcxx_debug=no
@@ -152,6 +172,7 @@ AC_DEFUN(GLIBCXX_CONFIGURE, [
#c_compatibility=no
#enable_abi_check=no
#enable_symvers=no
+ #enable_hosted_libstdcxx=yes
# Find platform-specific directories containing configuration info.
# Also possibly modify flags used elsewhere, as needed by the platform.
@@ -560,7 +581,7 @@ dnl Substs:
dnl baseline_dir
dnl
AC_DEFUN(GLIBCXX_CONFIGURE_TESTSUITE, [
- if $GLIBCXX_IS_NATIVE; then
+ if $GLIBCXX_IS_NATIVE && test $is_hosted = yes; then
# Do checks for memory limit functions.
GLIBCXX_CHECK_SETRLIMIT
@@ -573,7 +594,7 @@ AC_DEFUN(GLIBCXX_CONFIGURE_TESTSUITE, [
AC_SUBST(baseline_dir)
# Determine if checking the ABI is desirable.
- if test $enable_symvers = no; then
+ if test $enable_symvers = no || test $is_hosted = no; then
enable_abi_check=no
else
case "$host" in
@@ -584,8 +605,8 @@ AC_DEFUN(GLIBCXX_CONFIGURE_TESTSUITE, [
esac
fi
- AM_CONDITIONAL(GLIBCXX_TEST_WCHAR_T, test $enable_wchar_t = yes)
- AM_CONDITIONAL(GLIBCXX_TEST_ABI, test $enable_abi_check = yes)
+ GLIBCXX_CONDITIONAL(GLIBCXX_TEST_WCHAR_T, test $enable_wchar_t = yes)
+ GLIBCXX_CONDITIONAL(GLIBCXX_TEST_ABI, test $enable_abi_check = yes)
])
@@ -897,9 +918,9 @@ AC_DEFUN(GLIBCXX_ENABLE_CHEADERS, [
C_INCLUDE_DIR='${glibcxx_srcdir}/include/'$enable_cheaders
AC_SUBST(C_INCLUDE_DIR)
- AM_CONDITIONAL(GLIBCXX_C_HEADERS_C, test $enable_cheaders = c)
- AM_CONDITIONAL(GLIBCXX_C_HEADERS_C_STD, test $enable_cheaders = c_std)
- AM_CONDITIONAL(GLIBCXX_C_HEADERS_COMPATIBILITY, test $c_compatibility = yes)
+ GLIBCXX_CONDITIONAL(GLIBCXX_C_HEADERS_C, test $enable_cheaders = c)
+ GLIBCXX_CONDITIONAL(GLIBCXX_C_HEADERS_C_STD, test $enable_cheaders = c_std)
+ GLIBCXX_CONDITIONAL(GLIBCXX_C_HEADERS_COMPATIBILITY, test $c_compatibility = yes)
])
@@ -1213,7 +1234,7 @@ AC_DEFUN(GLIBCXX_ENABLE_DEBUG, [
AC_MSG_CHECKING([for additional debug build])
GLIBCXX_ENABLE(libstdcxx-debug,$1,,[build extra debug library])
AC_MSG_RESULT($enable_libstdcxx_debug)
- AM_CONDITIONAL(GLIBCXX_BUILD_DEBUG, test $enable_libstdcxx_debug = yes)
+ GLIBCXX_CONDITIONAL(GLIBCXX_BUILD_DEBUG, test $enable_libstdcxx_debug = yes)
])
@@ -1247,6 +1268,34 @@ AC_DEFUN(GLIBCXX_ENABLE_DEBUG_FLAGS, [
dnl
+dnl Check if the user only wants a freestanding library implementation.
+dnl
+dnl --disable-hosted-libstdcxx will turn off most of the library build,
+dnl installing only the headers required by [17.4.1.3] and the language
+dnl support library. More than that will be built (to keep the Makefiles
+dnl conveniently clean), but not installed.
+dnl
+dnl Sets:
+dnl is_hosted (yes/no)
+dnl
+AC_DEFUN(GLIBCXX_ENABLE_HOSTED, [
+ AC_ARG_ENABLE([hosted-libstdcxx],
+ AC_HELP_STRING([--disable-hosted-libstdcxx],
+ [only build freestanding C++ runtime support]),,
+ [enable_hosted_libstdcxx=yes])
+ if test "$enable_hosted_libstdcxx" = no; then
+ AC_MSG_NOTICE([Only freestanding libraries will be built])
+ is_hosted=no
+ enable_abi_check=no
+ enable_libstdcxx_pch=no
+ else
+ is_hosted=yes
+ fi
+ GLIBCXX_CONDITIONAL(GLIBCXX_HOSTED, test $is_hosted = yes)
+])
+
+
+dnl
dnl Check for libunwind exception handling support. If enabled, then
dnl we assume that the _Unwind_* functions that make up the Unwind ABI
dnl (_Unwind_RaiseException, _Unwind_Resume, etc.) are defined by
@@ -1351,7 +1400,7 @@ AC_DEFUN(GLIBCXX_ENABLE_PCH, [
enable_libstdcxx_pch=$glibcxx_cv_prog_CXX_pch
fi
- AM_CONDITIONAL(GLIBCXX_BUILD_PCH, test $enable_libstdcxx_pch = yes)
+ GLIBCXX_CONDITIONAL(GLIBCXX_BUILD_PCH, test $enable_libstdcxx_pch = yes)
if test $enable_libstdcxx_pch = yes; then
glibcxx_PCHFLAGS="-include bits/stdc++.h"
else
@@ -1523,7 +1572,7 @@ esac
AC_SUBST(SYMVER_MAP)
AC_SUBST(port_specific_symbol_files)
-AM_CONDITIONAL(GLIBCXX_BUILD_VERSIONED_SHLIB, test $enable_symvers != no)
+GLIBCXX_CONDITIONAL(GLIBCXX_BUILD_VERSIONED_SHLIB, test $enable_symvers != no)
AC_MSG_NOTICE(versioning on shared library symbols is $enable_symvers)
])
Index: configure.ac
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/configure.ac,v
retrieving revision 1.5
diff -u -3 -p -r1.5 configure.ac
--- configure.ac 27 Aug 2003 00:38:27 -0000 1.5
+++ configure.ac 27 Aug 2003 18:58:16 -0000
@@ -70,10 +70,15 @@ AC_SUBST(enable_shared)
AC_SUBST(enable_static)
#AC_MSG_NOTICE([====== Finished libtool configuration]) ; sleep 10
+# Possibly disable most of the library.
+## XXX Consider skipping unncessary tests altogether in this case, rather
+## than just ignoring the results. Faster /and/ more correct, win win.
+GLIBCXX_ENABLE_HOSTED
+
# Check for support bits and g++ features that don't require linking.
GLIBCXX_ENABLE_SJLJ_EXCEPTIONS
GLIBCXX_ENABLE_LIBUNWIND_EXCEPTIONS
-GLIBCXX_ENABLE_PCH([yes])
+GLIBCXX_ENABLE_PCH($is_hosted)
# Enable all the variable C++ runtime options.
# NB: C_MBCHAR must come early.
@@ -266,6 +271,7 @@ AC_SUBST(OS_INC_SRCDIR)
#AM_CONDITIONAL(CANADIAN, test $CANADIAN = yes)
# from GLIBCXX_CHECK_COMPLEX_MATH_SUPPORT:
#AM_CONDITIONAL(GLIBCXX_BUILD_LIBMATH, test $need_libmath = yes)
+GLIBCXX_EVALUATE_CONDITIONALS
AC_CACHE_SAVE
Index: include/Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/Makefile.am,v
retrieving revision 1.68
diff -u -3 -p -r1.68 Makefile.am
--- include/Makefile.am 27 Aug 2003 00:38:27 -0000 1.68
+++ include/Makefile.am 27 Aug 2003 18:58:16 -0000
@@ -510,10 +510,30 @@ ${pch_input}: ${allstamped} ${host_build
# `$(mkinstalldirs)' instead of `mkdir -p'. In particular,
# host_headers_extra are taken out of the build tree staging area;
# the rest are taken from the original source tree.
-gxx_include_dir = @gxx_include_dir@
+if GLIBCXX_HOSTED
install-data-local: install-headers ${pch_install}
+else
+install-data-local: install-freestanding-headers
+endif
+# This is a subset of the full install-headers rule. We only need <cstddef>,
+# <limits>, <cstdlib>, <cstdarg>, <new>, <typeinfo>, <exception>, and any
+# files which they include (and which we provide). The last three headers
+# are installed by libsupc++, so only the first four and the sub-includes
+# are copied here.
+install-freestanding-headers:
+ $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}
+ $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${host_builddir}
+ for file in ${host_srcdir}/os_defines.h ${host_builddir}/c++config.h; do \
+ $(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${host_builddir}; done
+ $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${std_builddir}
+ $(INSTALL_DATA) ${std_builddir}/limits $(DESTDIR)${gxx_include_dir}/${std_builddir}
+ $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${c_base_builddir}
+ for file in cstddef cstdlib cstdarg; do \
+ $(INSTALL_DATA) ${c_base_builddir}/$${file} $(DESTDIR)${gxx_include_dir}/${c_base_builddir}; done
+
+# The real deal.
install-headers:
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${bits_builddir}