shithub: h264bsd

ref: 3e6e13f8f0a30b18eda44a507946b2608cdeebf6
dir: /js/Rakefile/

View raw version
EMCC_FLAGS = ENV["EMCC_FLAGS"] || "-O3 -D_ERROR_PRINT"

EMCC_FLAGS = "-O0 -g4 -D_ASSERT_USED -D_ERROR_PRINT" if ENV["DEBUG"]

rule '.o' => ['.c'] do |t|
  sh "emcc #{t.source} -c #{EMCC_FLAGS} -o #{t.name}"
end

o_files = FileList["../src/*.c"].gsub(/c$/, 'o')

export_functions = [
	"_h264bsdAlloc",
	"_h264bsdFree",
	"_h264bsdInit",
	"_h264bsdDecode",
	"_h264bsdShutdown",
	"_h264bsdNextOutputPicture",
	"_h264bsdNextOutputPictureRGBA",
	"_h264bsdPicWidth",
	"_h264bsdPicHeight",
	"_h264bsdCroppingParams",
	"_h264bsdCheckValidParamSets",
	"_h264bsdConvertToRGBA",
]

file "h264bsd_asm.js" => o_files do
	sh "emcc #{o_files.join(' ')} -s TOTAL_MEMORY=268435456 -s EXPORTED_FUNCTIONS='[\"#{export_functions.join('", "')}\"]' #{EMCC_FLAGS} -o h264bsd_asm.js"
end

source_files = [
	"h264bsd_asm.js",
	"h264bsd_decoder.js",
	"h264bsd_canvas.js",
]

file "h264bsd.min.js" => source_files do
	sh "uglifyjs #{source_files.join(' ')} -c -o h264bsd.min.js"
end

task :compress => ["h264bsd.min.js"]

task :clean do
	o_files.each{|o| FileUtils.rm_f(o)}
	FileUtils.rm_f("h264bsd_asm.js")
	FileUtils.rm_f("h264bsd.min.js")
end

desc "Check for prereq tools"
task :setup do
	sh("emcc --version") { |ok, res| fail("Can't find emscripten binaries.") unless ok }
	sh("uglifyjs --version") { |ok, res| fail("Can't find UglifyJS2 tool for minification.") unless ok }
	puts("Ready to go")
end

task :default => [:setup, "h264bsd.min.js"]