homebrew-core/Formula/swig.rb
2019-05-01 03:57:51 +08:00

53 lines
1.6 KiB
Ruby

class Swig < Formula
desc "Generate scripting interfaces to C/C++ code"
homepage "http://www.swig.org/"
url "https://downloads.sourceforge.net/project/swig/swig/swig-4.0.0/swig-4.0.0.tar.gz"
sha256 "e8a39cd6437e342cdcbd5af27a9bf11b62dc9efec9248065debcb8276fcbb925"
bottle do
sha256 "9eff7a235762c2727dfdb767217be4a48a55f29efcae5fedc450c3dfeb806904" => :mojave
sha256 "aed79cb436b3a0ac5812c4085e3121ffd62866397b8c7eaa06815ed8ec1e22b7" => :high_sierra
sha256 "af4c42215d5c7c042d83e98aecb70958acd73038dfc2b59d1854f2287fb50980" => :sierra
end
head do
url "https://github.com/swig/swig.git"
depends_on "autoconf" => :build
depends_on "automake" => :build
end
depends_on "pcre"
def install
system "./autogen.sh" if build.head?
system "./configure", "--disable-dependency-tracking",
"--prefix=#{prefix}"
system "make"
system "make", "install"
end
test do
(testpath/"test.c").write <<~EOS
int add(int x, int y)
{
return x + y;
}
EOS
(testpath/"test.i").write <<~EOS
%module test
%inline %{
extern int add(int x, int y);
%}
EOS
(testpath/"run.rb").write <<~EOS
require "./test"
puts Test.add(1, 1)
EOS
system "#{bin}/swig", "-ruby", "test.i"
system ENV.cc, "-c", "test.c"
system ENV.cc, "-c", "test_wrap.c", "-I#{MacOS.sdk_path}/System/Library/Frameworks/Ruby.framework/Headers/"
system ENV.cc, "-bundle", "-undefined", "dynamic_lookup", "test.o", "test_wrap.o", "-o", "test.bundle"
assert_equal "2", shell_output("/usr/bin/ruby run.rb").strip
end
end