nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at 22.05-pre 301 lines 11 kB view raw
1source $stdenv/setup 2 3 4oldOpts="$(shopt -po nounset)" || true 5set -euo pipefail 6 7 8export NIX_FIXINC_DUMMY="$NIX_BUILD_TOP/dummy" 9mkdir "$NIX_FIXINC_DUMMY" 10 11 12if test "$staticCompiler" = "1"; then 13 EXTRA_LDFLAGS="-static" 14else 15 EXTRA_LDFLAGS="-Wl,-rpath,${!outputLib}/lib" 16fi 17 18 19# GCC interprets empty paths as ".", which we don't want. 20if test -z "${CPATH-}"; then unset CPATH; fi 21if test -z "${LIBRARY_PATH-}"; then unset LIBRARY_PATH; fi 22echo "\$CPATH is \`${CPATH-}'" 23echo "\$LIBRARY_PATH is \`${LIBRARY_PATH-}'" 24 25if test "$noSysDirs" = "1"; then 26 27 declare \ 28 EXTRA_FLAGS_FOR_BUILD EXTRA_FLAGS EXTRA_FLAGS_FOR_TARGET \ 29 EXTRA_LDFLAGS_FOR_BUILD EXTRA_LDFLAGS_FOR_TARGET 30 31 # Extract flags from Bintools Wrappers 32 for post in '_FOR_BUILD' ''; do 33 curBintools="NIX_BINTOOLS${post}" 34 35 declare -a extraLDFlags=() 36 if [[ -e "${!curBintools}/nix-support/orig-libc" ]]; then 37 # Figure out what extra flags when linking to pass to the gcc 38 # compilers being generated to make sure that they use our libc. 39 extraLDFlags=($(< "${!curBintools}/nix-support/libc-ldflags") $(< "${!curBintools}/nix-support/libc-ldflags-before" || true)) 40 if [ -e ${!curBintools}/nix-support/ld-set-dynamic-linker ]; then 41 extraLDFlags=-dynamic-linker=$(< ${!curBintools}/nix-support/dynamic-linker) 42 fi 43 44 # The path to the Libc binaries such as `crti.o'. 45 libc_libdir="$(< "${!curBintools}/nix-support/orig-libc")/lib" 46 else 47 # Hack: support impure environments. 48 extraLDFlags=("-L/usr/lib64" "-L/usr/lib") 49 libc_libdir="/usr/lib" 50 fi 51 extraLDFlags=("-L$libc_libdir" "-rpath" "$libc_libdir" 52 "${extraLDFlags[@]}") 53 for i in "${extraLDFlags[@]}"; do 54 declare EXTRA_LDFLAGS${post}+=" -Wl,$i" 55 done 56 done 57 58 # Extract flags from CC Wrappers 59 for post in '_FOR_BUILD' ''; do 60 curCC="NIX_CC${post}" 61 curFIXINC="NIX_FIXINC_DUMMY${post}" 62 63 declare -a extraFlags=() 64 if [[ -e "${!curCC}/nix-support/orig-libc" ]]; then 65 # Figure out what extra compiling flags to pass to the gcc compilers 66 # being generated to make sure that they use our libc. 67 extraFlags=($(< "${!curCC}/nix-support/libc-crt1-cflags") $(< "${!curCC}/nix-support/libc-cflags")) 68 69 # The path to the Libc headers 70 libc_devdir="$(< "${!curCC}/nix-support/orig-libc-dev")" 71 72 # Use *real* header files, otherwise a limits.h is generated that 73 # does not include Libc's limits.h (notably missing SSIZE_MAX, 74 # which breaks the build). 75 declare NIX_FIXINC_DUMMY${post}="$libc_devdir/include" 76 else 77 # Hack: support impure environments. 78 extraFlags=("-isystem" "/usr/include") 79 declare NIX_FIXINC_DUMMY${post}=/usr/include 80 fi 81 82 extraFlags=("-I${!curFIXINC}" "${extraFlags[@]}") 83 84 # BOOT_CFLAGS defaults to `-g -O2'; since we override it below, make 85 # sure to explictly add them so that files compiled with the bootstrap 86 # compiler are optimized and (optionally) contain debugging information 87 # (info "(gccinstall) Building"). 88 if test -n "${dontStrip-}"; then 89 extraFlags=("-O2" "-g" "${extraFlags[@]}") 90 else 91 # Don't pass `-g' at all; this saves space while building. 92 extraFlags=("-O2" "${extraFlags[@]}") 93 fi 94 95 declare EXTRA_FLAGS${post}="${extraFlags[*]}" 96 done 97 98 if test -z "${targetConfig-}"; then 99 # host = target, so the flags are the same 100 EXTRA_FLAGS_FOR_TARGET="$EXTRA_FLAGS" 101 EXTRA_LDFLAGS_FOR_TARGET="$EXTRA_LDFLAGS" 102 fi 103 104 # CFLAGS_FOR_TARGET are needed for the libstdc++ configure script to find 105 # the startfiles. 106 # FLAGS_FOR_TARGET are needed for the target libraries to receive the -Bxxx 107 # for the startfiles. 108 makeFlagsArray+=( 109 "BUILD_SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY_FOR_BUILD" 110 "SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY_FOR_BUILD" 111 "NATIVE_SYSTEM_HEADER_DIR=$NIX_FIXINC_DUMMY" 112 113 "LDFLAGS_FOR_BUILD=$EXTRA_LDFLAGS_FOR_BUILD" 114 #"LDFLAGS=$EXTRA_LDFLAGS" 115 "LDFLAGS_FOR_TARGET=$EXTRA_LDFLAGS_FOR_TARGET" 116 117 "CFLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD" 118 "CXXFLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD" 119 "FLAGS_FOR_BUILD=$EXTRA_FLAGS_FOR_BUILD $EXTRA_LDFLAGS_FOR_BUILD" 120 121 # It seems there is a bug in GCC 5 122 #"CFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS" 123 #"CXXFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS" 124 125 "CFLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" 126 "CXXFLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" 127 "FLAGS_FOR_TARGET=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" 128 ) 129 130 if test -z "${targetConfig-}"; then 131 makeFlagsArray+=( 132 "BOOT_CFLAGS=$EXTRA_FLAGS $EXTRA_LDFLAGS" 133 "BOOT_LDFLAGS=$EXTRA_FLAGS_FOR_TARGET $EXTRA_LDFLAGS_FOR_TARGET" 134 ) 135 fi 136 137 if test "$crossStageStatic" == 1; then 138 # We don't want the gcc build to assume there will be a libc providing 139 # limits.h in this stage 140 makeFlagsArray+=( 141 'LIMITS_H_TEST=false' 142 ) 143 else 144 makeFlagsArray+=( 145 'LIMITS_H_TEST=true' 146 ) 147 fi 148fi 149 150if [ -n "${targetConfig-}" ]; then 151 # if stripping gcc, include target directory too 152 stripDebugList="${stripDebugList-lib lib32 lib64 libexec bin sbin} $targetConfig" 153fi 154 155eval "$oldOpts" 156 157providedPreConfigure="$preConfigure"; 158preConfigure() { 159 if test -n "$newlibSrc"; then 160 tar xvf "$newlibSrc" -C .. 161 ln -s ../newlib-*/newlib newlib 162 # Patch to get armvt5el working: 163 sed -i -e 's/ arm)/ arm*)/' newlib/configure.host 164 fi 165 166 # Bug - they packaged zlib 167 if test -d "zlib"; then 168 # This breaks the build without-headers, which should build only 169 # the target libgcc as target libraries. 170 # See 'configure:5370' 171 rm -Rf zlib 172 fi 173 174 if test -f "$NIX_CC/nix-support/orig-libc"; then 175 # Patch the configure script so it finds glibc headers. It's 176 # important for example in order not to get libssp built, 177 # because its functionality is in glibc already. 178 sed -i \ 179 -e "s,glibc_header_dir=/usr/include,glibc_header_dir=$libc_dev/include", \ 180 gcc/configure 181 fi 182 183 if test -n "$crossMingw" -a -n "$crossStageStatic"; then 184 mkdir -p ../mingw 185 # --with-build-sysroot expects that: 186 cp -R $libcCross/include ../mingw 187 configureFlags="$configureFlags --with-build-sysroot=`pwd`/.." 188 fi 189 190 # Eval the preConfigure script from nix expression. 191 eval "$providedPreConfigure" 192 193 # Perform the build in a different directory. 194 mkdir ../build 195 cd ../build 196 configureScript=../$sourceRoot/configure 197} 198 199 200postConfigure() { 201 # Don't store the configure flags in the resulting executables. 202 sed -e '/TOPLEVEL_CONFIGURE_ARGUMENTS=/d' -i Makefile 203} 204 205 206preInstall() { 207 mkdir -p "$out/${targetConfig}/lib" 208 mkdir -p "${!outputLib}/${targetConfig}/lib" 209 # Make ‘lib64’ symlinks to ‘lib’. 210 if [ -n "$is64bit" -a -z "$enableMultilib" ]; then 211 ln -s lib "$out/${targetConfig}/lib64" 212 ln -s lib "${!outputLib}/${targetConfig}/lib64" 213 fi 214} 215 216 217postInstall() { 218 # Move runtime libraries to lib output. 219 moveToOutput "${targetConfig+$targetConfig/}lib/lib*.so*" "${!outputLib}" 220 moveToOutput "${targetConfig+$targetConfig/}lib/lib*.la" "${!outputLib}" 221 moveToOutput "${targetConfig+$targetConfig/}lib/lib*.dylib" "${!outputLib}" 222 moveToOutput "${targetConfig+$targetConfig/}lib/lib*.dll.a" "${!outputLib}" 223 moveToOutput "share/gcc-*/python" "${!outputLib}" 224 225 for i in "${!outputLib}/${targetConfig}"/lib/*.{la,py}; do 226 substituteInPlace "$i" --replace "$out" "${!outputLib}" 227 done 228 229 if [ -n "$enableMultilib" ]; then 230 moveToOutput "${targetConfig+$targetConfig/}lib64/lib*.so*" "${!outputLib}" 231 moveToOutput "${targetConfig+$targetConfig/}lib64/lib*.la" "${!outputLib}" 232 moveToOutput "${targetConfig+$targetConfig/}lib64/lib*.dylib" "${!outputLib}" 233 234 for i in "${!outputLib}/${targetConfig}"/lib64/*.{la,py}; do 235 substituteInPlace "$i" --replace "$out" "${!outputLib}" 236 done 237 fi 238 239 # Remove `fixincl' to prevent a retained dependency on the 240 # previous gcc. 241 rm -rf $out/libexec/gcc/*/*/install-tools 242 rm -rf $out/lib/gcc/*/*/install-tools 243 244 # More dependencies with the previous gcc or some libs (gccbug stores the build command line) 245 rm -rf $out/bin/gccbug 246 247 if [[ buildConfig == *"linux"* ]]; then 248 # Take out the bootstrap-tools from the rpath, as it's not needed at all having $out 249 for i in $(find "$out"/libexec/gcc/*/*/* -type f -a \! -name '*.la'); do 250 PREV_RPATH=`patchelf --print-rpath "$i"` 251 NEW_RPATH=`echo "$PREV_RPATH" | sed 's,:[^:]*bootstrap-tools/lib,,g'` 252 patchelf --set-rpath "$NEW_RPATH" "$i" && echo OK 253 done 254 fi 255 256 if [[ targetConfig == *"linux"* ]]; then 257 # For some reason, when building for linux on darwin, the libs retain 258 # RPATH to $out. 259 for i in "$lib"/"$targetConfig"/lib/{libtsan,libasan,libubsan}.so.*.*.*; do 260 PREV_RPATH=`patchelf --print-rpath "$i"` 261 NEW_RPATH=`echo "$PREV_RPATH" | sed "s,:${out}[^:]*,,g"` 262 patchelf --set-rpath "$NEW_RPATH" "$i" && echo OK 263 done 264 fi 265 266 if type "install_name_tool"; then 267 for i in "${!outputLib}"/lib/*.*.dylib "${!outputLib}"/lib/*.so.[0-9]; do 268 install_name_tool -id "$i" "$i" || true 269 for old_path in $(otool -L "$i" | grep "$out" | awk '{print $1}'); do 270 new_path=`echo "$old_path" | sed "s,$out,${!outputLib},"` 271 install_name_tool -change "$old_path" "$new_path" "$i" || true 272 done 273 done 274 fi 275 276 # Get rid of some "fixed" header files 277 rm -rfv $out/lib/gcc/*/*/include-fixed/{root,linux} 278 279 # Replace hard links for i686-pc-linux-gnu-gcc etc. with symlinks. 280 for i in $out/bin/*-gcc*; do 281 if cmp -s $out/bin/gcc $i; then 282 ln -sfn gcc $i 283 fi 284 done 285 286 for i in $out/bin/c++ $out/bin/*-c++* $out/bin/*-g++*; do 287 if cmp -s $out/bin/g++ $i; then 288 ln -sfn g++ $i 289 fi 290 done 291 292 # Two identical man pages are shipped (moving and compressing is done later) 293 for i in "$out"/share/man/man1/*g++.1; do 294 if test -e "$i"; then 295 man_prefix=`echo "$i" | sed "s,.*/\(.*\)g++.1,\1,"` 296 ln -sf "$man_prefix"gcc.1 "$i" 297 fi 298 done 299} 300 301genericBuild