Go to the documentation of this file.00001 from copy import copy
00002 import os
00003 import re
00004 import subprocess
00005 import sys
00006
00007 import sipconfig
00008 try:
00009 from PyQt4.pyqtconfig import Configuration
00010 except ImportError:
00011
00012 from PyQt4 import QtCore
00013
00014 class Configuration(sipconfig.Configuration):
00015 def __init__(self):
00016 env = copy(os.environ)
00017 env['QT_SELECT'] = '4'
00018 qtconfig = subprocess.check_output(
00019 ['qmake', '-query'], env=env, universal_newlines=True)
00020 qtconfig = dict(line.split(':', 1) for line in qtconfig.splitlines())
00021 pyqtconfig = {
00022 'qt_archdata_dir': qtconfig['QT_INSTALL_DATA'],
00023 'qt_data_dir': qtconfig['QT_INSTALL_DATA'],
00024 'qt_dir': qtconfig['QT_INSTALL_PREFIX'],
00025 'qt_inc_dir': qtconfig['QT_INSTALL_HEADERS'],
00026 'qt_lib_dir': qtconfig['QT_INSTALL_LIBS'],
00027 'qt_threaded': 1,
00028 'qt_version': QtCore.QT_VERSION,
00029 'qt_winconfig': 'shared',
00030 }
00031 sipconfig.Configuration.__init__(self, [pyqtconfig])
00032
00033 macros = sipconfig._default_macros.copy()
00034 macros['INCDIR_QT'] = qtconfig['QT_INSTALL_HEADERS']
00035 macros['LIBDIR_QT'] = qtconfig['QT_INSTALL_LIBS']
00036 macros['MOC'] = 'moc-qt4'
00037 self.set_build_macros(macros)
00038
00039 if len(sys.argv) != 8:
00040 print('usage: %s build-dir sip-file output_dir include_dirs libs lib_dirs ldflags' % sys.argv[0])
00041 sys.exit(1)
00042
00043
00044 build_dir, sip_file, output_dir, include_dirs, libs, lib_dirs, ldflags = sys.argv[1:]
00045
00046
00047 build_file = 'pyqtscripting.sbf'
00048
00049
00050 config = Configuration()
00051
00052
00053
00054
00055 try:
00056 sip_dir = config.pyqt_sip_dir
00057 sip_flags = config.pyqt_sip_flags
00058 except AttributeError:
00059
00060 sip_dir = sipconfig._pkg_config['default_sip_dir'] + '/PyQt4'
00061 sip_flags = QtCore.PYQT_CONFIGURATION['sip_flags']
00062
00063 try:
00064 os.makedirs(build_dir)
00065 except OSError:
00066 pass
00067
00068
00069
00070 cmd = [
00071 config.sip_bin,
00072 '-c', build_dir,
00073 '-b', os.path.join(build_dir, build_file),
00074 '-I', sip_dir,
00075 '-w'
00076 ]
00077 cmd += sip_flags.split(' ')
00078 cmd.append(sip_file)
00079 subprocess.check_call(cmd)
00080
00081
00082
00083
00084 makefile = sipconfig.SIPModuleMakefile(
00085 dir=build_dir,
00086 configuration=config,
00087 build_file=build_file,
00088 qt=['QtCore', 'QtGui']
00089 )
00090
00091
00092 default_platform_lib_function = sipconfig.SIPModuleMakefile.platform_lib
00093
00094
00095 def custom_platform_lib_function(self, clib, framework=0):
00096 if os.path.isabs(clib):
00097 return clib
00098 return default_platform_lib_function(self, clib, framework)
00099 sipconfig.SIPModuleMakefile.platform_lib = custom_platform_lib_function
00100
00101
00102
00103
00104 def split_paths(paths):
00105 paths = re.split('(?<=[^\\\\]) ', paths)
00106 return paths
00107
00108 for include_dir in split_paths(include_dirs):
00109 include_dir = include_dir.replace('\\', '')
00110 makefile.extra_include_dirs.append(include_dir)
00111 for lib in split_paths(libs):
00112 makefile.extra_libs.append(lib)
00113 for lib_dir in split_paths(lib_dirs):
00114 lib_dir = lib_dir.replace('\\', '')
00115 makefile.extra_lib_dirs.append(lib_dir)
00116 for ldflag in ldflags.split('\\ '):
00117 makefile.LFLAGS.append(ldflag)
00118
00119
00120 makefile._target = '"%s"' % os.path.join(output_dir, makefile._target)
00121
00122
00123 makefile.generate()