forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildocaml.js
59 lines (48 loc) · 1.58 KB
/
buildocaml.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//@ts-check
var cp = require('child_process')
var path = require('path')
var fs = require('fs')
/**
* @type {string}
*/
var cached = undefined
// FIXME: this works in CI, but for release build, submodule
// is carried, so it needs to be fixed
/**
* @returns{string}
*/
function getVersionPrefix(){
if(cached !== undefined){
return cached
}
var file = path.join(__dirname, '..', 'ocaml', 'VERSION')
if(fs.existsSync(file)){
var version = fs.readFileSync(file, 'ascii')
cached = version.substr(0, version.indexOf('+'))
return cached
}
file = path.join(__dirname,'..','OCAML_VERSION')
if(fs.existsSync(file)){
var version = fs.readFileSync(file, 'ascii')
cached = version.substr(0, version.indexOf('+'))
return cached
}
throw new Error("version file not found")
}
exports.getVersionPrefix = getVersionPrefix
function build() {
var ocamlSrcDir = path.join(__dirname, '..', 'ocaml')
if(!fs.existsSync(ocamlSrcDir)){
fs.mkdirSync(ocamlSrcDir)
}
if (!fs.existsSync(path.join(ocamlSrcDir, 'VERSION'))) {
cp.execSync(`tar xzvf ocaml.tar.gz`, { cwd: ocamlSrcDir, stdio: [0, 1, 2] })
}
var prefix = path.normalize(path.join(__dirname, '..', 'native', getVersionPrefix()))
cp.execSync('./configure -prefix ' + prefix + ' -no-ocamlbuild -no-curses -no-graph -no-pthread -no-debugger && make clean && make -j9 world.opt && make install '
, { cwd: path.join(__dirname, '..', 'ocaml'), stdio: [0, 1, 2] })
}
exports.build = build
if(require.main === module){
build()
}