about summary refs log tree commit diff
path: root/nixpkgs/pkgs/by-name/ma/maloader/package.nix
blob: bb0f744f37b64672e72ea48d5d7552650b2fc11d (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
{
  lib,
  llvmPackages,
  fetchFromGitHub,
  opencflite,
  libuuid,
  zlib,
}:

let
  stdenv = llvmPackages.libcxxStdenv;
in
stdenv.mkDerivation {
  pname = "maloader";
  version = "0-unstable-2018-05-02";

  src = fetchFromGitHub {
    owner = "shinh";
    repo = "maloader";
    rev = "464a90fdfd06a54c9da5d1a3725ed6229c0d3d60";
    hash = "sha256-0N3+tr8XUsn3WhJNsPVknumBrfMgDawTEXVRkIs/IV8=";
  };

  postPatch = ''
    substituteInPlace ld-mac.cc \
      --replace-fail 'loadLibMac(mypath)' 'loadLibMac("${placeholder "out"}/lib/")' \
      --replace-fail 'libCoreFoundation.so' '${opencflite}/lib/libCoreFoundation.so'
    substituteInPlace libmac/stack_protector-obsd.c \
      --replace-fail 'sys/sysctl.h' 'linux/sysctl.h'
  '';

  buildInputs = [
    libuuid
    zlib
  ];

  buildFlags = [
    "USE_LIBCXX=1"
    "release"
  ];

  env.NIX_CFLAGS_COMPILE = "-Wno-error=unused-command-line-argument";

  installPhase = ''
    runHook preInstall

    install -vD libmac.so "$out/lib/libmac.so"

    for bin in extract macho2elf ld-mac; do
      install -vD "$bin" "$out/bin/$bin"
    done

    runHook postInstall
  '';

  meta = {
    description = "Mach-O loader for Linux";
    homepage = "https://github.com/shinh/maloader";
    license = lib.licenses.bsd2;
    maintainers = with lib.maintainers; [ wegank ];
    inherit (opencflite.meta) platforms;
  };
}