at v192 251 lines 8.8 kB view raw
1source $stdenv/setup 2 3 4export NIX_FIXINC_DUMMY=$NIX_BUILD_TOP/dummy 5mkdir $NIX_FIXINC_DUMMY 6 7 8if test "$staticCompiler" = "1"; then 9 EXTRA_LDFLAGS="-static" 10else 11 EXTRA_LDFLAGS="" 12fi 13 14# GCC interprets empty paths as ".", which we don't want. 15if test -z "$CPATH"; then unset CPATH; fi 16if test -z "$LIBRARY_PATH"; then unset LIBRARY_PATH; fi 17echo "\$CPATH is \`$CPATH'" 18echo "\$LIBRARY_PATH is \`$LIBRARY_PATH'" 19 20if test "$noSysDirs" = "1"; then 21 22 if test -e $NIX_CC/nix-support/orig-libc; then 23 24 # Figure out what extra flags to pass to the gcc compilers 25 # being generated to make sure that they use our glibc. 26 extraFlags="$(cat $NIX_CC/nix-support/libc-cflags)" 27 extraLDFlags="$(cat $NIX_CC/nix-support/libc-ldflags) $(cat $NIX_CC/nix-support/libc-ldflags-before)" 28 29 # Use *real* header files, otherwise a limits.h is generated 30 # that does not include Glibc's limits.h (notably missing 31 # SSIZE_MAX, which breaks the build). 32 export NIX_FIXINC_DUMMY=$(cat $NIX_CC/nix-support/orig-libc)/include 33 34 # The path to the Glibc binaries such as `crti.o'. 35 glibc_libdir="$(cat $NIX_CC/nix-support/orig-libc)/lib" 36 37 else 38 # Hack: support impure environments. 39 extraFlags="-isystem /usr/include" 40 extraLDFlags="-L/usr/lib64 -L/usr/lib" 41 glibc_libdir="/usr/lib" 42 export NIX_FIXINC_DUMMY=/usr/include 43 fi 44 45 extraFlags="-I$NIX_FIXINC_DUMMY $extraFlags" 46 extraLDFlags="-L$glibc_libdir -rpath $glibc_libdir $extraLDFlags" 47 48 # BOOT_CFLAGS defaults to `-g -O2'; since we override it below, 49 # make sure to explictly add them so that files compiled with the 50 # bootstrap compiler are optimized and (optionally) contain 51 # debugging information (info "(gccinstall) Building"). 52 if test -n "$dontStrip"; then 53 extraFlags="-O2 -g $extraFlags" 54 else 55 # Don't pass `-g' at all; this saves space while building. 56 extraFlags="-O2 $extraFlags" 57 fi 58 59 EXTRA_FLAGS="$extraFlags" 60 for i in $extraLDFlags; do 61 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,$i" 62 done 63 64 if test -n "$targetConfig"; then 65 # Cross-compiling, we need gcc not to read ./specs in order to build 66 # the g++ compiler (after the specs for the cross-gcc are created). 67 # Having LIBRARY_PATH= makes gcc read the specs from ., and the build 68 # breaks. Having this variable comes from the default.nix code to bring 69 # gcj in. 70 unset LIBRARY_PATH 71 unset CPATH 72 if test -z "$crossStageStatic"; then 73 EXTRA_TARGET_CFLAGS="-B${libcCross}/lib -idirafter ${libcCross}/include" 74 EXTRA_TARGET_LDFLAGS="-Wl,-L${libcCross}/lib" 75 fi 76 else 77 if test -z "$NIX_CC_CROSS"; then 78 EXTRA_TARGET_CFLAGS="$EXTRA_FLAGS" 79 EXTRA_TARGET_LDFLAGS="$EXTRA_LDFLAGS" 80 else 81 # This the case of cross-building the gcc. 82 # We need special flags for the target, different than those of the build 83 # Assertion: 84 test -e $NIX_CC_CROSS/nix-support/orig-libc 85 86 # Figure out what extra flags to pass to the gcc compilers 87 # being generated to make sure that they use our glibc. 88 extraFlags="$(cat $NIX_CC_CROSS/nix-support/libc-cflags)" 89 extraLDFlags="$(cat $NIX_CC_CROSS/nix-support/libc-ldflags) $(cat $NIX_CC_CROSS/nix-support/libc-ldflags-before)" 90 91 # Use *real* header files, otherwise a limits.h is generated 92 # that does not include Glibc's limits.h (notably missing 93 # SSIZE_MAX, which breaks the build). 94 NIX_FIXINC_DUMMY_CROSS=$(cat $NIX_CC_CROSS/nix-support/orig-libc)/include 95 96 # The path to the Glibc binaries such as `crti.o'. 97 glibc_libdir="$(cat $NIX_CC_CROSS/nix-support/orig-libc)/lib" 98 99 extraFlags="-I$NIX_FIXINC_DUMMY_CROSS $extraFlags" 100 extraLDFlags="-L$glibc_libdir -rpath $glibc_libdir $extraLDFlags" 101 102 EXTRA_TARGET_CFLAGS="$extraFlags" 103 for i in $extraLDFlags; do 104 EXTRA_TARGET_LDFLAGS="$EXTRA_TARGET_LDFLAGS -Wl,$i" 105 done 106 fi 107 fi 108 109 110 # CFLAGS_FOR_TARGET are needed for the libstdc++ configure script to find 111 # the startfiles. 112 # FLAGS_FOR_TARGET are needed for the target libraries to receive the -Bxxx 113 # for the startfiles. 114 makeFlagsArray=( \ 115 "${makeFlagsArray[@]}" \ 116 NATIVE_SYSTEM_HEADER_DIR="$NIX_FIXINC_DUMMY" \ 117 SYSTEM_HEADER_DIR="$NIX_FIXINC_DUMMY" \ 118 CFLAGS_FOR_BUILD="$EXTRA_FLAGS $EXTRA_LDFLAGS" \ 119 CFLAGS_FOR_TARGET="$EXTRA_TARGET_CFLAGS $EXTRA_TARGET_LDFLAGS" \ 120 FLAGS_FOR_TARGET="$EXTRA_TARGET_CFLAGS $EXTRA_TARGET_LDFLAGS" \ 121 LDFLAGS_FOR_BUILD="$EXTRA_FLAGS $EXTRA_LDFLAGS" \ 122 LDFLAGS_FOR_TARGET="$EXTRA_TARGET_LDFLAGS $EXTRA_TARGET_LDFLAGS" \ 123 ) 124 125 if test -z "$targetConfig"; then 126 makeFlagsArray=( \ 127 "${makeFlagsArray[@]}" \ 128 BOOT_CFLAGS="$EXTRA_FLAGS $EXTRA_LDFLAGS" \ 129 BOOT_LDFLAGS="$EXTRA_TARGET_CFLAGS $EXTRA_TARGET_LDFLAGS" \ 130 ) 131 fi 132 133 if test -n "$targetConfig" -a "$crossStageStatic" == 1; then 134 # We don't want the gcc build to assume there will be a libc providing 135 # limits.h in this stagae 136 makeFlagsArray=( \ 137 "${makeFlagsArray[@]}" \ 138 LIMITS_H_TEST=false \ 139 ) 140 else 141 makeFlagsArray=( \ 142 "${makeFlagsArray[@]}" \ 143 LIMITS_H_TEST=true \ 144 ) 145 fi 146fi 147 148if test -n "$targetConfig"; then 149 # The host strip will destroy some important details of the objects 150 dontStrip=1 151fi 152 153 154preConfigure() { 155 if test -n "$newlibSrc"; then 156 tar xvf "$newlibSrc" -C .. 157 ln -s ../newlib-*/newlib newlib 158 # Patch to get armvt5el working: 159 sed -i -e 's/ arm)/ arm*)/' newlib/configure.host 160 fi 161 # Bug - they packaged zlib 162 if test -d "zlib"; then 163 # This breaks the build without-headers, which should build only 164 # the target libgcc as target libraries. 165 # See 'configure:5370' 166 rm -Rf zlib 167 fi 168 169 if test -f "$NIX_CC/nix-support/orig-libc"; then 170 # Patch the configure script so it finds glibc headers. It's 171 # important for example in order not to get libssp built, 172 # because its functionality is in glibc already. 173 glibc_headers="$(cat $NIX_CC/nix-support/orig-libc)/include" 174 sed -i \ 175 -e "s,glibc_header_dir=/usr/include,glibc_header_dir=$glibc_headers", \ 176 gcc/configure 177 fi 178 179 if test -n "$crossMingw" -a -n "$crossStageStatic"; then 180 mkdir -p ../mingw 181 # --with-build-sysroot expects that: 182 cp -R $libcCross/include ../mingw 183 configureFlags="$configureFlags --with-build-sysroot=`pwd`/.." 184 fi 185 186 # Perform the build in a different directory. 187 mkdir ../build 188 cd ../build 189 configureScript=../$sourceRoot/configure 190} 191 192 193postConfigure() { 194 # Don't store the configure flags in the resulting executables. 195 sed -e '/TOPLEVEL_CONFIGURE_ARGUMENTS=/d' -i Makefile 196} 197 198 199preInstall() { 200 # Make ‘lib64’ a symlink to ‘lib’. 201 if [ -n "$is64bit" -a -z "$enableMultilib" ]; then 202 mkdir -p $out/lib 203 ln -s lib $out/lib64 204 fi 205} 206 207 208postInstall() { 209 # Remove precompiled headers for now. They are very big and 210 # probably not very useful yet. 211 find $out/include -name "*.gch" -exec rm -rf {} \; -prune 212 213 # Remove `fixincl' to prevent a retained dependency on the 214 # previous gcc. 215 rm -rf $out/libexec/gcc/*/*/install-tools 216 rm -rf $out/lib/gcc/*/*/install-tools 217 218 # More dependencies with the previous gcc or some libs (gccbug stores the build command line) 219 rm -rf $out/bin/gccbug 220 # Take out the bootstrap-tools from the rpath, as it's not needed at all having $out 221 for i in $out/libexec/gcc/*/*/*; do 222 if PREV_RPATH=`patchelf --print-rpath $i`; then 223 patchelf --set-rpath `echo $PREV_RPATH | sed 's,:[^:]*bootstrap-tools/lib,,'` $i 224 fi 225 done 226 227 # Get rid of some "fixed" header files 228 rm -rf $out/lib/gcc/*/*/include/root 229 230 # Replace hard links for i686-pc-linux-gnu-gcc etc. with symlinks. 231 for i in $out/bin/*-gcc*; do 232 if cmp -s $out/bin/gcc $i; then 233 ln -sfn gcc $i 234 fi 235 done 236 237 for i in $out/bin/c++ $out/bin/*-c++* $out/bin/*-g++*; do 238 if cmp -s $out/bin/g++ $i; then 239 ln -sfn g++ $i 240 fi 241 done 242 243 # Disable RANDMMAP on grsec, which causes segfaults when using 244 # precompiled headers. 245 # See https://bugs.gentoo.org/show_bug.cgi?id=301299#c31 246 paxmark r $out/libexec/gcc/*/*/{cc1,cc1plus} 247 248 eval "$postInstallGhdl" 249} 250 251genericBuild