1{ stdenv, fetchFromGitHub, lib
2, cmake, uthash, pkg-config
3, python, freetype, zlib, glib, giflib, libpng, libjpeg, libtiff, libxml2, cairo, pango
4, readline, woff2, zeromq
5, withSpiro ? false, libspiro
6, withGTK ? false, gtk3
7, withGUI ? withGTK
8, withPython ? true
9, withExtras ? true
10, Carbon, Cocoa
11}:
12
13assert withGTK -> withGUI;
14
15stdenv.mkDerivation rec {
16 pname = "fontforge";
17 version = "20230101";
18
19 src = fetchFromGitHub {
20 owner = pname;
21 repo = pname;
22 rev = version;
23 sha256 = "sha256-/RYhvL+Z4n4hJ8dmm+jbA1Ful23ni2DbCRZC5A3+pP0=";
24 };
25
26 # use $SOURCE_DATE_EPOCH instead of non-deterministic timestamps
27 postPatch = ''
28 find . -type f -name '*.c' -exec sed -r -i 's#\btime\(&(.+)\)#if (getenv("SOURCE_DATE_EPOCH")) \1=atol(getenv("SOURCE_DATE_EPOCH")); else &#g' {} \;
29 sed -r -i 's#author\s*!=\s*NULL#& \&\& !getenv("SOURCE_DATE_EPOCH")#g' fontforge/cvexport.c fontforge/dumppfa.c fontforge/print.c fontforge/svg.c fontforge/splineutil2.c
30 sed -r -i 's#\bb.st_mtime#getenv("SOURCE_DATE_EPOCH") ? atol(getenv("SOURCE_DATE_EPOCH")) : &#g' fontforge/parsepfa.c fontforge/sfd.c fontforge/svg.c
31 sed -r -i 's#^\s*ttf_fftm_dump#if (!getenv("SOURCE_DATE_EPOCH")) ttf_fftm_dump#g' fontforge/tottf.c
32 sed -r -i 's#sprintf\(.+ author \);#if (!getenv("SOURCE_DATE_EPOCH")) &#g' fontforgeexe/fontinfo.c
33 '';
34
35 # do not use x87's 80-bit arithmetic, rouding errors result in very different font binaries
36 env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isi686 "-msse2 -mfpmath=sse";
37
38 nativeBuildInputs = [ pkg-config cmake ];
39 buildInputs = [
40 readline uthash woff2 zeromq
41 python freetype zlib glib giflib libpng libjpeg libtiff libxml2
42 ]
43 ++ lib.optionals withSpiro [ libspiro ]
44 ++ lib.optionals withGUI [ gtk3 cairo pango ]
45 ++ lib.optionals stdenv.isDarwin [ Carbon Cocoa ];
46
47 cmakeFlags = [ "-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON" ]
48 ++ lib.optional (!withSpiro) "-DENABLE_LIBSPIRO=OFF"
49 ++ lib.optional (!withGUI) "-DENABLE_GUI=OFF"
50 ++ lib.optional (!withGTK) "-DENABLE_X11=ON"
51 ++ lib.optional withExtras "-DENABLE_FONTFORGE_EXTRAS=ON";
52
53 preConfigure = ''
54 # The way $version propagates to $version of .pe-scripts (https://github.com/dejavu-fonts/dejavu-fonts/blob/358190f/scripts/generate.pe#L19)
55 export SOURCE_DATE_EPOCH=$(date -d ${version} +%s)
56 '';
57
58 postInstall =
59 # get rid of the runtime dependency on python
60 lib.optionalString (!withPython) ''
61 rm -r "$out/share/fontforge/python"
62 '';
63
64 meta = with lib; {
65 description = "A font editor";
66 homepage = "https://fontforge.github.io";
67 platforms = platforms.all;
68 license = licenses.bsd3;
69 maintainers = [ maintainers.erictapen ];
70 };
71}