Enable out-of-tree building of extension modules

This commit is contained in:
Kovid Goyal 2016-07-01 15:18:53 +05:30
parent add980d6e6
commit 7808cd4794
2 changed files with 14 additions and 7 deletions

View File

@ -20,7 +20,7 @@ sys.setup_dir = os.path.dirname(os.path.abspath(__file__))
SRC = os.path.abspath(os.path.join(os.path.dirname(sys.setup_dir), 'src')) SRC = os.path.abspath(os.path.join(os.path.dirname(sys.setup_dir), 'src'))
sys.path.insert(0, SRC) sys.path.insert(0, SRC)
sys.resources_location = os.path.join(os.path.dirname(SRC), 'resources') sys.resources_location = os.path.join(os.path.dirname(SRC), 'resources')
sys.extensions_location = os.path.join(SRC, 'calibre', 'plugins') sys.extensions_location = os.path.abspath(os.environ.get('CALIBRE_SETUP_EXTENSIONS_PATH', os.path.join(SRC, 'calibre', 'plugins')))
sys.running_from_setup = True sys.running_from_setup = True
__version__ = __appname__ = modules = functions = basenames = scripts = None __version__ = __appname__ = modules = functions = basenames = scripts = None

View File

@ -398,14 +398,21 @@ class Build(Command):
', '.join(choices)+'. Default:%default')) ', '.join(choices)+'. Default:%default'))
parser.add_option('--no-compile', default=False, action='store_true', parser.add_option('--no-compile', default=False, action='store_true',
help='Skip compiling all C/C++ extensions.') help='Skip compiling all C/C++ extensions.')
parser.add_option('--build-dir', default=None,
help='Path to directory in which to place object files during the build process, defaults to "build"')
parser.add_option('--output-dir', default=None,
help='Path to directory in which to place the built extensions. Defaults to src/calibre/plugins')
def run(self, opts): def run(self, opts):
if opts.no_compile: if opts.no_compile:
self.info('--no-compile specified, skipping compilation') self.info('--no-compile specified, skipping compilation')
return return
self.obj_dir = os.path.join(os.path.dirname(SRC), 'build', 'objects') self.build_dir = os.path.abspath(opts.build_dir or os.path.join(os.path.dirname(SRC), 'build'))
if not os.path.exists(self.obj_dir): self.output_dir = os.path.abspath(opts.output_dir or os.path.join(os.path.dirname(SRC), 'calibre', 'plugins'))
os.makedirs(self.obj_dir) self.obj_dir = os.path.join(self.build_dir, 'objects')
for x in (self.output_dir, self.obj_dir):
if not os.path.exists(x):
os.makedirs(x)
for ext in extensions: for ext in extensions:
if opts.only != 'all' and opts.only != ext.name: if opts.only != 'all' and opts.only != ext.name:
continue continue
@ -425,7 +432,7 @@ class Build(Command):
def dest(self, ext): def dest(self, ext):
ex = '.pyd' if iswindows else '.so' ex = '.pyd' if iswindows else '.so'
return os.path.join(SRC, 'calibre', 'plugins', getattr(ext, 'name', ext))+ex return os.path.join(self.output_dir, getattr(ext, 'name', ext))+ex
def inc_dirs_to_cflags(self, dirs): def inc_dirs_to_cflags(self, dirs):
return ['-I'+x for x in dirs] return ['-I'+x for x in dirs]
@ -545,7 +552,7 @@ class Build(Command):
''').format( ''').format(
headers=' '.join(headers), sources=' '.join(sources), others=' '.join(others), destdir=self.d( headers=' '.join(headers), sources=' '.join(sources), others=' '.join(others), destdir=self.d(
target), glib=glib_flags, fontconfig=fontconfig_flags, freetype=' '.join(ft_inc_dirs)) target), glib=glib_flags, fontconfig=fontconfig_flags, freetype=' '.join(ft_inc_dirs))
bdir = self.j(self.d(self.SRC), 'build', 'headless') bdir = self.j(self.build_dir, 'headless')
if not os.path.exists(bdir): if not os.path.exists(bdir):
os.makedirs(bdir) os.makedirs(bdir)
pf = self.j(bdir, 'headless.pro') pf = self.j(bdir, 'headless.pro')
@ -580,7 +587,7 @@ class Build(Command):
return {x:read(x) for x in ('target', 'sources', 'headers')} return {x:read(x) for x in ('target', 'sources', 'headers')}
def build_pyqt_extension(self, ext, dest): def build_pyqt_extension(self, ext, dest):
pyqt_dir = self.j(self.d(self.SRC), 'build', 'pyqt') pyqt_dir = self.j(self.build_dir, 'pyqt')
src_dir = self.j(pyqt_dir, ext.name) src_dir = self.j(pyqt_dir, ext.name)
if not os.path.exists(src_dir): if not os.path.exists(src_dir):
os.makedirs(src_dir) os.makedirs(src_dir)