1{
2 stdenv,
3 lib,
4 fetchurl,
5 makeWrapper,
6 writeText,
7 fpc,
8 gtk2,
9 glib,
10 pango,
11 atk,
12 gdk-pixbuf,
13 libXi,
14 xorgproto,
15 libX11,
16 libXext,
17 gdb,
18 gnumake,
19 binutils,
20 withQt ? false,
21 qtbase ? null,
22 libqtpas ? null,
23 wrapQtAppsHook ? null,
24}:
25
26# TODO:
27# 1. the build date is embedded in the binary through `$I %DATE%` - we should dump that
28
29let
30 version = "4.0-0";
31
32 # as of 2.0.10 a suffix is being added. That may or may not disappear and then
33 # come back, so just leave this here.
34 majorMinorPatch = v: builtins.concatStringsSep "." (lib.take 2 (lib.splitVersion v));
35
36 overrides = writeText "revision.inc" (
37 lib.concatStringsSep "\n" (
38 lib.mapAttrsToList (k: v: "const ${k} = '${v}';") {
39 # this is technically the SVN revision but as we don't have that replace
40 # it with the version instead of showing "Unknown"
41 RevisionStr = version;
42 }
43 )
44 );
45
46 qtVersion = lib.versions.major qtbase.version;
47in
48stdenv.mkDerivation rec {
49 pname = "lazarus-${LCL_PLATFORM}";
50 inherit version;
51
52 src = fetchurl {
53 url = "mirror://sourceforge/lazarus/Lazarus%20Zip%20_%20GZip/Lazarus%20${majorMinorPatch version}/lazarus-${version}.tar.gz";
54 hash = "sha256-vIM7RxzXqCYSiavND1OhFjuMcG5FmD+zq6kmEiM5z8s=";
55 };
56
57 postPatch = ''
58 cp ${overrides} ide/${overrides.name}
59 '';
60
61 buildInputs = [
62 # we need gtk2 unconditionally as that is the default target when building applications with lazarus
63 fpc
64 gtk2
65 glib
66 libXi
67 xorgproto
68 libX11
69 libXext
70 pango
71 atk
72 stdenv.cc
73 gdk-pixbuf
74 ]
75 ++ lib.optionals withQt [
76 libqtpas
77 qtbase
78 ];
79
80 # Disable parallel build, errors:
81 # Fatal: (1018) Compilation aborted
82 enableParallelBuilding = false;
83
84 nativeBuildInputs = [
85 makeWrapper
86 ]
87 ++ lib.optional withQt wrapQtAppsHook;
88
89 makeFlags = [
90 "FPC=fpc"
91 "PP=fpc"
92 "LAZARUS_INSTALL_DIR=${placeholder "out"}/share/lazarus/"
93 "INSTALL_PREFIX=${placeholder "out"}/"
94 "REQUIRE_PACKAGES+=tachartlazaruspkg"
95 "bigide"
96 ];
97
98 LCL_PLATFORM = if withQt then "qt${qtVersion}" else "gtk2";
99
100 NIX_LDFLAGS = lib.concatStringsSep " " (
101 [
102 "-L${lib.getLib stdenv.cc.cc}/lib"
103 "-lX11"
104 "-lXext"
105 "-lXi"
106 "-latk-1.0"
107 "-lc"
108 "-lcairo"
109 "-lgcc_s"
110 "-lgdk-x11-2.0"
111 "-lgdk_pixbuf-2.0"
112 "-lglib-2.0"
113 "-lgtk-x11-2.0"
114 "-lpango-1.0"
115 ]
116 ++ lib.optionals withQt [
117 "-L${lib.getLib libqtpas}/lib"
118 "-lQt${qtVersion}Pas"
119 ]
120 );
121
122 preBuild = ''
123 mkdir -p $out/share "$out/lazarus"
124 tar xf ${fpc.src} --strip-components=1 -C $out/share -m
125 substituteInPlace ide/packages/ideconfig/include/unix/lazbaseconf.inc \
126 --replace '/usr/fpcsrc' "$out/share/fpcsrc"
127 '';
128
129 postInstall =
130 let
131 ldFlags = ''$(echo "$NIX_LDFLAGS" | sed -re 's/-rpath [^ ]+//g')'';
132 in
133 ''
134 wrapProgram $out/bin/startlazarus \
135 --prefix NIX_LDFLAGS ' ' "${ldFlags}" \
136 --prefix NIX_LDFLAGS_${binutils.suffixSalt} ' ' "${ldFlags}" \
137 --prefix LCL_PLATFORM ' ' "$LCL_PLATFORM" \
138 --prefix PATH ':' "${
139 lib.makeBinPath [
140 fpc
141 gdb
142 gnumake
143 binutils
144 ]
145 }"
146 '';
147
148 meta = with lib; {
149 description = "Graphical IDE for the FreePascal language";
150 homepage = "https://www.lazarus.freepascal.org";
151 license = licenses.gpl2Plus;
152 maintainers = with maintainers; [ raskin ];
153 platforms = platforms.linux;
154 };
155}