lol
1{ stdenv, binutils-unwrapped, cctools
2}:
3
4# Make sure both underlying packages claim to have prepended their binaries
5# with the same targetPrefix.
6assert binutils-unwrapped.targetPrefix == cctools.targetPrefix;
7
8let
9 inherit (binutils-unwrapped) targetPrefix;
10 cmds = [
11 "ar" "ranlib" "as" "dsymutil" "install_name_tool"
12 "ld" "strip" "otool" "lipo" "nm" "strings" "size"
13 ];
14in
15
16# TODO loop over targetPrefixed binaries too
17stdenv.mkDerivation {
18 name = "${targetPrefix}cctools-binutils-darwin";
19 outputs = [ "out" "info" "man" ];
20 buildCommand = ''
21 mkdir -p $out/bin $out/include
22
23 ln -s ${binutils-unwrapped.out}/bin/${targetPrefix}c++filt $out/bin/${targetPrefix}c++filt
24
25 # We specifically need:
26 # - ld: binutils doesn't provide it on darwin
27 # - as: as above
28 # - ar: the binutils one prodices .a files that the cctools ld doesn't like
29 # - ranlib: for compatibility with ar
30 # - dsymutil: soon going away once it goes into LLVM (this one is fake anyway)
31 # - otool: we use it for some of our name mangling
32 # - install_name_tool: we use it to rewrite stuff in our bootstrap tools
33 # - strip: the binutils one seems to break mach-o files
34 # - lipo: gcc build assumes it exists
35 # - nm: the gnu one doesn't understand many new load commands
36 for i in ${stdenv.lib.concatStringsSep " " (builtins.map (e: targetPrefix + e) cmds)}; do
37 ln -sf "${cctools}/bin/$i" "$out/bin/$i"
38 done
39
40 ln -s ${binutils-unwrapped.out}/share $out/share
41
42 ln -s ${cctools}/libexec $out/libexec
43
44 mkdir -p "$info/nix-support" "$man/nix-support"
45 printWords ${binutils-unwrapped.info} \
46 >> $info/nix-support/propagated-build-inputs
47 # FIXME: cctools missing man pages
48 printWords ${binutils-unwrapped.man} \
49 >> $man/nix-support/propagated-build-inputs
50 '';
51
52 passthru = {
53 inherit targetPrefix;
54 };
55}