From 522c1904cf62afac25a9d974091211adac760c25 Mon Sep 17 00:00:00 2001
From: Daniel Trujillo Viedma <danihacker.viedma@gmail.com>
Date: Sat, 14 Aug 2021 00:00:55 +0200
Subject: [PATCH] Add prusa-slicer

---
 gnu/packages/engineering.scm                       | 58 ++++++++++++++++++++++
 .../patches/prusa-slicer-backport-fix-5542.patch   | 31 ++++++++++++
 2 files changed, 89 insertions(+)
 create mode 100644 gnu/packages/patches/prusa-slicer-backport-fix-5542.patch

diff --git a/gnu/packages/engineering.scm b/gnu/packages/engineering.scm
index 33c124a2ea..047d99c0af 100644
--- a/gnu/packages/engineering.scm
+++ b/gnu/packages/engineering.scm
@@ -2863,3 +2863,61 @@ for hooking Linux system calls in user space.  This is achieved by
 hot-patching the machine code of the standard C library in the memory of
 a process.")
       (license license:bsd-2))))
+
+(define-public prusa-slicer
+  (package
+    (name "prusa-slicer")
+    (version "2.3.3")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/prusa3d/PrusaSlicer")
+             (commit (string-append "version_" version))))
+       (sha256
+        (base32 "0w0synqi3iz9aigsgv6x1c6sg123fasbx19h4w3ic1l48r8qmpwm"))
+     (patches (search-patches "prusa-slicer-backport-fix-5542.patch"))))
+    (build-system cmake-build-system)
+    (arguments
+       `(#:configure-flags `("-DSLIC3R_GTK=3")))
+    (native-inputs
+       `(("pkg-config" ,pkg-config)))
+    (inputs
+       `(("perl" ,perl)
+         ("glibc-locales" ,glibc-locales)
+         ("adwaita-icon-theme" ,adwaita-icon-theme)
+         ("boost" ,boost)
+         ("tbb" ,tbb)
+         ("curl" ,curl)
+         ("zlib" ,zlib)
+         ("eigen" ,eigen)
+         ("expat" ,expat)
+         ("libpng" ,libpng)
+         ("mesa" ,mesa)
+         ("glew" ,glew)
+         ("cereal" ,cereal)
+         ("nlopt" ,nlopt)
+         ("openvdb" ,openvdb)
+         ("cgal" ,cgal)
+         ("gmp" ,gmp)
+         ("mpfr" ,mpfr)
+         ("qhull" ,qhull)
+         ("wxwidgets" ,wxwidgets-3.1)
+         ("coreutils" ,coreutils)
+         ("grep" ,grep)
+         ("sed" ,sed)
+         ("openexr" ,openexr)
+         ("glib" ,glib)
+         ("glibc" ,glibc)
+         ("gtk+" ,gtk+)
+         ("pango" ,pango)
+         ("dbus" ,dbus)))
+    (home-page "https://www.prusa3d.com/prusaslicer/")
+    (synopsis "G-code generator for 3D printers (RepRap, Makerbot, Ultimaker etc.)")
+    (description
+     "PrusaSlicer (formerly known as Slic3r Prusa Edition or Slic3r PE) is
+our own in-house developed slicer software based on the open-source project
+Slic3r.  PrusaSlicer is an open-source, feature-rich, frequently updated
+tool that contains everything you need to export the perfect print files
+for your Original Prusa 3D printer.")
+    (license license:agpl3)))
diff --git a/gnu/packages/patches/prusa-slicer-backport-fix-5542.patch b/gnu/packages/patches/prusa-slicer-backport-fix-5542.patch
new file mode 100644
index 0000000000..63d2a45be1
--- /dev/null
+++ b/gnu/packages/patches/prusa-slicer-backport-fix-5542.patch
@@ -0,0 +1,31 @@
+This patch backports a solution for the issue:
+https://github.com/prusa3d/PrusaSlicer/issues/5542
+that causes PrusaSlicer to crash when invoked
+from the command line by means of the $PATH variable.
+This fix is applied in:
+https://github.com/prusa3d/PrusaSlicer/commit/293f85b6cf9b805af93b9f79f5ff878b6d673969
+quite after the release of 2.3.3, so this backport is needed.
+
+diff --git a/src/PrusaSlicer.cpp b/src/PrusaSlicer.cpp
+index b0df2c99a..31e30af81 100644
+--- a/src/PrusaSlicer.cpp
++++ b/src/PrusaSlicer.cpp
+@@ -28,6 +28,7 @@
+ #include <boost/nowide/cenv.hpp>
+ #include <boost/nowide/iostream.hpp>
+ #include <boost/nowide/integration/filesystem.hpp>
++#include <boost/dll/runtime_symbol_info.hpp>
+ 
+ #include "unix/fhs.hpp"  // Generated by CMake from ../platform/unix/fhs.hpp.in
+ 
+@@ -612,7 +613,9 @@ bool CLI::setup(int argc, char **argv)
+     // Detect the operating system flavor after SLIC3R_LOGLEVEL is set.
+     detect_platform();
+ 
+-    boost::filesystem::path path_to_binary = boost::filesystem::system_complete(argv[0]);
++    // See Invoking prusa-slicer from $PATH environment variable crashes #5542
++    // boost::filesystem::path path_to_binary = boost::filesystem::system_complete(argv[0]);
++    boost::filesystem::path path_to_binary = boost::dll::program_location();
+ 
+     // Path from the Slic3r binary to its resources.
+ #ifdef __APPLE__
-- 
2.11.0


