Bug 1350362 Fix NSS Build System for MinGW draft
authorTom Ritter <tom@mozilla.com>
Wed, 19 Apr 2017 12:37:27 -0500
changeset 565388 11f69086c635381a92645c5ad89a0e5c44b55600
parent 565231 19481ad2bf99b103ca181d6c790dd4ca05dcf986
child 565389 73fe02b7b40faa4874fc8c013159e19d8f9d644c
push id54836
push userbmo:tom@mozilla.com
push dateWed, 19 Apr 2017 19:25:16 +0000
bugs1350362
milestone55.0a1
Bug 1350362 Fix NSS Build System for MinGW MozReview-Commit-ID: 1XURWIta6cw
security/generate_mapfile.py
security/moz.build
security/nss/coreconf/config.gypi
security/nss/lib/freebl/freebl.gyp
security/nss/lib/freebl/freebl_base.gypi
--- a/security/generate_mapfile.py
+++ b/security/generate_mapfile.py
@@ -18,32 +18,32 @@ import buildconfig
 
 def main(output, input):
     is_darwin = buildconfig.substs['OS_ARCH'] == 'Darwin'
 
     with open(input, 'rb') as f:
         for line in f:
             line = line.rstrip()
             # Remove all lines containing ';-'
-            if ';-' in line:
-                continue
+            #if ';-' in line:
+            #    continue
             # On OS X, remove all lines containing ';+'
             if is_darwin and ';+' in line:
                 continue
             # Remove the string ' DATA '.
             line = line.replace(' DATA ', '')
             # Remove the string ';+'
-            line = line.replace(';+', '')
+            #line = line.replace(';+', '')
             # Remove the string ';;'
             line = line.replace(';;', '')
             # If a ';' is present, remove everything after it,
             # and on OS X, remove it as well.
             i = line.find(';')
             if i != -1:
-                if is_darwin:
+                if is_darwin or True:
                     line = line[:i]
                 else:
                     line = line[:i+1]
             # On OS X, symbols get an underscore in front.
             if line and is_darwin:
                 output.write('_')
             output.write(line)
             output.write('\n')
--- a/security/moz.build
+++ b/security/moz.build
@@ -88,16 +88,18 @@ else:
     gyp_vars['nspr_include_dir'] = CONFIG['NSPR_INCLUDE_DIR']
     gyp_vars['nspr_lib_dir'] = CONFIG['NSPR_LIB_DIR']
     # The Python scripts that detect clang need it to be set as CC
     # in the environment, which isn't true here. I don't know that
     # setting that would be harmful, but we already have this information
     # anyway.
     if CONFIG['CLANG_CXX'] or CONFIG['CLANG_CL']:
         gyp_vars['cc_is_clang'] = 1
+    if CONFIG['GNU_CC'] and CONFIG['OS_TARGET'] == 'WINNT':
+        gyp_vars['cc_is_mingw'] = 1
 
     GYP_DIRS += ['nss']
     GYP_DIRS['nss'].input = 'nss/nss.gyp'
     GYP_DIRS['nss'].variables = gyp_vars
 
     sandbox_vars = {
         # NSS explicitly exports its public symbols
         # with linker scripts.
@@ -105,19 +107,21 @@ else:
         # XXX: We should fix these warnings.
         'ALLOW_COMPILER_WARNINGS': True,
         # NSS' build system doesn't currently build NSS with PGO.
         # We could probably do so, but not without a lot of
         # careful consideration.
         'NO_PGO': True,
     }
     if CONFIG['OS_TARGET'] == 'WINNT':
-        if CONFIG['CPU_ARCH'] == 'x86':
+        if CONFIG['CPU_ARCH'] == 'x86' and not gyp_vars['cc_is_mingw']:
             # This should really be the default.
             sandbox_vars['ASFLAGS'] = ['-safeseh']
+        if CONFIG['MOZ_FOLD_LIBS_FLAGS']:
+            sandbox_vars['CFLAGS'] = [CONFIG['MOZ_FOLD_LIBS_FLAGS']]
     if CONFIG['OS_TARGET'] == 'Android':
         sandbox_vars['CFLAGS'] = [
             '-include', TOPSRCDIR + '/security/manager/android_stub.h',
             # Setting sandbox_vars['DEFINES'] is broken currently.
             '-DCHECK_FORK_GETPID',
         ]
         if CONFIG['ANDROID_VERSION']:
             sandbox_vars['CFLAGS'] += ['-DANDROID_VERSION=' + CONFIG['ANDROID_VERSION']]
