at v192 200 lines 6.8 kB view raw
1source $stdenv/setup 2 3 4export NIX_FIXINC_DUMMY=$NIX_BUILD_TOP/dummy 5mkdir $NIX_FIXINC_DUMMY 6 7 8# libstdc++ needs this; otherwise it will use /lib/cpp, which is a Bad 9# Thing. 10export CPP="gcc -E" 11 12if test "$staticCompiler" = "1"; then 13 EXTRA_LDFLAGS="-static" 14else 15 EXTRA_LDFLAGS="" 16fi 17 18if test "$noSysDirs" = "1"; then 19 20 if test -e $NIX_CC/nix-support/orig-libc; then 21 22 # Figure out what extra flags to pass to the gcc compilers 23 # being generated to make sure that they use our glibc. 24 extraFlags="$(cat $NIX_CC/nix-support/libc-cflags)" 25 extraLDFlags="$(cat $NIX_CC/nix-support/libc-ldflags) $(cat $NIX_CC/nix-support/libc-ldflags-before)" 26 27 # Use *real* header files, otherwise a limits.h is generated 28 # that does not include Glibc's limits.h (notably missing 29 # SSIZE_MAX, which breaks the build). 30 export NIX_FIXINC_DUMMY=$(cat $NIX_CC/nix-support/orig-libc)/include 31 32 # The path to the Glibc binaries such as `crti.o'. 33 glibc_libdir="$(cat $NIX_CC/nix-support/orig-libc)/lib" 34 35 else 36 # Hack: support impure environments. 37 extraFlags="-isystem /usr/include" 38 extraLDFlags="-L/usr/lib64 -L/usr/lib" 39 glibc_libdir="/usr/lib" 40 export NIX_FIXINC_DUMMY=/usr/include 41 fi 42 43 extraFlags="-g0 -O2 -I$NIX_FIXINC_DUMMY $extraFlags" 44 extraLDFlags="--strip-debug -L$glibc_libdir -rpath $glibc_libdir $extraLDFlags" 45 46 EXTRA_FLAGS="$extraFlags" 47 for i in $extraLDFlags; do 48 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,$i" 49 done 50 51 if test -n "$targetConfig"; then 52 # Cross-compiling, we need gcc not to read ./specs in order to build 53 # the g++ compiler (after the specs for the cross-gcc are created). 54 # Having LIBRARY_PATH= makes gcc read the specs from ., and the build 55 # breaks. Having this variable comes from the default.nix code to bring 56 # gcj in. 57 unset LIBRARY_PATH 58 unset CPATH 59 if test -z "$crossStageStatic"; then 60 EXTRA_FLAGS_TARGET="-g0 -O2 -B${libcCross}/lib -idirafter ${libcCross}/include" 61 EXTRA_LDFLAGS_TARGET="-Wl,-L${libcCross}/lib" 62 fi 63 else 64 if test -z "$NIX_CC_CROSS"; then 65 EXTRA_FLAGS_TARGET="$EXTRA_FLAGS" 66 EXTRA_LDFLAGS_TARGET="$EXTRA_LDFLAGS" 67 else 68 # This the case of cross-building the gcc. 69 # We need special flags for the target, different than those of the build 70 # Assertion: 71 test -e $NIX_CC_CROSS/nix-support/orig-libc 72 73 # Figure out what extra flags to pass to the gcc compilers 74 # being generated to make sure that they use our glibc. 75 extraFlags="$(cat $NIX_CC_CROSS/nix-support/libc-cflags)" 76 extraLDFlags="$(cat $NIX_CC_CROSS/nix-support/libc-ldflags) $(cat $NIX_CC_CROSS/nix-support/libc-ldflags-before)" 77 78 # Use *real* header files, otherwise a limits.h is generated 79 # that does not include Glibc's limits.h (notably missing 80 # SSIZE_MAX, which breaks the build). 81 NIX_FIXINC_DUMMY_CROSS=$(cat $NIX_CC_CROSS/nix-support/orig-libc)/include 82 83 # The path to the Glibc binaries such as `crti.o'. 84 glibc_libdir="$(cat $NIX_CC_CROSS/nix-support/orig-libc)/lib" 85 86 extraFlags="-g0 -O2 -I$NIX_FIXINC_DUMMY_CROSS $extraFlags" 87 extraLDFlags="--strip-debug -L$glibc_libdir -rpath $glibc_libdir $extraLDFlags" 88 89 EXTRA_FLAGS_TARGET="$extraFlags" 90 for i in $extraLDFlags; do 91 EXTRA_LDFLAGS_TARGET="$EXTRA_LDFLAGS_TARGET -Wl,$i" 92 done 93 fi 94 fi 95 96 97 # CFLAGS_FOR_TARGET are needed for the libstdc++ configure script to find 98 # the startfiles. 99 # FLAGS_FOR_TARGET are needed for the target libraries to receive the -Bxxx 100 # for the startfiles. 101 makeFlagsArray=( \ 102 "${makeFlagsArray[@]}" \ 103 NATIVE_SYSTEM_HEADER_DIR="$NIX_FIXINC_DUMMY" \ 104 SYSTEM_HEADER_DIR="$NIX_FIXINC_DUMMY" \ 105 CFLAGS_FOR_BUILD="$EXTRA_FLAGS $EXTRA_LDFLAGS" \ 106 CFLAGS_FOR_TARGET="$EXTRA_FLAGS_TARGET $EXTRA_LDFLAGS_TARGET" \ 107 FLAGS_FOR_TARGET="$EXTRA_FLAGS_TARGET $EXTRA_LDFLAGS_TARGET" \ 108 LDFLAGS_FOR_BUILD="$EXTRA_FLAGS $EXTRA_LDFLAGS" \ 109 LDFLAGS_FOR_TARGET="$EXTRA_FLAGS_TARGET $EXTRA_LDFLAGS_TARGET" \ 110 ) 111 112 if test -z "$targetConfig"; then 113 makeFlagsArray=( \ 114 "${makeFlagsArray[@]}" \ 115 BOOT_CFLAGS="$EXTRA_FLAGS $EXTRA_LDFLAGS" \ 116 BOOT_LDFLAGS="$EXTRA_FLAGS_TARGET $EXTRA_LDFLAGS_TARGET" \ 117 ) 118 fi 119 120 if test -n "$targetConfig" -a "$crossStageStatic" == 1; then 121 # We don't want the gcc build to assume there will be a libc providing 122 # limits.h in this stagae 123 makeFlagsArray=( \ 124 "${makeFlagsArray[@]}" \ 125 LIMITS_H_TEST=false \ 126 ) 127 else 128 makeFlagsArray=( \ 129 "${makeFlagsArray[@]}" \ 130 LIMITS_H_TEST=true \ 131 ) 132 fi 133fi 134 135if test -n "$targetConfig"; then 136 # The host strip will destroy some important details of the objects 137 dontStrip=1 138fi 139 140preConfigure() { 141 if test -n "$newlibSrc"; then 142 tar xvf "$newlibSrc" -C .. 143 ln -s ../newlib-*/newlib newlib 144 # Patch to get armvt5el working: 145 sed -i -e 's/ arm)/ arm*)/' newlib/configure.host 146 fi 147 # Bug - they packaged zlib 148 if test -d "zlib"; then 149 # This breaks the build without-headers, which should build only 150 # the target libgcc as target libraries. 151 # See 'configure:5370' 152 rm -Rf zlib 153 fi 154 155 # Perform the build in a different directory. 156 mkdir ../build 157 cd ../build 158 configureScript=../$sourceRoot/configure 159} 160 161 162postInstall() { 163 # Remove precompiled headers for now. They are very big and 164 # probably not very useful yet. 165 find $out/include -name "*.gch" -exec rm -rf {} \; -prune 166 167 # Remove `fixincl' to prevent a retained dependency on the 168 # previous gcc. 169 rm -rf $out/libexec/gcc/*/*/install-tools 170 rm -rf $out/lib/gcc/*/*/install-tools 171 172 # Get rid of some "fixed" header files 173 rm -rf $out/lib/gcc/*/*/include/root 174 175 # Replace hard links for i686-pc-linux-gnu-gcc etc. with symlinks. 176 for i in $out/bin/*-gcc*; do 177 if cmp -s $out/bin/gcc $i; then 178 ln -sfn gcc $i 179 fi 180 done 181 182 for i in $out/bin/*-c++* $out/bin/*-g++*; do 183 if cmp -s $out/bin/g++ $i; then 184 ln -sfn g++ $i 185 fi 186 done 187 188 eval "$postInstallGhdl" 189} 190 191 192if test -z "$targetConfig" && test -z "$crossConfig"; then 193 if test -z "$profiledCompiler"; then 194 buildFlags="bootstrap $buildFlags" 195 else 196 buildFlags="profiledbootstrap $buildFlags" 197 fi 198fi 199 200genericBuild