@@ -1,53 +1,107 @@
1−{ stdenv, fetchurl, makeWrapper
1+{ stdenv, lib, fetchurl, makeWrapper, writeText
22, fpc, gtk2, glib, pango, atk, gdk-pixbuf
33, libXi, xorgproto, libX11, libXext
44, gdb, gnumake, binutils
5+, withQt ? false, qtbase ? null, libqt5pas ? null, wrapQtAppsHook ? null
56}:
7+
8+# TODO:
9+# 1. the build date is embedded in the binary through `$I %DATE%` - we should dump that
10+
11+let
12+ version = "2.0.10-2";
13+
14+ # as of 2.0.10 a suffix is being added. That may or may not disappear and then
15+ # come back, so just leave this here.
16+ majorMinorPatch = v:
17+ builtins.concatStringsSep "." (lib.take 3 (lib.splitVersion v));
18+
19+ overrides = writeText "revision.inc" (lib.concatStringsSep "\n" (lib.mapAttrsToList (k: v:
20+ "const ${k} = '${v}';") {
21+ # this is technically the SVN revision but as we don't have that replace
22+ # it with the version instead of showing "Unknown"
23+ RevisionStr = version;
24+ }));
25+
26+in
627stdenv.mkDerivation rec {
7− pname = "lazarus";
8− version = "2.0.8";
28+ pname = "lazarus-${LCL_PLATFORM}";
29+ inherit version;
930
1031 src = fetchurl {
11− url = "mirror://sourceforge/lazarus/Lazarus%20Zip%20_%20GZip/Lazarus%20${version}/lazarus-${version}.tar.gz";
12− sha256 = "1iciqydb0miqdrh89aj59gy7kfcwikkycqssq9djcqsw1ql3gc4h";
32+ url = "mirror://sourceforge/lazarus/Lazarus%20Zip%20_%20GZip/Lazarus%20${majorMinorPatch version}/lazarus-${version}.tar.gz";
33+ sha256 = "sha256-ZNViZGjdJKMzKyBfOr0KWBq33hsGCi1X4hhkBmz9Q7c=";
1334 };
1435
36+ postPatch = ''
37+ cp ${overrides} ide/${overrides.name}
38+ '';
39+
1540 buildInputs = [
41+ # we need gtk2 unconditionally as that is the default target when building applications with lazarus
1642 fpc gtk2 glib libXi xorgproto
1743 libX11 libXext pango atk
18− stdenv.cc makeWrapper gdk-pixbuf
19− ];
44+ stdenv.cc gdk-pixbuf
45+ ]
46+ ++ lib.optionals withQt [ libqt5pas qtbase ];
47+
48+ nativeBuildInputs = [
49+ makeWrapper
50+ ] ++ lib.optional withQt wrapQtAppsHook;
2051
2152 makeFlags = [
2253 "FPC=fpc"
2354 "PP=fpc"
55+ "LAZARUS_INSTALL_DIR=${placeholder "out"}/share/lazarus/"
56+ "INSTALL_PREFIX=${placeholder "out"}/"
2457 "REQUIRE_PACKAGES+=tachartlazaruspkg"
2558 "bigide"
2659 ];
2760
61+ LCL_PLATFORM = if withQt then "qt5" else "gtk2";
62+
63+ NIX_LDFLAGS = lib.concatStringsSep " " ([
64+ "-L${stdenv.cc.cc.lib}/lib"
65+ "-lX11"
66+ "-lXext"
67+ "-lXi"
68+ "-latk-1.0"
69+ "-lc"
70+ "-lcairo"
71+ "-lgcc_s"
72+ "-lgdk-x11-2.0"
73+ "-lgdk_pixbuf-2.0"
74+ "-lglib-2.0"
75+ "-lgtk-x11-2.0"
76+ "-lpango-1.0"
77+ ]
78+ ++ lib.optionals withQt [
79+ "-L${lib.getLib libqt5pas}/lib"
80+ "-lQt5Pas"
81+ ]);
82+
2883 preBuild = ''
29− export makeFlags="$makeFlags LAZARUS_INSTALL_DIR=$out/share/lazarus/ INSTALL_PREFIX=$out/"
30− export NIX_LDFLAGS="$NIX_LDFLAGS -L${stdenv.cc.cc.lib}/lib -lXi -lX11 -lglib-2.0 -lgtk-x11-2.0 -lgdk-x11-2.0 -lc -lXext -lpango-1.0 -latk-1.0 -lgdk_pixbuf-2.0 -lcairo -lgcc_s"
31− export LCL_PLATFORM=gtk2
3284 mkdir -p $out/share "$out/lazarus"
3385 tar xf ${fpc.src} --strip-components=1 -C $out/share -m
34− sed -e 's@/usr/fpcsrc@'"$out/share/fpcsrc@" -i ide/include/unix/lazbaseconf.inc
86+ substituteInPlace ide/include/unix/lazbaseconf.inc \
87+ --replace '/usr/fpcsrc' "$out/share/fpcsrc"
3588 '';
3689
37− postInstall = ''
38− wrapProgram $out/bin/startlazarus --prefix NIX_LDFLAGS ' ' \
39− "$(echo "$NIX_LDFLAGS" | sed -re 's/-rpath [^ ]+//g')" \
40− --prefix NIX_LDFLAGS_${binutils.suffixSalt} ' ' \
41− "$(echo "$NIX_LDFLAGS" | sed -re 's/-rpath [^ ]+//g')" \
90+ postInstall = let
91+ ldFlags = ''$(echo "$NIX_LDFLAGS" | sed -re 's/-rpath [^ ]+//g')'';
92+ in ''
93+ wrapProgram $out/bin/startlazarus \
94+ --prefix NIX_LDFLAGS ' ' "${ldFlags}" \
95+ --prefix NIX_LDFLAGS_${binutils.suffixSalt} ' ' "${ldFlags}" \
4296 --prefix LCL_PLATFORM ' ' "$LCL_PLATFORM" \
43− --prefix PATH ':' "${fpc}/bin:${gdb}/bin:${gnumake}/bin:${binutils}/bin"
97+ --prefix PATH ':' "${lib.makeBinPath [ fpc gdb gnumake binutils ]}"
4498 '';
4599
46100 meta = with stdenv.lib; {
47− description = "Lazarus graphical IDE for FreePascal language";
48− homepage = "http://www.lazarus.freepascal.org";
101+ description = "Lazarus graphical IDE for the FreePascal language";
102+ homepage = "https://www.lazarus.freepascal.org";
49103 license = licenses.gpl2Plus ;
104+ maintainers = with maintainers; [ raskin ];
50105 platforms = platforms.linux;
51− maintainers = [ maintainers.raskin ];
52106 };
53107}