Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
375 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
node_modules/ | ||
roms | ||
roms*/ | ||
pcejs-build-config.json | ||
build/ | ||
build-native/ | ||
pce-js/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
PCEJSBuild = require('./pcejs_build') | ||
|
||
module.exports = (grunt) -> | ||
pcejs = new PCEJSBuild(grunt) | ||
pcejs.loadConfig() # extend with saved config | ||
|
||
packagedir = pcejs.config.packagedir | ||
|
||
# Project configuration. | ||
grunt.initConfig | ||
pkg: grunt.file.readJSON('package.json') | ||
|
||
# Main tasks | ||
grunt.task.registerTask 'reset', 'Reset config to default', -> | ||
pcejs.initConfig() # discard loaded config, reset to defaults | ||
pcejs.saveConfig() | ||
|
||
grunt.task.registerTask 'target', 'Choose build target (macplus,ibmpc,atarist)', (target) -> | ||
pcejs.config.target = target | ||
pcejs.saveConfig() | ||
|
||
grunt.task.registerTask 'configure', 'Configure emulator build', (arch) -> | ||
if (arch is 'native') | ||
pcejs.config.emscripten = false | ||
pcejs.config.prefix = 'build-native/' | ||
if (arch is 'em') | ||
pcejs.config.emscripten = true | ||
pcejs.config.prefix = 'build/' | ||
|
||
pcejs.run(this.async(), './scripts/10-configure.sh') | ||
|
||
pcejs.saveConfig() | ||
|
||
grunt.task.registerTask 'make', 'Build emulator', -> | ||
pcejs.run(this.async(), './scripts/20-make.sh') | ||
|
||
grunt.task.registerTask 'clean', 'Clean source tree', (full) -> | ||
if full | ||
pcejs.run(this.async(), './scripts/a0-clean.sh') | ||
else | ||
pcejs.run(this.async(), 'make', ['clean']) | ||
grunt.task.registerTask 'afterbuild', 'Package build for web', (target) -> | ||
pcejs.config.target = target if target | ||
|
||
pcejs.run(this.async(), './scripts/30-afterbuild.sh') | ||
|
||
grunt.registerTask 'build', 'Configure, build and package for web', (target) -> | ||
pcejs.config.target = target if target | ||
|
||
if target is 'native' | ||
grunt.task.run.apply(grunt.task, [ | ||
'configure:native', | ||
'make' | ||
]) | ||
else | ||
grunt.task.run.apply(grunt.task, [ | ||
'configure:em', | ||
'make', | ||
'afterbuild:'+pcejs.config.target | ||
]) | ||
|
||
grunt.task.registerTask 'run', 'Run emulator', -> | ||
pcejs.run(this.async(), 'http-server', [packagedir]) | ||
|
||
console.log('serving emulator at http://localhost:8080/') | ||
|
||
grunt.task.registerTask 'romdir', 'Set rom/config/data directory', (romdir) -> | ||
pcejs.run(this.async(), './scripts/a1-romdir.sh', [], PCEJS_ROMDIR: romdir) | ||
|
||
# Alias tasks | ||
grunt.registerTask('rebuild', [ | ||
'make', | ||
'afterbuild' | ||
]) | ||
|
||
# Default task | ||
# grunt.registerTask('default', []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "jspce", | ||
"version": "0.1.0", | ||
"devDependencies": { | ||
"grunt": "~0.4.1", | ||
"lodash": "~1.3.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
util = require('util') | ||
path = require('path') | ||
child_process = require('child_process') | ||
_ = require('lodash') | ||
|
||
# utils | ||
spawnRun = (done, command, args, opts) -> | ||
process = child_process.spawn(command, args, opts) | ||
|
||
process.stdout.setEncoding('utf8') | ||
process.stdout.on('data', (data) -> util.print(data)) | ||
|
||
process.stderr.setEncoding('utf8') | ||
process.stderr.on('data', (data) -> util.error(data)) | ||
|
||
process.on('close', (code) -> done(code)) | ||
|
||
class PCEJSBuild | ||
defaultConfig: | ||
target: 'macplus' | ||
emscripten: true | ||
asmjs: true | ||
optlvl: 'O2' | ||
memory: 256 | ||
prefix: 'build/' | ||
packagedir: 'pce-js/' | ||
outputformat: 'js' | ||
|
||
configFilePath: './pcejs-build-config.json' | ||
|
||
constructor: (@grunt) -> | ||
this.initConfig() | ||
|
||
initConfig: (@config = _.clone(@defaultConfig)) -> | ||
|
||
extendConfig: (extraConfig) -> _.extend(@config, extraConfig) | ||
|
||
# extend config from saved | ||
loadConfig: (path = @configFilePath) -> | ||
try | ||
this.extendConfig(@grunt.file.readJSON(path)) | ||
catch e | ||
console.warn(path+' file not found') | ||
|
||
saveConfig: (path = @configFilePath) -> | ||
try | ||
@grunt.file.write(path, JSON.stringify(@config, undefined, 2)) | ||
catch e | ||
console.error(path+' could not save') | ||
|
||
getEmscriptenFlags: -> | ||
flags = [] | ||
flags.push('-s TOTAL_MEMORY=' + @config.memory*1024*1024) if @config.memory? | ||
flags.push('-s ASM_JS=1') if @config.asmjs | ||
if @config.exportfuncs | ||
flags.push('-s EXPORTED_FUNCTIONS='+JSON.stringify(@config.exportfuncs)+'') | ||
flags.push('-'+@config.optlvl) if @config.optlvl? | ||
flags.join(' ') | ||
|
||
getEnv: -> | ||
env = | ||
PCEJS_PREFIX: path.resolve(@config.prefix) | ||
PCEJS_PACKAGEDIR: path.resolve(@config.packagedir) | ||
PCEJS_TARGET: @config.target | ||
PCEJS_OUTPUT_FORMAT: @config.outputformat | ||
|
||
if @config.emscripten | ||
emflags = this.getEmscriptenFlags() | ||
|
||
env.PCEJS_EMSCRIPTEN = "yes" | ||
env.PCEJS_EMFLAGS = emflags | ||
env.PCEJS_CFLAGS = "-Qunused-arguments -include src/include/pcedeps.h #{emflags}" | ||
env.PCEJS_CONFIGURE = "emconfigure ./configure" | ||
else | ||
env.PCEJS_CFLAGS = "-I/usr/local/opt/emscripten/system/include/emscripten/" | ||
env.PCEJS_CONFIGURE = "./configure" | ||
|
||
return env | ||
|
||
configEnv: (baseEnv) -> _.extend(_.clone(baseEnv), this.getEnv()) | ||
|
||
run: (done, command, args = [], env = {}) -> | ||
spawnRun done, command, args, | ||
cwd: process.env.PWD | ||
env: _.extend(this.configEnv(process.env), env) | ||
|
||
module.exports = PCEJSBuild |
Oops, something went wrong.