diff --git a/Jakefile b/Jakefile new file mode 100644 index 0000000..b993e35 --- /dev/null +++ b/Jakefile @@ -0,0 +1,4 @@ +'use strict'; + +desc('Default task'); +task('default', ['fetch:precompiled'], function () {}); \ No newline at end of file diff --git a/jakelib/build.jake b/jakelib/build.jake new file mode 100644 index 0000000..ebbe6b3 --- /dev/null +++ b/jakelib/build.jake @@ -0,0 +1,65 @@ +'use strict'; + +var os = require('os'); +var fs = require('fs-extra'); + +namespace('build', function () { + task('generate', {async: true}, function () { + var opts = 'use_gold=false is_debug=false rtc_include_tests=false'; + + process.env.PATH = process.cwd() + '/Dependencies/depot_tools:' + process.env.PATH; + process.chdir('src'); + jake.exec('gn gen out/Default --args=\'' + opts + '\'', function () { + complete(); + }); + }); + + task('ninja', ['build:generate'], {async: true}, function () { + var packages = 'libjingle_peerconnection field_trial_default metrics_default'; + + console.log('Building WebRTC...'); + jake.exec('ninja -C out/Default ' + packages, { printStdout: true }, function () { + complete(); + }); + }); + + task('merge', ['build:ninja'], {async: true}, function () { + var prefix = os.platform() !== 'windows' ? 'lib' : ''; + var suffix = os.platform() === 'windows' ? '.lib' : '.a'; + var path = '../lib/' + prefix + 'webrtc' + suffix; + + console.log('Merging libraries...'); + + if (!fs.existsSync('../lib')) { + fs.mkdir('../lib'); + } + + jake.exec('python webrtc/build/merge_libs.py out/Default ' + path, function () { + complete(); + }); + }); + + task('include', ['build:merge'], function () { + var fileList = new jake.FileList(); + var files; + + console.log('Copying include files...'); + if (!fs.existsSync('../include')) { + fs.mkdir('../include'); + } + + fileList.include('webrtc/**/*.h'); + files = fileList.toArray(); + + for (var file in files) { + fs.copySync(files[file], '../include/' + files[file]); + } + }); + + task('default', [ + 'generate', + 'ninja', + 'merge', + 'include' + ], function () {}); +}); diff --git a/jakelib/common.js b/jakelib/common.js new file mode 100644 index 0000000..20f57a2 --- /dev/null +++ b/jakelib/common.js @@ -0,0 +1,22 @@ +'use strict'; + +var os = require('os'); +var pkg = require('../package.json'); + +function getPackageName() { + var version = pkg.version; + var platform = os.platform(); + var arch = os.arch(); + var nodever = process.version; + var suffix = (platform === 'windows') ? '.zip' : '.tar.gz'; + + return pkg.config.filename + .replace('{VERSION}', version) + .replace('{PLATFORM}', platform) + .replace('{ARCH}', arch) + .replace('{NODEVER}', nodever) + suffix; +} + +module.exports = { + getPackageName: getPackageName +}; diff --git a/jakelib/fetch.jake b/jakelib/fetch.jake new file mode 100644 index 0000000..26b5040 --- /dev/null +++ b/jakelib/fetch.jake @@ -0,0 +1,87 @@ +'use strict'; + +var download = require('download'); +var getPackageName = require('./common').getPackageName; +var os = require('os'); +var pkg = require('../package.json'); + +var WebRTCUrl = pkg.config.webrtc.url; +var WebRTCRev = pkg.config.webrtc.revision; +var ChromiumUrl = pkg.config.chromium.url; + +namespace('fetch', function () { + task('precompiled', {async: true}, function () { + var packageName = getPackageName(); + var url = pkg.config.url + '/' + pkg.version + '/' + packageName; + + console.log('Downloading', url); + download(url, '.') + .then(function () { + console.log('Extracting', packageName); + jake.exec('tar xf ' + packageName, function () { + console.log('Done'); + complete(); + }); + }) + .catch(function (err) { + var task = jake.Task['fetch:source']; + + console.log('Failed, building libwebrtc from source.'); + task.addListener('complete', function () { + console.log('Build done.'); + complete(); + }); + + task.invoke(); + }); + }); + + task('gclient', {async: true}, function () { + console.log('Updating submodules...'); + jake.exec(['git submodule init', 'git submodule update'], {printStdout: true}, function () { + complete(); + }); + }); + + task('configure', ['fetch:gclient'], {async: true}, function () { + console.log('Configuring gclient to fetch WebRTC code'); + process.env.PATH = process.cwd() + '/Dependencies/depot_tools:' + process.env.PATH; + jake.exec('gclient config --name src ' + WebRTCUrl, {printStdout: true}, function () { + complete(); + }); + }); + + task('sync', ['fetch:configure'], {async: true}, function () { + console.log('Retrieving WebRTC source code'); + jake.exec('gclient sync --revision ' + WebRTCRev + ' -n -D', {printStdout: true}, function () { + complete(); + }); + }); + + task('chromium', ['fetch:sync'], {async: true}, function () { + console.log('Retrieving Chromium dependencies'); + jake.exec('git clone ' + ChromiumUrl + ' src/chromium/src', { breakOnError: false, printStdout: true }, function () { + complete(); + }); + }); + + task('clang', ['fetch:chromium'], {async: true}, function () { + console.log('Updating clang'); + jake.exec('python src/chromium/src/tools/clang/scripts/update.py', {printStdout: true}, function () { + complete(); + }); + }); + + task('links', ['fetch:clang'], {async: true}, function () { + console.log('Creating symbolic links'); + jake.exec('python src/setup_links.py', {printStdout: true}, function () { + complete(); + }); + }); + + task('source', [ + 'links', + 'build:default' + ], function () { + }); +}); \ No newline at end of file diff --git a/jakelib/package.jake b/jakelib/package.jake new file mode 100644 index 0000000..e37a111 --- /dev/null +++ b/jakelib/package.jake @@ -0,0 +1,15 @@ +'use strict'; + +var os = require('os'); +var getPackageName = require('./common').getPackageName; + +task('package', {async: true}, function () { + var packageName = getPackageName(); + + console.log('Creating ' + packageName + '...'); + if (os.platform() !== 'windows') { + jake.exec('tar cfz ' + packageName + ' include lib', function () { + complete(); + }); + } +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..5b263d5 --- /dev/null +++ b/package.json @@ -0,0 +1,33 @@ +{ + "name": "libwebrtc-src", + "version": "0.0.1-rc.1", + "description": "libwebrtc source code", + "main": "index.js", + "config": { + "filename": "libwebrtc-{VERSION}-{PLATFORM}-{ARCH}", + "url": "https://github.com/aisouard/libwebrtc/releases/download", + "webrtc": { + "url": "https://chromium.googlesource.com/external/webrtc.git", + "revision": "7502401788fcba5c9f81a9e4701e2f0831e78698" + }, + "chromium": { + "url": "https://github.com/aisouard/libwebrtc-chromium-deps.git" + } + }, + "scripts": { + "install": "jake", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://github.com//aisouard/libwebrtc" + }, + "author": "Axel Isouard ", + "license": "MIT", + "dependencies": { + "download": "^5.0.2", + "fs-extra": "^0.30.0", + "jake": "^8.0.14", + "npm": "^3.10.8" + } +}