class Emscripten < Formula desc "LLVM bytecode to JavaScript compiler" homepage "https://kripken.github.io/emscripten-site/" stable do url "https://github.com/kripken/emscripten/archive/1.37.36.tar.gz" sha256 "b2694e911ea7901f0afdcca74f0f38fe52d1e534358c14051552ba845083e43b" resource "fastcomp" do url "https://github.com/kripken/emscripten-fastcomp/archive/1.37.36.tar.gz" sha256 "9491b3136cdf8799506fa6a7c8c8648b0ab9bfb17d7965950ff02434d0ff802d" end resource "fastcomp-clang" do url "https://github.com/kripken/emscripten-fastcomp-clang/archive/1.37.36.tar.gz" sha256 "3b727be7779d4c6152cace41a1b67d7c43a06c4f5f7e3bffea7300d013323f99" end end bottle do cellar :any sha256 "b802c4e077d0431417357c925eb8a6bf0331bf675a966cfc8484c77119e42bba" => :high_sierra sha256 "79f6fbe651af93b36461c02fb3d9a03abe25d0d319c8305f1e7b54570ae56169" => :sierra sha256 "4c1ace0e74a0632b0eec69e1e8436af74e51af23120d9384747972d05be2806e" => :el_capitan end head do url "https://github.com/kripken/emscripten.git", :branch => "master" resource "fastcomp" do url "https://github.com/kripken/emscripten-fastcomp.git", :branch => "master" end resource "fastcomp-clang" do url "https://github.com/kripken/emscripten-fastcomp-clang.git", :branch => "master" end end needs :cxx11 depends_on "python@2" if MacOS.version <= :snow_leopard depends_on "cmake" => :build depends_on "node" depends_on "closure-compiler" => :optional depends_on "yuicompressor" def install ENV.cxx11 # OSX doesn't provide a "python2" binary so use "python" instead. python2_shebangs = `grep --recursive --files-with-matches ^#!/usr/bin/.*python2$ #{buildpath}` python2_shebang_files = python2_shebangs.lines.sort.uniq python2_shebang_files.map! { |f| Pathname(f.chomp) } python2_shebang_files.reject! &:symlink? inreplace python2_shebang_files, %r{^(#!/usr/bin/.*python)2$}, "\\1" # All files from the repository are required as emscripten is a collection # of scripts which need to be installed in the same layout as in the Git # repository. libexec.install Dir["*"] (buildpath/"fastcomp").install resource("fastcomp") (buildpath/"fastcomp/tools/clang").install resource("fastcomp-clang") cmake_args = std_cmake_args.reject { |s| s["CMAKE_INSTALL_PREFIX"] } cmake_args = [ "-DCMAKE_BUILD_TYPE=Release", "-DCMAKE_INSTALL_PREFIX=#{libexec}/llvm", "-DLLVM_TARGETS_TO_BUILD='X86;JSBackend'", "-DLLVM_INCLUDE_EXAMPLES=OFF", "-DLLVM_INCLUDE_TESTS=OFF", "-DCLANG_INCLUDE_TESTS=OFF", "-DOCAMLFIND=/usr/bin/false", "-DGO_EXECUTABLE=/usr/bin/false", ] mkdir "fastcomp/build" do system "cmake", "..", *cmake_args system "make" system "make", "install" end %w[em++ em-config emar emcc emcmake emconfigure emlink.py emmake emranlib emrun emscons].each do |emscript| bin.install_symlink libexec/emscript end end def caveats; <<~EOS Manually set LLVM_ROOT to #{opt_libexec}/llvm/bin and comment out BINARYEN_ROOT in ~/.emscripten after running `emcc` for the first time. EOS end test do system bin/"emcc" assert_predicate testpath/".emscripten", :exist?, "Failed to create sample config" end end