Merge pull request #119126 from fabaff/pycomfoconnect
[NixPkgs.git] / pkgs / development / beam-modules / build-erlang-mk.nix
bloba94524276b26a613f3eb781054aadad082ba9fcf
1 { stdenv, writeText, erlang, perl, which, gitMinimal, wget, lib }:
3 { name, version
4 , src
5 , setupHook ? null
6 , buildInputs ? []
7 , beamDeps ? []
8 , postPatch ? ""
9 , compilePorts ? false
10 , installPhase ? null
11 , buildPhase ? null
12 , configurePhase ? null
13 , meta ? {}
14 , enableDebugInfo ? false
15 , buildFlags ? []
16 , ... }@attrs:
18 with lib;
20 let
21   debugInfoFlag = lib.optionalString (enableDebugInfo || erlang.debugInfo) "+debug_info";
23   shell = drv: stdenv.mkDerivation {
24           name = "interactive-shell-${drv.name}";
25           buildInputs = [ drv ];
26     };
28   pkg = self: stdenv.mkDerivation ( attrs // {
29     app_name = name;
30     name = "${name}-${version}";
31     inherit version;
33     dontStrip = true;
35     inherit src;
37     setupHook = if setupHook == null
38     then writeText "setupHook.sh" ''
39        addToSearchPath ERL_LIBS "$1/lib/erlang/lib"
40     ''
41     else setupHook;
43     buildInputs = buildInputs ++ [ erlang perl which gitMinimal wget ];
44     propagatedBuildInputs = beamDeps;
46     buildFlags = [ "SKIP_DEPS=1" ]
47       ++ lib.optional (enableDebugInfo || erlang.debugInfo) ''ERL_OPTS="$ERL_OPTS +debug_info"''
48       ++ buildFlags;
50     configurePhase = if configurePhase == null
51     then ''
52       runHook preConfigure
54       # We shouldnt need to do this, but it seems at times there is a *.app in
55       # the repo/package. This ensures we start from a clean slate
56       make SKIP_DEPS=1 clean
58       runHook postConfigure
59     ''
60     else configurePhase;
62     buildPhase = if buildPhase == null
63     then ''
64         runHook preBuild
66         make $buildFlags "''${buildFlagsArray[@]}"
68         runHook postBuild
69     ''
70     else buildPhase;
72     installPhase =  if installPhase == null
73     then ''
74         runHook preInstall
76         mkdir -p $out/lib/erlang/lib/${name}
77         cp -r ebin $out/lib/erlang/lib/${name}/
78         cp -r src $out/lib/erlang/lib/${name}/
80         if [ -d include ]; then
81           cp -r include $out/lib/erlang/lib/${name}/
82         fi
84         if [ -d priv ]; then
85           cp -r priv $out/lib/erlang/lib/${name}/
86         fi
88         if [ -d doc ]; then
89           cp -r doc $out/lib/erlang/lib/${name}/
90         fi
92         runHook postInstall
93     ''
94     else installPhase;
96     passthru = {
97       packageName = name;
98       env = shell self;
99       inherit beamDeps;
100     };
102 in fix pkg