Skip to content

Commit

Permalink
build system improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jsdf committed Oct 29, 2013
1 parent 3551802 commit b8188c6
Show file tree
Hide file tree
Showing 17 changed files with 375 additions and 50 deletions.
7 changes: 7 additions & 0 deletions .gitignore
@@ -0,0 +1,7 @@
node_modules/
roms
roms*/
pcejs-build-config.json
build/
build-native/
pce-js/
77 changes: 77 additions & 0 deletions Gruntfile.coffee
@@ -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', [])
10 changes: 9 additions & 1 deletion Makefile.in
@@ -1,5 +1,7 @@
# Makefile

EMSCRIPTEN = @EMSCRIPTEN@

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
Expand All @@ -22,6 +24,11 @@ QP = @
QR = @
endif

ifneq "$(EMSCRIPTEN)" "yes"
ARFLAGS = -rc
else
ARFLAGS = rc
endif

all: all2

Expand Down Expand Up @@ -205,7 +212,8 @@ dist-extra:
%.a:
$(QP)echo " AR $@"
$(QR)rm -f $@
$(QR)$(AR) -rc $@ $^
$(QP)echo "$(AR) $(ARFLAGS) $@ $^"
$(QR)$(AR) $(ARFLAGS) $@ $^
$(QP)echo " RANLIB $@"
$(QR)$(RANLIB) $@

Expand Down
51 changes: 30 additions & 21 deletions configure
Expand Up @@ -622,6 +622,7 @@ ac_includes_default="\

ac_subst_vars='LTLIBOBJS
LIBOBJS
EMSCRIPTEN
PCE_DIR_DATA
PCE_DIR_ETC
PCE_READLINE_LIBS
Expand Down Expand Up @@ -4607,15 +4608,17 @@ if test "x$no_x" = "xyes" ; then
PCE_X11_LIBS=""
else
PCE_ENABLE_X11=1
if test -n "$x_includes" ; then
PCE_X11_CFLAGS="-I$x_includes"
else
PCE_X11_CFLAGS=""
fi
if test -n "$x_libraries" ; then
PCE_X11_LIBS="-L$x_libraries -lX11"
else
PCE_X11_LIBS="-lX11"
if test "x$EMSCRIPTEN" != "xyes" ; then
if test -n "$x_includes" ; then
PCE_X11_CFLAGS="-I$x_includes"
else
PCE_X11_CFLAGS=""
fi
if test -n "$x_libraries" ; then
PCE_X11_LIBS="-L$x_libraries -lX11"
else
PCE_X11_LIBS="-lX11"
fi
fi
$as_echo "#define PCE_ENABLE_X11 1" >>confdefs.h
Expand Down Expand Up @@ -4657,32 +4660,34 @@ $as_echo "no (detected)" >&6; }
fi
if test "x$PCE_ENABLE_SDL" != "x0" ; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for static SDL" >&5
if test "x$EMSCRIPTEN" != "xyes" ; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for static SDL" >&5
$as_echo_n "checking for static SDL... " >&6; }
# Check whether --enable-static-sdl was given.
# Check whether --enable-static-sdl was given.
if test "${enable_static_sdl+set}" = set; then :
enableval=$enable_static_sdl;
if test "x$enableval" = "xyes" ; then
PCE_SDL_LIBS=`sdl-config --static-libs`
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes (forced)" >&5
if test "x$enableval" = "xyes" ; then
PCE_SDL_LIBS=`sdl-config --static-libs`
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes (forced)" >&5
$as_echo "yes (forced)" >&6; }
else
PCE_SDL_LIBS=`sdl-config --libs`
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no (forced)" >&5
else
PCE_SDL_LIBS=`sdl-config --libs`
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no (forced)" >&5
$as_echo "no (forced)" >&6; }
fi
fi
else
PCE_SDL_LIBS=`sdl-config --libs`
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no (default)" >&5
PCE_SDL_LIBS=`sdl-config --libs`
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no (default)" >&5
$as_echo "no (default)" >&6; }
fi
PCE_SDL_CFLAGS=`sdl-config --cflags`
PCE_SDL_CFLAGS=`sdl-config --cflags`
fi
$as_echo "#define PCE_ENABLE_SDL 1" >>confdefs.h
fi
Expand Down Expand Up @@ -5578,6 +5583,8 @@ _ACEOF
emu1=""
emu2=""
Expand Down Expand Up @@ -7041,3 +7048,5 @@ echo " Sound drivers built: $sound1"
echo " Sound drivers not built:$sound2"
echo " Enabled options: $option1"
echo " Disabled options: $option2"
echo
echo " EMSCRIPTEN: $EMSCRIPTEN"
64 changes: 36 additions & 28 deletions configure.in
Expand Up @@ -255,15 +255,17 @@ if test "x$no_x" = "xyes" ; then
PCE_X11_LIBS=""
else
PCE_ENABLE_X11=1
if test -n "$x_includes" ; then
PCE_X11_CFLAGS="-I$x_includes"
else
PCE_X11_CFLAGS=""
fi
if test -n "$x_libraries" ; then
PCE_X11_LIBS="-L$x_libraries -lX11"
else
PCE_X11_LIBS="-lX11"
if test "x$EMSCRIPTEN" != "xyes" ; then
if test -n "$x_includes" ; then
PCE_X11_CFLAGS="-I$x_includes"
else
PCE_X11_CFLAGS=""
fi
if test -n "$x_libraries" ; then
PCE_X11_LIBS="-L$x_libraries -lX11"
else
PCE_X11_LIBS="-lX11"
fi
fi
AC_DEFINE(PCE_ENABLE_X11)
fi
Expand Down Expand Up @@ -295,25 +297,27 @@ AC_ARG_WITH(sdl,
]
)
if test "x$PCE_ENABLE_SDL" != "x0" ; then
AC_MSG_CHECKING([for static SDL])
AC_ARG_ENABLE(static-sdl,
[AS_HELP_STRING([--enable-static-sdl], [Link to static SDL [no]])],
[
if test "x$enableval" = "xyes" ; then
PCE_SDL_LIBS=`sdl-config --static-libs`
AC_MSG_RESULT([yes (forced)])
else
PCE_SDL_LIBS=`sdl-config --libs`
AC_MSG_RESULT([no (forced)])
fi
],
[
PCE_SDL_LIBS=`sdl-config --libs`
AC_MSG_RESULT([no (default)])
]
)

