core/pkgs/by-name/gc/gcc/common/extra-target-flags.nix

31 lines
1.3 KiB
Nix
Raw Normal View History

2024-05-02 00:46:19 +00:00
{ lib, stdenv, withoutTargetLibc, langD ? false, libcCross, threadsCross }:
2024-05-13 21:24:10 +00:00
let inherit (stdenv) hostPlatform targetPlatform;
2024-05-02 00:46:19 +00:00
2024-05-13 21:24:10 +00:00
in {
2024-05-02 00:46:19 +00:00
# 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
2024-05-13 21:24:10 +00:00
mkFlags = dep: langD:
lib.optionals (targetPlatform != hostPlatform && dep != null && !langD)
([ "-O2 -idirafter ${lib.getDev dep}${dep.incdir or "/include"}" ]
++ lib.optionals (!withoutTargetLibc)
[ "-B${lib.getLib dep}${dep.libdir or "/lib"}" ]);
in mkFlags libcCross langD ++ lib.optionals (!withoutTargetLibc)
(mkFlags (threadsCross.package or null) langD);
2024-05-02 00:46:19 +00:00
EXTRA_LDFLAGS_FOR_TARGET = let
2024-05-13 21:24:10 +00:00
mkFlags = dep:
lib.optionals (targetPlatform != hostPlatform && dep != null)
([ "-Wl,-L${lib.getLib dep}${dep.libdir or "/lib"}" ]
++ (if withoutTargetLibc then
[ "-B${lib.getLib dep}${dep.libdir or "/lib"}" ]
else [
2024-05-02 00:46:19 +00:00
"-Wl,-rpath,${lib.getLib dep}${dep.libdir or "/lib"}"
"-Wl,-rpath-link,${lib.getLib dep}${dep.libdir or "/lib"}"
2024-05-13 21:24:10 +00:00
]));
in mkFlags libcCross ++ lib.optionals (!withoutTargetLibc)
(mkFlags (threadsCross.package or null));
2024-05-02 00:46:19 +00:00
}