summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Chaplin <>2012-04-21 15:17:34 +0800
committerSteve Chaplin <>2012-04-21 15:17:34 +0800
commit0c5c297b67381f341e089e5a26c511807fa9290f (patch)
tree8f4525ba818d3b87aeddab371c0db95ff87f7840
parent4bdcaf76248fc18253e4130fd1304b6f3b0ac3ab (diff)
downloadpycairo-0c5c297b67381f341e089e5a26c511807fa9290f.tar.gz
Update waf file.
Create a setup.py file (since waf does not work properly for me)
-rw-r--r--.gitignore4
-rw-r--r--INSTALL8
-rw-r--r--py3cairo.pc8
-rwxr-xr-xsetup.py118
-rwxr-xr-xwafbin83653 -> 87674 bytes
5 files changed, 138 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index f3db509..6d02441 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,5 +10,9 @@
.lock*
.waf*
+waf.*
+build
build_directory
+
+src/config.h
diff --git a/INSTALL b/INSTALL
index 14357b8..1522306 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,5 +1,13 @@
Install Procedure
-----------------
+
+Method 1: Python distutils (recommended method)
+--------------------------
+$ python setup.py install
+
+
+Method 2: Waf
+--------------
$ ./waf --help # shows available waf options
$ ./waf configure # use --prefix and --libdir if necessary
# --prefix=/usr --libdir=/usr/lib64 for Fedora 64-bit
diff --git a/py3cairo.pc b/py3cairo.pc
new file mode 100644
index 0000000..aea7820
--- /dev/null
+++ b/py3cairo.pc
@@ -0,0 +1,8 @@
+prefix=/a
+
+Name: Pycairo
+Description: Python 3 bindings for cairo
+Version: 1.10.0
+Requires: cairo
+Cflags: -I${prefix}/include/pycairo
+Libs:
diff --git a/setup.py b/setup.py
new file mode 100755
index 0000000..f4bc373
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,118 @@
+#!/usr/bin/env python
+
+import distutils.core as dic
+import distutils.dir_util as dut
+import distutils.file_util as fut
+import distutils.sysconfig as dsy
+import io
+import os
+import subprocess
+import sys
+
+pycairo_version = '1.10.0'
+cairo_version_required = '1.10.0'
+python_version_required = (3,0)
+pkgconfig_file = 'py3cairo.pc'
+config_file = 'src/config.h'
+
+
+def call(command):
+ pipe = subprocess.Popen(command, shell=True,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ pipe.wait()
+ return pipe
+
+def pkg_config_version_check(pkg, version):
+ pipe = call('pkg-config --print-errors --exists "%s >= %s"' %
+ (pkg, version))
+ if pipe.returncode == 0:
+ print('%s >= %s detected' % (pkg, version))
+ else:
+ print(pipe.stderr.read())
+ raise SystemExit('Error: %s >= %s not found' % (pkg, version))
+
+def pkg_config_parse(opt, pkg):
+ pipe = call("pkg-config %s %s" % (opt, pkg))
+ output = pipe.stdout.read()
+ output = output.decode() # get the str
+ opt = opt[-2:]
+ return [x.lstrip(opt) for x in output.split()]
+
+
+def createPcFile(PcFile):
+ print('creating %s' % PcFile)
+ with open(PcFile, 'w') as fo:
+ fo.write ("""\
+prefix=%s
+
+Name: Pycairo
+Description: Python 3 bindings for cairo
+Version: %s
+Requires: cairo
+Cflags: -I${prefix}/include/pycairo
+Libs:
+""" % (sys.prefix, pycairo_version)
+ )
+
+def createConfigFile(ConfigFile):
+ print('creating %s' % ConfigFile)
+ v = pycairo_version.split('.')
+
+ with open(ConfigFile, 'w') as fo:
+ fo.write ("""\
+// Configuration header created by setup.py - do not edit
+#ifndef _CONFIG_H
+#define _CONFIG_H 1
+
+#define PYCAIRO_VERSION_MAJOR %s
+#define PYCAIRO_VERSION_MICRO %s
+#define PYCAIRO_VERSION_MINOR %s
+#define VERSION "%s"
+
+#endif // _CONFIG_H
+""" % (v[0], v[1], v[2], pycairo_version)
+ )
+
+
+if sys.version_info < python_version_required:
+ raise SystemExit('Error: Python >= %s is required' %s (python_version_required,))
+
+pkg_config_version_check ('cairo', cairo_version_required)
+if sys.platform == 'win32':
+ runtime_library_dirs = []
+else:
+ runtime_library_dirs = pkg_config_parse('--libs-only-L', 'cairo')
+
+createPcFile(pkgconfig_file)
+createConfigFile(config_file)
+
+
+cairo = dic.Extension(
+ name = 'cairo._cairo',
+ sources = ['src/cairomodule.c',
+ 'src/context.c',
+ 'src/font.c',
+ 'src/matrix.c',
+ 'src/path.c',
+ 'src/pattern.c',
+ 'src/surface.c',
+ ],
+ include_dirs = pkg_config_parse('--cflags-only-I', 'cairo'),
+ library_dirs = pkg_config_parse('--libs-only-L', 'cairo'),
+ libraries = pkg_config_parse('--libs-only-l', 'cairo'),
+ runtime_library_dirs = runtime_library_dirs,
+ )
+
+dic.setup(
+ name = "pycairo",
+ version = pycairo_version,
+ description = "python interface for cairo",
+ ext_modules = [cairo],
+ data_files = [
+ ('include/pycairo', ['src/py3cairo.h']),
+ ('lib/pkgconfig', [pkgconfig_file]),
+ (os.path.join(dsy.get_python_lib(), 'cairo'),
+ ['src/__init__.py']),
+ ],
+ )
diff --git a/waf b/waf
index 9212ce9..e1e34d4 100755
--- a/waf
+++ b/waf
Binary files differ