Skip to content

Commit

Permalink
configure.js: Freebsd Install (#96)
Browse files Browse the repository at this point in the history
Build on FreeBSD

PR-URL: #110
Reviewed-By: Howard Hellyer <hhellyer@uk.ibm.com>
  • Loading branch information
No9 authored and hhellyer committed Aug 14, 2017
1 parent 9cabf0b commit f3147ef
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 3 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,31 @@ make -C out/ -j9
sudo make install-linux
```

### FreeBSD

```bash
# Clone this repo
git clone https://github.com/nodejs/llnode.git && cd llnode

# Install llvm with lldb and headers
pkg install llvm39
rm -f /usr/bin/lldb
ln -s /usr/local/bin/lldb39 /usr/bin/lldb

# Initialize GYP
git clone https://chromium.googlesource.com/external/gyp.git tools/gyp

# Configure
./gyp_llnode -Dlldb_dir=/usr/local/llvm39/

# Build
gmake -C out/ -j9
```

(The LLDB function ComputeSystemPluginsDirectory is not implemented on FreeBSD.
The plugin library must be loaded manually.)


## Loading the lldb plugin library.

The simplest method is:
Expand Down Expand Up @@ -145,6 +170,15 @@ To install the plugin in the LLDB system plugin directory, use the
npm copy `node_modules/llnode/llnode.so` to
`/usr/lib/lldb/plugins`.

### FreeBSD

```
lldb
(lldb) plugin load ./node_modules/llnode/llnode.so
```
LLDB does not support the system plugin directory on FreeBSD.

# Usage

To use llnode with a core dump the core dump needs to be loaded into lldb
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"//": "(Blame C++)",
"scripts": {
"preinstall": "node scripts/configure.js",
"install": "./gyp_llnode && make -C out/",
"install": "./gyp_llnode && ( gmake -C out/ || make -C out/ )",
"postinstall": "node scripts/cleanup.js",
"test": "tape test/*-test.js"
},
Expand Down
56 changes: 54 additions & 2 deletions scripts/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const os = require('os');
const fs = require('fs');
const path = require('path');
const child_process = require('child_process');

const lldbReleases = {
Expand Down Expand Up @@ -52,7 +53,7 @@ if (osName === 'Darwin') {
}

// console.log('lldb_version is ' + lldb_version)
var installedHeadersDir = getLinuxHeadersDir(lldbVersion);
const installedHeadersDir = getLinuxHeadersDir(lldbVersion);
// console.log('installed_headers_dir is ' + installed_headers_dir);
if (installedHeadersDir === undefined) {
// Initialising lldb_headers_branch will cause us to clone them.
Expand All @@ -61,6 +62,28 @@ if (osName === 'Darwin') {
} else {
lldbIncludeDir = installedHeadersDir;
}
} else if (osName === 'FreeBSD') {

lldbExe = getLldbExecutable();
lldbVersion = getFreeBSDVersion(lldbExe);

if (lldbVersion === undefined) {
console.log('Unable to locate lldb binary. llnode installation failed.');
process.exit(1);
}

const installedHeadersDir = getFreeBSDHeadersDir(lldbVersion);
if (installedHeadersDir === undefined) {
// As this is a BSD we know this system is in an improper state
// So we can exit with an error
console.log('The system isn\'t set up correcly.');
console.log('Try `pkg install llvm39');
console.log('And `ln -s /usr/local/bin/lldb39 /usr/bin/lldb`');
process.exit(1);
} else {
lldbIncludeDir = installedHeadersDir;
}

}

console.log(`Installing llnode for ${lldbExe}, lldb version ${lldbVersion}`);
Expand Down Expand Up @@ -94,13 +117,18 @@ if (process.env.npm_config_global) {
gypSubDir = 'npm/node_modules/node-gyp';
}

// npm can be in a different location than the current
// location for global installs so we need find out where the npm is
var npmLocation = child_process.execFileSync('which', ['npm']);
var npmModules = path.join(npmLocation.toString(), '../../lib/node_modules/npm');

// Initialize GYP
// We can use the node-gyp that comes with npm.
// We can locate it with npm -g explore npm npm explore node-gyp pwd
// It might have been neater to make node-gyp one of our dependencies
// *but* they don't get installed until after the install step has run.
var gypDir = child_process.execFileSync('npm',
['-g', 'explore', 'npm', 'npm', 'explore', gypSubDir, 'pwd'],
['-g', 'explore', npmModules, 'npm', 'explore', gypSubDir, 'pwd'],
{cwd: buildDir}).toString().trim();
child_process.execSync('rm -rf tools');
fs.mkdirSync('tools');
Expand Down Expand Up @@ -193,6 +221,30 @@ function getLinuxVersion(lldbExe) {
return undefined;
}

// Shim this for consistancy in OS naming
function getFreeBSDVersion(lldbExe) {
//Strip the dots for BSD
return getLinuxVersion(lldbExe).replace('.','');
}

function getFreeBSDHeadersDir(version) {

console.log('Checking for headers, version is ' + version);

try {
var includeDir = child_process.execFileSync('llvm-config' + version,
['--prefix']).toString().trim();
if (fs.existsSync(includeDir + '/include/lldb')) {
return includeDir;
}
} catch (err) {
console.log(includeDir + '/include/lldb doesn\'nt exist');
console.log('Please see README.md');
console.log(err);
process.exit(1);
}
return undefined;
}
function getLinuxHeadersDir(version) {
// Get the directory which should contain the headers and
// check if they are present.
Expand Down

0 comments on commit f3147ef

Please sign in to comment.