Skip to content

Commit f3147ef

Browse files
No9hhellyer
authored andcommitted
configure.js: Freebsd Install (#96)
Build on FreeBSD PR-URL: #110 Reviewed-By: Howard Hellyer <hhellyer@uk.ibm.com>
1 parent 9cabf0b commit f3147ef

3 files changed

Lines changed: 89 additions & 3 deletions

File tree

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,31 @@ make -C out/ -j9
9696
sudo make install-linux
9797
```
9898

99+
### FreeBSD
100+
101+
```bash
102+
# Clone this repo
103+
git clone https://github.com/nodejs/llnode.git && cd llnode
104+
105+
# Install llvm with lldb and headers
106+
pkg install llvm39
107+
rm -f /usr/bin/lldb
108+
ln -s /usr/local/bin/lldb39 /usr/bin/lldb
109+
110+
# Initialize GYP
111+
git clone https://chromium.googlesource.com/external/gyp.git tools/gyp
112+
113+
# Configure
114+
./gyp_llnode -Dlldb_dir=/usr/local/llvm39/
115+
116+
# Build
117+
gmake -C out/ -j9
118+
```
119+
120+
(The LLDB function ComputeSystemPluginsDirectory is not implemented on FreeBSD.
121+
The plugin library must be loaded manually.)
122+
123+
99124
## Loading the lldb plugin library.
100125

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

173+
### FreeBSD
174+
175+
```
176+
lldb
177+
178+
(lldb) plugin load ./node_modules/llnode/llnode.so
179+
```
180+
LLDB does not support the system plugin directory on FreeBSD.
181+
148182
# Usage
149183

150184
To use llnode with a core dump the core dump needs to be loaded into lldb

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"//": "(Blame C++)",
1313
"scripts": {
1414
"preinstall": "node scripts/configure.js",
15-
"install": "./gyp_llnode && make -C out/",
15+
"install": "./gyp_llnode && ( gmake -C out/ || make -C out/ )",
1616
"postinstall": "node scripts/cleanup.js",
1717
"test": "tape test/*-test.js"
1818
},

scripts/configure.js

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const os = require('os');
44
const fs = require('fs');
5+
const path = require('path');
56
const child_process = require('child_process');
67

78
const lldbReleases = {
@@ -52,7 +53,7 @@ if (osName === 'Darwin') {
5253
}
5354

5455
// console.log('lldb_version is ' + lldb_version)
55-
var installedHeadersDir = getLinuxHeadersDir(lldbVersion);
56+
const installedHeadersDir = getLinuxHeadersDir(lldbVersion);
5657
// console.log('installed_headers_dir is ' + installed_headers_dir);
5758
if (installedHeadersDir === undefined) {
5859
// Initialising lldb_headers_branch will cause us to clone them.
@@ -61,6 +62,28 @@ if (osName === 'Darwin') {
6162
} else {
6263
lldbIncludeDir = installedHeadersDir;
6364
}
65+
} else if (osName === 'FreeBSD') {
66+
67+
lldbExe = getLldbExecutable();
68+
lldbVersion = getFreeBSDVersion(lldbExe);
69+
70+
if (lldbVersion === undefined) {
71+
console.log('Unable to locate lldb binary. llnode installation failed.');
72+
process.exit(1);
73+
}
74+
75+
const installedHeadersDir = getFreeBSDHeadersDir(lldbVersion);
76+
if (installedHeadersDir === undefined) {
77+
// As this is a BSD we know this system is in an improper state
78+
// So we can exit with an error
79+
console.log('The system isn\'t set up correcly.');
80+
console.log('Try `pkg install llvm39');
81+
console.log('And `ln -s /usr/local/bin/lldb39 /usr/bin/lldb`');
82+
process.exit(1);
83+
} else {
84+
lldbIncludeDir = installedHeadersDir;
85+
}
86+
6487
}
6588

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

120+
// npm can be in a different location than the current
121+
// location for global installs so we need find out where the npm is
122+
var npmLocation = child_process.execFileSync('which', ['npm']);
123+
var npmModules = path.join(npmLocation.toString(), '../../lib/node_modules/npm');
124+
97125
// Initialize GYP
98126
// We can use the node-gyp that comes with npm.
99127
// We can locate it with npm -g explore npm npm explore node-gyp pwd
100128
// It might have been neater to make node-gyp one of our dependencies
101129
// *but* they don't get installed until after the install step has run.
102130
var gypDir = child_process.execFileSync('npm',
103-
['-g', 'explore', 'npm', 'npm', 'explore', gypSubDir, 'pwd'],
131+
['-g', 'explore', npmModules, 'npm', 'explore', gypSubDir, 'pwd'],
104132
{cwd: buildDir}).toString().trim();
105133
child_process.execSync('rm -rf tools');
106134
fs.mkdirSync('tools');
@@ -193,6 +221,30 @@ function getLinuxVersion(lldbExe) {
193221
return undefined;
194222
}
195223

224+
// Shim this for consistancy in OS naming
225+
function getFreeBSDVersion(lldbExe) {
226+
//Strip the dots for BSD
227+
return getLinuxVersion(lldbExe).replace('.','');
228+
}
229+
230+
function getFreeBSDHeadersDir(version) {
231+
232+
console.log('Checking for headers, version is ' + version);
233+
234+
try {
235+
var includeDir = child_process.execFileSync('llvm-config' + version,
236+
['--prefix']).toString().trim();
237+
if (fs.existsSync(includeDir + '/include/lldb')) {
238+
return includeDir;
239+
}
240+
} catch (err) {
241+
console.log(includeDir + '/include/lldb doesn\'nt exist');
242+
console.log('Please see README.md');
243+
console.log(err);
244+
process.exit(1);
245+
}
246+
return undefined;
247+
}
196248
function getLinuxHeadersDir(version) {
197249
// Get the directory which should contain the headers and
198250
// check if they are present.

0 commit comments

Comments
 (0)