Fix static archive libstdc++.a for gcc 5.0
authorJohn Marino <draco@marino.st>
Tue, 10 Feb 2015 19:28:22 +0000 (20:28 +0100)
committerJohn Marino <draco@marino.st>
Tue, 10 Feb 2015 19:28:22 +0000 (20:28 +0100)
The libstdc++ libaries for gcc 5.0 are built differently than they have
been in the past, and closely mirror what the vendor build system does.
Three "convenience" librarys are built first: c++98, c++11, and supc++.
Both static and PIC versions are built.  The final library combines the
three components along with about 10 unique objects.

It worked fine for the shared version (libstd.so.9) but the static
version was unreadable.  I fixed it by creating a dedicated "ar" script
to dictate what gets assembled in the new static archive.  It would
have been a sweet solution has "ar" not had an incredible limitation:
The script can not have consecutive "+" characters on any line.  To
work around this, I had to:
  1) rename the 3 component libraries (all had ++ in the name)
  2) rename the output library (libstdc++.a => libstdcxx.a)
  3) copy all the cc files with "++" in their names to a new filename.
     This affected about 3-4 files.
  4) move the output library back to the proper name of libstdc++.a

What a pain those hacks were, but it works and gcc-5.0 can now build
itself.  It still can't complete world due to Werror trigging on new
warnings, but it's a good fix.

gnu/lib/gcc50/libstdcxx/components/libconv_1998/Makefile
gnu/lib/gcc50/libstdcxx/components/libconv_2011/Makefile
gnu/lib/gcc50/libstdcxx/components/libconv_supc/Makefile
gnu/lib/gcc50/libstdcxx/headers/Makefile
gnu/lib/gcc50/libstdcxx/product/Makefile

index 9042467..ea0081e 100644 (file)
@@ -3,7 +3,7 @@ RELUP=  /../..
 SRCDIR=        ${GCCDIR}/libstdc++-v3
 .include "Makefile.src"
 
-LIB=                   c++98convenience
+LIB=                   cxx98convenience
 INTERNALLIB=           yes
 NOPROFILE=             yes
 INSTALL_PIC_ARCHIVE=   yes
index 7cf85ab..f819741 100644 (file)
@@ -3,7 +3,7 @@ RELUP=  /../..
 SRCDIR=        ${GCCDIR}/libstdc++-v3
 .include "Makefile.src"
 
-LIB=                   c++11convenience
+LIB=                   cxx11convenience
 INTERNALLIB=           yes
 NOPROFILE=             yes
 INSTALL_PIC_ARCHIVE=   yes
index bcfb1fa..1e3b599 100644 (file)
@@ -3,7 +3,7 @@ RELUP=  /../..
 SRCDIR=        ${GCCDIR}/libstdc++-v3
 .include "Makefile.src"
 
-LIB=                   supc++convenience
+LIB=                   supcxxconvenience
 INTERNALLIB=           yes
 NOPROFILE=             yes
 INSTALL_PIC_ARCHIVE=   yes
@@ -12,11 +12,11 @@ INSTALL_PIC_ARCHIVE=        yes
 .PATH: ${GCCDIR}/libgcc
 .PATH: ${SRCDIR}/libsupc++
 
-CFLAGS+=       -I${.OBJDIR}
-CFLAGS+=       -I${GCCDIR}/libgcc
-CXXFLAGS+=     -fno-implicit-templates
-CXXFLAGS+=     -fdiagnostics-show-location=once
-CXXFLAGS+=     -ffunction-sections -fdata-sections
+CFLAGS+=               -I${.OBJDIR}
+CFLAGS+=               -I${GCCDIR}/libgcc
+CXXFLAGS+=             -fno-implicit-templates
+CXXFLAGS+=             -fdiagnostics-show-location=once
+CXXFLAGS+=             -ffunction-sections -fdata-sections
 SHARED_CXXFLAGS=       -D_GLIBCXX_SHARED
 
 FLAGS_GROUPS=          gnu11 gnu14 mangle
@@ -30,6 +30,13 @@ gnu14_FLAGS_FILES=   del_ops.cc del_opvs.cc
 mangle_FLAGS=          -DIN_GLIBCPP_V3
 mangle_FLAGS_FILES=    cp-demangle.c
 
