class Erlang < Formula desc "Programming language for highly scalable real-time systems" homepage "https://www.erlang.org/" # Download tarball from GitHub; it is served faster than the official tarball. # Don't forget to update the documentation resource along with the url! url "https://github.com/erlang/otp/releases/download/OTP-28.3.1/otp_src_28.3.1.tar.gz" sha256 "faf7293df4aaf13ae297508597d3f758353b952dcc99dd88483993cd0548ea12" license "Apache-2.0" livecheck do url :stable regex(/^OTP[._-]v?(\d+(?:\.\d+)+)$/i) end bottle do sha256 cellar: :any, arm64_tahoe: "5d3c49d68da9c5ffdc7155ff31113ce93d5de9c5e097d71f66f2e6a77bee6c73" sha256 cellar: :any, arm64_sequoia: "21ff36f7889009200cd946aaecb1300b99052a62e47a4f1124fb6b99f4ab1842" sha256 cellar: :any, arm64_sonoma: "d0a75d20678d697460cc133a5a7ee9d9945c4cf94fcd334db80f51d977350e67" sha256 cellar: :any, sonoma: "f53fc8dca78b7349d056eb6468fde74f95ed1e2fe0af32b8a20fac22a0107d4f" sha256 cellar: :any_skip_relocation, arm64_linux: "04fd8fdd323db9742a565806fe4359f432780e0c35766a686b1afa7028983800" sha256 cellar: :any_skip_relocation, x86_64_linux: "b07f7820e0cf84efb969e85554b67953178f38fa70b1d2624515cfade2a03c10" end head do url "https://github.com/erlang/otp.git", branch: "master" depends_on "autoconf" => :build depends_on "libtool" => :build end depends_on "openssl@3" depends_on "unixodbc" depends_on "wxwidgets@3.2" # for GUI apps like observer uses_from_macos "libxslt" => :build uses_from_macos "ncurses" uses_from_macos "zlib" on_linux do depends_on "mesa-glu" end resource "html" do url "https://github.com/erlang/otp/releases/download/OTP-28.3.1/otp_doc_html_28.3.1.tar.gz" mirror "https://fossies.org/linux/misc/otp_doc_html_28.3.1.tar.gz" sha256 "9ffb9235b0b311cebe45f5b8d923720cc860d231376c83340f68755eba3ca1a6" livecheck do formula :parent end end # https://github.com/erlang/otp/blob/OTP-#{version}/make/ex_doc_link resource "ex_doc" do url "https://github.com/elixir-lang/ex_doc/releases/download/v0.38.1/ex_doc_otp_27" sha256 "4aaafd13d056aeeca8b23a016b330114947c8d33ea657c22f637259e626e701e" end def install ex_doc_url = (buildpath/"make/ex_doc_link").read.strip odie "`ex_doc` resource needs updating!" if ex_doc_url != resource("ex_doc").url odie "html resource needs to be updated" if version != resource("html").version # Unset these so that building wx, kernel, compiler and # other modules doesn't fail with an unintelligible error. %w[LIBS FLAGS AFLAGS ZFLAGS].each { |k| ENV.delete("ERL_#{k}") } # Do this if building from a checkout to generate configure system "./otp_build", "autoconf" unless File.exist? "configure" wxwidgets = deps.find { |dep| dep.name.match?(/^wxwidgets(@\d+(\.\d+)*)?$/) }.to_formula wx_config = wxwidgets.opt_bin/"wx-config-#{wxwidgets.version.major_minor}" args = %W[ --enable-dynamic-ssl-lib --with-odbc=#{Formula["unixodbc"].opt_prefix} --with-ssl=#{Formula["openssl@3"].opt_prefix} --without-javac --with-wx-config=#{wx_config} ] if OS.mac? args << "--enable-darwin-64bit" args << "--enable-kernel-poll" args << "--with-dynamic-trace=dtrace" if MacOS::CLT.installed? end # The definition of `WX_CC` does not use our configuration of `--with-wx-config`, unfortunately. inreplace "lib/wx/configure", "WX_CC=`wx-config --cc`", "WX_CC=`#{wx_config} --cc`" system "./configure", *std_configure_args, *args system "make" system "make", "install" resource("ex_doc").stage do |r| (buildpath/"bin").install File.basename(r.url) => "ex_doc" end chmod "+x", "bin/ex_doc" # Build the doc chunks (manpages are also built by default) ENV.deparallelize { system "make", "docs", "install-docs", "DOC_TARGETS=chunks man" } doc.install resource("html") end def caveats <<~EOS Man pages can be found in: #{opt_lib}/erlang/man Access them with `erl -man`, or add this directory to MANPATH. EOS end test do system bin/"erl", "-noshell", "-eval", "crypto:start().", "-s", "init", "stop" (testpath/"factorial").write <<~EOS #!#{bin}/escript %% -*- erlang -*- %%! -smp enable -sname factorial -mnesia debug verbose main([String]) -> try N = list_to_integer(String), F = fac(N), io:format("factorial ~w = ~w\n", [N,F]) catch _:_ -> usage() end; main(_) -> usage(). usage() -> io:format("usage: factorial integer\n"). fac(0) -> 1; fac(N) -> N * fac(N-1). EOS chmod 0755, "factorial" assert_match "usage: factorial integer", shell_output("./factorial") assert_match "factorial 42 = 1405006117752879898543142606244511569936384000000000", shell_output("./factorial 42") end end