ref: 77d2f0d7571f5f830177189e8ac370f49db99256
dir: /js/Rakefile/
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(' ')} --memory-init-file 0 -s TOTAL_MEMORY=67108864 -s EXPORT_ALL=1 #{EMCC_FLAGS} -o h264bsd_asm.js" end source_files = [ "h264bsd_canvas.js" ] worker_source_files = [ "h264bsd_asm.js", "h264bsd_decoder.js" ] file "h264bsd.min.js" => worker_source_files do sh "uglifyjs #{source_files.join(' ')} -c -m -o h264bsd.min.js" end file "h264bsd_decoder.min.js" => worker_source_files do sh "uglifyjs h264bsd_decoder.js -o _h264bsd_decoder.min.js" sh "cat h264bsd_asm.js > h264bsd_decoder.min.js" sh "cat _h264bsd_decoder.min.js >> h264bsd_decoder.min.js" end task :compress => ["h264bsd.min.js", "h264bsd_decoder.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") FileUtils.rm_f("h264bsd_decoder.min.js") FileUtils.rm_f("_h264bsd_decoder.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", "h264bsd_decoder.min.js"]