diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc
index bdb2eecbe2e47..8bd06d340f7c3 100644
--- a/src/google/protobuf/port_def.inc
+++ b/src/google/protobuf/port_def.inc
@@ -313,7 +313,10 @@
#if defined(PROTOBUF_DEPRECATED_MSG)
#error PROTOBUF_DEPRECATED_MSG was previously defined
#endif
-#if __has_attribute(deprecated) || PROTOBUF_GNUC_MIN(3, 0)
+#if defined(PROTOBUF_ALLOW_DEPRECATED)
+# define PROTOBUF_DEPRECATED
+# define PROTOBUF_DEPRECATED_MSG(msg)
+#elif __has_attribute(deprecated) || PROTOBUF_GNUC_MIN(3, 0)
# define PROTOBUF_DEPRECATED __attribute__((deprecated))
# define PROTOBUF_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
#elif defined(_MSC_VER)
@@ -327,7 +330,9 @@
#if defined(PROTOBUF_DEPRECATED_ENUM)
#error PROTOBUF_DEPRECATED_ENUM was previously defined
#endif
-#if defined(__clang__) || PROTOBUF_GNUC_MIN(6, 0)
+#if defined(PROTOBUF_ALLOW_DEPRECATED)
+# define PROTOBUF_DEPRECATED_ENUM
+#elif defined(__clang__) || PROTOBUF_GNUC_MIN(6, 0)
// https://gcc.gnu.org/gcc-6/changes.html
# define PROTOBUF_DEPRECATED_ENUM __attribute__((deprecated))
#else