···11+{ stdenv, callPackage
22+, withLinuxHeaders ? true
33+, installLocales ? true
44+, profilingLibraries ? false
55+, withGd ? false
66+}:
77+88+assert stdenv.cc.isGNU;
99+1010+callPackage ./common-2.27.nix { inherit stdenv; } {
1111+ name = "glibc" + stdenv.lib.optionalString withGd "-gd";
1212+1313+ inherit withLinuxHeaders profilingLibraries installLocales withGd;
1414+1515+ NIX_NO_SELF_RPATH = true;
1616+1717+ postConfigure = ''
1818+ # Hack: get rid of the `-static' flag set by the bootstrap stdenv.
1919+ # This has to be done *after* `configure' because it builds some
2020+ # test binaries.
2121+ export NIX_CFLAGS_LINK=
2222+ export NIX_LDFLAGS_BEFORE=
2323+2424+ export NIX_DONT_SET_RPATH=1
2525+ unset CFLAGS
2626+2727+ # Apparently --bindir is not respected.
2828+ makeFlagsArray+=("bindir=$bin/bin" "sbindir=$bin/sbin" "rootsbindir=$bin/sbin")
2929+ '';
3030+3131+ # The stackprotector and fortify hardening flags are autodetected by glibc
3232+ # and enabled by default if supported. Setting it for every gcc invocation
3333+ # does not work.
3434+ hardeningDisable = [ "stackprotector" "fortify" ];
3535+3636+ # When building glibc from bootstrap-tools, we need libgcc_s at RPATH for
3737+ # any program we run, because the gcc will have been placed at a new
3838+ # store path than that determined when built (as a source for the
3939+ # bootstrap-tools tarball)
4040+ # Building from a proper gcc staying in the path where it was installed,
4141+ # libgcc_s will not be at {gcc}/lib, and gcc's libgcc will be found without
4242+ # any special hack.
4343+ preInstall = ''
4444+ if [ -f ${stdenv.cc.cc}/lib/libgcc_s.so.1 ]; then
4545+ mkdir -p $out/lib
4646+ cp ${stdenv.cc.cc}/lib/libgcc_s.so.1 $out/lib/libgcc_s.so.1
4747+ # the .so It used to be a symlink, but now it is a script
4848+ cp -a ${stdenv.cc.cc}/lib/libgcc_s.so $out/lib/libgcc_s.so
4949+ fi
5050+ '';
5151+5252+ postInstall = ''
5353+ if test -n "$installLocales"; then
5454+ make -j''${NIX_BUILD_CORES:-1} -l''${NIX_BUILD_CORES:-1} localedata/install-locales
5555+ fi
5656+5757+ test -f $out/etc/ld.so.cache && rm $out/etc/ld.so.cache
5858+5959+ if test -n "$linuxHeaders"; then
6060+ # Include the Linux kernel headers in Glibc, except the `scsi'
6161+ # subdirectory, which Glibc provides itself.
6262+ (cd $dev/include && \
6363+ ln -sv $(ls -d $linuxHeaders/include/* | grep -v scsi\$) .)
6464+ fi
6565+6666+ # Fix for NIXOS-54 (ldd not working on x86_64). Make a symlink
6767+ # "lib64" to "lib".
6868+ if test -n "$is64bit"; then
6969+ ln -s lib $out/lib64
7070+ fi
7171+7272+ # Get rid of more unnecessary stuff.
7373+ rm -rf $out/var $bin/bin/sln
7474+7575+ # For some reason these aren't stripped otherwise and retain reference
7676+ # to bootstrap-tools; on cross-arm this stripping would break objects.
7777+ if [ -z "$crossConfig" ]; then
7878+ for i in "$out"/lib/*.a; do
7979+ [ "$i" = "$out/lib/libm.a" ] || strip -S "$i"
8080+ done
8181+ fi
8282+8383+ # Put libraries for static linking in a separate output. Note
8484+ # that libc_nonshared.a and libpthread_nonshared.a are required
8585+ # for dynamically-linked applications.
8686+ mkdir -p $static/lib
8787+ mv $out/lib/*.a $static/lib
8888+ mv $static/lib/lib*_nonshared.a $out/lib
8989+ # Some of *.a files are linker scripts where moving broke the paths.
9090+ sed "/^GROUP/s|$out/lib/lib|$static/lib/lib|g" \
9191+ -i "$static"/lib/*.a
9292+9393+ # Work around a Nix bug: hard links across outputs cause a build failure.
9494+ cp $bin/bin/getconf $bin/bin/getconf_
9595+ mv $bin/bin/getconf_ $bin/bin/getconf
9696+ '';
9797+9898+ separateDebugInfo = true;
9999+100100+ meta.description = "The GNU C Library";
101101+ }
+208
pkgs/development/libraries/glibc/common-2.27.nix
···11+/* Build configuration used to build glibc, Info files, and locale
22+ information. */
33+44+{ stdenv, lib
55+, buildPlatform, hostPlatform
66+, buildPackages
77+, fetchurl
88+, linuxHeaders ? null
99+, gd ? null, libpng ? null
1010+, bison
1111+}:
1212+1313+{ name
1414+, withLinuxHeaders ? false
1515+, profilingLibraries ? false
1616+, installLocales ? false
1717+, withGd ? false
1818+, meta
1919+, ...
2020+} @ args:
2121+2222+let
2323+ version = "2.27";
2424+ patchSuffix = "";
2525+ sha256 = "0wpwq7gsm7sd6ysidv0z575ckqdg13cr2njyfgrbgh4f65adwwji";
2626+ cross = if buildPlatform != hostPlatform then hostPlatform else null;
2727+in
2828+2929+assert withLinuxHeaders -> linuxHeaders != null;
3030+assert withGd -> gd != null && libpng != null;
3131+3232+stdenv.mkDerivation ({
3333+ inherit installLocales;
3434+ linuxHeaders = if withLinuxHeaders then linuxHeaders else null;
3535+3636+ # The host/target system.
3737+ crossConfig = if cross != null then cross.config else null;
3838+3939+ inherit (stdenv) is64bit;
4040+4141+ enableParallelBuilding = true;
4242+4343+ patches =
4444+ [
4545+ /* Have rpcgen(1) look for cpp(1) in $PATH. */
4646+ ./rpcgen-path.patch
4747+4848+ /* Allow NixOS and Nix to handle the locale-archive. */
4949+ ./nix-locale-archive-2.27.patch
5050+5151+ /* Don't use /etc/ld.so.cache, for non-NixOS systems. */
5252+ ./dont-use-system-ld-so-cache-2.27.patch
5353+5454+ /* Don't use /etc/ld.so.preload, but /etc/ld-nix.so.preload. */
5555+ ./dont-use-system-ld-so-preload.patch
5656+5757+ /* The command "getconf CS_PATH" returns the default search path
5858+ "/bin:/usr/bin", which is inappropriate on NixOS machines. This
5959+ patch extends the search path by "/run/current-system/sw/bin". */
6060+ ./fix_path_attribute_in_getconf.patch
6161+6262+ /* Allow running with RHEL 6 -like kernels. The patch adds an exception
6363+ for glibc to accept 2.6.32 and to tag the ELFs as 2.6.32-compatible
6464+ (otherwise the loader would refuse libc).
6565+ Note that glibc will fully work only on their heavily patched kernels
6666+ and we lose early mismatch detection on 2.6.32.
6767+6868+ On major glibc updates we should check that the patched kernel supports
6969+ all the required features. ATM it's verified up to glibc-2.26-131.
7070+ # HOWTO: check glibc sources for changes in kernel requirements
7171+ git log -p glibc-2.25.. sysdeps/unix/sysv/linux/x86_64/kernel-features.h sysdeps/unix/sysv/linux/kernel-features.h
7272+ # get kernel sources (update the URL)
7373+ mkdir tmp && cd tmp
7474+ curl http://vault.centos.org/6.9/os/Source/SPackages/kernel-2.6.32-696.el6.src.rpm | rpm2cpio - | cpio -idmv
7575+ tar xf linux-*.bz2
7676+ # check syscall presence, for example
7777+ less linux-*?/arch/x86/kernel/syscall_table_32.S
7878+ */
7979+ ./allow-kernel-2.6.32.patch
8080+ ]
8181+ ++ lib.optional stdenv.isx86_64 ./fix-x64-abi.patch;
8282+8383+ postPatch =
8484+ ''
8585+ # Needed for glibc to build with the gnumake 3.82
8686+ # http://comments.gmane.org/gmane.linux.lfs.support/31227
8787+ sed -i 's/ot \$/ot:\n\ttouch $@\n$/' manual/Makefile
8888+8989+ # nscd needs libgcc, and we don't want it dynamically linked
9090+ # because we don't want it to depend on bootstrap-tools libs.
9191+ echo "LDFLAGS-nscd += -static-libgcc" >> nscd/Makefile
9292+ '';
9393+9494+ configureFlags =
9595+ [ "-C"
9696+ "--enable-add-ons"
9797+ "--enable-obsolete-nsl"
9898+ "--enable-obsolete-rpc"
9999+ "--sysconfdir=/etc"
100100+ "--enable-stackguard-randomization"
101101+ (if withLinuxHeaders
102102+ then "--with-headers=${linuxHeaders}/include"
103103+ else "--without-headers")
104104+ (if profilingLibraries
105105+ then "--enable-profile"
106106+ else "--disable-profile")
107107+ ] ++ lib.optionals withLinuxHeaders [
108108+ "--enable-kernel=3.2.0" # can't get below with glibc >= 2.26
109109+ ] ++ lib.optionals (cross != null) [
110110+ (if cross ? float && cross.float == "soft" then "--without-fp" else "--with-fp")
111111+ ] ++ lib.optionals (cross != null) [
112112+ "--with-__thread"
113113+ ] ++ lib.optionals (cross == null && stdenv.isArm) [
114114+ "--host=arm-linux-gnueabi"
115115+ "--build=arm-linux-gnueabi"
116116+117117+ # To avoid linking with -lgcc_s (dynamic link)
118118+ # so the glibc does not depend on its compiler store path
119119+ "libc_cv_as_needed=no"
120120+ ] ++ lib.optional withGd "--with-gd";
121121+122122+ installFlags = [ "sysconfdir=$(out)/etc" ];
123123+124124+ outputs = [ "out" "bin" "dev" "static" ];
125125+126126+ depsBuildBuild = [ buildPackages.stdenv.cc ];
127127+ nativeBuildInputs = [ bison ];
128128+ buildInputs = lib.optionals withGd [ gd libpng ];
129129+130130+ # Needed to install share/zoneinfo/zone.tab. Set to impure /bin/sh to
131131+ # prevent a retained dependency on the bootstrap tools in the stdenv-linux
132132+ # bootstrap.
133133+ BASH_SHELL = "/bin/sh";
134134+}
135135+136136+// (removeAttrs args [ "withLinuxHeaders" "withGd" ]) //
137137+138138+{
139139+ name = name + "-${version}${patchSuffix}";
140140+141141+ src = fetchurl {
142142+ url = "mirror://gnu/glibc/glibc-${version}.tar.xz";
143143+ inherit sha256;
144144+ };
145145+146146+ # Remove absolute paths from `configure' & co.; build out-of-tree.
147147+ preConfigure = ''
148148+ export PWD_P=$(type -tP pwd)
149149+ for i in configure io/ftwtest-sh; do
150150+ # Can't use substituteInPlace here because replace hasn't been
151151+ # built yet in the bootstrap.
152152+ sed -i "$i" -e "s^/bin/pwd^$PWD_P^g"
153153+ done
154154+155155+ mkdir ../build
156156+ cd ../build
157157+158158+ configureScript="`pwd`/../$sourceRoot/configure"
159159+160160+ ${lib.optionalString (stdenv.cc.libc != null)
161161+ ''makeFlags="$makeFlags BUILD_LDFLAGS=-Wl,-rpath,${stdenv.cc.libc}/lib"''
162162+ }
163163+164164+165165+ '' + lib.optionalString (cross != null) ''
166166+ sed -i s/-lgcc_eh//g "../$sourceRoot/Makeconfig"
167167+168168+ cat > config.cache << "EOF"
169169+ libc_cv_forced_unwind=yes
170170+ libc_cv_c_cleanup=yes
171171+ libc_cv_gnu89_inline=yes
172172+ EOF
173173+ '';
174174+175175+ preBuild = lib.optionalString withGd "unset NIX_DONT_SET_RPATH";
176176+177177+ meta = {
178178+ homepage = http://www.gnu.org/software/libc/;
179179+ description = "The GNU C Library";
180180+181181+ longDescription =
182182+ '' Any Unix-like operating system needs a C library: the library which
183183+ defines the "system calls" and other basic facilities such as
184184+ open, malloc, printf, exit...
185185+186186+ The GNU C library is used as the C library in the GNU system and
187187+ most systems with the Linux kernel.
188188+ '';
189189+190190+ license = lib.licenses.lgpl2Plus;
191191+192192+ maintainers = [ lib.maintainers.eelco ];
193193+ platforms = lib.platforms.linux;
194194+ } // meta;
195195+}
196196+197197+// lib.optionalAttrs (cross != null) {
198198+ preInstall = null; # clobber the native hook
199199+200200+ dontStrip = true;
201201+202202+ separateDebugInfo = false; # this is currently broken for crossDrv
203203+204204+ # To avoid a dependency on the build system 'bash'.
205205+ preFixup = ''
206206+ rm -f $bin/bin/{ldd,tzselect,catchsegv,xtrace}
207207+ '';
208208+})