19 enableX11 ? (!stdenv.hostPlatform.isDarwin),
47 assert enablePython -> enableCxx;
51 freeglut-mupdf = freeglut.overrideAttrs (old: rec {
52 pname = "freeglut-mupdf";
53 version = "3.0.0-r${src.rev}";
54 src = fetchFromGitHub {
55 owner = "ArtifexSoftware";
56 repo = "thirdparty-freeglut";
57 rev = "13ae6aa2c2f9a7b4266fc2e6116c876237f40477";
58 hash = "sha256-0fuE0lm9rlAaok2Qe0V1uUrgP4AjMWgp3eTbw8G6PMM=";
64 stdenv.mkDerivation rec {
69 url = "https://mupdf.com/downloads/archive/${pname}-${version}-source.tar.gz";
70 hash = "sha256-Nsz2peaR4Yis+NtumNCL8F8nu0zjBDLcFfx20ympLU0=";
74 # Upstream makefile does not work with system deps on macOS by default, so
75 # we reuse the Linux section instead.
76 ./fix-darwin-system-deps.patch
77 # Upstream C++ wrap script only defines fixed-sized integers on macOS but
78 # this is required on aarch64-linux too.
83 substituteInPlace Makerules --replace "(shell pkg-config" "(shell $PKG_CONFIG"
85 patchShebangs scripts/mupdfwrap.py
87 # slip in makeFlags when building bindings
88 sed -i -e 's/^\( *make_args *=\)/\1 """ $(echo ''${makeFlagsArray[@]@Q})"""/' scripts/wrap/__main__.py
90 # fix libclang unnamed struct format
91 for wrapper in ./scripts/wrap/{cpp,state}.py; do
92 substituteInPlace "$wrapper" --replace 'struct (unnamed' '(unnamed struct'
100 "USE_SYSTEM_LIBS=yes"
101 "PKG_CONFIG=${buildPackages.pkg-config}/bin/${buildPackages.pkg-config.targetPrefix}pkg-config"
103 ++ lib.optionals (!enableX11) [ "HAVE_X11=no" ]
104 ++ lib.optionals (!enableGL) [ "HAVE_GLUT=no" ]
105 ++ lib.optionals (enableOcr) [ "USE_TESSERACT=yes" ];
109 ++ lib.optional (enableGL || enableX11) copyDesktopItems
110 ++ lib.optional (stdenv.hostPlatform.isDarwin && (enableGL || enableX11)) desktopToDarwinBundle
111 ++ lib.optionals (enableCxx || enablePython) [
112 (python3.pythonOnBuildForHost.withPackages (ps: [
117 ++ lib.optionals (enablePython) [
121 ++ lib.optionals stdenv.hostPlatform.isDarwin [
135 ++ lib.optionals enableX11 [
141 ++ lib.optionals enableCurl [
145 ++ lib.optionals enableGL (
146 if stdenv.hostPlatform.isDarwin then
147 with darwin.apple_sdk.frameworks;
158 ++ lib.optionals enableOcr [
172 # Don't remove mujs because upstream version is incompatible
173 rm -rf thirdparty/{curl,freetype,glfw,harfbuzz,jbig2dec,libjpeg,openjpeg,zlib}
176 postBuild = lib.optionalString (enableCxx || enablePython) ''
177 for dir in build/*; do
178 ./scripts/mupdfwrap.py -d "$dir" -b ${lib.optionalString (enableCxx) "01"}${lib.optionalString (enablePython) "23"}
182 desktopItems = lib.optionals (enableGL || enableX11) [
186 comment = meta.description;
188 exec = "${pname} %f";
191 "application/epub+zip"
194 "application/vnd.ms-xpsdocument"
219 mkdir -p "$out/lib/pkgconfig"
220 cat >"$out/lib/pkgconfig/mupdf.pc" <<EOF
222 libdir=\''${prefix}/lib
223 includedir=\''${prefix}/include
226 Description: Library for rendering PDF documents
228 Libs: -L\''${libdir} -lmupdf
229 Cflags: -I\''${includedir}
232 moveToOutput "bin" "$bin"
234 + (lib.optionalString (stdenv.hostPlatform.isDarwin) ''
235 for exe in $bin/bin/*; do
236 install_name_tool -change build/shared-release/libmupdf.dylib $out/lib/libmupdf.dylib "$exe"
239 + (lib.optionalString (enableX11 || enableGL) ''
240 mkdir -p $bin/share/icons/hicolor/48x48/apps
241 cp docs/logo/mupdf-icon-48.png $bin/share/icons/hicolor/48x48/apps
246 ln -s "$bin/bin/mupdf-gl" "$bin/bin/mupdf"
249 lib.optionalString (enableX11) ''
250 ln -s "$bin/bin/mupdf-x11" "$bin/bin/mupdf"
253 + (lib.optionalString (enableCxx) ''
254 cp platform/c++/include/mupdf/*.h $out/include/mupdf
255 cp build/*/libmupdfcpp.so $out/lib
257 + (lib.optionalString (enablePython) (
259 mkdir -p $out/${python3.sitePackages}/mupdf
260 cp build/*/_mupdf.so $out/${python3.sitePackages}/mupdf
261 cp build/*/mupdf.py $out/${python3.sitePackages}/mupdf/__init__.py
263 + lib.optionalString (stdenv.hostPlatform.isDarwin) ''
264 install_name_tool -add_rpath $out/lib $out/${python3.sitePackages}/mupdf/_mupdf.so
268 enableParallelBuilding = true;
270 env.USE_SONAME = "no";
274 inherit cups-filters zathura;
275 inherit (python3.pkgs) pikepdf pymupdf;
276 mupdf-all = mupdf.override {
285 updateScript = gitUpdater {
286 url = "https://git.ghostscript.com/mupdf.git";
287 ignoredVersions = ".rc.*";
292 homepage = "https://mupdf.com";
293 description = "Lightweight PDF, XPS, and E-book viewer and toolkit written in portable C";
294 changelog = "https://git.ghostscript.com/?p=mupdf.git;a=blob_plain;f=CHANGES;hb=${version}";
295 license = licenses.agpl3Plus;
296 maintainers = with maintainers; [ fpletz ];
297 platforms = platforms.unix;
298 mainProgram = "mupdf";