Bug 1243872: Refactor zlib support in Makefiles. r=mt,wtc
authorEKR <ekr@rtfm.com>
Sun, 31 Jan 2016 17:24:05 -0800
changeset 11829 2388b32dc14f7faf35b31cc7a8f54acfa7a5be60
parent 11828 7e08253b18a5e085a76cc565355ce2ae9ff1d65d
child 11830 d6ecb8117a436848f339be85ca0f78e6fc02ebbf
push id943
push userekr@mozilla.com
push dateTue, 02 Feb 2016 14:43:14 +0000
reviewersmt, wtc
bugs1243872
Bug 1243872: Refactor zlib support in Makefiles. r=mt,wtc
cmd/modutil/Makefile
cmd/platlibs.mk
cmd/signtool/Makefile
coreconf/config.mk
coreconf/zlib.mk
external_tests/ssl_gtest/Makefile
lib/ssl/config.mk
lib/ssl/ssl3con.c
lib/ssl/sslimpl.h
--- a/cmd/modutil/Makefile
+++ b/cmd/modutil/Makefile
@@ -18,23 +18,19 @@ include $(CORE_DEPTH)/coreconf/config.mk
 
 #######################################################################
 # (3) Include "component" configuration information. (OPTIONAL)       #
 #######################################################################
 
 #######################################################################
 # (4) Include "local" platform-dependent assignments (OPTIONAL).      #
 #######################################################################
+
 include ../platlibs.mk
-
-ifdef USE_SYSTEM_ZLIB
-OS_LIBS += $(ZLIB_LIBS)
-else
-EXTRA_LIBS += $(ZLIB_LIBS)
-endif
+include $(CORE_DEPTH)/coreconf/zlib.mk
 
 #######################################################################
 # (5) Execute "global" rules. (OPTIONAL)                              #
 #######################################################################
 
 include $(CORE_DEPTH)/coreconf/rules.mk
 
 #######################################################################
--- a/cmd/platlibs.mk
+++ b/cmd/platlibs.mk
@@ -254,16 +254,9 @@ endif # USE_STATIC_LIBS
 # If a platform has a system freebl, set USE_SYSTEM_FREEBL to 1 and
 # FREEBL_LIBS to the linker command-line arguments for the system nss-util
 # (for example, -lfreebl3 on fedora) in the platform's config file in coreconf.
 ifdef NSS_USE_SYSTEM_FREEBL
 FREEBL_LIBS = $(FREEBL_LIB_DIR)/$(LIB_PREFIX)freebl.$(LIB_SUFFIX)
 EXTRA_LIBS += $(FREEBL_LIBS)
 endif
 
-# If a platform has a system zlib, set USE_SYSTEM_ZLIB to 1 and
-# ZLIB_LIBS to the linker command-line arguments for the system zlib
-# (for example, -lz) in the platform's config file in coreconf.
-ifndef USE_SYSTEM_ZLIB
-ZLIB_LIBS = $(DIST)/lib/$(LIB_PREFIX)zlib.$(LIB_SUFFIX)
-endif
-
 JAR_LIBS = $(DIST)/lib/$(LIB_PREFIX)jar.$(LIB_SUFFIX)
--- a/cmd/signtool/Makefile
+++ b/cmd/signtool/Makefile
@@ -20,22 +20,17 @@ include $(CORE_DEPTH)/coreconf/config.mk
 # (3) Include "component" configuration information. (OPTIONAL)       #
 #######################################################################
 
 #######################################################################
 # (4) Include "local" platform-dependent assignments (OPTIONAL).      #
 #######################################################################
 
 include ../platlibs.mk
-
-ifdef USE_SYSTEM_ZLIB
-OS_LIBS += $(ZLIB_LIBS)
-else
-EXTRA_LIBS += $(ZLIB_LIBS)
-endif
+include $(CORE_DEPTH)/coreconf/zlib.mk
 
 #######################################################################
 # (5) Execute "global" rules. (OPTIONAL)                              #
 #######################################################################
 
 include $(CORE_DEPTH)/coreconf/rules.mk
 
 #######################################################################
--- a/coreconf/config.mk
+++ b/coreconf/config.mk
@@ -144,17 +144,17 @@ endif
 
 #######################################################################
 # [16.0] Global environ ment defines
 #######################################################################
 
 ifdef NSS_DISABLE_ECC
 DEFINES += -DNSS_DISABLE_ECC
 endif
- 
+
 ifdef NSS_ECC_MORE_THAN_SUITE_B
 DEFINES += -DNSS_ECC_MORE_THAN_SUITE_B
 endif
 
 ifdef NSS_ALLOW_UNSUPPORTED_CRITICAL
 DEFINES += -DNSS_ALLOW_UNSUPPORTED_CRITICAL
 endif
 
@@ -183,8 +183,13 @@ endif
 DEFINES += -DUSE_UTIL_DIRECTLY
 USE_UTIL_DIRECTLY = 1
 
 # Build with NO_NSPR_10_SUPPORT to avoid using obsolete NSPR features
 DEFINES += -DNO_NSPR_10_SUPPORT
 
 # Hide old, deprecated, TLS cipher suite names when building NSS
 DEFINES += -DSSL_DISABLE_DEPRECATED_CIPHER_SUITE_NAMES
