1{ stdenv, fetchFromGitHub, fetchpatch, lib
2, autoconf, automake, gnum4, libtool, perl, gnulib, uthash, pkgconfig, gettext
3, python, freetype, zlib, glib, libungif, libpng, libjpeg, libtiff, libxml2, pango
4, withSpiro ? false, libspiro
5, withGTK ? false, gtk2
6, withPython ? true
7, Carbon ? null, Cocoa ? null
8}:
9
10stdenv.mkDerivation rec {
11 name = "fontforge-${version}";
12 version = "20170730";
13
14 src = fetchFromGitHub {
15 owner = "fontforge";
16 repo = "fontforge";
17 rev = version;
18 sha256 = "15k6x97383p8l40jvcivalhwgbbcdg5vciyjz6m9r0lrlnjqkv99";
19 };
20
21 patches = [ ./fontforge-20140813-use-system-uthash.patch ];
22
23 # use $SOURCE_DATE_EPOCH instead of non-determenistic timestamps
24 postPatch = ''
25 find . -type f -name '*.c' -exec sed -r -i 's#\btime\(&(.+)\)#if (getenv("SOURCE_DATE_EPOCH")) \1=atol(getenv("SOURCE_DATE_EPOCH")); else &#g' {} \;
26 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
27 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
28 sed -r -i 's#^\s*ttf_fftm_dump#if (!getenv("SOURCE_DATE_EPOCH")) ttf_fftm_dump#g' fontforge/tottf.c
29 sed -r -i 's#sprintf\(.+ author \);#if (!getenv("SOURCE_DATE_EPOCH")) &#g' fontforgeexe/fontinfo.c
30 '';
31
32 # do not use x87's 80-bit arithmetic, rouding errors result in very different font binaries
33 NIX_CFLAGS_COMPILE = lib.optionals stdenv.isi686 [ "-msse2" "-mfpmath=sse" ];
34
35 nativeBuildInputs = [ pkgconfig ];
36 buildInputs = [
37 autoconf automake gnum4 libtool perl gettext uthash
38 python freetype zlib glib libungif libpng libjpeg libtiff libxml2
39 ]
40 ++ lib.optionals withSpiro [libspiro]
41 ++ lib.optionals withGTK [ gtk2 pango ]
42 ++ lib.optionals stdenv.isDarwin [ Carbon Cocoa ];
43
44 configureFlags =
45 lib.optionals (!withPython) [ "--disable-python-scripting" "--disable-python-extension" ]
46 ++ lib.optional withGTK "--enable-gtk2-use"
47 ++ lib.optional (!withGTK) "--without-x";
48
49 # work-around: git isn't really used, but configuration fails without it
50 preConfigure = ''
51 # The way $version propagates to $version of .pe-scripts (https://github.com/dejavu-fonts/dejavu-fonts/blob/358190f/scripts/generate.pe#L19)
52 export SOURCE_DATE_EPOCH=$(date -d ${version} +%s)
53
54 export GIT="$(type -P true)"
55 cp -r "${gnulib}" ./gnulib
56 chmod +w -R ./gnulib
57 ./bootstrap --skip-git --gnulib-srcdir=./gnulib
58 '';
59
60 postInstall =
61 # get rid of the runtime dependency on python
62 lib.optionalString (!withPython) ''
63 rm -r "$out/share/fontforge/python"
64 '';
65
66 enableParallelBuilding = true;
67
68 meta = {
69 description = "A font editor";
70 homepage = http://fontforge.github.io;
71 platforms = stdenv.lib.platforms.all;
72 license = stdenv.lib.licenses.bsd3;
73 };
74}
75