homebrew-core/Formula/sip.rb
2018-06-30 03:03:22 -07:00

105 lines
3.2 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://dl.bintray.com/homebrew/mirror/sip-4.19.8.tar.gz"
mirror "https://downloads.sourceforge.net/project/pyqt/sip/sip-4.19.8/sip-4.19.8.tar.gz"
sha256 "7eaf7a2ea7d4d38a56dd6d2506574464bddf7cf284c960801679942377c297bc"
revision 5
head "https://www.riverbankcomputing.com/hg/sip", :using => :hg
bottle do
cellar :any_skip_relocation
sha256 "ec4c53082f161ffce908cdb2d5ed6abf46e0ebeee25d202c2fb6ea6f7c6eb8f7" => :high_sierra
sha256 "e79829d883081c92c94a95323e233319f877740caa0825e13b15ef35a729f4a9" => :sierra
sha256 "ad58acf490fa260cedd239270502cac93d36e9dd7dac4c6cf934de414e399b5a" => :el_capitan
end
depends_on "python" => :recommended
depends_on "python@2" => :recommended
def install
ENV.prepend_path "PATH", Formula["python"].opt_libexec/"bin"
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|
ENV.delete("SDKROOT") # Avoid picking up /Application/Xcode.app paths
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
The sip-dir for Python is #{HOMEBREW_PREFIX}/share/sip.
EOS
end
test do
(testpath/"test.h").write <<~EOS
#pragma once
class Test {
public:
Test();
void test();
};
EOS
(testpath/"test.cpp").write <<~EOS
#include "test.h"
#include <iostream>
Test::Test() {}
void Test::test()
{
std::cout << "Hello World!" << std::endl;
}
EOS
(testpath/"test.sip").write <<~EOS
%Module test
class Test {
%TypeHeaderCode
#include "test.h"
%End
public:
Test();
void test();
};
EOS
(testpath/"generate.py").write <<~EOS
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
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