PCE_SDL_CFLAGS=`sdl-config --cflags`
if test "x$EMSCRIPTEN" != "xyes" ; then
AC_MSG_CHECKING([for static SDL])
AC_ARG_ENABLE(static-sdl,
[AS_HELP_STRING([--enable-static-sdl], [Link to static SDL [no]])],
[
if test "x$enableval" = "xyes" ; then
PCE_SDL_LIBS=`sdl-config --static-libs`
AC_MSG_RESULT([yes (forced)])
else
PCE_SDL_LIBS=`sdl-config --libs`
AC_MSG_RESULT([no (forced)])
fi
],
[
PCE_SDL_LIBS=`sdl-config --libs`
AC_MSG_RESULT([no (default)])
]
)

PCE_SDL_CFLAGS=`sdl-config --cflags`
fi
AC_DEFINE(PCE_ENABLE_SDL)
fi
AC_SUBST(PCE_ENABLE_SDL)
Expand Down Expand Up @@ -900,6 +904,8 @@ AC_DEFINE_UNQUOTED(PCE_DIR_ETC, "$pce_etcdir")
AC_DEFINE_UNQUOTED(PCE_DIR_DATA, "$pce_datdir")


AC_SUBST(EMSCRIPTEN)

dnl --------------------------------------------------------------------------

emu1=""
Expand Down Expand Up @@ -1084,3 +1090,5 @@ echo " Sound drivers built: $sound1"
echo " Sound drivers not built:$sound2"
echo " Enabled options: $option1"
echo " Disabled options: $option2"
echo
echo " EMSCRIPTEN: $EMSCRIPTEN"
8 changes: 8 additions & 0 deletions package.json
@@ -0,0 +1,8 @@
{
"name": "jspce",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.1",
"lodash": "~1.3.1"
}
}
87 changes: 87 additions & 0 deletions pcejs_build.coffee
@@ -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

0 comments on commit b8188c6

Please sign in to comment.