diff --git a/.flatpak-rpm-macros.metadata b/.flatpak-rpm-macros.metadata
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/.flatpak-rpm-macros.metadata
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/.gitignore
diff --git a/SOURCES/distutils.cfg b/SOURCES/distutils.cfg
new file mode 100644
index 0000000..cc02c1b
--- /dev/null
+++ b/SOURCES/distutils.cfg
@@ -0,0 +1,2 @@
+[install]
+prefix=/app
diff --git a/SOURCES/flatpak.xml b/SOURCES/flatpak.xml
new file mode 100644
index 0000000..cee69ad
--- /dev/null
+++ b/SOURCES/flatpak.xml
@@ -0,0 +1,72 @@
+
+
+
+
+
+ flatpak-jar
+ jpp
+
+ app/share/java
+
+
+
+
+
+
+ jar
+
+
+
+ native
+ true
+
+
+
+
+
+
+ zip
+
+
+
+
+
+ flatpak-jni
+ jpp
+
+ app/lib/java
+
+
+
+
+
+ jar
+
+
+ native
+ true
+
+
+
+
+
+
+ install
+ compound
+
+
+ flatpak-jar
+ flatpak-jni
+ base-install
+
+
+
+
+
diff --git a/SOURCES/fontconfig-flatpak.prov b/SOURCES/fontconfig-flatpak.prov
new file mode 100755
index 0000000..e8c274a
--- /dev/null
+++ b/SOURCES/fontconfig-flatpak.prov
@@ -0,0 +1,24 @@
+#!/usr/bin/bash
+#
+# Script to install in:
+# /usr/lib/rpm/redhat/find-provides.d
+#
+# Transform font files into RPM provides
+# Requires fontconfig >= 2.6.90
+#
+# Author: Behdad Esfahbod
+# Based on other provides scripts from RPM
+#
+
+fcquery=/usr/bin/fc-query
+
+if [ ! -x $fcquery ]; then
+ cat > /dev/null
+ exit 0
+fi
+
+# filter out anything outside main fontconfig paths
+grep '/\(usr\|app\)/share/fonts/' |
+while read fn; do
+ $fcquery --format '%{=pkgkit}' "${fn}" 2> /dev/null
+done
diff --git a/SOURCES/macros.flatpak b/SOURCES/macros.flatpak
new file mode 100644
index 0000000..dfe894a
--- /dev/null
+++ b/SOURCES/macros.flatpak
@@ -0,0 +1,65 @@
+%flatpak 1
+%_prefix /app
+%_sysconfdir %{_prefix}/etc
+%build_ldflags -Wl,-z,relro %{_ld_as_needed_flags} %{_ld_symbols_flags} %{_hardened_ldflags} %[ "%{toolchain}" == "clang" ? "%{?_lto_cflags}" : "" ] -L%{_libdir}
+%python3_sitelib %{_prefix}/lib/python3.9/site-packages
+%python3_sitearch %{_libdir}/python3.9/site-packages
+
+%___build_pre \
+ RPM_SOURCE_DIR=\"%{u2p:%{_sourcedir}}\"\
+ RPM_BUILD_DIR=\"%{u2p:%{_builddir}}\"\
+ RPM_OPT_FLAGS=\"%{optflags}\"\
+ RPM_LD_FLAGS=\"%{?__global_ldflags}\"\
+ RPM_ARCH=\"%{_arch}\"\
+ RPM_OS=\"%{_os}\"\
+ export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_LD_FLAGS RPM_ARCH RPM_OS\
+ RPM_DOC_DIR=\"%{_docdir}\"\
+ export RPM_DOC_DIR\
+ RPM_PACKAGE_NAME=\"%{name}\"\
+ RPM_PACKAGE_VERSION=\"%{version}\"\
+ RPM_PACKAGE_RELEASE=\"%{release}\"\
+ export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE\
+ LANG=C\
+ export LANG\
+ unset CDPATH DISPLAY ||:\
+ %{?buildroot:RPM_BUILD_ROOT=\"%{u2p:%{buildroot}}\"\
+ export RPM_BUILD_ROOT}\
+ %{?_javaclasspath:CLASSPATH=\"%{_javaclasspath}\"\
+ export CLASSPATH}\
+ CONFIG_SITE=${CONFIG_SITE:-NONE}\
+ export CONFIG_SITE\
+ ACLOCAL_PATH="%{_datadir}/aclocal:%{_usr}/share/aclocal"\
+ export ACLOCAL_PATH\
+ CPATH="%{_prefix}/include"\
+ export CPATH\
+ CPLUS_INCLUDE_PATH="%{_prefix}/include"\
+ export CPLUS_INCLUDE_PATH\
+ C_INCLUDE_PATH="%{_prefix}/include"\
+ export C_INCLUDE_PATH\
+ GI_TYPELIB_PATH="%{_libdir}/girepository-1.0:%{_usr}/%{_lib}/girepository-1.0"\
+ export GI_TYPELIB_PATH\
+ INFOPATH="%{_datadir}/info"\
+ export INFOPATH\
+ MANPATH="%{_datadir}/man:"\
+ export MANPATH\
+ OBJC_INCLUDE_PATH="%{_prefix}/include"\
+ export OBJC_INCLUDE_PATH\
+ PATH="%{_bindir}:%{_usr}/local/sbin:%{_usr}/bin:/bin:%{_usr}/sbin:/sbin"\
+ PKG_CONFIG_GLADEUI_2_0_CATALOGDIR="%{_datadir}/glade/catalogs"\
+ export PKG_CONFIG_GLADEUI_2_0_CATALOGDIR\
+ PKG_CONFIG_PATH="%{_libdir}/pkgconfig:%{_datadir}/pkgconfig:%{_usr}/%{_lib}/pkgconfig:%{_usr}/share/pkgconfig"\
+ export PKG_CONFIG_PATH\
+ XDG_CONFIG_DIRS="%{_sysconfdir}/xdg:/etc/xdg"\
+ export XDG_CONFIG_DIRS\
+ XDG_DATA_DIRS="%{_datadir}:%{_usr}/local/share:%{_usr}/share"\
+ export XDG_DATA_DIRS\
+ GVFS_REMOTE_VOLUME_MONITOR_IGNORE="1"\
+ export GVFS_REMOTE_VOLUME_MONITOR_IGNORE\
+ \
+ %{verbose:set -x}%{!verbose:exec > /dev/null}\
+ umask 022\
+ cd \"%{u2p:%{_builddir}}\"\
+
+# Override /usr/lib/rpm/fontconfig.prov with a version that also handles fonts
+# in /app/share/fonts
+%__font_provides %{_rpmconfigdir}/fontconfig-flatpak.prov
diff --git a/SPECS/flatpak-rpm-macros.spec b/SPECS/flatpak-rpm-macros.spec
new file mode 100644
index 0000000..5853e9f
--- /dev/null
+++ b/SPECS/flatpak-rpm-macros.spec
@@ -0,0 +1,129 @@
+Name: flatpak-rpm-macros
+Version: 34
+Release: 1%{?dist}
+Summary: Macros for building RPMS for flatpaks
+Source0: macros.flatpak
+Source1: distutils.cfg
+Source2: flatpak.xml
+Source3: fontconfig-flatpak.prov
+License: MIT
+
+# Buildrequire these to satisfy Pyton byte-compilation hooks
+BuildRequires: python3
+
+%description
+The macros in this package set up the RPM build environment so built
+applications install in /app rather than /usr. This package is meant
+only for installation in buildroots for modules that will be packaged
+as Flatpaks.
+
+%prep
+
+%build
+
+%install
+mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/rpm
+install -t $RPM_BUILD_ROOT%{_sysconfdir}/rpm -p -m 644 %{SOURCE0}
+for v in 3.9 ; do
+ mkdir -p $RPM_BUILD_ROOT%{_libdir}/python$v/distutils/
+ install -t $RPM_BUILD_ROOT%{_libdir}/python$v/distutils/ %{SOURCE1}
+done
+mkdir -p $RPM_BUILD_ROOT%{_datadir}/xmvn/config.d
+install -t $RPM_BUILD_ROOT%{_datadir}/xmvn/config.d -m 644 %{SOURCE2}
+mkdir -p $RPM_BUILD_ROOT%{_rpmconfigdir}
+install -t $RPM_BUILD_ROOT%{_rpmconfigdir} -m 755 %{SOURCE3}
+
+%files
+# The location in sysconfdir contradicts
+# https://fedoraproject.org/wiki/Packaging:Guidelines#Packaging_of_Additional_RPM_Macros
+# but I believe is necessary to properly override macros that are otherwise set.
+%{_sysconfdir}/rpm/
+%{_libdir}/python*/distutils/distutils.cfg
+%{_datadir}/xmvn/config.d/flatpak.xml
+%{_rpmconfigdir}/fontconfig-flatpak.prov
+
+%changelog
+* Tue Jun 29 2021 Kalev Lember - 34-1
+- Override RPM's fontconfig auto-provide to handle /app/share/fonts
+
+* Tue Jan 26 2021 Fedora Release Engineering - 33-3
+- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild
+
+* Sat Sep 19 2020 Kalev Lember - 33-2
+- Redefine __python2 macro to point to /app/bin/python2
+
+* Mon Sep 14 2020 Kalev Lember - 33-1
+- Update %%python_sitearch for python-3.9
+
+* Sat Aug 01 2020 Fedora Release Engineering - 32-4
+- Second attempt - Rebuilt for
+ https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild
+
+* Mon Jul 27 2020 Fedora Release Engineering - 32-3
+- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild
+
+* Wed Mar 18 2020 Kalev Lember - 32-2
+- Remove Python 2 support (#1805232)
+
+* Wed Mar 18 2020 Stephan Bergmann - 32-1
+- Let xmvn_install store artifacts under /app
+
+* Thu Feb 06 2020 David King - 29-12
+- Update %%python_sitearch for python-3.8 (#1799346)
+
+* Tue Jan 28 2020 Fedora Release Engineering - 29-11
+- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild
+
+* Thu Jul 25 2019 Fedora Release Engineering - 29-10
+- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild
+
+* Thu Jun 20 2019 Kalev Lember - 29-9
+- Use optflags, rather than __global_compiler_flags
+
+* Thu Apr 04 2019 Stephan Bergmann - 29-8
+- Add CFLAGS and CXXFLAGS to macros.flatpak, to match LDFLAGS
+
+* Thu Jan 31 2019 Fedora Release Engineering - 29-7
+- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild
+
+* Thu Sep 27 2018 Owen Taylor - 29-6
+- Fix accidentally not installing the macro file
+
+* Thu Sep 27 2018 Owen Taylor - 29-5
+- Install a distutils.cfg to redirect installation of Python packages to /app
+ this makes the package no longer noarch because the file is in
+ /usr/lib or /usr/lib64.
+
+* Tue Sep 25 2018 Owen Taylor - 29-4
+- Remove space in -L
+
+* Thu Sep 20 2018 Owen Taylor - 29-3
+- Extend set of overriden Python macros
+
+* Wed Sep 19 2018 Owen Taylor - 29-2
+- Improve LDFLAGS flags handling in macros.flatpak
+
+* Sat Sep 8 2018 Owen Taylor - 29-1
+- Instead of defining %%app to true, define %%flatpak to 1
+- Update %%python_sitearch for python-3.7
+
+* Fri Jul 13 2018 Fedora Release Engineering - 27-6
+- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild
+
+* Wed Feb 07 2018 Fedora Release Engineering - 27-5
+- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild
+
+* Wed Aug 02 2017 Fedora Release Engineering - 27-4
+- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild
+
+* Wed Jul 26 2017 Fedora Release Engineering - 27-3
+- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild
+
+* Tue Jun 13 2017 Owen Taylor - 27-2
+See https://bugzilla.redhat.com/show_bug.cgi?id=1460076
+- Wrap description lines
+- Own /etc/rpm, to avoid requiring rpm package
+- Preserve timestamp on installation
+
+* Wed May 31 2017 Owen Taylor - 27-1
+- Initial version, based on work by Alex Larsson