1{ lib, stdenv, fetchurl, fetchpatch, flex, bison, file }:
2
3stdenv.mkDerivation rec {
4 pname = "libstdc++5";
5 version = "3.3.6";
6
7 src = [
8 (fetchurl {
9 url = "mirror://gcc/releases/gcc-${version}/gcc-core-${version}.tar.bz2";
10 sha256 = "1dpyrpsgakilz2rnh5f8gvrzq5pwzvndacc0df6m04bpqn5fx6sg";
11 })
12 (fetchurl {
13 url = "mirror://gcc/releases/gcc-${version}/gcc-g++-${version}.tar.bz2";
14 sha256 = "14lxl81f7adpc9jxfiwzdxsdzs5zv4piv8xh7f9w910hfzrgvsby";
15 })
16 ];
17
18 patches = [
19 ./no-sys-dirs.patch
20 (fetchpatch {
21 name = "siginfo.patch";
22 url = "https://raw.githubusercontent.com/archlinux/svntogit-packages/e36ee8ed9bb5942db14cf6249a2ead14974a2bfa/trunk/siginfo.patch";
23 sha256 = "15zldbm33yba293dgrgsbv3j332hkc3iqpyc8fa7zl42mh9qk22j";
24 extraPrefix = "";
25 })
26 (fetchpatch {
27 name = "gcc-3.4.3-no_multilib_amd64.patch";
28 url = "https://raw.githubusercontent.com/archlinux/svntogit-packages/e36ee8ed9bb5942db14cf6249a2ead14974a2bfa/trunk/gcc-3.4.3-no_multilib_amd64.patch";
29 sha256 = "11m5lc51b0addhc4yq4rz0dwpv6k73rrj73wya3lqdk8rly6cjpm";
30 extraPrefix = "";
31 })
32 # Required because of glibc 2.26
33 ./struct-ucontext.patch
34 ];
35
36 postPatch = ''
37 # fix build issue with recent gcc
38 sed -i "s#O_CREAT#O_CREAT, 0666#" gcc/collect2.c
39
40 # No fixincludes
41 sed -i -e 's@\./fixinc\.sh@-c true@' gcc/Makefile.in
42 '';
43
44 preConfigure = ''
45 mkdir ../build
46 cd ../build
47 configureScript=../$sourceRoot/configure
48 '';
49
50 preBuild = ''
51 # libstdc++ needs this; otherwise it will use /lib/cpp, which is a Bad
52 # Thing.
53 export CPP="gcc -E"
54
55 # Use *real* header files, otherwise a limits.h is generated
56 # that does not include Glibc's limits.h (notably missing
57 # SSIZE_MAX, which breaks the build).
58 export NIX_FIXINC_DUMMY="$(cat $NIX_CC/nix-support/orig-libc-dev)/include"
59
60 # The path to the Glibc binaries such as `crti.o'.
61 glibc_libdir="$(cat $NIX_CC/nix-support/orig-libc)/lib"
62
63 # Figure out what extra flags to pass to the gcc compilers
64 # being generated to make sure that they use our glibc.
65 EXTRA_FLAGS="-I$NIX_FIXINC_DUMMY $(cat $NIX_CC/nix-support/libc-crt1-cflags) $(cat $NIX_CC/nix-support/libc-cflags) -O2"
66
67 extraLDFlags="-L$glibc_libdir -rpath $glibc_libdir $(cat $NIX_BINTOOLS/nix-support/libc-ldflags || true) $(cat $NIX_BINTOOLS/nix-support/libc-ldflags-before || true)"
68 for i in $extraLDFlags; do
69 EXTRA_FLAGS="$EXTRA_FLAGS -Wl,$i"
70 done
71
72 # CFLAGS_FOR_TARGET are needed for the libstdc++ configure script to find
73 # the startfiles.
74 # FLAGS_FOR_TARGET are needed for the target libraries to receive the -Bxxx
75 # for the startfiles.
76 makeFlagsArray=( \
77 "''${makeFlagsArray[@]}" \
78 NATIVE_SYSTEM_HEADER_DIR="$NIX_FIXINC_DUMMY" \
79 SYSTEM_HEADER_DIR="$NIX_FIXINC_DUMMY" \
80 CFLAGS_FOR_BUILD="$EXTRA_FLAGS" \
81 CFLAGS_FOR_TARGET="$EXTRA_FLAGS" \
82 CXXFLAGS_FOR_BUILD="$EXTRA_FLAGS" \
83 CXXFLAGS_FOR_TARGET="$EXTRA_FLAGS" \
84 FLAGS_FOR_TARGET="$EXTRA_FLAGS" \
85 LDFLAGS_FOR_BUILD="$EXTRA_FLAGS" \
86 LDFLAGS_FOR_TARGET="$EXTRA_FLAGS" \
87 BOOT_CFLAGS="$EXTRA_FLAGS" \
88 BOOT_LDFLAGS="$EXTRA_FLAGS"
89 )
90 '';
91
92 hardeningDisable = [ "format" ];
93
94 nativeBuildInputs = [ flex bison file ];
95
96 configureFlags = [ "--disable-multilib" "--enable-__cxa-atexit" "--enable-threads=posix" "--enable-languages=c++" "--enable-clocale=gnu" ];
97
98 buildFLags = [ "all-target-libstdc++-v3" ];
99
100 installFlags = [ "install-target-libstdc++-v3" ];
101
102 postInstall = ''
103 # Remove includefiles and libs provided by gcc
104 shopt -s extglob
105 rm -rf $out/{bin,include,share,man,info}
106 rm -f $out/lib/*.a
107 rm -rf $out/lib/!(libstdc++*)
108 '';
109
110 meta = with lib; {
111 homepage = "https://gcc.gnu.org/";
112 license = licenses.lgpl3Plus;
113 description = "GNU Compiler Collection, version ${version} -- C++ standard library";
114 platforms = platforms.linux;
115 maintainers = with maintainers; [ abbradar ];
116 # never built on aarch64-linux since first introduction in nixpkgs
117 broken = stdenv.isLinux && stdenv.isAarch64;
118 };
119}