1{ stdenv, callPackage
2, withLinuxHeaders ? true
3, installLocales ? true
4, profilingLibraries ? false
5, withGd ? false
6}:
7
8assert stdenv.cc.isGNU;
9
10callPackage ./common.nix { inherit stdenv; } {
11 name = "glibc" + stdenv.lib.optionalString withGd "-gd";
12
13 inherit withLinuxHeaders profilingLibraries installLocales withGd;
14
15 NIX_NO_SELF_RPATH = true;
16
17 postConfigure = ''
18 # Hack: get rid of the `-static' flag set by the bootstrap stdenv.
19 # This has to be done *after* `configure' because it builds some
20 # test binaries.
21 export NIX_CFLAGS_LINK=
22 export NIX_LDFLAGS_BEFORE=
23
24 export NIX_DONT_SET_RPATH=1
25 unset CFLAGS
26
27 # Apparently --bindir is not respected.
28 makeFlagsArray+=("bindir=$bin/bin" "sbindir=$bin/sbin" "rootsbindir=$bin/sbin")
29 '';
30
31 # The stackprotector and fortify hardening flags are autodetected by glibc
32 # and enabled by default if supported. Setting it for every gcc invocation
33 # does not work.
34 hardeningDisable = [ "stackprotector" "fortify" ];
35
36 # When building glibc from bootstrap-tools, we need libgcc_s at RPATH for
37 # any program we run, because the gcc will have been placed at a new
38 # store path than that determined when built (as a source for the
39 # bootstrap-tools tarball)
40 # Building from a proper gcc staying in the path where it was installed,
41 # libgcc_s will not be at {gcc}/lib, and gcc's libgcc will be found without
42 # any special hack.
43 preInstall = ''
44 if [ -f ${stdenv.cc.cc}/lib/libgcc_s.so.1 ]; then
45 mkdir -p $out/lib
46 cp ${stdenv.cc.cc}/lib/libgcc_s.so.1 $out/lib/libgcc_s.so.1
47 # the .so It used to be a symlink, but now it is a script
48 cp -a ${stdenv.cc.cc}/lib/libgcc_s.so $out/lib/libgcc_s.so
49 fi
50 '';
51
52 postInstall = ''
53 if test -n "$installLocales"; then
54 make -j''${NIX_BUILD_CORES:-1} -l''${NIX_BUILD_CORES:-1} localedata/install-locales
55 fi
56
57 test -f $out/etc/ld.so.cache && rm $out/etc/ld.so.cache
58
59 if test -n "$linuxHeaders"; then
60 # Include the Linux kernel headers in Glibc, except the `scsi'
61 # subdirectory, which Glibc provides itself.
62 (cd $dev/include && \
63 ln -sv $(ls -d $linuxHeaders/include/* | grep -v scsi\$) .)
64 fi
65
66 # Fix for NIXOS-54 (ldd not working on x86_64). Make a symlink
67 # "lib64" to "lib".
68 if test -n "$is64bit"; then
69 ln -s lib $out/lib64
70 fi
71
72 # Get rid of more unnecessary stuff.
73 rm -rf $out/var $bin/bin/sln
74
75 # For some reason these aren't stripped otherwise and retain reference
76 # to bootstrap-tools; on cross-arm this stripping would break objects.
77 if [ -z "$crossConfig" ]; then
78 for i in "$out"/lib/*.a; do
79 [ "$i" = "$out/lib/libm.a" ] || strip -S "$i"
80 done
81 fi
82
83 # Put libraries for static linking in a separate output. Note
84 # that libc_nonshared.a and libpthread_nonshared.a are required
85 # for dynamically-linked applications.
86 mkdir -p $static/lib
87 mv $out/lib/*.a $static/lib
88 mv $static/lib/lib*_nonshared.a $out/lib
89 # Some of *.a files are linker scripts where moving broke the paths.
90 sed "/^GROUP/s|$out/lib/lib|$static/lib/lib|g" \
91 -i "$static"/lib/*.a
92
93 # Work around a Nix bug: hard links across outputs cause a build failure.
94 cp $bin/bin/getconf $bin/bin/getconf_
95 mv $bin/bin/getconf_ $bin/bin/getconf
96 '';
97
98 separateDebugInfo = true;
99
100 meta.description = "The GNU C Library";
101 }