homebrew-core/Formula/sip.rb
2017-09-15 23:23:03 -07:00

107 lines
3.4 KiB
Ruby

class Sip < Formula
desc "Tool to create Python bindings for C and C++ libraries"
homepage "https://www.riverbankcomputing.com/software/sip/intro"
url "https://downloads.sourceforge.net/project/pyqt/sip/sip-4.19.3/sip-4.19.3.tar.gz"
sha256 "740df844f80cc45dcc9b23294a92492923bc403ce88e68c35783f27c177c4b74"
revision 1
head "https://www.riverbankcomputing.com/hg/sip", :using => :hg
bottle do
cellar :any_skip_relocation
sha256 "aabadb1813fd15e4896a189cc6f0db7e0073616f46098131648e2c2d19bc0b59" => :high_sierra
sha256 "329a7dea0091b0f1b09ab9cf72113fc849df487f2882943ba585186b064f163d" => :sierra
sha256 "6b3f7334bf4ad58843be4d7a7d46d724f0ab26812b2687e2d15863c0411271cf" => :el_capitan
sha256 "77d2b23f8e75974ce18143f8e1591b99c512c1e75450b51b1eda6a46bf697672" => :yosemite
end
depends_on :python => :recommended
depends_on :python3 => :recommended
def install
if build.without?("python3") && build.without?("python")
odie "sip: --with-python3 must be specified when using --without-python"
end
if build.head?
# Link the Mercurial repository into the download directory so
# build.py can use it to figure out a version number.
ln_s cached_download/".hg", ".hg"
# build.py doesn't run with python3
system "python", "build.py", "prepare"
end
Language::Python.each_python(build) do |python, version|
# Note the binary `sip` is the same for python 2.x and 3.x
system python, "configure.py",
"--deployment-target=#{MacOS.version}",
"--destdir=#{lib}/python#{version}/site-packages",
"--bindir=#{bin}",
"--incdir=#{include}",
"--sipdir=#{HOMEBREW_PREFIX}/share/sip"
system "make"
system "make", "install"
system "make", "clean"
end
end
def post_install
(HOMEBREW_PREFIX/"share/sip").mkpath
end
def caveats; <<-EOS.undent
The sip-dir for Python is #{HOMEBREW_PREFIX}/share/sip.
EOS
end
test do
(testpath/"test.h").write <<-EOS.undent
#pragma once
class Test {
public:
Test();
void test();
};
EOS
(testpath/"test.cpp").write <<-EOS.undent
#include "test.h"
#include <iostream>
Test::Test() {}
void Test::test()
{
std::cout << "Hello World!" << std::endl;
}
EOS
(testpath/"test.sip").write <<-EOS.undent
%Module test
class Test {
%TypeHeaderCode
#include "test.h"
%End
public:
Test();
void test();
};
EOS
(testpath/"generate.py").write <<-EOS.undent
from sipconfig import SIPModuleMakefile, Configuration
m = SIPModuleMakefile(Configuration(), "test.build")
m.extra_libs = ["test"]
m.extra_lib_dirs = ["."]
m.generate()
EOS
(testpath/"run.py").write <<-EOS.undent
from test import Test
t = Test()
t.test()
EOS
system ENV.cxx, "-shared", "-Wl,-install_name,#{testpath}/libtest.dylib",
"-o", "libtest.dylib", "test.cpp"
system bin/"sip", "-b", "test.build", "-c", ".", "test.sip"
Language::Python.each_python(build) do |python, version|
ENV["PYTHONPATH"] = lib/"python#{version}/site-packages"
system python, "generate.py"
system "make", "-j1", "clean", "all"
system python, "run.py"
end
end
end