homebrew-core/Formula/sip.rb
2017-03-08 22:48:13 -08:00

106 lines
3.3 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.1/sip-4.19.1.tar.gz"
sha256 "501852b8325349031b769d1c03d6eab04f7b9b97f790ec79f3d3d04bf065d83e"
head "https://www.riverbankcomputing.com/hg/sip", :using => :hg
bottle do
cellar :any_skip_relocation
sha256 "ce53b8b0bdd40a8b9098b72aaa21b1d9b7e0c26910af50c6bb8a3031a0b82ba2" => :sierra
sha256 "cbc6a67d6e6d3bde3323b92dba982e73fd443354c6f5467f98d22e95a4138b18" => :el_capitan
sha256 "5058e22711e17b4942eaf95b3e0bb85fd1ecb750d27813b8cbc200f5544a3dfd" => :yosemite
end
option "without-python", "Build without python2 support"
depends_on :python => :recommended if MacOS.version <= :snow_leopard
depends_on :python3 => :optional
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