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 rebuild 1 sha256 cellar: :any, arm64_tahoe: "2a01d4c54b348b0746b97be6ce155d77d29da97b6ed47cc8b1b0f13d3bbc1978" sha256 cellar: :any, arm64_sequoia: "38e8fb994d45ecba83eba95b09d7a6dbaaafe98cf3325218fccd25f6906d06a2" sha256 cellar: :any, arm64_sonoma: "c77b573e91682a3ab7585c3f1dd23a10571420d71d2db95403f647ee1818d01a" sha256 cellar: :any, sonoma: "935827eccb9c4ae4da939020caa39071dad538eb332e9c989bbf84386bd9486c" sha256 cellar: :any_skip_relocation, arm64_linux: "012ed6ff7cff03c31a10bcdcd594f2d2f1ecf3383bfd38b34f0c84917a4bf2b4" sha256 cellar: :any_skip_relocation, x86_64_linux: "8f3d10da557e0d174c7d1c0022b378c95b21547c5bcb478e8d04b95fddb4153d" 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" on_linux do depends_on "mesa-glu" depends_on "zlib-ng-compat" 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