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.2/otp_src_28.2.tar.gz" sha256 "b0f6e1273a034e91c4fa6895e8cb84276baf5ca7a23b29da4f04ff9d0419a0c2" license "Apache-2.0" livecheck do url :stable regex(/^OTP[._-]v?(\d+(?:\.\d+)+)$/i) end bottle do sha256 cellar: :any, arm64_tahoe: "74879e1a45ec26bbd78b1d9d35ee7a097f76e6bd366f572bfdb9c34443609cc6" sha256 cellar: :any, arm64_sequoia: "1595b9db3961ad31a97e273719c34f0a86a0243acc1b44bcc0cc83e1dd77751e" sha256 cellar: :any, arm64_sonoma: "c1cea949cdfc7913bf14273fd09f36a3749b5c5db77f05c0c6c3ac4eabf1da62" sha256 cellar: :any, sonoma: "6d6cda25532527bcefdb3d0a9b01c584557af2bd6ff0092af95682e876bb1dd7" sha256 cellar: :any_skip_relocation, arm64_linux: "6609b4f73c02641caa374dac47ec57fc146eec19b4bbd05f997abe857fc93adb" sha256 cellar: :any_skip_relocation, x86_64_linux: "74b1182d2db16e1dfade4c8cbaee9f09c54618ffbb8f887fedf0f70c236062c2" 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.2/otp_doc_html_28.2.tar.gz" mirror "https://fossies.org/linux/misc/otp_doc_html_28.2.tar.gz" sha256 "a07c180e4a9bac49b120f84b1424ccc11666006bb07a59eeef43328c5150ebd7" 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