ref: 117a053f900e26959aee54834081902073a012a9
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 directory "min" full_source_files = [ "h264bsd_asm.js", "h264bsd_decoder.js", "h264bsd_canvas.js" ] file "min/h264bsd_full.min.js" => full_source_files + ["min"] do sh "uglifyjs #{full_source_files.join(' ')} -c -m -o min/h264bsd_full.min.js" end canvas_source_files = [ "h264bsd_canvas.js" ] file "min/h264bsd_canvas.min.js" => canvas_source_files + ["min"] do sh "uglifyjs #{canvas_source_files.join(' ')} -c -m -o min/h264bsd_canvas.min.js" end worker_source_files = [ "h264bsd_asm.js", "h264bsd_decoder.js", "h264bsd_worker.js" ] file "min/h264bsd_worker.min.js" => worker_source_files + ["min"] do sh "uglifyjs #{worker_source_files.join(' ')} -c -m -o min/h264bsd_worker.min.js" end task :compress => ["min/h264bsd_full.min.js", "min/h264bsd_canvas.min.js", "min/h264bsd_worker.min.js"] task :clean do o_files.each{|o| FileUtils.rm_f(o)} FileUtils.rm_f("h264bsd_asm.js") FileUtils.rm_f("min") 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, :compress]