···1-source $stdenv/setup
2-3-4-export NIX_FIXINC_DUMMY=$NIX_BUILD_TOP/dummy
5-mkdir $NIX_FIXINC_DUMMY
6-7-8-# libstdc++ needs this; otherwise it will use /lib/cpp, which is a Bad
9-# Thing.
10-export CPP="gcc -E"
11-12-13-if test "$noSysDirs" = "1"; then
14-15- # Figure out what extra flags to pass to the gcc compilers being
16- # generated to make sure that they use our glibc.
17- if test -e $NIX_CC/nix-support/orig-glibc; then
18- glibc=$(cat $NIX_CC/nix-support/orig-glibc)
19-20- # Ugh. Copied from gcc-wrapper/builder.sh. We can't just
21- # source in $NIX_CC/nix-support/add-flags, since that would
22- # cause *this* GCC to be linked against the *previous* GCC.
23- # Need some more modularity there.
24- extraCFlags="-B$glibc/lib -isystem $glibc/include"
25- extraLDFlags="-B$glibc/lib -L$glibc/lib -Wl,-s \
26- -Wl,-dynamic-linker,$glibc/lib/ld-linux.so.2"
27-28- # Oh, what a hack. I should be shot for this. In stage 1, we
29- # should link against the previous GCC, but not afterwards.
30- # Otherwise we retain a dependency. However, ld-wrapper,
31- # which adds the linker flags for the previous GCC, is also
32- # used in stage 2/3. We can prevent it from adding them by
33- # NIX_GLIBC_FLAGS_SET, but then gcc-wrapper will also not add
34- # them, thereby causing stage 1 to fail. So we use a trick to
35- # only set the flags in gcc-wrapper.
36- hook=$(pwd)/ld-wrapper-hook
37- echo "NIX_GLIBC_FLAGS_SET=1" > $hook
38- export NIX_LD_WRAPPER_START_HOOK=$hook
39-40- # Use *real* header files, otherwise a limits.h is generated
41- # that does not include Glibc's limits.h (notably missing
42- # SSIZE_MAX, which breaks the build).
43- export NIX_FIXINC_DUMMY=$glibc/include
44- fi
45-46- export NIX_EXTRA_CFLAGS=$extraCFlags
47- export NIX_EXTRA_LDFLAGS=$extraLDFlags
48- export CFLAGS=$extraCFlags
49- export CXXFLAGS=$extraCFlags
50- export LDFLAGS=$extraLDFlags
51-fi
52-53-54-preConfigure() {
55-56- # Determine the frontends to build.
57- langs="c"
58- if test -n "$langCC"; then
59- langs="$langs,c++"
60- fi
61- if test -n "$langF77"; then
62- langs="$langs,f95"
63- fi
64- if test -n "$langObjC"; then
65- langs="$langs,objc"
66- fi
67-68- # Perform the build in a different directory.
69- mkdir ../build
70- cd ../build
71-72- configureScript=../$sourceRoot/configure
73- 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"
74-}
75-76-77-postInstall() {
78- # Remove precompiled headers for now. They are very big and
79- # probably not very useful yet.
80- find $out/include -name "*.gch" -exec rm -rf {} \; -prune
81-82- # Remove `fixincl' to prevent a retained dependency on the
83- # previous gcc.
84- rm -rf $out/libexec/gcc/*/*/install-tools
85-}
86-87-88-postUnpack() {
89- mv $libstdcxx/libstdcxx $sourceRoot/
90-}
91-92-93-STDCXX_INCDIR="$out/include/c++/4.2.1"
94-95-genericBuild
96-97-98-echo '-------------------------------------------------------------------------------------------------------------------------'
99-echo 'libstdcxx'
100-echo '-------------------------------------------------------------------------------------------------------------------------'
101-102-cd ..
103-pwd
104-105-unpackPhase () {
106- true
107-}
108-109-patchPhase() {
110- true
111-}
112-113-preConfigure() {
114- # Perform the build in a different directory.
115- mkdir ../build_libstdcxx
116- cd ../build_libstdcxx
117-118- ln -s ../build/gcc gcc
119-120- configureScript=../$sourceRoot/libstdcxx/configure
121- configureFlags="--disable-libstdcxx-pch --disable-libstdcxx-debug --disable-multilib --with-gxx-include-dir=${STDCXX_INCDIR}"
122-}
123-124-postInstall() {
125- echo "cp -v ${STDCXX_INCDIR}/*/bits/* ${STDCXX_INCDIR}/bits/"
126- cp -v ${STDCXX_INCDIR}/*/bits/* ${STDCXX_INCDIR}/bits/
127-}
128-129-genericBuild
130-131-ln -s $out/lib/x86_64 $out/lib64
···1---- gcc-5666.3/gcc/toplev.h
2-+++ gcc-5666.3/gcc/toplev.h
3-@@ -151,6 +151,8 @@
4- /* Return true iff flags are set as if -ffast-math. */
5- extern bool fast_math_flags_set_p (void);
6-7-+#if GCC_VERSION < 3004
8-+
9- /* Return log2, or -1 if not exact. */
10- extern int exact_log2 (unsigned HOST_WIDE_INT);
11-12-@@ -158,7 +160,7 @@
13- extern int floor_log2 (unsigned HOST_WIDE_INT);
14-15- /* Inline versions of the above for speed. */
16--#if GCC_VERSION >= 3004
17-+#else /* GCC_VERSION < 3004 */
18- # if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
19- # define CLZ_HWI __builtin_clzl
20- # define CTZ_HWI __builtin_ctzl
21-@@ -172,18 +172,18 @@
22- # define CTZ_HWI __builtin_ctz
23- # endif
24-25--extern inline int
26-+static inline int
27- floor_log2 (unsigned HOST_WIDE_INT x)
28- {
29- return x ? HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x) : -1;
30- }
31-32--extern inline int
33-+static inline int
34- exact_log2 (unsigned HOST_WIDE_INT x)
35- {
36- return x == (x & -x) && x ? (int) CTZ_HWI (x) : -1;
37- }
38--#endif /* GCC_VERSION >= 3004 */
39-+#endif /* GCC_VERSION < 3004 */
40-41- /* Functions used to get and set GCC's notion of in what directory
42- compilation was started. */
43---- gcc-5666.3/gcc/toplev.c
44-+++ gcc-5666.3/gcc/toplev.c
45-@@ -555,7 +555,7 @@
46- for floor_log2 and exact_log2; see toplev.h. That construct, however,
47- conflicts with the ISO C++ One Definition Rule. */
48-49--#if GCC_VERSION < 3004 || !defined (__cplusplus)
50-+#if GCC_VERSION < 3004
51-52- /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
53- If X is 0, return -1. */
54-@@ -607,7 +607,7 @@
55- #endif
56- }
57-58--#endif /* GCC_VERSION < 3004 || !defined (__cplusplus) */
59-+#endif /* GCC_VERSION < 3004 */
60-61- /* Handler for fatal signals, such as SIGSEGV. These are transformed
62- into ICE messages, which is much more user friendly. In case the
···1-diff -ruN gcc-4.1.0/gcc/Makefile.in gcc-4.1.0.new/gcc/Makefile.in
2---- gcc-4.1.0/gcc/Makefile.in 2006-02-16 16:23:24.000000000 +0100
3-+++ gcc-4.1.0.new/gcc/Makefile.in 2006-03-01 18:55:12.000000000 +0100
4-@@ -219,7 +219,7 @@
5- CPPFLAGS = @CPPFLAGS@
6-7- # These exists to be overridden by the x-* and t-* files, respectively.
8--X_CFLAGS =
9-+X_CFLAGS = $(NIX_EXTRA_CFLAGS) $(NIX_EXTRA_LDFLAGS)
10- T_CFLAGS =
11-12- X_CPPFLAGS =
13-@@ -383,7 +383,11 @@
14- MD5_H = $(srcdir)/../include/md5.h
15-16- # Default native SYSTEM_HEADER_DIR, to be overridden by targets.
17--NATIVE_SYSTEM_HEADER_DIR = /usr/include
18-+# Nix: we override NATIVE_SYSTEM_HEADER_DIR in order to prevent
19-+# `fixinc' from fixing header files in /usr/include. However,
20-+# NATIVE_SYSTEM_HEADER_DIR must point to an existing directory, so set
21-+# it to some dummy directory.
22-+NATIVE_SYSTEM_HEADER_DIR = $(NIX_FIXINC_DUMMY)
23- # Default cross SYSTEM_HEADER_DIR, to be overridden by targets.
24- CROSS_SYSTEM_HEADER_DIR = @CROSS_SYSTEM_HEADER_DIR@
25-26-@@ -395,7 +399,7 @@
27- STMP_FIXINC = @STMP_FIXINC@
28-29- # Test to see whether <limits.h> exists in the system header files.
30--LIMITS_H_TEST = [ -f $(SYSTEM_HEADER_DIR)/limits.h ]
31-+LIMITS_H_TEST = true
32-33- # Directory for prefix to system directories, for
34- # each of $(system_prefix)/usr/include, $(system_prefix)/usr/lib, etc.
35-@@ -3002,7 +3006,7 @@
36- -DGPLUSPLUS_INCLUDE_DIR=\"$(gcc_gxx_include_dir)\" \
37- -DGPLUSPLUS_TOOL_INCLUDE_DIR=\"$(gcc_gxx_include_dir)/$(target_noncanonical)\" \
38- -DGPLUSPLUS_BACKWARD_INCLUDE_DIR=\"$(gcc_gxx_include_dir)/backward\" \
39-- -DLOCAL_INCLUDE_DIR=\"$(local_includedir)\" \
40-+ -DLOCAL_INCLUDE_DIR=\"/no-such-dir\" \
41- -DCROSS_INCLUDE_DIR=\"$(CROSS_SYSTEM_HEADER_DIR)\" \
42- -DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\" \
43- @TARGET_SYSTEM_ROOT_DEFINE@
44-45-diff -ruN gcc-4.1.0/ltcf-cxx.sh gcc-4.1.0.new/ltcf-cxx.sh
46---- gcc-4.1.0/ltcf-cxx.sh 2005-07-16 04:30:53.000000000 +0200
47-+++ gcc-4.1.0.new/ltcf-cxx.sh 2006-03-01 18:58:15.000000000 +0100
48-@@ -989,7 +989,7 @@
49- # the conftest object file.
50- pre_test_object_deps_done=no
51-52-- for p in `eval $output_verbose_link_cmd`; do
53-+ for p in `true`; do
54-55- case $p in
56-57-diff -ruN gcc-4.1.0/ltconfig gcc-4.1.0.new/ltconfig
58---- gcc-4.1.0/ltconfig 2005-07-16 04:30:53.000000000 +0200
59-+++ gcc-4.1.0.new/ltconfig 2006-03-01 18:59:58.000000000 +0100
60-@@ -2322,6 +2322,11 @@
61- # A language-specific compiler.
62- CC=$CC
63-64-+# Ugly hack to get libmudflap (and possibly other libraries) to build.
65-+# Libtool filters out \`-B' flags when linking (why?), so the \`-B' flag
66-+# to Glibc gets lost. Here we forcibly add it to any invocation.
67-+CC="\$CC $NIX_EXTRA_LDFLAGS"
68-+
69- # Is the compiler the GNU C compiler?
70- with_gcc=$with_gcc
71-72-diff -ruN gcc-4.1.0/Makefile.in gcc-4.1.0.new/Makefile.in
73---- gcc-4.1.0/Makefile.in 2005-12-15 15:02:02.000000000 +0100
74-+++ gcc-4.1.0.new/Makefile.in 2006-03-01 19:41:04.000000000 +0100
75-@@ -286,7 +286,7 @@
76- WINDRES = @WINDRES@
77-78- CFLAGS = @CFLAGS@
79--LDFLAGS =
80-+LDFLAGS = $(NIX_EXTRA_LDFLAGS)
81- LIBCFLAGS = $(CFLAGS)
82- CXXFLAGS = @CXXFLAGS@
83- LIBCXXFLAGS = $(CXXFLAGS) -fno-implicit-templates
84-@@ -329,12 +329,12 @@
85- # CFLAGS will be just -g. We want to ensure that TARGET libraries
86- # (which we know are built with gcc) are built with optimizations so
87- # prepend -O2 when setting CFLAGS_FOR_TARGET.
88--CFLAGS_FOR_TARGET = -O2 $(CFLAGS) $(SYSROOT_CFLAGS_FOR_TARGET)
89-+CFLAGS_FOR_TARGET = -O2 $(CFLAGS) $(SYSROOT_CFLAGS_FOR_TARGET) $(NIX_EXTRA_CFLAGS)
90- SYSROOT_CFLAGS_FOR_TARGET = @SYSROOT_CFLAGS_FOR_TARGET@
91--CXXFLAGS_FOR_TARGET = $(CXXFLAGS) $(SYSROOT_CFLAGS_FOR_TARGET)
92-+CXXFLAGS_FOR_TARGET = $(CXXFLAGS) $(SYSROOT_CFLAGS_FOR_TARGET) $(NIX_EXTRA_CFLAGS)
93- LIBCFLAGS_FOR_TARGET = $(CFLAGS_FOR_TARGET)
94- LIBCXXFLAGS_FOR_TARGET = $(CXXFLAGS_FOR_TARGET) -fno-implicit-templates
95--LDFLAGS_FOR_TARGET =
96-+LDFLAGS_FOR_TARGET = $(NIX_EXTRA_LDFLAGS)
97- PICFLAG_FOR_TARGET =
98-99- # ------------------------------------