-SRCS=  ${libsupc__convenience_la_SOURCES}
+SRCS=                  ${libsupc__convenience_la_SOURCES}
+
+unwind.h: unwind-generic.h
+       cp ${.ALLSRC} ${.TARGET}
+
+GENHD=         unwind.h
+CLEANFILES=    ${GENHD}
+beforedepend:  ${GENHD}
 
 .include <bsd.lib.mk>
index fdc23b2..6d523d8 100644 (file)
@@ -49,12 +49,6 @@ host_headers_extraNAME_c_locale.h=           c++locale.h
 host_headers_extraNAME_c_io_stdio.h+=          c++io.h
 host_headers_extraNAME_new_allocator_base.h=   c++allocator.h
 
-unwind.h: unwind-generic.h
-       cp ${.ALLSRC} ${.TARGET}
-
-unwind-cxx.h: ${SRCDIR}/libsupc++/unwind-cxx.h
-       cp ${.ALLSRC} ${.TARGET}
-
 cxxabi_forced.h: ${SRCDIR}/libsupc++/cxxabi_forced.h
        cp ${.ALLSRC} ${.TARGET}
 
@@ -109,6 +103,6 @@ c++config.h: config.h
        echo "#endif // _GLIBCXX_CXX_CONFIG_H" >> ${.TARGET}
 
 CLEANFILES=    gthr.h gthr-default.h gthr-single.h gthr-posix.h \
-               c++config.h 
+               c++config.h cxxabi_forced.h
 
 .include <bsd.lib.mk>
index ddb1f75..c0e8274 100644 (file)
@@ -18,21 +18,46 @@ VERSION_MAP=        ${.CURDIR}/libstdc++-symbols.ver
 
 FLAGS_GROUPS=          gnu11
 gnu11_FLAGS=           -std=gnu++11
-gnu11_FLAGS_FILES=     ${cxx11_sources}
+gnu11_FLAGS_FILES=     ${cxx11_sources:S|++|xx|}
 
-CONVARCS=      ../components/libconv_supc/libsupc++convenience.a
-CONVARCS+=     ../components/libconv_1998/libc++98convenience.a
-CONVARCS+=     ../components/libconv_2011/libc++11convenience.a
+CONVARCS=      ../components/libconv_supc/libsupcxxconvenience.a
+CONVARCS+=     ../components/libconv_1998/libcxx98convenience.a
+CONVARCS+=     ../components/libconv_2011/libcxx11convenience.a
 LDADD=         -Wl,--whole-archive ${CONVARCS:.a=_pic.a} -lm
 LDADD+=                -Wl,--no-whole-archive
 ARADD=         ${CONVARCS} ${LIBM}
 
-SRCS=  ${libstdc___la_SOURCES}
+# The AR script is a nice trick, but it *cannot* handle "++" on any line
+# To work around this incredible limitation, copy files with "++" in
+# their names to a new file name (transform ++ => xx)
 
-gstdint.h:
-       echo "#include <stdint.h>" > ${.TARGET}
+SRCS=          ${libstdc___la_SOURCES:S|++|xx|}
+PROBLEMS=      ${libstdc___la_SOURCES:M*++*}
+
+libstdc++.a: ${SRCS:.cc=.o} script.ar
+       @${ECHO} building static ${LIB} library via script
+       rm -f ${.TARGET}
+       ${AR} -M < script.ar
+       mv libstdcxx.a ${.TARGET}
 
-beforedepend:  gstdint.h
-CLEANFILES=    gstdint.h
+${PROBLEMS:S|++|xx|}: ${PROBLEMS}
+       cp ${SRCDIR}/src/c++11/${.TARGET:S|xx|++|} ${.TARGET}
+
+gstdint.h:
+       @echo "#include <stdint.h>" > ${.TARGET}
+
+script.ar:
+       @echo "CREATE libstdcxx.a"      >  ${.TARGET}
+.for arc in ${CONVARCS}
+       @echo "ADDLIB ${arc}"           >> ${.TARGET}
+.endfor
+.for obj in ${SRCS:.cc=.o}
+       @echo "ADDMOD ${obj}"           >> ${.TARGET}
+.endfor
+       @echo "SAVE"                    >> ${.TARGET}
+       @echo "END"                     >> ${.TARGET}
+
+beforedepend:  gstdint.h script.ar ${PROBLEMS:S|++|xx|}
+CLEANFILES=    gstdint.h script.ar ${PROBLEMS:S|++|xx|}
 
 .include <bsd.lib.mk>