+
+# Mozilla's mozilla/modules/zlib/src/zconf.h adds the MOZ_Z_ prefix to zlib
+# exported symbols, which causes problem when NSS is built as part of Mozilla.
+# So we add a NSS_ENABLE_SSL_ZLIB variable to allow Mozilla to turn this off.
+NSS_ENABLE_SSL_ZLIB = 1
new file mode 100644
--- /dev/null
+++ b/coreconf/zlib.mk
@@ -0,0 +1,17 @@
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Configuration information for linking against zlib.
+
+# If a platform has a system zlib, set USE_SYSTEM_ZLIB to 1 and
+# ZLIB_LIBS to the linker command-line arguments for the system zlib
+# (for example, -lz) in the platform's config file in coreconf.
+ifdef USE_SYSTEM_ZLIB
+OS_LIBS += $(ZLIB_LIBS)
+else
+ZLIB_LIBS = $(DIST)/lib/$(LIB_PREFIX)zlib.$(LIB_SUFFIX)
+EXTRA_LIBS += $(ZLIB_LIBS)
+endif
+
--- a/external_tests/ssl_gtest/Makefile
+++ b/external_tests/ssl_gtest/Makefile
@@ -22,24 +22,28 @@ include $(CORE_DEPTH)/coreconf/config.mk
 
 
 #######################################################################
 # (4) Include "local" platform-dependent assignments (OPTIONAL).      #
 #######################################################################
 
 include ../common/gtest.mk
 
+CFLAGS += -I$(CORE_DEPTH)/lib/ssl
+
+ifdef NSS_ENABLE_SSL_ZLIB
+include $(CORE_DEPTH)/coreconf/zlib.mk
+endif
+
 #######################################################################
 # (5) Execute "global" rules. (OPTIONAL)                              #
 #######################################################################
 
 include $(CORE_DEPTH)/coreconf/rules.mk
 
 #######################################################################
 # (6) Execute "component" rules. (OPTIONAL)                           #
 #######################################################################
 
 
 #######################################################################
 # (7) Execute "local" rules. (OPTIONAL).                              #
 #######################################################################
-
-CFLAGS += -I$(CORE_DEPTH)/lib/ssl
--- a/lib/ssl/config.mk
+++ b/lib/ssl/config.mk
@@ -67,27 +67,13 @@ EXTRA_SHARED_LIBS += \
 	$(NULL)
 
 ifeq ($(OS_ARCH), BeOS)
 EXTRA_SHARED_LIBS += -lbe
 endif
 
 endif
 
-# Mozilla's mozilla/modules/zlib/src/zconf.h adds the MOZ_Z_ prefix to zlib
-# exported symbols, which causes problem when NSS is built as part of Mozilla.
-# So we add a NSS_ENABLE_ZLIB variable to allow Mozilla to turn this off.
-NSS_ENABLE_ZLIB = 1
-ifdef NSS_ENABLE_ZLIB
-
-DEFINES += -DNSS_ENABLE_ZLIB
-
-# If a platform has a system zlib, set USE_SYSTEM_ZLIB to 1 and
-# ZLIB_LIBS to the linker command-line arguments for the system zlib
-# (for example, -lz) in the platform's config file in coreconf.
-ifdef USE_SYSTEM_ZLIB
-OS_LIBS += $(ZLIB_LIBS)
-else
-ZLIB_LIBS = $(DIST)/lib/$(LIB_PREFIX)zlib.$(LIB_SUFFIX)
-EXTRA_LIBS += $(ZLIB_LIBS)
+ifdef NSS_ENABLE_SSL_ZLIB
+DEFINES += -DNSS_ENABLE_SSL_ZLIB
+include $(CORE_DEPTH)/coreconf/zlib.mk
 endif
 
-endif
--- a/lib/ssl/ssl3con.c
+++ b/lib/ssl/ssl3con.c
@@ -29,17 +29,17 @@
 
 #include "pk11func.h"
 #include "secmod.h"
 #ifndef NO_PKCS11_BYPASS
 #include "blapi.h"
 #endif
 
 #include <stdio.h>
-#ifdef NSS_ENABLE_ZLIB
+#ifdef NSS_ENABLE_SSL_ZLIB
 #include "zlib.h"
 #endif
 
 #ifndef PK11_SETATTRS
 #define PK11_SETATTRS(x,id,v,l) (x)->type = (id); \
 		(x)->pValue=(v); (x)->ulValueLen = (l);
 #endif
 
