build: support building io.js as a static library
authorMarat Abdullin <dakota@brokenpipe.ru>
Sat, 4 Apr 2015 14:04:49 +0000 (17:04 +0300)
committerBen Noordhuis <info@bnoordhuis.nl>
Sat, 11 Apr 2015 04:53:17 +0000 (06:53 +0200)
One static library could not be bundled into another, that's why
it's necessary to skip `-force_load` and `--whole-archive` linker
options to build io.js itself as a static library.

`node_target_type` variable has been added to node.gyp, along
with `--enable-static` option in configure script.

Fixes: https://github.com/iojs/io.js/issues/686
PR-URL: https://github.com/iojs/io.js/pull/1341
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
configure
node.gyp

index e4148a7..16d71a8 100755 (executable)
--- a/configure
+++ b/configure
@@ -295,6 +295,11 @@ parser.add_option('--xcode',
     dest='use_xcode',
     help='generate build files for use with xcode')
 
+parser.add_option('--enable-static',
+    action='store_true',
+    dest='enable_static',
+    help='build as static library')
+
 (options, args) = parser.parse_args()
 
 # set up auto-download list
@@ -589,6 +594,9 @@ def configure_node(o):
   if options.v8_options:
     o['variables']['node_v8_options'] = options.v8_options.replace('"', '\\"')
 
+  if options.enable_static:
+    o['variables']['node_target_type'] = 'static_library'
+
 
 def configure_libz(o):
   o['variables']['node_shared_zlib'] = b(options.shared_zlib)
index 6ae2fbc..5a7d1ff 100644 (file)
--- a/node.gyp
+++ b/node.gyp
@@ -12,6 +12,7 @@
     'node_use_openssl%': 'true',
     'node_shared_openssl%': 'false',
     'node_v8_options%': '',
+    'node_target_type%': 'executable',
     'library_files': [
       'src/node.js',
       'lib/_debug_agent.js',
@@ -76,7 +77,7 @@
   'targets': [
     {
       'target_name': 'iojs',
-      'type': 'executable',
+      'type': '<(node_target_type)',
 
       'dependencies': [
         'node_js2c#host',
       ],
 
       'conditions': [
+        # No node_main.cc for anything except executable
+        [ 'node_target_type!="executable"', {
+          'sources!': [
+            'src/node_main.cc',
+          ],
+        }],
         [ 'v8_enable_i18n_support==1', {
           'defines': [ 'NODE_HAVE_I18N_SUPPORT=1' ],
           'dependencies': [
                 './deps/openssl/openssl.gyp:openssl-cli',
               ],
               # Do not let unused OpenSSL symbols to slip away
-              'xcode_settings': {
-                'OTHER_LDFLAGS': [
-                  '-Wl,-force_load,<(PRODUCT_DIR)/libopenssl.a',
-                ],
-              },
               'conditions': [
-                ['OS in "linux freebsd"', {
-                  'ldflags': [
-                    '-Wl,--whole-archive <(PRODUCT_DIR)/libopenssl.a -Wl,--no-whole-archive',
+                # -force_load or --whole-archive are not applicable for
+                # the static library
+                [ 'node_target_type!="static_library"', {
+                  'xcode_settings': {
+                    'OTHER_LDFLAGS': [
+                      '-Wl,-force_load,<(PRODUCT_DIR)/libopenssl.a',
+                    ],
+                  },
+                  'conditions': [
+                    ['OS in "linux freebsd"', {
+                      'ldflags': [
+                        '-Wl,--whole-archive <(PRODUCT_DIR)/libopenssl.a',
+                        '-Wl,--no-whole-archive',
+                      ],
+                    }],
                   ],
                 }],
               ],
         } ],
         [ 'v8_postmortem_support=="true"', {
           'dependencies': [ 'deps/v8/tools/gyp/v8.gyp:postmortem-metadata' ],
-          'xcode_settings': {
-            'OTHER_LDFLAGS': [
-              '-Wl,-force_load,<(V8_BASE)',
-            ],
-          },
+          'conditions': [
+            # -force_load is not applicable for the static library
+            [ 'node_target_type!="static_library"', {
+              'xcode_settings': {
+                'OTHER_LDFLAGS': [
+                  '-Wl,-force_load,<(V8_BASE)',
+                ],
+              },
+            }],
+          ],
         }],
         [ 'node_shared_zlib=="false"', {
           'dependencies': [ 'deps/zlib/zlib.gyp:zlib' ],