summary refs log tree commit diff
path: root/pkgs/development/tools/lattice-diamond/default.nix
blob: e8bc4c1b1be533b4940d789d7e4c25d23e7d1cb3 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
{ lib, stdenv, rpmextract, patchelf, makeWrapper, file, requireFile, glib, zlib,
    freetype, fontconfig, xorg, libusb-compat-0_1 }:

stdenv.mkDerivation {
  pname = "diamond";
  version = "3.10";

  nativeBuildInputs = [ rpmextract patchelf makeWrapper file ];

  src = requireFile {
    name = "diamond_3_10-base_x64-111-2-x86_64-linux.rpm";
    url = "http://www.latticesemi.com/view_document?document_id=52180";
    sha256 = "ec0b370cf8bd55831eeed7c5eadcabacbd6e63ac657c20209d672119a07a5c0f";
  };

  buildCommand = ''
    origprefix=usr/local/diamond/3.10_x64
    prefix=diamond

    echo "Unpacking $src..."
    rpmextract $src

    # Move $pwd/usr/local/diamond/VERS to $out/diamond, cd.
    mkdir -p $out/$prefix
    rmdir $out/$prefix
    mv $origprefix $out/$prefix

    cd $out

    # Extract all tarballs.
    for tb in \
        cae_library/cae_library.tar.gz \
        embedded_source/embedded_source.tar.gz \
        ispfpga/ispfpga.tar.gz \
        synpbase/synpbase.tar.gz \
        tcltk/tcltk.tar.gz \
        bin/bin.tar.gz \
        examples/examples.tar.gz \
        data/data.tar.gz ; do

        echo "Extracting tarball $prefix/$tb"
        cd $out/$prefix/$(dirname $tb)
        tar xf $(basename $tb)
        rm $(basename $tb)
    done

    # Patch shebangs in start scripts .
    cd $out/$prefix/bin/lin64
    for tool in \
        programmer \
        pgrcmd \
        diamond_env \
        powercal \
        model300 \
        update \
        diamond \
        debugger \
        ddtcmd \
        cableserver \
        revealrva \
        ipexpress \
        fileutility \
        diamond ; do

        echo "Patching script $prefix/bin/lin64/$tool..."
        patchShebangs $tool
    done

    # Patch executable ELFs.
    for path in bin/lin64 ispfpga/bin/lin64; do
        cd $out/$prefix/$path
        for f in *; do
            if ! file $f | grep -q "ELF 64-bit LSB executable" ; then
                continue
            fi
            echo "Patching ELF $prefix/$path/$f..."
            # We force RPATH otherwise libraries from LD_LIBRARY_PATH (which the
            # tools mangle by themselves) will not be able to find their
            # dependencies from nix.
            patchelf \
                --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
                --set-rpath "$libPath" --force-rpath \
                $f
        done
    done

    # Remove 32-bit libz.
    rm $out/$prefix/bin/lin64/libz.{so,so.1}

    # Make wrappers (should these target more than the 'diamond' tool?).
    # The purpose of these is just to call the target program using its
    # absolute path - otherwise, it will crash.
    mkdir -p bin
    for tool in diamond ; do
        makeWrapper $out/$prefix/bin/lin64/$tool $out/bin/$tool
    done
  '';

  libPath = lib.makeLibraryPath [
    glib zlib freetype fontconfig
    xorg.libSM xorg.libICE xorg.libXrender xorg.libXext xorg.libX11 xorg.libXt
    libusb-compat-0_1
  ];

  meta = {
    description = "Vendor development tools for Lattice FPGA devices";
    longDescription = ''
      Lattice Diamond software is the leading-edge software design environment
      for cost- sensitive, low-power Lattice FPGA architectures. It is the
      next-generation replacement for ispLEVER.
    '';
    homepage = "https://www.latticesemi.com/latticediamond";
    license = lib.licenses.unfree;
    maintainers = with lib.maintainers; [ q3k ];
    platforms = [ "x86_64-linux" ];
  };
}