@@ -216,34 +216,34 @@ void ssl3_CheckCipherSuiteOrderConsisten
 }
 #endif
 
 /* This list of SSL3 compression methods is sorted in descending order of
  * precedence (desirability).  It only includes compression methods we
  * implement.
  */
 static const /*SSLCompressionMethod*/ PRUint8 compressions [] = {
-#ifdef NSS_ENABLE_ZLIB
+#ifdef NSS_ENABLE_SSL_ZLIB
     ssl_compression_deflate,
 #endif
     ssl_compression_null
 };
 
 static const int compressionMethodsCount =
     sizeof(compressions) / sizeof(compressions[0]);
 
 /* compressionEnabled returns true iff the compression algorithm is enabled
  * for the given SSL socket. */
 static PRBool
 compressionEnabled(sslSocket *ss, SSLCompressionMethod compression)
 {
     switch (compression) {
     case ssl_compression_null:
 	return PR_TRUE;  /* Always enabled */
-#ifdef NSS_ENABLE_ZLIB
+#ifdef NSS_ENABLE_SSL_ZLIB
     case ssl_compression_deflate:
         if (ss->version < SSL_LIBRARY_VERSION_TLS_1_3) {
             return ss->opt.enableDeflate;
         }
         return PR_FALSE;
 #endif
     default:
 	return PR_FALSE;
@@ -1486,17 +1486,17 @@ ssl3_SetupPendingCipherSpec(sslSocket *s
     pwSpec->compression_method = ss->ssl3.hs.compression;
     pwSpec->compressContext = NULL;
     pwSpec->decompressContext = NULL;
 
     ssl_ReleaseSpecWriteLock(ss);  /*******************************/
     return SECSuccess;
 }
 
-#ifdef NSS_ENABLE_ZLIB
+#ifdef NSS_ENABLE_SSL_ZLIB
 #define SSL3_DEFLATE_CONTEXT_SIZE sizeof(z_stream)
 
 static SECStatus
 ssl3_MapZlibError(int zlib_error)
 {
     switch (zlib_error) {
     case Z_OK:
         return SECSuccess;
@@ -1593,45 +1593,45 @@ ssl3_DestroyCompressContext(void *void_c
 static SECStatus
 ssl3_DestroyDecompressContext(void *void_context, PRBool unused)
 {
     inflateEnd(void_context);
     PORT_Free(void_context);
     return SECSuccess;
 }
 
-#endif /* NSS_ENABLE_ZLIB */
+#endif /* NSS_ENABLE_SSL_ZLIB */
 
 /* Initialize the compression functions and contexts for the given
  * CipherSpec.  */
 static SECStatus
 ssl3_InitCompressionContext(ssl3CipherSpec *pwSpec)
 {
     /* Setup the compression functions */
     switch (pwSpec->compression_method) {
     case ssl_compression_null:
 	pwSpec->compressor = NULL;
 	pwSpec->decompressor = NULL;
 	pwSpec->compressContext = NULL;
 	pwSpec->decompressContext = NULL;
 	pwSpec->destroyCompressContext = NULL;
 	pwSpec->destroyDecompressContext = NULL;
 	break;
-#ifdef NSS_ENABLE_ZLIB
+#ifdef NSS_ENABLE_SSL_ZLIB
     case ssl_compression_deflate:
 	pwSpec->compressor = ssl3_DeflateCompress;
 	pwSpec->decompressor = ssl3_DeflateDecompress;
 	pwSpec->compressContext = PORT_Alloc(SSL3_DEFLATE_CONTEXT_SIZE);
 	pwSpec->decompressContext = PORT_Alloc(SSL3_DEFLATE_CONTEXT_SIZE);
 	pwSpec->destroyCompressContext = ssl3_DestroyCompressContext;
 	pwSpec->destroyDecompressContext = ssl3_DestroyDecompressContext;
 	ssl3_DeflateInit(pwSpec->compressContext);
 	ssl3_InflateInit(pwSpec->decompressContext);
 	break;
-#endif /* NSS_ENABLE_ZLIB */
+#endif /* NSS_ENABLE_SSL_ZLIB */
     default:
 	PORT_Assert(0);
 	PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
 	return SECFailure;
     }
 
     return SECSuccess;
 }
--- a/lib/ssl/sslimpl.h
+++ b/lib/ssl/sslimpl.h
@@ -1509,23 +1509,23 @@ ssl3_CompressMACEncryptRecord(ssl3Cipher
 		              const SSL3Opaque * pIn,
 		              PRUint32           contentLen,
 		              sslBuffer *        wrBuf);
 extern PRInt32   ssl3_SendRecord(sslSocket *ss, DTLSEpoch epoch,
 				 SSL3ContentType type,
                                  const SSL3Opaque* pIn, PRInt32 nIn,
                                  PRInt32 flags);
 
-#ifdef NSS_ENABLE_ZLIB
+#ifdef NSS_ENABLE_SSL_ZLIB
 /*
  * The DEFLATE algorithm can result in an expansion of 0.1% + 12 bytes. For a
  * maximum TLS record payload of 2**14 bytes, that's 29 bytes.
  */
 #define SSL3_COMPRESSION_MAX_EXPANSION 29
-#else  /* !NSS_ENABLE_ZLIB */
+#else  /* !NSS_ENABLE_SSL_ZLIB */
 #define SSL3_COMPRESSION_MAX_EXPANSION 0
 #endif
 
 /*
  * make sure there is room in the write buffer for padding and
  * other compression and cryptographic expansions.
  */
 #define SSL3_BUFFER_FUDGE     100 + SSL3_COMPRESSION_MAX_EXPANSION