# HG changeset patch
# User Alexander Wilms <f.alexander.wilms@gmail.com>

Add Flatpak build manifest

---
 flatpak/appdata.patch                     |   8 +
 flatpak/epstool.patch                     |  12 ++
 flatpak/org.gnu.Octave.json               | 297 ++++++++++++++++++++++++++++++
 flatpak/pcre.patch                        |  56 ++++++
 flatpak/qscintilla.patch                  |  14 ++
 flatpak/shared-modules/glu/glu-9.0.0.json |  11 ++
 6 files changed, 398 insertions(+)
 create mode 100644 flatpak/appdata.patch
 create mode 100644 flatpak/epstool.patch
 create mode 100644 flatpak/org.gnu.Octave.json
 create mode 100644 flatpak/pcre.patch
 create mode 100644 flatpak/qscintilla.patch
 create mode 100644 flatpak/shared-modules/glu/glu-9.0.0.json

diff --git a/flatpak/appdata.patch b/flatpak/appdata.patch
new file mode 100644
index 0000000..c6d3bdd
--- /dev/null
+++ b/flatpak/appdata.patch
@@ -0,0 +1,8 @@
+--- ./etc/icons/octave.appdata.xml.in
++++ ./etc/icons/octave.appdata.xml.in
+@@ -58,5 +58,4 @@
+ 
+   <url type="homepage">http://www.octave.org</url>
+   <update_contact>maintainers@octave.org</update_contact>
+-  <project_group>GNU</project_group>
+ </component>
diff --git a/flatpak/epstool.patch b/flatpak/epstool.patch
new file mode 100644
index 0000000..f5119cc
--- /dev/null
+++ b/flatpak/epstool.patch
@@ -0,0 +1,12 @@
+--- ./makefile
++++ ./makefile
+@@ -45,7 +45,7 @@
+ 
+ include $(SRCDIR)/common.mak
+ 
+-EPSTOOL_ROOT=/usr/local
+-EPSTOOL_BASE=$(prefix)$(EPSTOOL_ROOT)
++
++EPSTOOL_BASE=/app
+ EPSTOOL_DOCDIR=$(EPSTOOL_BASE)/share/doc/epstool-$(EPSTOOL_VERSION)
+ EPSTOOL_MANDIR=$(EPSTOOL_BASE)/man
diff --git a/flatpak/org.gnu.Octave.json b/flatpak/org.gnu.Octave.json
new file mode 100644
index 0000000..c372c73
--- /dev/null
+++ b/flatpak/org.gnu.Octave.json
@@ -0,0 +1,297 @@
+{
+	"app-id": "org.gnu.Octave",
+	"runtime": "org.kde.Sdk",
+	"runtime-version": "5.9",
+	"sdk": "org.kde.Sdk",
+	"command": "octave",
+	"rename-icon": "octave",
+	"rename-desktop-file": "www.octave.org-octave.desktop",
+	"rename-appdata-file": "www.octave.org-octave.appdata.xml",
+	"finish-args":
+	[
+		"--socket=wayland",
+		"--socket=x11",
+		"--socket=pulseaudio",
+		"--share=network",
+		"--device=dri",
+		"--filesystem=home",
+		"--env=LIBGL_ALWAYS_SOFTWARE=1"
+	],
+	"build-options":
+	{
+		"cflags": "-O2",
+		"cxxflags": "-O2"
+	},
+	"modules":
+	[
+		{
+			"name": "gcc-fortran",
+			"build-options":
+			{
+				"ldflags": "-static-libgcc"
+			},
+			"config-opts":
+			[
+				"--enable-languages=c,c++,fortran",
+				"--disable-multilib",
+				"--disable-bootstrap",
+				"--with-system-zlib",
+				"--enable-checking=release",
+				"--disable-stage1-checking",
+				"--disable-libsanitizer",
+				"--disable-libssp"
+			],
+			"sources":
+			[
+				{
+					"type": "archive",
+					"url": "http://mirrors.kernel.org/gnu/gcc/gcc-7.1.0/gcc-7.1.0.tar.gz",
+					"sha256": "3c187ef42e4cf657eec0ed641aac7f7e46261bcb1cea31b72dcf2dedddbbdea5"
+				},
+				{
+					"type": "shell",
+					"commands":
+					[
+						"sed -e '/m64=/s/lib64/lib/' -i.orig gcc/config/i386/t-linux64"
+					]
+				}
+			]
+		},
+		{
+			"name": "openblas",
+			"no-autogen": true,
+			"build-options":
+			{
+				"ldflags": "-L/app/lib64"
+			},
+			"make-args":
+			[
+				"FC=gfortran",
+				"TARGET=PRESCOTT"
+			],
+			"make-install-args":
+			[
+				"PREFIX=/app"
+			],
+			"sources":
+			[
+				{
+					"type": "archive",
+					"url": "https://github.com/xianyi/OpenBLAS/archive/v0.2.19.tar.gz",
+					"sha256": "9c40b5e4970f27c5f6911cb0a28aa26b6c83f17418b69f8e5a116bb983ca8557"
+				}
+			]
+		},
+		{
+			"name": "qscintilla",
+			"buildsystem": "simple",
+			"sources":
+			[
+				{
+					"type": "archive",
+					"url": "https://sourceforge.net/projects/pyqt/files/QScintilla2/QScintilla-2.10/QScintilla_gpl-2.10.tar.gz",
+					"sha256": "16be30577bc178470936c458551f2512cc068aff6e7a7de6ed244e28c045f6ec"
+				},
+				{
+					"type": "patch",
+					"path": "qscintilla.patch"
+				},
+				{
+					"type": "script",
+					"commands":
+					[
+						"cd Qt4Qt5",
+						"qmake"
+					],
+					"dest-filename": "configure"
+				}
+			],
+			"build-commands":
+			[
+				"./configure --prefix=/app",
+				"make -C Qt4Qt5 install",
+				"ln -s /app/lib/libqscintilla2_qt5.so /app/lib/libqscintilla2-qt5.so"
+			]
+		},
+		"shared-modules/glu/glu-9.0.0.json",
+		{
+			"name": "gnuplot",
+			"sources":
+			[
+				{
+					"type": "archive",
+					"url": "https://sourceforge.net/projects/gnuplot/files/gnuplot/5.0.6/gnuplot-5.0.6.tar.gz",
+					"sha256": "5bbe4713e555c2e103b7d4ffd45fca69551fff09cf5c3f9cb17428aaacc9b460"
+				}
+			]
+		},
+		{
+			"name": "fontconfig",
+			"sources":
+			[
+				{
+					"type": "archive",
+					"url": "https://www.freedesktop.org/software/fontconfig/release/fontconfig-2.12.1.tar.gz",
+					"sha256": "a9f42d03949f948a3a4f762287dbc16e53a927c91a07ee64207ebd90a9e5e292"
+				}
+			]
+		},
+		{
+			"name": "freetype",
+			"sources":
+			[
+				{
+					"type": "archive",
+					"url": "http://download.savannah.gnu.org/releases/freetype/freetype-2.8.tar.gz",
+					"sha256": "33a28fabac471891d0523033e99c0005b95e5618dc8ffa7fa47f9dadcacb1c9b"
+				}
+			]
+		},
+		{
+			"name": "fltk",
+			"config-opts":
+			[
+				"--enable-shared"
+			],
+			"build-options":
+			{
+				"cflags": "-fPIC",
+				"cxxflags": "-fPIC"
+			},
+			"sources":
+			[
+				{
+					"type": "archive",
+					"url": "http://fltk.org/pub/fltk/1.3.4/fltk-1.3.4-1-source.tar.gz",
+					"sha256": "7fb2c8882433ce694e6900c94fda505e8f4ed3fa9c7e597007098a33b85c53f4"
+				}
+			]
+		},
+		{
+			"name": "cups",
+			"config-opts":
+			[
+				"--disable-static",
+				"--disable-dbus",
+				"--without-php",
+				"--disable-gssapi",
+				"--disable-ssl",
+				"--disable-cdsassl",
+				"--disable-gnutls",
+				"--disable-pam",
+				"--disable-dnssd",
+				"--disable-launchd",
+				"--libdir=/app/lib"
+			],
+			"make-args":
+			[
+				"libs"
+			],
+			"no-make-install": true,
+			"sources":
+			[
+				{
+					"type": "archive",
+					"url": "https://github.com/apple/cups/archive/v2.2.3.tar.gz",
+					"sha256": "7aa7e8d581f0eb204f75203082403bfa931f8c058bffae71b210800102e5feb5"
+				}
+			],
+			"post-install":
+			[
+				"make install-libs", "chmod +w /app/lib/libcups*"
+			]
+		},
+		{
+			"name": "ghostscript",
+			"build-options":
+			{
+				"ldflags": "-L/app/lib"
+			},
+			"sources":
+			[
+				{
+					"type": "archive",
+					"url": "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs921/ghostscript-9.21.tar.gz",
+					"sha256": "02bceadbc4dddeb6f2eec9c8b1623d945d355ca11b8b4df035332b217d58ce85"
+				}
+			]
+		},
+		{
+			"name": "gl2ps",
+			"buildsystem": "cmake",
+			"sources":
+			[
+				{
+					"type": "archive",
+					"url": "http://geuz.org/gl2ps/src/gl2ps-1.4.0.tgz",
+					"sha256": "03cb5e6dfcd87183f3b9ba3b22f04cd155096af81e52988cc37d8d8efe6cf1e2"
+				}
+			]
+		},
+		{
+			"name": "qhull",
+			"buildsystem": "cmake",
+			"sources":
+			[
+				{
+					"type": "archive",
+					"url": "http://www.qhull.org/download/qhull-2015-src-7.2.0.tgz",
+					"sha256": "78b010925c3b577adc3d58278787d7df08f7c8fb02c3490e375eab91bb58a436"
+				}
+			]
+		},
+		{
+			"name": "epstool",
+			"no-autogen": true,
+			"make-args": ["PREFIX=/app"],
+			"sources":
+			[
+				{
+					"type": "archive",
+					"url": "http://pkgs.fedoraproject.org/repo/pkgs/epstool/epstool-3.08.tar.gz/465a57a598dbef411f4ecbfbd7d4c8d7/epstool-3.08.tar.gz",
+					"sha256": "f3f14b95146868ff3f93c8720d5539deef3b6531630a552165664c7ee3c2cfdd"
+				},
+				{
+					"type": "patch",
+					"path": "epstool.patch"
+				}
+			]
+		},
+		{
+			"name": "octave",
+			"config-opts":
+			[
+				"--enable-shared",
+				"--disable-static",
+
+				"--with-blas=\"-lopenblas\"",
+				"--with-lapack=\"-lopenblas\"",
+
+				"--disable-docs"
+			],
+			"make-install-args": [
+				"prefix=/app"
+			],
+			"sources":
+			[
+				{
+					"type": "archive",
+					"url": "https://ftp.gnu.org/gnu/octave/octave-4.2.1.tar.gz",
+					"sha256": "80c28f6398576b50faca0e602defb9598d6f7308b0903724442c2a35a605333b"
+				},
+				{
+					"type": "patch",
+					"path": "appdata.patch"
+				},
+				{
+					"type": "patch",
+					"path": "pcre.patch"
+				},
+				{
+					"type": "shell",
+					"commands": ["autoreconf -i"]
+				}
+			]
+		}
+	]
+}
diff --git a/flatpak/pcre.patch b/flatpak/pcre.patch
new file mode 100644
index 0000000..3c8b852
--- /dev/null
+++ b/flatpak/pcre.patch
@@ -0,0 +1,56 @@
+--- ./configure.ac
++++ ./configure.ac
+@@ -1226,47 +1226,13 @@
+
+ ### Check for PCRE regex library.
+
+-PCRE_LIBS=
+-
+-pcre_fail_msg="to build Octave, you must have the PCRE library and header files installed"
+-
+-AC_CHECK_HEADERS([pcre.h pcre/pcre.h])
+-
+-AC_CACHE_CHECK([whether pcre.h defines the macros we need],
+-  [ac_cv_pcre_h_macros_present],
+-  [AC_EGREP_CPP([PCRE_HAS_MACROS_WE_NEED], [
+-    #if defined (HAVE_PCRE_H)
+-    # include <pcre.h>
+-    #elif defined (HAVE_PCRE_PCRE_H)
+-    # include <pcre/pcre.h>
+-    #error "NO PCRE HEADER"
+-    #endif
+-    #if defined (PCRE_INFO_NAMECOUNT) \
+-      && defined (PCRE_INFO_NAMEENTRYSIZE) \
+-      && defined (PCRE_INFO_NAMETABLE)
+-      PCRE_HAS_MACROS_WE_NEED
+-    #endif],
+-    ac_cv_pcre_h_macros_present=yes, ac_cv_pcre_h_macros_present=no)])
+-
+-if test $ac_cv_pcre_h_macros_present = yes; then
+-  ## check for pcre-config, and if so, get build variables
+-  AC_CHECK_PROG(HAVE_PCRE_CONFIG, pcre-config, [yes], [no])
+-  if test $HAVE_PCRE_CONFIG = yes; then
+-    PCRE_CPPFLAGS=`pcre-config --cflags`
+-    PCRE_LIBS=`pcre-config --libs`
+-  else
+-    PCRE_LIBS="-lpcre"
+-  fi
+-  save_LIBS="$LIBS"
+-  LIBS="$PCRE_LIBS $LIBS"
+-  AC_CHECK_FUNCS([pcre_compile],
+-    [AC_SUBST(PCRE_CPPFLAGS)
+-     AC_SUBST(PCRE_LIBS)],
+-    [AC_MSG_ERROR([$pcre_fail_msg])])
+-  LIBS="$save_LIBS"
+-else
+-  AC_MSG_ERROR([$pcre_fail_msg])
+-fi
++  PKG_CHECK_MODULES([PCRE], [libpcre], [
++    AC_DEFINE(HAVE_PCRE_H, 1, [Define if you have PCRE library])
++    LIBS="$LIBS $PCRE_LIBS"
++    CPPFLAGS="$CPPFLAGS $PCRE_CFLAGS"
++  ], [
++    AC_MSG_WARN([$PCRE_PKG_ERRORS])
++   ])
+
+ ### Check for ZLIB library.
diff --git a/flatpak/qscintilla.patch b/flatpak/qscintilla.patch
new file mode 100644
index 0000000..6d43918
--- /dev/null
+++ b/flatpak/qscintilla.patch
@@ -0,0 +1,14 @@
+--- ./Qt4Qt5/qscintilla.pro
++++ ./Qt4Qt5/qscintilla-new.pro
+@@ -47,10 +47,10 @@
+ # Scintilla namespace rather than pollute the global namespace.
+ #DEFINES += SCI_NAMESPACE
+ 
+-target.path = $$[QT_INSTALL_LIBS]
++target.path = /app/lib
+ INSTALLS += target
+ 
+-header.path = $$[QT_INSTALL_HEADERS]
++header.path = /app/include
+ header.files = Qsci
+ INSTALLS += header
diff --git a/flatpak/shared-modules/glu/glu-9.0.0.json b/flatpak/shared-modules/glu/glu-9.0.0.json
new file mode 100644
index 0000000..c4fd417
--- /dev/null
+++ b/flatpak/shared-modules/glu/glu-9.0.0.json
@@ -0,0 +1,11 @@
+{
+  "name": "glu",
+  "sources": [
+    {
+      "type": "archive",
+      "url": "https://mesa.freedesktop.org/archive/glu/glu-9.0.0.tar.bz2",
+      "sha256": "1f7ad0d379a722fcbd303aa5650c6d7d5544fde83196b42a73d1193568a4df12"
+    }
+  ],
+  "cleanup": [ "/include", "/lib/*.a", "/lib/*.la", "/lib/pkgconfig" ]
+}

