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.7/otp_src_27.3.4.7.tar.gz" sha256 "77e133c0662e89adbc5ce785f652c15d8cd8df1b7c1651ab605b274e196ec555" license "Apache-2.0" livecheck do url :stable regex(/^OTP[._-]v?(27(?:\.\d+)+)$/i) end bottle do sha256 cellar: :any, arm64_tahoe: "ba2140e43a13a8e347f7febbf4b899704a7ceb98eb7ae4c95487e428246dd0c2" sha256 cellar: :any, arm64_sequoia: "d960523890e1fd2504ca3b76e585410ff6ea7fa5c289e331776e945c3832c04d" sha256 cellar: :any, arm64_sonoma: "60e689576926e3b70dbad9a5982e2d709c0cdca12744381dfe04e56d2dd03261" sha256 cellar: :any, sonoma: "1d0a3b6f901050cb07bcc306d8082ae90fee18f7664ec1558bea2baa3b03607f" sha256 cellar: :any_skip_relocation, arm64_linux: "fff0b71970c7db1853fd9241e227230a8987bf2d0b63b12b5630b6acb650c470" sha256 cellar: :any_skip_relocation, x86_64_linux: "0cecd24c634082bc46d7f01b360539d5f2ed0de39e65d7002870479b75cb9a16" 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.7/otp_doc_html_27.3.4.7.tar.gz" mirror "https://fossies.org/linux/misc/otp_doc_html_27.3.4.7.tar.gz" sha256 "31ddcdb9b216e83c8dcc8975aeaf75492900bd9aede73d7cb4177300fe28fa1c" 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