about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/compilers/gcc/common/extra-target-flags.nix
blob: 0a5a7a1bc1cb965c661124649f7d43dd90b95920 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{ stdenv, crossStageStatic, langD ? false, libcCross, threadsCross }:

let
  inherit (stdenv) lib hostPlatform targetPlatform;
in

{
  # For non-cross builds these flags are currently assigned in builder.sh.
  # It would be good to consolidate the generation of makeFlags
  # ({C,CXX,LD}FLAGS_FOR_{BUILD,TARGET}, etc...) at some point.
  EXTRA_FLAGS_FOR_TARGET = let
      mkFlags = dep: langD: lib.optionals (targetPlatform != hostPlatform && dep != null && !langD) ([
        "-O2 -idirafter ${lib.getDev dep}${dep.incdir or "/include"}"
      ] ++ stdenv.lib.optionals (! crossStageStatic) [
        "-B${lib.getLib dep}${dep.libdir or "/lib"}"
      ]);
    in mkFlags libcCross langD
    ++ lib.optionals (!crossStageStatic) (mkFlags threadsCross langD)
    ;

  EXTRA_LDFLAGS_FOR_TARGET = let
      mkFlags = dep: lib.optionals (targetPlatform != hostPlatform && dep != null) ([
        "-Wl,-L${lib.getLib dep}${dep.libdir or "/lib"}"
      ] ++ (if crossStageStatic then [
          "-B${lib.getLib dep}${dep.libdir or "/lib"}"
        ] else [
          "-Wl,-rpath,${lib.getLib dep}${dep.libdir or "/lib"}"
          "-Wl,-rpath-link,${lib.getLib dep}${dep.libdir or "/lib"}"
      ]));
    in mkFlags libcCross
    ++ lib.optionals (!crossStageStatic) (mkFlags threadsCross)
    ;
}