sip_configure.py
Go to the documentation of this file.
00001 import os
00002 import re
00003 import subprocess
00004 import sys
00005 from PyQt4 import pyqtconfig
00006 
00007 if len(sys.argv) != 8:
00008     print('usage: %s build-dir sip-file output_dir include_dirs libs lib_dirs ldflags' % sys.argv[0])
00009     sys.exit(1)
00010 
00011 # The SIP build folder, the SIP file, the output directory, the include directories, the libraries, the library directories and the linker flags.
00012 build_dir, sip_file, output_dir, include_dirs, libs, lib_dirs, ldflags = sys.argv[1:]
00013 
00014 # The name of the SIP build file generated by SIP and used by the build system.
00015 build_file = 'pyqtscripting.sbf'
00016 
00017 # Get the PyQt configuration information.
00018 config = pyqtconfig.Configuration()
00019 
00020 # Get the extra SIP flags needed by the imported qt module.  Note that
00021 # this normally only includes those flags (-x and -t) that relate to SIP's
00022 # versioning system.
00023 qt_sip_flags = config.pyqt_sip_flags
00024 
00025 try:
00026     os.makedirs(build_dir)
00027 except OSError:
00028     pass
00029 
00030 # Run SIP to generate the code.  Note that we tell SIP where to find the qt
00031 # module's specification files using the -I flag.
00032 cmd = [
00033     config.sip_bin,
00034     '-c', build_dir,
00035     '-b', os.path.join(build_dir, build_file),
00036     '-I', config.pyqt_sip_dir,
00037     '-w'
00038 ]
00039 cmd += qt_sip_flags.split(' ')
00040 cmd.append(sip_file)
00041 subprocess.check_call(cmd)
00042 
00043 # Create the Makefile.  The QtModuleMakefile class provided by the
00044 # pyqtconfig module takes care of all the extra preprocessor, compiler and
00045 # linker flags needed by the Qt library.
00046 makefile = pyqtconfig.QtGuiModuleMakefile(
00047     dir=build_dir,
00048     configuration=config,
00049     build_file=build_file
00050 )
00051 
00052 # hack to override makefile behavior which always prepend -l to libraries which is wrong for absolute paths
00053 default_platform_lib_function = pyqtconfig.QtGuiModuleMakefile.platform_lib
00054 
00055 
00056 def custom_platform_lib_function(self, clib, framework=0):
00057     if os.path.isabs(clib):
00058         return clib
00059     return default_platform_lib_function(self, clib, framework)
00060 pyqtconfig.QtGuiModuleMakefile.platform_lib = custom_platform_lib_function
00061 
00062 
00063 # split paths on whitespace
00064 # while dealing with whitespaces within the paths if they are escaped with backslashes
00065 def split_paths(paths):
00066     paths = re.split('(?<=[^\\\\]) ', paths)
00067     return paths
00068 
00069 for include_dir in split_paths(include_dirs):
00070     include_dir = include_dir.replace('\\', '')
00071     makefile.extra_include_dirs.append(include_dir)
00072 for lib in split_paths(libs):
00073     makefile.extra_libs.append(lib)
00074 for lib_dir in split_paths(lib_dirs):
00075     lib_dir = lib_dir.replace('\\', '')
00076     makefile.extra_lib_dirs.append(lib_dir)
00077 for ldflag in ldflags.split('\\ '):
00078     makefile.LFLAGS.append(ldflag)
00079 
00080 # redirect location of generated library
00081 makefile._target = '"%s"' % os.path.join(output_dir, makefile._target)
00082 
00083 # Generate the Makefile itself
00084 makefile.generate()


python_qt_binding
Author(s): Dave Hershberger, Dorian Scholz, Dirk Thomas
autogenerated on Mon Oct 6 2014 03:57:26