class Libmagic < Formula desc "Implementation of the file(1) command" homepage "https://www.darwinsys.com/file/" url "ftp://ftp.astron.com/pub/file/file-5.36.tar.gz" sha256 "fb608290c0fd2405a8f63e5717abf6d03e22e183fb21884413d1edd918184379" bottle do sha256 "2f9cd29505ced7c842c5c673db528c68237acc69f552fb1ebe7b903f0e2597be" => :mojave sha256 "b63065cb2c3501a8b352d1587804a0c7af97e2fac27fd114987e7571dfc1c3ab" => :high_sierra sha256 "8187a0d50ab22d037e598c08d2e2793a84c9ce994748fa79ad8f505b889528c6" => :sierra end def install system "./configure", "--disable-dependency-tracking", "--disable-silent-rules", "--prefix=#{prefix}", "--enable-fsect-man5", "--enable-static" system "make", "install" (share/"misc/magic").install Dir["magic/Magdir/*"] # Don't dupe this system utility rm bin/"file" rm man1/"file.1" end test do (testpath/"test.c").write <<~EOS #include #include #include int main(int argc, char **argv) { magic_t cookie = magic_open(MAGIC_MIME_TYPE); assert(cookie != NULL); assert(magic_load(cookie, NULL) == 0); // Prints the MIME type of the file referenced by the first argument. puts(magic_file(cookie, argv[1])); } EOS system ENV.cc, "-I#{include}", "-L#{lib}", "-lmagic", "test.c", "-o", "test" cp test_fixtures("test.png"), "test.png" assert_equal "image/png", shell_output("./test test.png").chomp end end