class Sevenzip < Formula desc "7-Zip is a file archiver with a high compression ratio" homepage "https://7-zip.org" url "https://7-zip.org/a/7z2501-src.tar.xz" version "25.01" sha256 "ed087f83ee789c1ea5f39c464c55a5c9d4008deb0efe900814f2df262b82c36e" license all_of: ["LGPL-2.1-or-later", "BSD-3-Clause"] head "https://github.com/ip7z/7zip.git", branch: "main" livecheck do url "https://7-zip.org/download.html" regex(/>\s*Download\s+7-Zip\s+v?(\d+(?:\.\d+)+)\s+\([^)]+?\)/im) end no_autobump! because: :incompatible_version_format bottle do rebuild 1 sha256 cellar: :any, arm64_tahoe: "b2510dbf7cf321890d1f7434195ab966b4e24fb6439b149b5bd4c53cb0fd830a" sha256 cellar: :any, arm64_sequoia: "164df59691f0b22b908312d7352a048c348fbc5ca0f4cb01e90a0d588436af26" sha256 cellar: :any, arm64_sonoma: "061da1460500f02df5cd42a12f5301f76b7b4684fb75a76e590278b84445396c" sha256 cellar: :any, arm64_ventura: "640b7a4fe0208c77a79dd47d960f52b3f2e75d618615e16708b644220b6943df" sha256 cellar: :any, sonoma: "eb1f49451241d795505ed4c2d42d67a6f994cda22f151cf3acc51db6c52100a3" sha256 cellar: :any, ventura: "0764395d3853ff416c9b5b1d94578cd0a2c6a29b7ba7875066ecc36d70d156b9" sha256 cellar: :any_skip_relocation, arm64_linux: "38ddcf4c4583824aa90ee0efaee9a5a9c3b51f30fc11f5406afcd8b59ce1983f" sha256 cellar: :any_skip_relocation, x86_64_linux: "bdacdbbc0f28b2915b38c8e27d3a59ce64d7b5a23db36ad29f8f8fb5fc3dbdaa" end def install mac_suffix = Hardware::CPU.intel? ? "x64" : Hardware::CPU.arch mk_suffix, directory = if OS.mac? ["mac_#{mac_suffix}", "m_#{mac_suffix}"] else ["gcc", "g"] end cd "CPP/7zip/Bundles/Alone2" do system "make", "-f", "../../cmpl_#{mk_suffix}.mak", "DISABLE_RAR_COMPRESS=1" # Cherry pick the binary manually. This should be changed to something # like `make install' if the upstream adds an install target. # See: https://sourceforge.net/p/sevenzip/discussion/45797/thread/1d5b04f2f1/ bin.install "b/#{directory}/7zz" end cd "CPP/7zip/Bundles/Format7zF" do system "make", "-f", "../../cmpl_#{mk_suffix}.mak", "DISABLE_RAR_COMPRESS=1" lib.install "b/#{directory}/7z.so" lib.install_symlink "7z.so" => shared_library("lib7z") end end test do (testpath/"foo.txt").write("hello world!\n") system bin/"7zz", "a", "-t7z", "foo.7z", "foo.txt" system bin/"7zz", "e", "foo.7z", "-oout" assert_equal "hello world!\n", (testpath/"out/foo.txt").read (testpath/"test7z.c").write <<~C #include #include #include typedef int32_t HRESULT; #define S_OK ((HRESULT)0L) #define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0) typedef uint16_t VARTYPE; #define VT_UI4 19 typedef struct tagPROPVARIANT { VARTYPE vt; uint16_t wReserved1; uint16_t wReserved2; uint16_t wReserved3; union { uint32_t ulVal; int32_t lVal; uint64_t uhVal; int64_t hVal; int16_t iVal; uint16_t uiVal; char cVal; unsigned char bVal; int intVal; unsigned int uintVal; }; } PROPVARIANT; typedef int PROPID; HRESULT GetModuleProp(PROPID propID, PROPVARIANT *value); int main(void) { PROPVARIANT val; memset(&val, 0, sizeof(val)); HRESULT hr = GetModuleProp(1, &val); // 1 = kVersion if (!SUCCEEDED(hr) || val.vt != VT_UI4) { printf("GetModuleProp failed\\n"); return 1; } unsigned major = val.ulVal >> 16; unsigned minor = val.ulVal & 0xFFFF; printf("%02u.%02u", major, minor); return 0; } C system ENV.cc, "test7z.c", "-L#{lib}", "-l7z", "-o", "test7z" output = shell_output("./test7z").strip assert_equal version.to_s, output end end