nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 llvmPackages,
5 fetchpatch,
6 fetchurl,
7 pkg-config,
8 freetype,
9 cmake,
10 static ? stdenv.hostPlatform.isStatic,
11 testers,
12}:
13
14stdenv.mkDerivation (finalAttrs: {
15 version = "1.3.14";
16 pname = "graphite2";
17
18 src = fetchurl {
19 url =
20 with finalAttrs;
21 "https://github.com/silnrsi/graphite/releases/download/${version}/${pname}-${version}.tgz";
22 sha256 = "1790ajyhk0ax8xxamnrk176gc9gvhadzy78qia4rd8jzm89ir7gr";
23 };
24
25 outputs = [
26 "out"
27 "dev"
28 ];
29
30 nativeBuildInputs = [
31 pkg-config
32 cmake
33 ];
34 buildInputs = [
35 freetype
36 ]
37 ++ lib.optional (stdenv.targetPlatform.useLLVM or false) (
38 llvmPackages.compiler-rt.override {
39 doFakeLibgcc = true;
40 }
41 );
42
43 patches = [
44 # Fix build with gcc15
45 (fetchpatch {
46 url = "https://src.fedoraproject.org/rpms/graphite2/raw/deba28323b0a3b7a3dcfd06df1efc2195b102ed7/f/graphite2-1.3.14-gcc15.patch";
47 hash = "sha256-vkkGkHkcsj1mD3OHCHLWWgpcmFDv8leC4YQm+TsbIUw=";
48 })
49 ]
50 ++ lib.optionals stdenv.hostPlatform.isDarwin [ ./macosx.patch ];
51 postPatch = ''
52 # disable broken 'nametabletest' test, fails on gcc-13:
53 # https://github.com/silnrsi/graphite/pull/74
54 substituteInPlace tests/CMakeLists.txt \
55 --replace 'add_subdirectory(nametabletest)' '#add_subdirectory(nametabletest)'
56
57 # support cross-compilation by using target readelf binary:
58 substituteInPlace Graphite.cmake \
59 --replace 'readelf' "${stdenv.cc.targetPrefix}readelf"
60
61 # headers are located in the dev output:
62 substituteInPlace CMakeLists.txt \
63 --replace-fail ' ''${CMAKE_INSTALL_PREFIX}/include' " ${placeholder "dev"}/include"
64
65 # Fix the build with CMake 4.
66 #
67 # See: <https://github.com/silnrsi/graphite/issues/98>
68 badCmakeFiles=(
69 CMakeLists.txt
70 src/CMakeLists.txt
71 tests/{bittwiddling,json,sparsetest,utftest}/CMakeLists.txt
72 gr2fonttest/CMakeLists.txt
73 )
74 for file in "''${badCmakeFiles[@]}"; do
75 substituteInPlace "$file" \
76 --replace-fail \
77 'CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0 FATAL_ERROR)' \
78 'CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR)'
79 done
80 '';
81
82 cmakeFlags = lib.optionals static [
83 "-DBUILD_SHARED_LIBS=OFF"
84 ];
85
86 # Remove a test that fails to statically link (undefined reference to png and
87 # freetype symbols)
88 postConfigure = lib.optionalString static ''
89 sed -e '/freetype freetype.c/d' -i ../tests/examples/CMakeLists.txt
90 '';
91
92 doCheck = true;
93
94 passthru.tests = {
95 pkg-config = testers.hasPkgConfigModules {
96 package = finalAttrs.finalPackage;
97 };
98 };
99
100 meta = {
101 description = "Advanced font engine";
102 homepage = "https://graphite.sil.org/";
103 license = lib.licenses.lgpl21;
104 maintainers = [ lib.maintainers.raskin ];
105 pkgConfigModules = [ "graphite2" ];
106 mainProgram = "gr2fonttest";
107 platforms = lib.platforms.unix ++ lib.platforms.windows;
108 };
109})