···11-source $stdenv/setup
22-33-44-export NIX_FIXINC_DUMMY=$NIX_BUILD_TOP/dummy
55-mkdir $NIX_FIXINC_DUMMY
66-77-88-# libstdc++ needs this; otherwise it will use /lib/cpp, which is a Bad
99-# Thing.
1010-export CPP="gcc -E"
1111-1212-1313-if test "$noSysDirs" = "1"; then
1414-1515- # Figure out what extra flags to pass to the gcc compilers being
1616- # generated to make sure that they use our glibc.
1717- if test -e $NIX_CC/nix-support/orig-glibc; then
1818- glibc=$(cat $NIX_CC/nix-support/orig-glibc)
1919-2020- # Ugh. Copied from gcc-wrapper/builder.sh. We can't just
2121- # source in $NIX_CC/nix-support/add-flags, since that would
2222- # cause *this* GCC to be linked against the *previous* GCC.
2323- # Need some more modularity there.
2424- extraCFlags="-B$glibc/lib -isystem $glibc/include"
2525- extraLDFlags="-B$glibc/lib -L$glibc/lib -Wl,-s \
2626- -Wl,-dynamic-linker,$glibc/lib/ld-linux.so.2"
2727-2828- # Oh, what a hack. I should be shot for this. In stage 1, we
2929- # should link against the previous GCC, but not afterwards.
3030- # Otherwise we retain a dependency. However, ld-wrapper,
3131- # which adds the linker flags for the previous GCC, is also
3232- # used in stage 2/3. We can prevent it from adding them by
3333- # NIX_GLIBC_FLAGS_SET, but then gcc-wrapper will also not add
3434- # them, thereby causing stage 1 to fail. So we use a trick to
3535- # only set the flags in gcc-wrapper.
3636- hook=$(pwd)/ld-wrapper-hook
3737- echo "NIX_GLIBC_FLAGS_SET=1" > $hook
3838- export NIX_LD_WRAPPER_START_HOOK=$hook
3939-4040- # Use *real* header files, otherwise a limits.h is generated
4141- # that does not include Glibc's limits.h (notably missing
4242- # SSIZE_MAX, which breaks the build).
4343- export NIX_FIXINC_DUMMY=$glibc/include
4444- fi
4545-4646- export NIX_EXTRA_CFLAGS=$extraCFlags
4747- export NIX_EXTRA_LDFLAGS=$extraLDFlags
4848- export CFLAGS=$extraCFlags
4949- export CXXFLAGS=$extraCFlags
5050- export LDFLAGS=$extraLDFlags
5151-fi
5252-5353-5454-preConfigure() {
5555-5656- # Determine the frontends to build.
5757- langs="c"
5858- if test -n "$langCC"; then
5959- langs="$langs,c++"
6060- fi
6161- if test -n "$langF77"; then
6262- langs="$langs,f95"
6363- fi
6464- if test -n "$langObjC"; then
6565- langs="$langs,objc"
6666- fi
6767-6868- # Perform the build in a different directory.
6969- mkdir ../build
7070- cd ../build
7171-7272- configureScript=../$sourceRoot/configure
7373- configureFlags="--enable-languages=$langs --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-multilib --with-gxx-include-dir=${STDCXX_INCDIR} --host=x86_64-apple-darwin10 --build=x86_64-apple-darwin10 --target=x86_64-apple-darwin10"
7474-}
7575-7676-7777-postInstall() {
7878- # Remove precompiled headers for now. They are very big and
7979- # probably not very useful yet.
8080- find $out/include -name "*.gch" -exec rm -rf {} \; -prune
8181-8282- # Remove `fixincl' to prevent a retained dependency on the
8383- # previous gcc.
8484- rm -rf $out/libexec/gcc/*/*/install-tools
8585-}
8686-8787-8888-postUnpack() {
8989- mv $libstdcxx/libstdcxx $sourceRoot/
9090-}
9191-9292-9393-STDCXX_INCDIR="$out/include/c++/4.2.1"
9494-9595-genericBuild
9696-9797-9898-echo '-------------------------------------------------------------------------------------------------------------------------'
9999-echo 'libstdcxx'
100100-echo '-------------------------------------------------------------------------------------------------------------------------'
101101-102102-cd ..
103103-pwd
104104-105105-unpackPhase () {
106106- true
107107-}
108108-109109-patchPhase() {
110110- true
111111-}
112112-113113-preConfigure() {
114114- # Perform the build in a different directory.
115115- mkdir ../build_libstdcxx
116116- cd ../build_libstdcxx
117117-118118- ln -s ../build/gcc gcc
119119-120120- configureScript=../$sourceRoot/libstdcxx/configure
121121- configureFlags="--disable-libstdcxx-pch --disable-libstdcxx-debug --disable-multilib --with-gxx-include-dir=${STDCXX_INCDIR}"
122122-}
123123-124124-postInstall() {
125125- echo "cp -v ${STDCXX_INCDIR}/*/bits/* ${STDCXX_INCDIR}/bits/"
126126- cp -v ${STDCXX_INCDIR}/*/bits/* ${STDCXX_INCDIR}/bits/
127127-}
128128-129129-genericBuild
130130-131131-ln -s $out/lib/x86_64 $out/lib64
···11---- gcc-5666.3/gcc/toplev.h
22-+++ gcc-5666.3/gcc/toplev.h
33-@@ -151,6 +151,8 @@
44- /* Return true iff flags are set as if -ffast-math. */
55- extern bool fast_math_flags_set_p (void);
66-77-+#if GCC_VERSION < 3004
88-+
99- /* Return log2, or -1 if not exact. */
1010- extern int exact_log2 (unsigned HOST_WIDE_INT);
1111-1212-@@ -158,7 +160,7 @@
1313- extern int floor_log2 (unsigned HOST_WIDE_INT);
1414-1515- /* Inline versions of the above for speed. */
1616--#if GCC_VERSION >= 3004
1717-+#else /* GCC_VERSION < 3004 */
1818- # if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
1919- # define CLZ_HWI __builtin_clzl
2020- # define CTZ_HWI __builtin_ctzl
2121-@@ -172,18 +172,18 @@
2222- # define CTZ_HWI __builtin_ctz
2323- # endif
2424-2525--extern inline int
2626-+static inline int
2727- floor_log2 (unsigned HOST_WIDE_INT x)
2828- {
2929- return x ? HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x) : -1;
3030- }
3131-3232--extern inline int
3333-+static inline int
3434- exact_log2 (unsigned HOST_WIDE_INT x)
3535- {
3636- return x == (x & -x) && x ? (int) CTZ_HWI (x) : -1;
3737- }
3838--#endif /* GCC_VERSION >= 3004 */
3939-+#endif /* GCC_VERSION < 3004 */
4040-4141- /* Functions used to get and set GCC's notion of in what directory
4242- compilation was started. */
4343---- gcc-5666.3/gcc/toplev.c
4444-+++ gcc-5666.3/gcc/toplev.c
4545-@@ -555,7 +555,7 @@
4646- for floor_log2 and exact_log2; see toplev.h. That construct, however,
4747- conflicts with the ISO C++ One Definition Rule. */
4848-4949--#if GCC_VERSION < 3004 || !defined (__cplusplus)
5050-+#if GCC_VERSION < 3004
5151-5252- /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
5353- If X is 0, return -1. */
5454-@@ -607,7 +607,7 @@
5555- #endif
5656- }
5757-5858--#endif /* GCC_VERSION < 3004 || !defined (__cplusplus) */
5959-+#endif /* GCC_VERSION < 3004 */
6060-6161- /* Handler for fatal signals, such as SIGSEGV. These are transformed
6262- into ICE messages, which is much more user friendly. In case the
···11-diff -ruN gcc-4.1.0/gcc/Makefile.in gcc-4.1.0.new/gcc/Makefile.in
22---- gcc-4.1.0/gcc/Makefile.in 2006-02-16 16:23:24.000000000 +0100
33-+++ gcc-4.1.0.new/gcc/Makefile.in 2006-03-01 18:55:12.000000000 +0100
44-@@ -219,7 +219,7 @@
55- CPPFLAGS = @CPPFLAGS@
66-77- # These exists to be overridden by the x-* and t-* files, respectively.
88--X_CFLAGS =
99-+X_CFLAGS = $(NIX_EXTRA_CFLAGS) $(NIX_EXTRA_LDFLAGS)
1010- T_CFLAGS =
1111-1212- X_CPPFLAGS =
1313-@@ -383,7 +383,11 @@
1414- MD5_H = $(srcdir)/../include/md5.h
1515-1616- # Default native SYSTEM_HEADER_DIR, to be overridden by targets.
1717--NATIVE_SYSTEM_HEADER_DIR = /usr/include
1818-+# Nix: we override NATIVE_SYSTEM_HEADER_DIR in order to prevent
1919-+# `fixinc' from fixing header files in /usr/include. However,
2020-+# NATIVE_SYSTEM_HEADER_DIR must point to an existing directory, so set
2121-+# it to some dummy directory.
2222-+NATIVE_SYSTEM_HEADER_DIR = $(NIX_FIXINC_DUMMY)
2323- # Default cross SYSTEM_HEADER_DIR, to be overridden by targets.
2424- CROSS_SYSTEM_HEADER_DIR = @CROSS_SYSTEM_HEADER_DIR@
2525-2626-@@ -395,7 +399,7 @@
2727- STMP_FIXINC = @STMP_FIXINC@
2828-2929- # Test to see whether <limits.h> exists in the system header files.
3030--LIMITS_H_TEST = [ -f $(SYSTEM_HEADER_DIR)/limits.h ]
3131-+LIMITS_H_TEST = true
3232-3333- # Directory for prefix to system directories, for
3434- # each of $(system_prefix)/usr/include, $(system_prefix)/usr/lib, etc.
3535-@@ -3002,7 +3006,7 @@
3636- -DGPLUSPLUS_INCLUDE_DIR=\"$(gcc_gxx_include_dir)\" \
3737- -DGPLUSPLUS_TOOL_INCLUDE_DIR=\"$(gcc_gxx_include_dir)/$(target_noncanonical)\" \
3838- -DGPLUSPLUS_BACKWARD_INCLUDE_DIR=\"$(gcc_gxx_include_dir)/backward\" \
3939-- -DLOCAL_INCLUDE_DIR=\"$(local_includedir)\" \
4040-+ -DLOCAL_INCLUDE_DIR=\"/no-such-dir\" \
4141- -DCROSS_INCLUDE_DIR=\"$(CROSS_SYSTEM_HEADER_DIR)\" \
4242- -DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\" \
4343- @TARGET_SYSTEM_ROOT_DEFINE@
4444-4545-diff -ruN gcc-4.1.0/ltcf-cxx.sh gcc-4.1.0.new/ltcf-cxx.sh
4646---- gcc-4.1.0/ltcf-cxx.sh 2005-07-16 04:30:53.000000000 +0200
4747-+++ gcc-4.1.0.new/ltcf-cxx.sh 2006-03-01 18:58:15.000000000 +0100
4848-@@ -989,7 +989,7 @@
4949- # the conftest object file.
5050- pre_test_object_deps_done=no
5151-5252-- for p in `eval $output_verbose_link_cmd`; do
5353-+ for p in `true`; do
5454-5555- case $p in
5656-5757-diff -ruN gcc-4.1.0/ltconfig gcc-4.1.0.new/ltconfig
5858---- gcc-4.1.0/ltconfig 2005-07-16 04:30:53.000000000 +0200
5959-+++ gcc-4.1.0.new/ltconfig 2006-03-01 18:59:58.000000000 +0100
6060-@@ -2322,6 +2322,11 @@
6161- # A language-specific compiler.
6262- CC=$CC
6363-6464-+# Ugly hack to get libmudflap (and possibly other libraries) to build.
6565-+# Libtool filters out \`-B' flags when linking (why?), so the \`-B' flag
6666-+# to Glibc gets lost. Here we forcibly add it to any invocation.
6767-+CC="\$CC $NIX_EXTRA_LDFLAGS"
6868-+
6969- # Is the compiler the GNU C compiler?
7070- with_gcc=$with_gcc
7171-7272-diff -ruN gcc-4.1.0/Makefile.in gcc-4.1.0.new/Makefile.in
7373---- gcc-4.1.0/Makefile.in 2005-12-15 15:02:02.000000000 +0100
7474-+++ gcc-4.1.0.new/Makefile.in 2006-03-01 19:41:04.000000000 +0100
7575-@@ -286,7 +286,7 @@
7676- WINDRES = @WINDRES@
7777-7878- CFLAGS = @CFLAGS@
7979--LDFLAGS =
8080-+LDFLAGS = $(NIX_EXTRA_LDFLAGS)
8181- LIBCFLAGS = $(CFLAGS)
8282- CXXFLAGS = @CXXFLAGS@
8383- LIBCXXFLAGS = $(CXXFLAGS) -fno-implicit-templates
8484-@@ -329,12 +329,12 @@
8585- # CFLAGS will be just -g. We want to ensure that TARGET libraries
8686- # (which we know are built with gcc) are built with optimizations so
8787- # prepend -O2 when setting CFLAGS_FOR_TARGET.
8888--CFLAGS_FOR_TARGET = -O2 $(CFLAGS) $(SYSROOT_CFLAGS_FOR_TARGET)
8989-+CFLAGS_FOR_TARGET = -O2 $(CFLAGS) $(SYSROOT_CFLAGS_FOR_TARGET) $(NIX_EXTRA_CFLAGS)
9090- SYSROOT_CFLAGS_FOR_TARGET = @SYSROOT_CFLAGS_FOR_TARGET@
9191--CXXFLAGS_FOR_TARGET = $(CXXFLAGS) $(SYSROOT_CFLAGS_FOR_TARGET)
9292-+CXXFLAGS_FOR_TARGET = $(CXXFLAGS) $(SYSROOT_CFLAGS_FOR_TARGET) $(NIX_EXTRA_CFLAGS)
9393- LIBCFLAGS_FOR_TARGET = $(CFLAGS_FOR_TARGET)
9494- LIBCXXFLAGS_FOR_TARGET = $(CXXFLAGS_FOR_TARGET) -fno-implicit-templates
9595--LDFLAGS_FOR_TARGET =
9696-+LDFLAGS_FOR_TARGET = $(NIX_EXTRA_LDFLAGS)
9797- PICFLAG_FOR_TARGET =
9898-9999- # ------------------------------------