about summary refs log tree commit diff
path: root/pkgs/by-name/sw/swt/package.nix
blob: c67424f4fc06b45a795190805106c6ae7cabab17 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
{
  atk,
  fetchzip,
  glib,
  gtk2,
  jdk,
  lib,
  libGL,
  libGLU,
  libXt,
  libXtst,
  pkg-config,
  stdenv,
  stripJavaArchivesHook,
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "swt";
  version = "4.5";
  fullVersion = "${finalAttrs.version}-201506032000";

  hardeningDisable = [ "format" ];

  passthru.srcMetadataByPlatform = {
    x86_64-linux.platform = "gtk-linux-x86_64";
    x86_64-linux.sha256 = "17frac2nsx22hfa72264as31rn35hfh9gfgy0n6wvc3knl5d2716";
    i686-linux.platform = "gtk-linux-x86";
    i686-linux.sha256 = "13ca17rga9yvdshqvh0sfzarmdcl4wv4pid0ls7v35v4844zbc8b";
    x86_64-darwin.platform = "cocoa-macosx-x86_64";
    x86_64-darwin.sha256 = "0wjyxlw7i9zd2m8syd6k1q85fj8pzhxlfsrl8fpgsj37p698bd0a";
  };
  passthru.srcMetadata =
    finalAttrs.passthru.srcMetadataByPlatform.${stdenv.hostPlatform.system} or null;
  # Alas, the Eclipse Project apparently doesn't produce source-only
  # releases of SWT.  So we just grab a binary release and extract
  # "src.zip" from that.
  src =
    let
      inherit (finalAttrs.passthru) srcMetadata;
    in
    assert srcMetadata != null;
    fetchzip {
      url = "https://archive.eclipse.org/eclipse/downloads/drops4/R-${finalAttrs.fullVersion}/swt-${finalAttrs.version}-${srcMetadata.platform}.zip";
      inherit (srcMetadata) sha256;
      stripRoot = false;
      postFetch = ''
        mkdir "$unpackDir"
        cd "$unpackDir"

        renamed="$TMPDIR/src.zip"
        mv -- "$out/src.zip" "$renamed"
        unpackFile "$renamed"
        rm -r -- "$out"

        mv -- "$unpackDir" "$out"
      '';
    };

  nativeBuildInputs = [
    stripJavaArchivesHook
    pkg-config
  ];
  buildInputs = [
    atk
    gtk2
    jdk
    libGL
    libGLU
    libXtst
  ] ++ lib.optionals (lib.hasPrefix "8u" jdk.version) [ libXt ];

  patches = [
    ./awt-libs.patch
    ./gtk-libs.patch
  ];

  prePatch = ''
    # clear whitespace from makefiles (since we match on EOL later)
    sed -i 's/ \+$//' ./*.mak
  '';

  postPatch =
    let
      makefile-sed = builtins.toFile "swt-makefile.sed" ''
        # fix pkg-config invocations in CFLAGS/LIBS pairs.
        #
        # change:
        #     FOOCFLAGS = `pkg-config --cflags `foo bar`
        #     FOOLIBS = `pkg-config --libs-only-L foo` -lbaz
        # into:
        #     FOOCFLAGS = `pkg-config --cflags foo bar`
        #     FOOLIBS = `pkg-config --libs foo bar`
        #
        # the latter works more consistently.
        /^[A-Z0-9_]\+CFLAGS = `pkg-config --cflags [^`]\+`$/ {
          N
          s/${''
            ^\([A-Z0-9_]\+\)CFLAGS = `pkg-config --cflags \(.\+\)`\
            \1LIBS = `pkg-config --libs-only-L .\+$''}/${''
            \1CFLAGS = `pkg-config --cflags \2`\
            \1LIBS = `pkg-config --libs \2`''}/
        }
        # fix WebKit libs not being there
        s/\$(WEBKIT_LIB) \$(WEBKIT_OBJECTS)$/\0 `pkg-config --libs glib-2.0`/g
      '';
    in
    ''
      declare -a makefiles=(./*.mak)
      sed -i -f ${makefile-sed} "''${makefiles[@]}"
      # assign Makefile variables eagerly & change backticks to `$(shell …)`
      sed -i -e 's/ = `\([^`]\+\)`/ := $(shell \1)/' \
        -e 's/`\([^`]\+\)`/$(shell \1)/' \
        "''${makefiles[@]}"
    '';

  buildPhase = ''
    runHook preBuild

    export JAVA_HOME=${jdk}

    ./build.sh

    mkdir out
    find org/ -name '*.java' -type f -exec javac -d out/ {} +

    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    if [[ -n "$prefix" ]]; then
      install -d -- "$prefix"
    fi

    install -Dm 644 -t "$out/lib" -- *.so

    install -d -- "$out/jars"
    install -m 644 -t out -- version.txt
    (cd out && jar -c *) > "$out/jars/swt.jar"

    runHook postInstall
  '';

  meta = {
    homepage = "https://www.eclipse.org/swt/";
    description = ''
      A widget toolkit for Java to access the user-interface facilities of
      the operating systems on which it is implemented.
    '';
    license = lib.licenses.epl10;
    maintainers = [ ];
    platforms = lib.platforms.linux;
  };
})