--- /dev/null
+--- a/include/mednafen/desa68/Makefile.am
++++ b/include/mednafen/desa68/Makefile.am
+@@ -6,7 +6,7 @@
+
+ AUTOMAKE_OPTIONS = subdir-objects
+ AM_CFLAGS = @AM_CFLAGS@ -Wno-multichar
+-DEFS = -DLOCALEDIR=\"$(datadir)/locale\" @DEFS@
++DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
+ DEFAULT_INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir)/intl
+
+ noinst_LIBRARIES = libdesa68.a
+--- a/include/mednafen/drivers/Makefile.am
++++ b/include/mednafen/drivers/Makefile.am
+@@ -1,5 +1,5 @@
+ AUTOMAKE_OPTIONS = subdir-objects
+-DEFS = -DLOCALEDIR=\"$(datadir)/locale\" @DEFS@ @SDL_CFLAGS@
++DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ @SDL_CFLAGS@
+ DEFAULT_INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir)/intl
+
+ noinst_LIBRARIES = libmdfnsdl.a
+--- a/include/mednafen/drivers_dos/Makefile.am
++++ b/include/mednafen/drivers_dos/Makefile.am
+@@ -1,5 +1,5 @@
+ AUTOMAKE_OPTIONS = subdir-objects
+-DEFS = -DLOCALEDIR=\"$(datadir)/locale\" @DEFS@ @SDL_CFLAGS@
++DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ @SDL_CFLAGS@
+ DEFAULT_INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir)/intl
+
+ noinst_LIBRARIES = libmdfndos.a
+--- a/include/mednafen/Makefile.am
++++ b/include/mednafen/Makefile.am
+@@ -1,6 +1,6 @@
+ SUBDIRS = trio
+ AUTOMAKE_OPTIONS = subdir-objects
+-DEFS = -DLOCALEDIR=\"$(datadir)/locale\" @DEFS@ @SNDFILE_CFLAGS@
++DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ @SNDFILE_CFLAGS@
+ DEFAULT_INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir)/intl
+
+ bin_PROGRAMS = mednafen
+--- a/include/mednafen/ngp/Makefile.am
++++ b/include/mednafen/ngp/Makefile.am
+@@ -1,5 +1,5 @@
+ AUTOMAKE_OPTIONS = subdir-objects
+-DEFS = -DLOCALEDIR=\"$(datadir)/locale\" @DEFS@ -fno-strict-aliasing
++DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ -fno-strict-aliasing
+ DEFAULT_INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir)/intl
+
+ noinst_LIBRARIES = libngp.a
+--- a/include/mednafen/quicklz/Makefile.am
++++ b/include/mednafen/quicklz/Makefile.am
+@@ -1,6 +1,6 @@
+ AM_CFLAGS = @AM_CFLAGS@ -fno-strict-aliasing -Wno-shadow -Wno-unused-but-set-variable
+ AUTOMAKE_OPTIONS = subdir-objects
+-DEFS = -DLOCALEDIR=\"$(datadir)/locale\" @DEFS@ -fno-strict-aliasing
++DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ -fno-strict-aliasing
+ DEFAULT_INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir)/intl
+
+ noinst_LIBRARIES = libmdfnquicklz.a
+--- a/include/mednafen/sexyal/Makefile.am
++++ b/include/mednafen/sexyal/Makefile.am
+@@ -1,5 +1,5 @@
+ AUTOMAKE_OPTIONS = subdir-objects
+-DEFS = -DLOCALEDIR=\"$(datadir)/locale\" @DEFS@ @SDL_CFLAGS@ @ALSA_CFLAGS@ @JACK_CFLAGS@
++DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ @SDL_CFLAGS@ @ALSA_CFLAGS@ @JACK_CFLAGS@
+ DEFAULT_INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir)/intl
+
+ noinst_LIBRARIES = libsexyal.a
+--- a/include/mednafen/snes/Makefile.am
++++ b/include/mednafen/snes/Makefile.am
+@@ -1,7 +1,7 @@
+ AM_CFLAGS = @AM_CFLAGS@ @SNES_EXTRA_FLAGS@
+ AM_CXXFLAGS = @AM_CXXFLAGS@ @SNES_EXTRA_FLAGS@ @SNES_EXTRA_CXXFLAGS@
+ AUTOMAKE_OPTIONS = subdir-objects
+-DEFS = -DLOCALEDIR=\"$(datadir)/locale\" @DEFS@ -DNOMINMAX
++DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ -DNOMINMAX
+ DEFAULT_INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir)/intl -I$(srcdir)/src/lib
+
+ noinst_LIBRARIES = libsnes.a
+--- a/include/mednafen/ss/Makefile.am
++++ b/include/mednafen/ss/Makefile.am
+@@ -1,5 +1,5 @@
+ AUTOMAKE_OPTIONS = subdir-objects
+-DEFS = -DLOCALEDIR=\"$(datadir)/locale\" @DEFS@
++DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
+ AM_CXXFLAGS = @AM_CXXFLAGS@ @SS_EXTRA_FLAGS@ @NO_STACK_PROTECTOR_FLAGS@
+ # -Wpedantic
+ DEFAULT_INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir)/intl
+--- a/include/mednafen/trio/Makefile.am
++++ b/include/mednafen/trio/Makefile.am
+@@ -1,5 +1,5 @@
+ AUTOMAKE_OPTIONS = subdir-objects
+-DEFS = -DLOCALEDIR=\"$(datadir)/locale\" @DEFS@ @TRIO_CFLAGS@ @CFLAG_VISIBILITY@
++DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ @TRIO_CFLAGS@ @CFLAG_VISIBILITY@
+ DEFAULT_INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir)/intl
+
+ noinst_LIBRARIES = libtrio.a
--- /dev/null
+--- a/configure.ac
++++ b/configure.ac
+@@ -88,21 +88,6 @@
+ AC_CHECK_LIB([z], [zlibVersion],[], AC_MSG_ERROR([*** zlib not found!]))
+ AC_SUBST([ZLIB_LIBS], [-lz])
+
+-dnl -fno-fast-math and -fno-unsafe-math-optimizations to make sure it's disabled, as the fast-math feature on certain older
+-dnl versions of gcc produces horribly broken code(and even when it's working correctly, it can have somewhat unpredictable effects).
+-dnl
+-dnl -fno-aggressive-loop-optimizations because I don't trust gcc's aggressive loop optimizations, and there miiight be old code
+-dnl in Mednafen that would cause problems.
+-dnl
+-dnl -fomit-frame-pointer is required for some x86 inline assembly to compile.
+-dnl
+-OPTIMIZER_FLAGS=""
+-AX_CFLAGS_GCC_OPTION([-fno-fast-math], OPTIMIZER_FLAGS)
+-AX_CFLAGS_GCC_OPTION([-fno-unsafe-math-optimizations], OPTIMIZER_FLAGS)
+-AX_CFLAGS_GCC_OPTION([-fno-aggressive-loop-optimizations], OPTIMIZER_FLAGS)
+-AX_CFLAGS_GCC_OPTION([-fno-ipa-icf], OPTIMIZER_FLAGS)
+-AX_CFLAGS_GCC_OPTION([-fomit-frame-pointer], OPTIMIZER_FLAGS)
+-
+ dnl
+ dnl Aggressively try to disable PIC and PIE, as it has a significant performance overhead and will
+ dnl break some code(with compile-time failures or run-time assert()s triggering).
--- /dev/null
+--- a/include/mednafen/compress/Makefile.am.inc
++++ b/include/mednafen/compress/Makefile.am.inc
+@@ -1 +1 @@
+-mednafen_SOURCES += compress/minilzo.c compress/ioapi.c compress/unzip.c compress/GZFileStream.cpp compress/ZLInflateFilter.cpp
++mednafen_SOURCES += compress/minilzo.c compress/ioapi.c compress/GZFileStream.cpp compress/ZLInflateFilter.cpp
+--- a/include/mednafen/file.cpp
++++ b/include/mednafen/file.cpp
+@@ -29,7 +29,7 @@
+ #include <errno.h>
+ #include <trio/trio.h>
+
+-#include "compress/unzip.h"
++#include <minizip/unzip.h>
+
+ #include "file.h"
+ #include "general.h"
+--- a/include/mednafen/Makefile.am
++++ b/include/mednafen/Makefile.am
+@@ -6,7 +6,7 @@
+ bin_PROGRAMS = mednafen
+
+ mednafen_SOURCES = debug.cpp error.cpp mempatcher.cpp settings.cpp endian.cpp mednafen.cpp git.cpp file.cpp general.cpp memory.cpp netplay.cpp state.cpp state_rewind.cpp movie.cpp player.cpp PSFLoader.cpp SSFLoader.cpp SNSFLoader.cpp SPCReader.cpp tests.cpp qtrecord.cpp Stream.cpp MemoryStream.cpp FileStream.cpp IPSPatcher.cpp
+-mednafen_LDADD = trio/libtrio.a
++mednafen_LDADD = trio/libtrio.a -lminizip
+ mednafen_DEPENDENCIES = trio/libtrio.a
+
+ if HAVE_SDL
--- /dev/null
+# Copyright 1999-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+EAPI=6
+
+inherit autotools flag-o-matic pax-utils
+
+DESCRIPTION="An advanced NES, GB/GBC/GBA, TurboGrafx 16/CD, NGPC and Lynx emulator"
+HOMEPAGE="http://mednafen.fobby.net/"
+SRC_URI="http://mednafen.fobby.net/releases/files/${P}.tar.bz2"
+
+LICENSE="GPL-2+"
+SLOT="0"
+KEYWORDS="~amd64 ~ppc ~x86"
+IUSE="alsa altivec cjk debugger jack nls pax_kernel"
+
+RDEPEND="
+ dev-libs/libcdio
+ media-libs/libsdl[sound,joystick,opengl,video]
+ media-libs/libsndfile
+ media-libs/sdl-net
+ sys-libs/zlib[minizip]
+ virtual/opengl
+ alsa? ( media-libs/alsa-lib )
+ jack? ( media-sound/jack-audio-connection-kit )
+ nls? ( virtual/libintl )"
+DEPEND="${RDEPEND}
+ virtual/pkgconfig
+ nls? ( sys-devel/gettext )"
+
+S=${WORKDIR}/${PN}
+
+PATCHES=(
+ "${FILESDIR}"/${PN}-0.9.39.2-remove-cflags.patch
+ "${FILESDIR}"/${PN}-0.9.39.2-localedir.patch
+ "${FILESDIR}"/${PN}-0.9.39.2-zlib.patch
+)
+
+pkg_pretend() {
+ if has ccache ${FEATURES}; then
+ ewarn
+ ewarn "If you experience build failure, try turning off ccache in FEATURES."
+ ewarn
+ fi
+}
+
+src_prepare() {
+ default
+ eautoreconf
+}
+
+src_configure() {
+ # very sensitive code (bug #539992)
+ strip-flags
+ append-flags -fomit-frame-pointer -fwrapv
+ econf \
+ $(use_enable alsa) \
+ $(use_enable altivec) \
+ $(use_enable cjk cjk-fonts) \
+ $(use_enable debugger) \
+ $(use_enable jack) \
+ $(use_enable nls)
+}
+
+src_install() {
+ default
+ dodoc Documentation/cheats.txt
+
+ if use pax_kernel; then
+ pax-mark m "${ED%/}"/bin/mednafen || die
+ fi
+}