forked from imagemin/jpegtran-bin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
77 lines (63 loc) · 2.04 KB
/
build.js
File metadata and controls
77 lines (63 loc) · 2.04 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'use strict';
var exec = require('child_process').exec;
var path = require('path');
var os = require('os');
var which = require('which');
var chalk = require('chalk');
var tar = require('tar');
var request = require('request');
var zlib = require('zlib');
var tmpdir = os.tmpdir ? os.tmpdir() : os.tmpDir();
var binPath = require('./lib/jpegtran').path;
var version = '1.3.0';
var tmpPath = path.join(tmpdir, 'libjpeg-turbo-' + version);
var urlPath = 'http://downloads.sourceforge.net/project/libjpeg-turbo/' + version + '/libjpeg-turbo-' + version + '.tar.gz';
module.exports = function () {
if (!(process.platform === 'darwin' || process.platform === 'linux')) {
return;
}
var opts = {
type: 'Directory',
path: tmpPath,
strip: 1
};
var proxy = process.env.http_proxy || process.env.HTTP_PROXY ||
process.env.https_proxy || process.env.HTTPS_PROXY || '';
console.log(chalk.yellow('Fetching %s...'), urlPath);
var req = request.defaults({ proxy: proxy }).get(urlPath, function (err, resp) {
if (resp.statusCode !== 200) {
throw err;
}
});
req
.pipe(zlib.Gunzip())
.pipe(tar.Extract(opts))
.on('close', function () {
console.log(chalk.green('Done in %s'), tmpPath);
which('make', function (err) {
if (err) {
throw err;
}
console.log(chalk.yellow('\nBuilding libjpeg-turbo...'));
var binDir = path.dirname(binPath);
var configureFlags = '--disable-shared ';
if (process.platform === 'darwin') {
configureFlags += '--host i686-apple-darwin ';
}
if (process.platform === 'linux' && process.arch === 'x64') {
configureFlags += 'CFLAGS=\'-O3 -m64\' LDFLAGS=-m64';
} else {
configureFlags += 'CFLAGS=\'-O3 -m32\' LDFLAGS=-m32';
}
var buildScript = './configure ' + configureFlags + ' &&' +
'make install prefix=' + tmpPath +
' bindir=' + binDir + ' bin_PROGRAMS=jpegtran';
exec(buildScript, { cwd: tmpPath }, function (err) {
if (err) {
throw err;
}
console.log(chalk.green('libjpeg-turbo rebuilt successfully'));
});
});
});
};