--- a/security/nss/coreconf/config.gypi
+++ b/security/nss/coreconf/config.gypi
@@ -167,17 +167,17 @@
           ],
         },
         'conditions': [
           [ 'cc_use_gnu_ld==1', {
             'ldflags': [
               '-Wl,--version-script,<(INTERMEDIATE_DIR)/out.>(mapfile)',
             ],
           }],
-          [ 'OS=="win"', {
+          [ 'cc_is_mingw!=1 and OS=="win"', {
             # On Windows, .def files are used directly as sources.
             'sources': [
               '>(mapfile)',
             ],
           }, {
             # On other platforms, .def files need processing.
             'sources': [
               '<(INTERMEDIATE_DIR)/out.>(mapfile)',
@@ -209,17 +209,17 @@
         ],
         'library_dirs': [
           '<(nspr_lib_dir)',
         ],
       }],
       # Shared library specific settings.
       [ '_type=="shared_library"', {
         'conditions': [
-          [ 'cc_use_gnu_ld==1', {
+          [ 'cc_is_mingw==1 or cc_use_gnu_ld==1', {
             'ldflags': [
               '-Wl,--gc-sections',
             ],
             'conditions': [
               ['no_zdefs==0', {
                 'ldflags': [
                   '-Wl,-z,defs',
                 ],
@@ -526,17 +526,17 @@
           'Release_x64': {
             'inherit_from': ['Release'],
           },
         }],
       ],
     },
   },
   'conditions': [
-    [ 'cc_use_gnu_ld==1', {
+    [ 'cc_is_mingw--1 or cc_use_gnu_ld==1', {
       'variables': {
         'process_map_file': ['/bin/sh', '-c', '/usr/bin/env grep -v ";-" >(mapfile) | sed -e "s,;+,," -e "s; DATA ;;" -e "s,;;,," -e "s,;.*,;," > >@(_outputs)'],
       },
     }],
     [ 'OS=="mac"', {
       'variables': {
         'process_map_file': ['/bin/sh', '-c', '/usr/bin/grep -v ";+" >(mapfile) | grep -v ";-" | sed -e "s; DATA ;;" -e "s,;;,," -e "s,;.*,," -e "s,^,_," > >@(_outputs)'],
       },
--- a/security/nss/lib/freebl/freebl.gyp
+++ b/security/nss/lib/freebl/freebl.gyp
@@ -171,30 +171,45 @@
           },
         },
       }],
       [ 'OS=="win" and target_arch=="x64"', {
         'msvs_settings': {
           'VCCLCompilerTool': {
             #TODO: -Ox optimize flags
             'PreprocessorDefinitions': [
+	      # Should be copied to mingw defines below
               'NSS_USE_64',
               'NSS_X86_OR_X64',
               'NSS_X64',
               'MP_IS_LITTLE_ENDIAN',
               'NSS_BEVAND_ARCFOUR',
               'MPI_AMD64',
               'MP_ASSEMBLY_MULTIPLY',
               'NSS_USE_COMBA',
               'USE_HW_AES',
               'INTEL_GCM',
             ],
           },
         },
       }],
+      [ 'cc_is_mingw==1 and OS=="win" and target_arch=="x64"', {
+      	'defines': [
+          'NSS_USE_64',
+          'NSS_X86_OR_X64',
+          'NSS_X64',
+          'MP_IS_LITTLE_ENDIAN',
+#          'NSS_BEVAND_ARCFOUR',
+#          'MPI_AMD64',
+#          'MP_ASSEMBLY_MULTIPLY',
+#          'NSS_USE_COMBA',
+#          'USE_HW_AES',
+#          'INTEL_GCM',
+	  ],
+      }],
       [ 'OS!="win"', {
         'conditions': [
           [ 'target_arch=="x64"', {
             'defines': [
               'NSS_USE_64',
               'NSS_X86_OR_X64',
               'NSS_X64',
               # The Makefile does version-tests on GCC, but we're not doing that here.
--- a/security/nss/lib/freebl/freebl_base.gypi
+++ b/security/nss/lib/freebl/freebl_base.gypi
@@ -100,26 +100,27 @@
       'sources': [
         #TODO: building with mingw should not need this.
         'ecl/uint128.c',
       ],
       'libraries': [
         'advapi32.lib',
       ],
       'conditions': [
-        [ 'target_arch=="x64"', {
+        [ 'cc_is_mingw!=1 and target_arch=="x64"', {
           'sources': [
             'arcfour-amd64-masm.asm',
             'mpi/mpi_amd64.c',
             'mpi/mpi_amd64_masm.asm',
             'mpi/mp_comba_amd64_masm.asm',
             'intel-aes-x64-masm.asm',
             'intel-gcm-x64-masm.asm',
           ],
-        }, {
+        }],
+	[ 'cc_is_mingw!=1 and target_arch!="x64"', {
           # not x64
           'sources': [
             'mpi/mpi_x86_asm.c',
             'intel-aes-x86-masm.asm',
             'intel-gcm-x86-masm.asm',
           ],
         }],
         [ 'cc_is_clang!=1', {