homebrew-core/Formula/expat.rb
2019-06-21 13:45:26 +02:00

71 lines
2.1 KiB
Ruby

class Expat < Formula
desc "XML 1.0 parser"
homepage "https://libexpat.github.io/"
url "https://github.com/libexpat/libexpat/releases/download/R_2_2_7/expat-2.2.7.tar.xz"
sha256 "30e3f40acf9a8fdbd5c379bdcc8d1178a1d9af306de29fc8ece922bc4c57bef8"
bottle do
cellar :any
sha256 "1f66114d9aa512cbe153665e6b9102d41d83d164089214ed588ad8a6bbbc3efe" => :mojave
sha256 "b1bb9a07d7f8a8ef94530a8caad7024f761754d8d251a05fc59cab9113fd5444" => :high_sierra
sha256 "b7522b1e884f5705fd0a7051fcbf7360c2521857ad6783b886761fdae0057ebe" => :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 <stdio.h>
#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[] = "<str>Hello, world!</str>";
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