Skip to content

Commit cd38a4a

Browse files
hohobnoordhuis
authored andcommitted
build: support building io.js as a static library
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: #686 PR-URL: #1341 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 93a1a07 commit cd38a4a

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-14
lines changed

configure

+8
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ parser.add_option('--xcode',
295295
dest='use_xcode',
296296
help='generate build files for use with xcode')
297297

298+
parser.add_option('--enable-static',
299+
action='store_true',
300+
dest='enable_static',
301+
help='build as static library')
302+
298303
(options, args) = parser.parse_args()
299304

300305
# set up auto-download list
@@ -589,6 +594,9 @@ def configure_node(o):
589594
if options.v8_options:
590595
o['variables']['node_v8_options'] = options.v8_options.replace('"', '\\"')
591596

597+
if options.enable_static:
598+
o['variables']['node_target_type'] = 'static_library'
599+
592600

593601
def configure_libz(o):
594602
o['variables']['node_shared_zlib'] = b(options.shared_zlib)

node.gyp

+33-14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
'node_use_openssl%': 'true',
1313
'node_shared_openssl%': 'false',
1414
'node_v8_options%': '',
15+
'node_target_type%': 'executable',
1516
'library_files': [
1617
'src/node.js',
1718
'lib/_debug_agent.js',
@@ -76,7 +77,7 @@
7677
'targets': [
7778
{
7879
'target_name': 'iojs',
79-
'type': 'executable',
80+
'type': '<(node_target_type)',
8081

8182
'dependencies': [
8283
'node_js2c#host',
@@ -183,6 +184,12 @@
183184
],
184185

185186
'conditions': [
187+
# No node_main.cc for anything except executable
188+
[ 'node_target_type!="executable"', {
189+
'sources!': [
190+
'src/node_main.cc',
191+
],
192+
}],
186193
[ 'v8_enable_i18n_support==1', {
187194
'defines': [ 'NODE_HAVE_I18N_SUPPORT=1' ],
188195
'dependencies': [
@@ -215,15 +222,22 @@
215222
'./deps/openssl/openssl.gyp:openssl-cli',
216223
],
217224
# Do not let unused OpenSSL symbols to slip away
218-
'xcode_settings': {
219-
'OTHER_LDFLAGS': [
220-
'-Wl,-force_load,<(PRODUCT_DIR)/libopenssl.a',
221-
],
222-
},
223225
'conditions': [
224-
['OS in "linux freebsd"', {
225-
'ldflags': [
226-
'-Wl,--whole-archive <(PRODUCT_DIR)/libopenssl.a -Wl,--no-whole-archive',
226+
# -force_load or --whole-archive are not applicable for
227+
# the static library
228+
[ 'node_target_type!="static_library"', {
229+
'xcode_settings': {
230+
'OTHER_LDFLAGS': [
231+
'-Wl,-force_load,<(PRODUCT_DIR)/libopenssl.a',
232+
],
233+
},
234+
'conditions': [
235+
['OS in "linux freebsd"', {
236+
'ldflags': [
237+
'-Wl,--whole-archive <(PRODUCT_DIR)/libopenssl.a',
238+
'-Wl,--no-whole-archive',
239+
],
240+
}],
227241
],
228242
}],
229243
],
@@ -304,11 +318,16 @@
304318
} ],
305319
[ 'v8_postmortem_support=="true"', {
306320
'dependencies': [ 'deps/v8/tools/gyp/v8.gyp:postmortem-metadata' ],
307-
'xcode_settings': {
308-
'OTHER_LDFLAGS': [
309-
'-Wl,-force_load,<(V8_BASE)',
310-
],
311-
},
321+
'conditions': [
322+
# -force_load is not applicable for the static library
323+
[ 'node_target_type!="static_library"', {
324+
'xcode_settings': {
325+
'OTHER_LDFLAGS': [
326+
'-Wl,-force_load,<(V8_BASE)',
327+
],
328+
},
329+
}],
330+
],
312331
}],
313332
[ 'node_shared_zlib=="false"', {
314333
'dependencies': [ 'deps/zlib/zlib.gyp:zlib' ],

0 commit comments

Comments
 (0)