|
| 1 | +/* Build configuration used to build glibc, Info files, and locale |
| 2 | + information. */ |
| 3 | + |
| 4 | +{ stdenv, lib |
| 5 | +, buildPlatform, hostPlatform |
| 6 | +, buildPackages |
| 7 | +, fetchurl |
| 8 | +, linuxHeaders ? null |
| 9 | +, gd ? null, libpng ? null |
| 10 | +, bison |
| 11 | +}: |
| 12 | + |
| 13 | +{ name |
| 14 | +, withLinuxHeaders ? false |
| 15 | +, profilingLibraries ? false |
| 16 | +, installLocales ? false |
| 17 | +, withGd ? false |
| 18 | +, meta |
| 19 | +, ... |
| 20 | +} @ args: |
| 21 | + |
| 22 | +let |
| 23 | + version = "2.27"; |
| 24 | + patchSuffix = ""; |
| 25 | + sha256 = "0wpwq7gsm7sd6ysidv0z575ckqdg13cr2njyfgrbgh4f65adwwji"; |
| 26 | + cross = if buildPlatform != hostPlatform then hostPlatform else null; |
| 27 | +in |
| 28 | + |
| 29 | +assert withLinuxHeaders -> linuxHeaders != null; |
| 30 | +assert withGd -> gd != null && libpng != null; |
| 31 | + |
| 32 | +stdenv.mkDerivation ({ |
| 33 | + inherit installLocales; |
| 34 | + linuxHeaders = if withLinuxHeaders then linuxHeaders else null; |
| 35 | + |
| 36 | + # The host/target system. |
| 37 | + crossConfig = if cross != null then cross.config else null; |
| 38 | + |
| 39 | + inherit (stdenv) is64bit; |
| 40 | + |
| 41 | + enableParallelBuilding = true; |
| 42 | + |
| 43 | + patches = |
| 44 | + [ |
| 45 | + /* Have rpcgen(1) look for cpp(1) in $PATH. */ |
| 46 | + ./rpcgen-path.patch |
| 47 | + |
| 48 | + /* Allow NixOS and Nix to handle the locale-archive. */ |
| 49 | + ./nix-locale-archive-2.27.patch |
| 50 | + |
| 51 | + /* Don't use /etc/ld.so.cache, for non-NixOS systems. */ |
| 52 | + ./dont-use-system-ld-so-cache-2.27.patch |
| 53 | + |
| 54 | + /* Don't use /etc/ld.so.preload, but /etc/ld-nix.so.preload. */ |
| 55 | + ./dont-use-system-ld-so-preload.patch |
| 56 | + |
| 57 | + /* The command "getconf CS_PATH" returns the default search path |
| 58 | + "/bin:/usr/bin", which is inappropriate on NixOS machines. This |
| 59 | + patch extends the search path by "/run/current-system/sw/bin". */ |
| 60 | + ./fix_path_attribute_in_getconf.patch |
| 61 | + |
| 62 | + /* Allow running with RHEL 6 -like kernels. The patch adds an exception |
| 63 | + for glibc to accept 2.6.32 and to tag the ELFs as 2.6.32-compatible |
| 64 | + (otherwise the loader would refuse libc). |
| 65 | + Note that glibc will fully work only on their heavily patched kernels |
| 66 | + and we lose early mismatch detection on 2.6.32. |
| 67 | +
|
| 68 | + On major glibc updates we should check that the patched kernel supports |
| 69 | + all the required features. ATM it's verified up to glibc-2.26-131. |
| 70 | + # HOWTO: check glibc sources for changes in kernel requirements |
| 71 | + git log -p glibc-2.25.. sysdeps/unix/sysv/linux/x86_64/kernel-features.h sysdeps/unix/sysv/linux/kernel-features.h |
| 72 | + # get kernel sources (update the URL) |
| 73 | + mkdir tmp && cd tmp |
| 74 | + curl http://vault.centos.org/6.9/os/Source/SPackages/kernel-2.6.32-696.el6.src.rpm | rpm2cpio - | cpio -idmv |
| 75 | + tar xf linux-*.bz2 |
| 76 | + # check syscall presence, for example |
| 77 | + less linux-*?/arch/x86/kernel/syscall_table_32.S |
| 78 | + */ |
| 79 | + ./allow-kernel-2.6.32.patch |
| 80 | + ] |
| 81 | + ++ lib.optional stdenv.isx86_64 ./fix-x64-abi.patch; |
| 82 | + |
| 83 | + postPatch = |
| 84 | + '' |
| 85 | + # Needed for glibc to build with the gnumake 3.82 |
| 86 | + # http://comments.gmane.org/gmane.linux.lfs.support/31227 |
| 87 | + sed -i 's/ot \$/ot:\n\ttouch $@\n$/' manual/Makefile |
| 88 | +
|
| 89 | + # nscd needs libgcc, and we don't want it dynamically linked |
| 90 | + # because we don't want it to depend on bootstrap-tools libs. |
| 91 | + echo "LDFLAGS-nscd += -static-libgcc" >> nscd/Makefile |
| 92 | + ''; |
| 93 | + |
| 94 | + configureFlags = |
| 95 | + [ "-C" |
| 96 | + "--enable-add-ons" |
| 97 | + "--enable-obsolete-nsl" |
| 98 | + "--enable-obsolete-rpc" |
| 99 | + "--sysconfdir=/etc" |
| 100 | + "--enable-stackguard-randomization" |
| 101 | + (if withLinuxHeaders |
| 102 | + then "--with-headers=${linuxHeaders}/include" |
| 103 | + else "--without-headers") |
| 104 | + (if profilingLibraries |
| 105 | + then "--enable-profile" |
| 106 | + else "--disable-profile") |
| 107 | + ] ++ lib.optionals withLinuxHeaders [ |
| 108 | + "--enable-kernel=3.2.0" # can't get below with glibc >= 2.26 |
| 109 | + ] ++ lib.optionals (cross != null) [ |
| 110 | + (if cross ? float && cross.float == "soft" then "--without-fp" else "--with-fp") |
| 111 | + ] ++ lib.optionals (cross != null) [ |
| 112 | + "--with-__thread" |
| 113 | + ] ++ lib.optionals (cross == null && stdenv.isArm) [ |
| 114 | + "--host=arm-linux-gnueabi" |
| 115 | + "--build=arm-linux-gnueabi" |
| 116 | + |
| 117 | + # To avoid linking with -lgcc_s (dynamic link) |
| 118 | + # so the glibc does not depend on its compiler store path |
| 119 | + "libc_cv_as_needed=no" |
| 120 | + ] ++ lib.optional withGd "--with-gd"; |
| 121 | + |
| 122 | + installFlags = [ "sysconfdir=$(out)/etc" ]; |
| 123 | + |
| 124 | + outputs = [ "out" "bin" "dev" "static" ]; |
| 125 | + |
| 126 | + depsBuildBuild = [ buildPackages.stdenv.cc ]; |
| 127 | + nativeBuildInputs = [ bison ]; |
| 128 | + buildInputs = lib.optionals withGd [ gd libpng ]; |
| 129 | + |
| 130 | + # Needed to install share/zoneinfo/zone.tab. Set to impure /bin/sh to |
| 131 | + # prevent a retained dependency on the bootstrap tools in the stdenv-linux |
| 132 | + # bootstrap. |
| 133 | + BASH_SHELL = "/bin/sh"; |
| 134 | +} |
| 135 | + |
| 136 | +// (removeAttrs args [ "withLinuxHeaders" "withGd" ]) // |
| 137 | + |
| 138 | +{ |
| 139 | + name = name + "-${version}${patchSuffix}"; |
| 140 | + |
| 141 | + src = fetchurl { |
| 142 | + url = "mirror://gnu/glibc/glibc-${version}.tar.xz"; |
| 143 | + inherit sha256; |
| 144 | + }; |
| 145 | + |
| 146 | + # Remove absolute paths from `configure' & co.; build out-of-tree. |
| 147 | + preConfigure = '' |
| 148 | + export PWD_P=$(type -tP pwd) |
| 149 | + for i in configure io/ftwtest-sh; do |
| 150 | + # Can't use substituteInPlace here because replace hasn't been |
| 151 | + # built yet in the bootstrap. |
| 152 | + sed -i "$i" -e "s^/bin/pwd^$PWD_P^g" |
| 153 | + done |
| 154 | +
|
| 155 | + mkdir ../build |
| 156 | + cd ../build |
| 157 | +
|
| 158 | + configureScript="`pwd`/../$sourceRoot/configure" |
| 159 | +
|
| 160 | + ${lib.optionalString (stdenv.cc.libc != null) |
| 161 | + ''makeFlags="$makeFlags BUILD_LDFLAGS=-Wl,-rpath,${stdenv.cc.libc}/lib"'' |
| 162 | + } |
| 163 | +
|
| 164 | +
|
| 165 | + '' + lib.optionalString (cross != null) '' |
| 166 | + sed -i s/-lgcc_eh//g "../$sourceRoot/Makeconfig" |
| 167 | +
|
| 168 | + cat > config.cache << "EOF" |
| 169 | + libc_cv_forced_unwind=yes |
| 170 | + libc_cv_c_cleanup=yes |
| 171 | + libc_cv_gnu89_inline=yes |
| 172 | + EOF |
| 173 | + ''; |
| 174 | + |
| 175 | + preBuild = lib.optionalString withGd "unset NIX_DONT_SET_RPATH"; |
| 176 | + |
| 177 | + meta = { |
| 178 | + homepage = http://www.gnu.org/software/libc/; |
| 179 | + description = "The GNU C Library"; |
| 180 | + |
| 181 | + longDescription = |
| 182 | + '' Any Unix-like operating system needs a C library: the library which |
| 183 | + defines the "system calls" and other basic facilities such as |
| 184 | + open, malloc, printf, exit... |
| 185 | +
|
| 186 | + The GNU C library is used as the C library in the GNU system and |
| 187 | + most systems with the Linux kernel. |
| 188 | + ''; |
| 189 | + |
| 190 | + license = lib.licenses.lgpl2Plus; |
| 191 | + |
| 192 | + maintainers = [ lib.maintainers.eelco ]; |
| 193 | + platforms = lib.platforms.linux; |
| 194 | + } // meta; |
| 195 | +} |
| 196 | + |
| 197 | +// lib.optionalAttrs (cross != null) { |
| 198 | + preInstall = null; # clobber the native hook |
| 199 | + |
| 200 | + dontStrip = true; |
| 201 | + |
| 202 | + separateDebugInfo = false; # this is currently broken for crossDrv |
| 203 | + |
| 204 | + # To avoid a dependency on the build system 'bash'. |
| 205 | + preFixup = '' |
| 206 | + rm -f $bin/bin/{ldd,tzselect,catchsegv,xtrace} |
| 207 | + ''; |
| 208 | +}) |
0 commit comments