class ErlangAT27 < 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-27.3.4.6/otp_src_27.3.4.6.tar.gz" sha256 "658529f94cc5b8833907aa680a5e979e67c32dd6ebba69ed3b90b95f526ccda2" license "Apache-2.0" livecheck do url :stable regex(/^OTP[._-]v?(27(?:\.\d+)+)$/i) end bottle do sha256 cellar: :any, arm64_tahoe: "67deb9381da6446e648cff696674eb4cb680ba093bbe33408fca537e5b45f70d" sha256 cellar: :any, arm64_sequoia: "3d0e31c6b65ea4e35fdbad7e6509d14bc1e4bb74c71f001c982655bfd9c1a70d" sha256 cellar: :any, arm64_sonoma: "432b10677cbd0d0f51c1c74060d06e40d63ea214793a85de8eca1272b2f527eb" sha256 cellar: :any, sonoma: "4694262fab0028d5df46732891018657d83196d0560bcdd0397ac717d59ee593" sha256 cellar: :any_skip_relocation, arm64_linux: "22699013d000d47fb5e487749a6960ab8ad721c286310563f8f7a3995107df11" sha256 cellar: :any_skip_relocation, x86_64_linux: "390376a0a1e8f525157a940722ed11d66aa5588d565ec54b96f8f999d99fd192" end keg_only :versioned_formula 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-27.3.4.6/otp_doc_html_27.3.4.6.tar.gz" mirror "https://fossies.org/linux/misc/otp_doc_html_27.3.4.6.tar.gz" sha256 "5405323e8ffc2b151faeff0488ec9b73ec9ce9e634cce0cbd4df9112b29d54a7" 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.37.3/ex_doc_otp_26" sha256 "b127190c72fe456ee4c291d4ca94eb955d0b3c0ca2d061481f65cbf0975e13dc" 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