This is jemalloc-5.3.0-gentoo-fixups.patch, rebased on top of 5.4.0 tag.
From: Jory Pratt <anarchy@gentoo.org>
Date: Tue, 23 Apr 2019 10:04:19 -0500
Subject: [PATCH] Don't override user cflags, disable html_doc from being
 installed

Signed-off-by: Jory Pratt <anarchy@gentoo.org>
Signed-off-by: Zurab Kvachadze <zurabid2016@gmail.com>
diff --git a/configure.ac b/configure.ac
index b049c892..b74956ac 100644
--- a/configure.ac
+++ b/configure.ac
@@ -270,7 +270,6 @@ if test "x$GCC" = "xyes" ; then
       AC_DEFINE_UNQUOTED([JEMALLOC_HAS_RESTRICT], [ ], [ ])
     fi
   fi
-  JE_CFLAGS_ADD([-Werror=unknown-warning-option])
   JE_CFLAGS_ADD([-Wall])
   JE_CFLAGS_ADD([-Wextra])
   JE_CFLAGS_ADD([-Wshorten-64-to-32])
@@ -286,8 +285,6 @@ if test "x$GCC" = "xyes" ; then
   dnl This one too.
   JE_CFLAGS_ADD([-Wno-missing-field-initializers])
   JE_CFLAGS_ADD([-Wno-missing-attributes])
-  JE_CFLAGS_ADD([-pipe])
-  JE_CFLAGS_ADD([-g3])
 elif test "x$je_cv_msvc" = "xyes" ; then
   CC="$CC -nologo"
   JE_CFLAGS_ADD([-Zi])
@@ -347,7 +344,6 @@ if test "x$enable_cxx" = "x1" ; then
     dnl shared with the C++ sources via the internal headers.
     JE_CXXFLAGS_ADD([-Wno-missing-braces])
     JE_CXXFLAGS_ADD([-Wno-missing-field-initializers])
-    JE_CXXFLAGS_ADD([-g3])
 
     SAVED_LIBS="${LIBS}"
     case "${with_cxx_stdlib}" in
@@ -1454,21 +1450,6 @@ if test "x$enable_debug" = "x1" ; then
 fi
 AC_SUBST([enable_debug])
 
-dnl Only optimize if not debugging.
-if test "x$enable_debug" = "x0" ; then
-  if test "x$GCC" = "xyes" ; then
-    JE_CFLAGS_ADD([-O3])
-    JE_CXXFLAGS_ADD([-O3])
-    JE_CFLAGS_ADD([-funroll-loops])
-  elif test "x$je_cv_msvc" = "xyes" ; then
-    JE_CFLAGS_ADD([-O2])
-    JE_CXXFLAGS_ADD([-O2])
-  else
-    JE_CFLAGS_ADD([-O])
-    JE_CXXFLAGS_ADD([-O])
-  fi
-fi
-
 dnl Enable statistics calculation by default.
 AC_ARG_ENABLE([stats],
   [AS_HELP_STRING([--disable-stats],
