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