class Expat < Formula desc "XML 1.0 parser" homepage "https://libexpat.github.io/" url "https://github.com/libexpat/libexpat/releases/download/R_2_2_9/expat-2.2.9.tar.xz" sha256 "1ea6965b15c2106b6bbe883397271c80dfa0331cdf821b2c319591b55eadc0a4" bottle do cellar :any sha256 "202ebb6d7a1eb01066263128fe34ebbbc806e5ee35b283510fa1074b674c3739" => :catalina sha256 "7440c3d35a2bd7d27bb6364a5d8c2f206509d6ebe09bd507039b701c133bb45d" => :mojave sha256 "5c51e4a42af80a11bf3f2c697a36aedc6df21b03bed3b51c3127472660b042b3" => :high_sierra end head do url "https://github.com/libexpat/libexpat.git" depends_on "autoconf" => :build depends_on "automake" => :build depends_on "docbook2x" => :build depends_on "libtool" => :build end keg_only :provided_by_macos def install cd "expat" if build.head? system "autoreconf", "-fiv" if build.head? args = ["--prefix=#{prefix}", "--mandir=#{man}"] args << "--with-docbook" if build.head? system "./configure", *args system "make", "install" end test do (testpath/"test.c").write <<~EOS #include #include "expat.h" static void XMLCALL my_StartElementHandler( void *userdata, const XML_Char *name, const XML_Char **atts) { printf("tag:%s|", name); } static void XMLCALL my_CharacterDataHandler( void *userdata, const XML_Char *s, int len) { printf("data:%.*s|", len, s); } int main() { static const char str[] = "Hello, world!"; int result; XML_Parser parser = XML_ParserCreate("utf-8"); XML_SetElementHandler(parser, my_StartElementHandler, NULL); XML_SetCharacterDataHandler(parser, my_CharacterDataHandler); result = XML_Parse(parser, str, sizeof(str), 1); XML_ParserFree(parser); return result; } EOS system ENV.cc, "test.c", "-I#{include}", "-L#{lib}", "-lexpat", "-o", "test" assert_equal "tag:str|data:Hello, world!|", shell_output("./test") end end