nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at netboot-syslinux-multiplatform 124 lines 5.7 kB view raw
1{ lib, version, buildPlatform, hostPlatform, targetPlatform 2, gnat-bootstrap ? null 3, langAda ? false 4, langJava ? false 5, langJit ? false 6, langGo 7, crossStageStatic 8, enableMultilib 9}: 10 11assert langJava -> lib.versionOlder version "7"; 12assert langAda -> gnat-bootstrap != null; let 13 needsLib 14 = (lib.versionOlder version "7" && (langJava || langGo)) 15 || (lib.versions.major version == "4" && lib.versions.minor version == "9" && targetPlatform.isDarwin); 16in lib.optionalString (hostPlatform.isSunOS && hostPlatform.is64bit) '' 17 export NIX_LDFLAGS=`echo $NIX_LDFLAGS | sed -e s~$prefix/lib~$prefix/lib/amd64~g` 18 export LDFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $LDFLAGS_FOR_TARGET" 19 export CXXFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $CXXFLAGS_FOR_TARGET" 20 export CFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $CFLAGS_FOR_TARGET" 21'' + lib.optionalString needsLib '' 22 export lib=$out; 23'' + lib.optionalString langAda '' 24 export PATH=${gnat-bootstrap}/bin:$PATH 25'' 26 27# On x86_64-darwin, the gnat-bootstrap bootstrap compiler that we need to build a 28# native GCC with Ada support emits assembly that is accepted by the Clang 29# integrated assembler, but not by the GNU assembler in cctools-port that Nix 30# usually in the x86_64-darwin stdenv. In particular, x86_64-darwin gnat-bootstrap 31# emits MOVQ as the mnemonic for quadword interunit moves, such as between XMM 32# and general registers (e.g "movq %xmm0, %rbp"); the cctools-port assembler, 33# however, only recognises MOVD for such moves. 34# 35# Therefore, for native x86_64-darwin builds that support Ada, we have to use 36# the Clang integrated assembler to build (at least stage 1 of) GCC, but have to 37# target GCC at the cctools-port GNU assembler. In the wrapped x86_64-darwin 38# gnat-bootstrap, the former is provided as `as`, while the latter is provided as 39# `gas`. 40# 41+ lib.optionalString ( 42 langAda 43 && buildPlatform == hostPlatform 44 && hostPlatform == targetPlatform 45 && targetPlatform.isx86_64 46 && targetPlatform.isDarwin 47 ) '' 48 export AS_FOR_BUILD=${gnat-bootstrap}/bin/as 49 export AS_FOR_TARGET=${gnat-bootstrap}/bin/gas 50'' 51 52# NOTE 2020/3/18: This environment variable prevents configure scripts from 53# detecting the presence of aligned_alloc on Darwin. There are many facts that 54# collectively make this fix necessary: 55# - Nix uses a fixed set of standard library headers on all MacOS systems, 56# regardless of their actual version. (Nix uses version 10.12 headers.) 57# - Nix uses the native standard library binaries for the build system. That 58# means the standard library binaries may not exactly match the standard 59# library headers. 60# - The aligned_alloc procedure is present in MacOS 10.15 (Catalina), but not 61# in earlier versions. Therefore on Catalina systems, aligned_alloc is 62# linkable (i.e. present in the binary libraries) but not present in the 63# headers. 64# - Configure scripts detect a procedure's existence by checking whether it is 65# linkable. They do not check whether it is present in the headers. 66# - GCC throws an error during compilation because aligned_alloc is not 67# defined in the headers---even though the linker can see it. 68# 69# This fix would not be necessary if ANY of the above were false: 70# - If Nix used native headers for each different MacOS version, aligned_alloc 71# would be in the headers on Catalina. 72# - If Nix used the same libary binaries for each MacOS version, aligned_alloc 73# would not be in the library binaries. 74# - If Catalina did not include aligned_alloc, this wouldn't be a problem. 75# - If the configure scripts looked for header presence as well as 76# linkability, they would see that aligned_alloc is missing. 77# - If GCC allowed implicit declaration of symbols, it would not fail during 78# compilation even if the configure scripts did not check header presence. 79# 80+ lib.optionalString (buildPlatform.isDarwin) '' 81 export build_configargs=ac_cv_func_aligned_alloc=no 82'' + lib.optionalString (hostPlatform.isDarwin) '' 83 export host_configargs=ac_cv_func_aligned_alloc=no 84'' + lib.optionalString (targetPlatform.isDarwin) '' 85 export target_configargs=ac_cv_func_aligned_alloc=no 86'' 87 88# In order to properly install libgccjit on macOS Catalina, strip(1) 89# upon installation must not remove external symbols, otherwise the 90# install step errors with "symbols referenced by indirect symbol 91# table entries that can't be stripped". 92+ lib.optionalString (hostPlatform.isDarwin && langJit) '' 93 export STRIP='strip -x' 94'' 95 96# HACK: if host and target config are the same, but the platforms are 97# actually different we need to convince the configure script that it 98# is in fact building a cross compiler although it doesn't believe it. 99+ lib.optionalString (targetPlatform.config == hostPlatform.config && targetPlatform != hostPlatform) '' 100 substituteInPlace configure --replace is_cross_compiler=no is_cross_compiler=yes 101'' 102 103# Normally (for host != target case) --without-headers automatically 104# enables 'inhibit_libc=true' in gcc's gcc/configure.ac. But case of 105# gcc->clang "cross"-compilation manages to evade it: there 106# hostPlatform != targetPlatform, hostPlatform.config == targetPlatform.config. 107# We explicitly inhibit libc headers use in this case as well. 108+ lib.optionalString (targetPlatform != hostPlatform && crossStageStatic) '' 109 export inhibit_libc=true 110'' 111 112+ lib.optionalString (!enableMultilib && hostPlatform.is64bit && !hostPlatform.isMips64n32) '' 113 export linkLib64toLib=1 114'' 115 116# On mips platforms, gcc follows the IRIX naming convention: 117# 118# $PREFIX/lib = mips32 119# $PREFIX/lib32 = mips64n32 120# $PREFIX/lib64 = mips64 121# 122+ lib.optionalString (!enableMultilib && targetPlatform.isMips64n32) '' 123 export linkLib32toLib=1 124''