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-3.0.10/swig-3.0.10.tar.gz" sha256 "2939aae39dec06095462f1b95ce1c958ac80d07b926e48871046d17c0094f44c" bottle do sha256 "9a5e3c160c2ace68d8c7995744bb8375929f21d30872a5ef24a09cf5474f6cda" => :sierra sha256 "81cc6f9f504d1a3631869e91398c0947c7423c867a3fbfc199dc28e8519b252a" => :el_capitan sha256 "b64748bfaf2d926b07ff5ccda98f4fdec22644f779169a27cee81e1946b803c0" => :yosemite sha256 "46c3ab7d5a99fbffd8ab47d3ea362efd1055b42bca82e1731c383584d51d7783" => :mavericks end option :universal depends_on "pcre" def install ENV.universal_binary if build.universal? system "./configure", "--disable-dependency-tracking", "--prefix=#{prefix}" system "make" system "make", "install" end test do (testpath/"test.c").write <<-EOS.undent int add(int x, int y) { return x + y; } EOS (testpath/"test.i").write <<-EOS.undent %module test %inline %{ extern int add(int x, int y); %} EOS (testpath/"run.rb").write <<-EOS.undent 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/System/Library/Frameworks/Ruby.framework/Headers/" system ENV.cc, "-bundle", "-flat_namespace", "-undefined", "suppress", "test.o", "test_wrap.o", "-o", "test.bundle" assert_equal "2", shell_output("ruby run.rb").strip end end