jackett 0.22.1382
[Homebrew/homebrew-core.git] / Formula / c / creduce.rb
blobd89074b9e512ec46991050840e41f21f529f63f2
1 class Creduce < Formula
2   desc "Reduce a C/C++ program while keeping a property of interest"
3   homepage "https://github.com/csmith-project/creduce"
4   license "BSD-3-Clause"
5   revision 5
6   head "https://github.com/csmith-project/creduce.git", branch: "master"
8   # Remove when patches are no longer needed.
9   stable do
10     # TODO: Check if we can use unversioned `llvm` at version bump.
11     url "https://github.com/csmith-project/creduce/archive/refs/tags/creduce-2.10.0.tar.gz"
12     sha256 "de320cd83bd77ec1a591f36dd6a4d0d1c47a0a28d850a6ebd348540feeab2297"
14     # Use shared libraries.
15     # Remove with the next release.
16     patch do
17       url "https://github.com/csmith-project/creduce/commit/e9bb8686c5ef83a961f63744671c5e70066cba4e.patch?full_index=1"
18       sha256 "d5878a2c8fb6ebc5a43ad25943a513ff5226e42b842bb84f466cdd07d7bd626a"
19     end
21     # Port to LLVM 15.0.
22     # Remove with the next release.
23     patch do
24       url "https://github.com/csmith-project/creduce/commit/e507cca4ccb32585c5692d49b8d907c1051c826c.patch?full_index=1"
25       sha256 "71d772bf7d48a46019a07e38c04559c0d517bf06a07a26d8e8101273e1fabd8f"
26     end
27     patch do
28       url "https://github.com/csmith-project/creduce/commit/8d56bee3e1d2577fc8afd2ecc03b1323d6873404.patch?full_index=1"
29       sha256 "d846e2a04c211f2da9a87194181e3644324c933ec48a7327a940e4f4b692cbae"
30     end
32     # Port to LLVM 16.0
33     # Remove with the next release
34     patch do
35       url "https://github.com/csmith-project/creduce/commit/8ab9a69caf13ce24172737e8bfd09de51a1ecb6a.patch?full_index=1"
36       sha256 "fb5dfed2f0255ea524f0c0074a5b162ae2acbcabb9ff1f31adf45ca025dd4419"
37     end
39     # Port to LLVM 17.0
40     # Remove with the next release
41     patch do
42       url "https://github.com/csmith-project/creduce/commit/a4f6cf3689d44513fd944b1090ca8fd6d5ae8cd5.patch?full_index=1"
43       sha256 "2752eba5204de7f0eeac215bdabc2fb02441b79cbd17e5584e021cc29b8521c5"
44     end
46     # Port to LLVM 18.0
47     # Remove with the next release
48     patch do
49       url "https://github.com/csmith-project/creduce/commit/98baa64699aedb943520f175a5e731582df2806f.patch?full_index=1"
50       sha256 "7a5a04ed394de464c09174997020a6cca0cc05154f58a3e855f20c8423fc8865"
51     end
52   end
54   livecheck do
55     url :stable
56     regex(/^(?:creduce[._-])?v?(\d+(?:\.\d+)+)$/i)
57   end
59   bottle do
60     sha256 cellar: :any,                 arm64_sequoia: "752bcd060b5ab5d04efc96dfd67d9128e6fd66a2d9b14b5e59735ba758d2d61b"
61     sha256 cellar: :any,                 arm64_sonoma:  "c489f889cd95d689d226e4965582120a96b1119eb4fb2902c481c6b9338122aa"
62     sha256 cellar: :any,                 arm64_ventura: "56cd23ed4e8cdf7a2928f740332b07eed6f3d5b8a22416cf30ab746fbecbe0a7"
63     sha256 cellar: :any,                 sonoma:        "487aebd04b8609040875fb262122692867f20507b7c71e25a8914a920521242d"
64     sha256 cellar: :any,                 ventura:       "937ef76ad140358b5458b394b8376746972ce80915e3fa91fc7b6065a94bc5ef"
65     sha256 cellar: :any_skip_relocation, x86_64_linux:  "299566ba27c179eb7e3aa48dfc766b6b3bfe6a4892a929b5777aede0b4e54a05"
66   end
68   depends_on "astyle"
69   depends_on "llvm@18" # LLVM 19 issue: https://github.com/csmith-project/creduce/issues/276
71   uses_from_macos "flex" => :build
72   uses_from_macos "perl"
74   resource "Exporter::Lite" do
75     url "https://cpan.metacpan.org/authors/id/N/NE/NEILB/Exporter-Lite-0.08.tar.gz"
76     sha256 "c05b3909af4cb86f36495e94a599d23ebab42be7a18efd0d141fc1586309dac2"
77   end
79   resource "File::Which" do
80     url "https://cpan.metacpan.org/authors/id/P/PL/PLICEASE/File-Which-1.23.tar.gz"
81     sha256 "b79dc2244b2d97b6f27167fc3b7799ef61a179040f3abd76ce1e0a3b0bc4e078"
82   end
84   resource "Getopt::Tabular" do
85     url "https://cpan.metacpan.org/authors/id/G/GW/GWARD/Getopt-Tabular-0.3.tar.gz"
86     sha256 "9bdf067633b5913127820f4e8035edc53d08372faace56ba6bfa00c968a25377"
87   end
89   resource "Regexp::Common" do
90     url "https://cpan.metacpan.org/authors/id/A/AB/ABIGAIL/Regexp-Common-2017060201.tar.gz"
91     sha256 "ee07853aee06f310e040b6bf1a0199a18d81896d3219b9b35c9630d0eb69089b"
92   end
94   resource "URI::Escape" do
95     on_linux do
96       url "https://cpan.metacpan.org/authors/id/E/ET/ETHER/URI-1.72.tar.gz"
97       sha256 "35f14431d4b300de4be1163b0b5332de2d7fbda4f05ff1ed198a8e9330d40a32"
98     end
99   end
101   def install
102     ENV.prepend_create_path "PERL5LIB", libexec/"lib/perl5"
104     llvm = deps.find { |dep| dep.name.match?(/^llvm(@\d+)?$/) }
105                .to_formula
106     # Avoid ending up with llvm's Cellar path hard coded.
107     ENV["CLANG_FORMAT"] = llvm.opt_bin/"clang-format"
109     resources.each do |r|
110       r.stage do
111         system "perl", "Makefile.PL", "INSTALL_BASE=#{libexec}"
112         system "make"
113         system "make", "install"
114       end
115     end
117     # Work around build failure seen on Apple Clang 13.1.6 by using LLVM Clang
118     # Undefined symbols for architecture x86_64:
119     #   "std::__1::basic_stringbuf<char, std::__1::char_traits<char>, ...
120     if DevelopmentTools.clang_build_version == 1316
121       ENV["CC"] = llvm.opt_bin/"clang"
122       ENV["CXX"] = llvm.opt_bin/"clang++"
123     end
125     system "./configure", *std_configure_args,
126                           "--disable-silent-rules",
127                           "--bindir=#{libexec}"
128     system "make"
129     system "make", "install"
131     (bin/"creduce").write_env_script("#{libexec}/creduce", PERL5LIB: ENV["PERL5LIB"])
132   end
134   test do
135     (testpath/"test1.c").write <<~C
136       int main() {
137         printf("%d\n", 0);
138       }
139     C
140     (testpath/"test1.sh").write <<~BASH
141       #!/usr/bin/env bash
143       #{ENV.cc} -Wall #{testpath}/test1.c 2>&1 | grep 'Wimplicit-function-declaration'
144     BASH
146     chmod 0755, testpath/"test1.sh"
147     system bin/"creduce", "test1.sh", "test1.c"
148   end