class Dmd < Formula desc "D programming language compiler for macOS" homepage "https://dlang.org/" license "BSL-1.0" stable do # make sure resources also use the same version url "https://github.com/dlang/dmd/archive/v2.101.2.tar.gz" sha256 "536ff1ec29be612c16db84cc10fdbf5c669d7f3c22eda66e53c0618505059576" resource "phobos" do url "https://github.com/dlang/phobos/archive/v2.101.2.tar.gz" sha256 "3295a62b14a1375802aaf4c9bcbaa2a7953912bd5eb6eb42704bb2a0452d71ca" end resource "tools" do url "https://github.com/dlang/tools/archive/v2.101.2.tar.gz" sha256 "89fb5b1090ef66413928ef5036bd171fce1de24f91c60c9e7f66ab8954b39108" end end bottle do sha256 ventura: "b4c272b96a0840b79065f74b08287db5e58795833aefc093d79f767785c159ae" sha256 monterey: "897435edb3ce1f47f09e6740ef2ea39d952b4725a4e25e57e15f2e8395754e86" sha256 big_sur: "0ffa1a373440cba52824818ef9c058c3764b71982ac03bfa85a607205e7a94f1" sha256 x86_64_linux: "35704087425f2c3b578ab27887bbb4d40ad87ec54ee8f4a33d1290e80851bb8c" end head do url "https://github.com/dlang/dmd.git", branch: "master" resource "phobos" do url "https://github.com/dlang/phobos.git", branch: "master" end resource "tools" do url "https://github.com/dlang/tools.git", branch: "master" end end depends_on "ldc" => :build depends_on arch: :x86_64 def install dmd_make_args = %W[ INSTALL_DIR=#{prefix} SYSCONFDIR=#{etc} HOST_DMD=#{Formula["ldc"].opt_bin/"ldmd2"} ENABLE_RELEASE=1 VERBOSE=1 ] system "ldc2", "compiler/src/build.d", "-of=compiler/src/build" system "./compiler/src/build", *dmd_make_args make_args = %W[ INSTALL_DIR=#{prefix} MODEL=64 BUILD=release DMD_DIR=#{buildpath} DRUNTIME_PATH=#{buildpath}/druntime PHOBOS_PATH=#{buildpath}/phobos -f posix.mak ] (buildpath/"phobos").install resource("phobos") system "make", "-C", "phobos", "VERSION=#{buildpath}/VERSION", *make_args resource("tools").stage do inreplace "posix.mak", "install: $(TOOLS) $(CURL_TOOLS)", "install: $(TOOLS) $(ROOT)/dustmite" system "make", "install", *make_args end kernel_name = OS.mac? ? "osx" : OS.kernel_name.downcase bin.install "generated/#{kernel_name}/release/64/dmd" pkgshare.install "compiler/samples" man.install Dir["compiler/docs/man/*"] (include/"dlang/dmd").install Dir["druntime/import/*"] cp_r ["phobos/std", "phobos/etc"], include/"dlang/dmd" lib.install Dir["druntime/**/libdruntime.*", "phobos/**/libphobos2.*"] (buildpath/"dmd.conf").write <<~EOS [Environment] DFLAGS=-I#{opt_include}/dlang/dmd -L-L#{opt_lib} EOS etc.install "dmd.conf" end # Previous versions of this formula may have left in place an incorrect # dmd.conf. If it differs from the newly generated one, move it out of place # and warn the user. def install_new_dmd_conf conf = etc/"dmd.conf" # If the new file differs from conf, etc.install drops it here: new_conf = etc/"dmd.conf.default" # Else, we're already using the latest version: return unless new_conf.exist? backup = etc/"dmd.conf.old" opoo "An old dmd.conf was found and will be moved to #{backup}." mv conf, backup mv new_conf, conf end def post_install install_new_dmd_conf end test do system bin/"dmd", "-fPIC", pkgshare/"samples/hello.d" system "./hello" end end