Skip to content

Commit

Permalink
ninja: shared_library for OS X
Browse files Browse the repository at this point in the history
See: #2
  • Loading branch information
indutny committed Jun 12, 2016
1 parent 43738d0 commit 6b557c9
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions lib/gyp/generator/ninja/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,22 @@ Ninja.prototype.output = function output() {
const targetDict = this.targetDict;
let res = [];

const gdv = generatorDefaultVariables;
let vars = gyp.common.shallowCopy(generatorDefaultVariables);
exports.calculateVariables(vars, {});

let prefix;
let suffix;

const type = this.type();
if (type === 'static_library') {
prefix = gdv.STATIC_LIB_PREFIX;
suffix = gdv.STATIC_LIB_SUFFIX;
prefix = vars.STATIC_LIB_PREFIX;
suffix = vars.STATIC_LIB_SUFFIX;
} else if (type === 'shared_library') {
prefix = vars.SHARED_LIB_PREFIX;
suffix = vars.SHARED_LIB_SUFFIX || '';
} else if (type === 'executable') {
prefix = gdv.EXECUTABLE_PREFIX;
suffix = gdv.EXECUTABLE_SUFFIX;
prefix = vars.EXECUTABLE_PREFIX;
suffix = vars.EXECUTABLE_SUFFIX;
} else if (type === 'none') {
// pass through
prefix = '';
Expand All @@ -162,9 +167,20 @@ Ninja.prototype.output = function output() {
throw new Error('Not implemented');
}

let out = this.targetName + suffix;
if (out.indexOf(prefix) !== 0)
out = prefix + out;
let name = this.targetName;

if (this.targetDict.hasOwnProperty('product_prefix'))
prefix = this.targetDict.product_prefix;
if (this.targetDict.product_extension)
suffix = '.' + this.targetDict.product_extension;
if (this.targetDict.hasOwnProperty('product_name'))
name = this.targetDict.product_name;

let out = name + suffix;
if (prefix === 'lib' && /^lib/.test(out))
out = out.slice(3);

out = prefix + out;

if (type !== 'none')
res.push(out);
Expand Down Expand Up @@ -366,6 +382,8 @@ Ninja.prototype.generate = function generate() {
let rule;
if (type === 'static_library')
rule = 'alink';
else if (type === 'shared_library')
rule = 'solink';
else if (type === 'executable')
rule = 'link';

Expand All @@ -374,6 +392,11 @@ Ninja.prototype.generate = function generate() {
if (type === 'static_library')
return /\.(o|obj)$/.test(obj);

// TODO(indunty): is it needed?
// Do not link .so to shared_libraries
if (type === 'shared_library')
return /\.(o|a|obj|lib)$/.test(obj);

return /\.(o|a|obj|dll|so|lib)$/.test(obj);
}

Expand Down Expand Up @@ -501,6 +524,16 @@ NinjaMain.prototype.rulesAndTargets = function rulesAndTargets() {
pool: 'link_pool',
description: 'LINK $out'
});
main.rule('solink', {
command: `$${useCxx ? 'ldxx' : 'ld'} -shared $ldflags` +
`${useCxx ? '$ldflags_cc $cflags_cc' : '$ldflags_c $cflags_c'} ` +
(process.platform === 'darwin' ?
'$in ' :
`-Wl,--start-group $in -Wl,--end-group `) +
`$cflags -o $out $solibs $libs`,
pool: 'link_pool',
description: 'LINK $out'
});

main.rule('alink', {
command: 'rm -rf $out && $ar rcs $arflags $out $in',
Expand Down

0 comments on commit 6b557c9

Please sign in to comment.