about summary refs log tree commit diff
path: root/pkgs/development/libraries/box2d/2.0.1.nix
blob: 9aa08caf00f4c43ce9f9d65026f6da35997e12f1 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
x@{builderDefsPackage
  , unzip, cmake, mesa, freeglut, libX11, xproto
  , inputproto, libXi
  , ...}:
builderDefsPackage
(a :  
let 
  helperArgNames = ["stdenv" "fetchurl" "builderDefsPackage"] ++ 
    [];

  buildInputs = map (n: builtins.getAttr n x)
    (builtins.attrNames (builtins.removeAttrs x helperArgNames));
  sourceInfo = rec {
    baseName="box2d";
    version="2.0.1";
    name="${baseName}-${version}";
    url="http://box2d.googlecode.com/files/Box2D_v${version}.zip";
    hash="62857048aa089b558561074154430883cee491eedd71247f75f488cba859e21f";
  };
in
rec {
  src = a.fetchurl {
    url = sourceInfo.url;
    sha256 = sourceInfo.hash;
  };

  inherit (sourceInfo) name version;
  inherit buildInputs;

  phaseNames = ["fixIncludes" "setVars" "changeSettings" "doMake" "doDeploy"];

  goSrcDir = ''cd Box2D'';

  fixIncludes = a.fullDepEntry ''
    sed -i Source/Dynamics/Contacts/b2PolyContact.cpp \
        -i Source/Dynamics/Contacts/b2CircleContact.cpp \
        -i Source/Dynamics/Contacts/b2PolyAndCircleContact.cpp \
        -i Source/Common/b2BlockAllocator.cpp \
        -i Source/Collision/b2BroadPhase.cpp \
        -i Examples/TestBed/Framework/Render.cpp \
        -i Examples/TestBed/Tests/BroadPhaseTest.cpp \
        -i Examples/TestBed/Tests/TestEntries.cpp \
        -e '1i#include <string.h>'
  '' ["minInit" "addInputs" "doUnpack"];

  setVars = a.noDepEntry ''
    export NIX_LDFLAGS="$NIX_LDFLAGS -lX11 -lXi"
  '';

  doDeploy = a.fullDepEntry ''
    ensureDir "$out"/lib
    ensureDir "$out"/include/Box2D
    cp Library/* Source/Gen/float/lib*.{a,so} "$out"/lib
    cp -r Source "$out"/include/Box2D/Source
    find "$out"/include/Box2D/Source ! -name '*.h' -exec rm '{}' ';'
    sed -e s@../Source@Box2D/Source@ -i Include/Box2D.h
    cp Include/Box2D.h "$out"/include/Box2D
    ensureDir "$out/share"
    cp -r Examples "$out/share"
  '' ["minInit" "addInputs" "doMake" "defEnsureDir"];

  changeSettings = a.fullDepEntry ''
    sed -i Source/Common/b2Settings.h -e 's@b2_maxPolygonVertices .*@b2_maxPolygonVertices = 15;@'
  '' ["minInit" "addInputs" "doUnpack"];
      
  meta = {
    description = "2D physics engine";
    maintainers = with a.lib.maintainers;
    [
      raskin
    ];
    platforms = with a.lib.platforms;
      linux;
    license = "bsd";
  };
  passthru = {
    updateInfo = {
      downloadPage = "http://code.google.com/p/box2d/downloads/list";
    };
  };
}) x