aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/pkgs/development/compilers/fpc/lazarus.nix
blob: 9f50ea9abba2fb38048f74e7184d122992a9b84b (plain)
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
{ stdenv, lib, fetchurl, makeWrapper, writeText
, fpc, gtk2, glib, pango, atk, gdk-pixbuf
, libXi, xorgproto, libX11, libXext
, gdb, gnumake, binutils
, withQt ? false, qtbase ? null, libqt5pas ? null, wrapQtAppsHook ? null
}:

# TODO:
#  1. the build date is embedded in the binary through `$I %DATE%` - we should dump that

let
  version = "2.0.10-2";

  # as of 2.0.10 a suffix is being added. That may or may not disappear and then
  # come back, so just leave this here.
  majorMinorPatch = v:
    builtins.concatStringsSep "." (lib.take 3 (lib.splitVersion v));

  overrides = writeText "revision.inc" (lib.concatStringsSep "\n" (lib.mapAttrsToList (k: v:
    "const ${k} = '${v}';") {
      # this is technically the SVN revision but as we don't have that replace
      # it with the version instead of showing "Unknown"
      RevisionStr = version;
    }));

in
stdenv.mkDerivation rec {
  pname = "lazarus-${LCL_PLATFORM}";
  inherit version;

  src = fetchurl {
    url = "mirror://sourceforge/lazarus/Lazarus%20Zip%20_%20GZip/Lazarus%20${majorMinorPatch version}/lazarus-${version}.tar.gz";
    sha256 = "sha256-ZNViZGjdJKMzKyBfOr0KWBq33hsGCi1X4hhkBmz9Q7c=";
  };

  postPatch = ''
    cp ${overrides} ide/${overrides.name}
  '';

  buildInputs = [
    # we need gtk2 unconditionally as that is the default target when building applications with lazarus
    fpc gtk2 glib libXi xorgproto
    libX11 libXext pango atk
    stdenv.cc gdk-pixbuf
  ]
  ++ lib.optionals withQt [ libqt5pas qtbase ];

  nativeBuildInputs = [
    makeWrapper
  ] ++ lib.optional withQt wrapQtAppsHook;

  makeFlags = [
    "FPC=fpc"
    "PP=fpc"
    "LAZARUS_INSTALL_DIR=${placeholder "out"}/share/lazarus/"
    "INSTALL_PREFIX=${placeholder "out"}/"
    "REQUIRE_PACKAGES+=tachartlazaruspkg"
    "bigide"
  ];

  LCL_PLATFORM = if withQt then "qt5" else "gtk2";

  NIX_LDFLAGS = lib.concatStringsSep " " ([
    "-L${stdenv.cc.cc.lib}/lib"
    "-lX11"
    "-lXext"
    "-lXi"
    "-latk-1.0"
    "-lc"
    "-lcairo"
    "-lgcc_s"
    "-lgdk-x11-2.0"
    "-lgdk_pixbuf-2.0"
    "-lglib-2.0"
    "-lgtk-x11-2.0"
    "-lpango-1.0"
  ]
  ++ lib.optionals withQt [
    "-L${lib.getLib libqt5pas}/lib"
    "-lQt5Pas"
  ]);

  preBuild = ''
    mkdir -p $out/share "$out/lazarus"
    tar xf ${fpc.src} --strip-components=1 -C $out/share -m
    substituteInPlace ide/include/unix/lazbaseconf.inc \
      --replace '/usr/fpcsrc' "$out/share/fpcsrc"
  '';

  postInstall = let
    ldFlags = ''$(echo "$NIX_LDFLAGS" | sed -re 's/-rpath [^ ]+//g')'';
  in ''
    wrapProgram $out/bin/startlazarus \
      --prefix NIX_LDFLAGS ' ' "${ldFlags}" \
      --prefix NIX_LDFLAGS_${binutils.suffixSalt} ' ' "${ldFlags}" \
      --prefix LCL_PLATFORM ' ' "$LCL_PLATFORM" \
      --prefix PATH ':' "${lib.makeBinPath [ fpc gdb gnumake binutils ]}"
  '';

  meta = with stdenv.lib; {
    description = "Lazarus graphical IDE for the FreePascal language";
    homepage = "https://www.lazarus.freepascal.org";
    license = licenses.gpl2Plus ;
    maintainers = with maintainers; [ raskin ];
    platforms = platforms.linux;
  };
}