mirror of https://github.com/kivy/kivy.git
setup: add pxd in extensions to help a little about compilation when a deps change. Closes #66
However, distutils doesn't support the introspection of pyx files to get deps. + add .PHONY in Makefile for all comamnds, now make build can be used even after a fetch + regenerate .h only when build_ext is called.
This commit is contained in:
parent
659f40eded
commit
d3fcbf79c5
2
Makefile
2
Makefile
|
@ -2,6 +2,8 @@ PYTHON = python
|
|||
CHECKSCRIPT = kivy/tools/pep8checker/pep8kivy.py
|
||||
KIVY_DIR = kivy/
|
||||
|
||||
.PHONY: build force mesabuild pdf style stylereport hook test batchtest cover clean distclean
|
||||
|
||||
build:
|
||||
$(PYTHON) setup.py build_ext --inplace
|
||||
|
||||
|
|
64
setup.py
64
setup.py
|
@ -5,6 +5,13 @@ from os import walk, environ
|
|||
from distutils.core import setup
|
||||
from distutils.extension import Extension
|
||||
|
||||
try:
|
||||
# check for cython
|
||||
from Cython.Distutils import build_ext
|
||||
except ImportError:
|
||||
print '\nCython is missing, its required for compiling kivy !\n\n'
|
||||
raise
|
||||
|
||||
# extract version (simulate doc generation, kivy will be not imported)
|
||||
environ['KIVY_DOC_INCLUDE'] = '1'
|
||||
import kivy
|
||||
|
@ -60,50 +67,45 @@ else:
|
|||
print 'Fallback to Desktop opengl headers.'
|
||||
c_options['use_opengl_es2'] = False
|
||||
|
||||
print 'Generate config.h'
|
||||
with open(join(dirname(__file__), 'kivy', 'graphics', 'config.h'), 'w') as fd:
|
||||
fd.write('// Autogenerated file for Kivy C configuration\n')
|
||||
for k, v in c_options.iteritems():
|
||||
fd.write('#define __%s %d\n' % (k.upper(), int(v)))
|
||||
|
||||
print 'Generate config.pxi'
|
||||
with open(join(dirname(__file__), 'kivy', 'graphics', 'config.pxi'), 'w') as fd:
|
||||
fd.write('# Autogenerated file for Kivy Cython configuration\n')
|
||||
for k, v in c_options.iteritems():
|
||||
fd.write('DEF %s = %d\n' % (k.upper(), int(v)))
|
||||
class KivyBuildExt(build_ext):
|
||||
|
||||
def build_extensions(self):
|
||||
print 'Generate config.h'
|
||||
config_h = join(dirname(__file__), 'kivy', 'graphics', 'config.h')
|
||||
with open(config_h, 'w') as fd:
|
||||
fd.write('// Autogenerated file for Kivy C configuration\n')
|
||||
for k, v in c_options.iteritems():
|
||||
fd.write('#define __%s %d\n' % (k.upper(), int(v)))
|
||||
|
||||
print 'Generate config.pxi'
|
||||
config_pxi = join(dirname(__file__), 'kivy', 'graphics', 'config.pxi')
|
||||
with open(config_pxi, 'w') as fd:
|
||||
fd.write('# Autogenerated file for Kivy Cython configuration\n')
|
||||
for k, v in c_options.iteritems():
|
||||
fd.write('DEF %s = %d\n' % (k.upper(), int(v)))
|
||||
|
||||
build_ext.build_extensions(self)
|
||||
|
||||
cmdclass['build_ext'] = KivyBuildExt
|
||||
|
||||
# extension modules
|
||||
ext_modules = []
|
||||
|
||||
# list all files to compile
|
||||
pyx_files = []
|
||||
pxd_files = []
|
||||
kivy_libs_dir = realpath(kivy.kivy_libs_dir)
|
||||
for root, dirnames, filenames in walk(join(dirname(__file__), 'kivy')):
|
||||
# ignore lib directory
|
||||
if realpath(root).startswith(kivy_libs_dir):
|
||||
continue
|
||||
for filename in fnfilter(filenames, '*.pxd'):
|
||||
pxd_files.append(join(root, filename))
|
||||
for filename in fnfilter(filenames, '*.pyx'):
|
||||
pyx_files.append(join(root, filename))
|
||||
|
||||
# check for cython
|
||||
try:
|
||||
have_cython = True
|
||||
from Cython.Distutils import build_ext
|
||||
except:
|
||||
have_cython = False
|
||||
|
||||
# create .c for every module
|
||||
if 'sdist' in argv and have_cython:
|
||||
from Cython.Compiler.Main import compile
|
||||
print 'Generating C files...',
|
||||
compile(pyx_files)
|
||||
print 'Done !'
|
||||
|
||||
# add cython core extension modules if cython is available
|
||||
if have_cython:
|
||||
cmdclass['build_ext'] = build_ext
|
||||
else:
|
||||
pyx_files = ['%s.c' % x[:-4] for x in pyx_files]
|
||||
|
||||
if True:
|
||||
libraries = []
|
||||
|
@ -150,14 +152,16 @@ if True:
|
|||
|
||||
# simple extensions
|
||||
for pyx in (x for x in pyx_files if not 'graphics' in x):
|
||||
pxd = [x for x in pxd_files if not 'graphics' in x]
|
||||
module_name = get_modulename_from_file(pyx)
|
||||
ext_modules.append(Extension(module_name, [pyx]))
|
||||
ext_modules.append(Extension(module_name, [pyx] + pxd))
|
||||
|
||||
# opengl aware modules
|
||||
for pyx in (x for x in pyx_files if 'graphics' in x):
|
||||
pxd = [x for x in pxd_files if 'graphics' in x]
|
||||
module_name = get_modulename_from_file(pyx)
|
||||
ext_modules.append(Extension(
|
||||
module_name, [pyx],
|
||||
module_name, [pyx] + pxd,
|
||||
libraries=libraries,
|
||||
include_dirs=include_dirs,
|
||||
extra_link_args=extra_link_args))
|
||||
|
|
Loading…
Reference in New Issue