def create_makefiles(macros): """Create the Makefiles. macros is the dictionary of platform specific build macros. """ # Bootstrap. Make sure we get the right one. sys.path.insert(0, os.path.curdir) invalidate_caches() import sipconfig cfg = sipconfig.Configuration() cfg.set_build_macros(macros) sipconfig.inform("Creating top level Makefile...") sipconfig.ParentMakefile( configuration=cfg, subdirs=["sipgen", "siplib"], installs=(["sipconfig.py", os.path.join(src_dir, "sipdistutils.py")], cfg.sip_mod_dir) ).generate() sipconfig.inform("Creating sip code generator Makefile...") sipconfig.ProgramMakefile( configuration=cfg, build_file=os.path.join(src_dir, "sipgen", "sipgen.sbf"), dir="sipgen", install_dir=os.path.dirname(cfg.sip_bin), console=1, warnings=0, universal=opts.universal, arch=opts.arch, deployment_target=opts.deployment_target ).generate() sipconfig.inform("Creating sip module Makefile...") makefile = sipconfig.ModuleMakefile( configuration=cfg, build_file=os.path.join(src_dir, "siplib", "siplib.sbf"), dir="siplib", install_dir=cfg.sip_mod_dir, installs=([os.path.join(src_dir, "siplib", "sip.h")], cfg.sip_inc_dir), console=1, warnings=0, static=opts.static, debug=opts.debug, universal=opts.universal, arch=opts.arch, deployment_target=opts.deployment_target ) makefile.generate()
def create_makefiles(macros): """Create the Makefiles. macros is the dictionary of platform specific build macros. """ # Bootstrap. import sipconfig cfg = sipconfig.Configuration() cfg.set_build_macros(macros) sipconfig.inform("Creating top level Makefile...") sipconfig.ParentMakefile( configuration=cfg, subdirs=["sipgen", "siplib"], installs=(["sipconfig.py", "sipdistutils.py"], cfg.sip_mod_dir) ).generate() sipconfig.inform("Creating sip code generator Makefile...") sipconfig.ProgramMakefile( configuration=cfg, build_file="sipgen.sbf", dir="sipgen", install_dir=os.path.dirname(cfg.sip_bin), console=1, warnings=0, universal=opts.universal ).generate() sipconfig.inform("Creating sip module Makefile...") makefile = sipconfig.ModuleMakefile( configuration=cfg, build_file="siplib.sbf", dir="siplib", install_dir=cfg.sip_mod_dir, installs=(["sip.h"], cfg.sip_inc_dir), console=1, warnings=0, static=opts.static, debug=opts.debug, universal=opts.universal ) makefile.generate()
def compile_qt_program(name, configuration, extra_defines=[], extra_include_dirs=[], extra_lib_dirs=[], extra_libs=[], verbose=False): """Compile a simple Qt application. name is the name of the single source file configuration is the pyqtconfig.Configuration() extra_defines is a list of extra preprocessor definitions extra_include_dirs is a list of extra directories to search for headers extra_lib_dirs is a list of extra directories to search for libraries extra_libs is a list of extra libraries """ makefile = sipconfig.ProgramMakefile( configuration, console=True, qt=['QtCore', 'QtGui', 'QtOpenGL', 'QtXml'], opengl=True, warnings=True) makefile.extra_defines.extend(extra_defines) makefile.extra_include_dirs.extend(extra_include_dirs) makefile.extra_lib_dirs.extend(extra_lib_dirs) makefile.extra_libs.extend(extra_libs) exe, build = makefile.build_command(name) # zap a spurious executable try: os.remove(exe) except OSError: pass if verbose: print(build) os.system(build) if not os.access(exe, os.X_OK): return None if sys.platform != 'win32': exe = './' + exe return exe
def create_makefiles(macros): """Create the Makefiles. macros is the dictionary of platform specific build macros. """ # Bootstrap. Make sure we get the right one. sys.path.insert(0, os.path.curdir) invalidate_caches() import sipconfig cfg = sipconfig.Configuration() cfg.set_build_macros(macros) if opts.no_tools: subdirs = ["siplib"] installs = None else: subdirs = ["sipgen", "siplib"] installs = (["sipconfig.py", os.path.join(src_dir, "sipdistutils.py")], cfg.sip_mod_dir) if opts.use_qmake: sipconfig.inform("Creating top level .pro file...") pro = open("sip.pro", "w") pro.write("TEMPLATE = subdirs\n") pro.write("SUBDIRS = %s\n" % " ".join(subdirs)) if installs is not None: files, path = installs pro.write("\n") pro.write("build_system.files = %s\n" % " ".join(files)) pro.write("build_system.path = %s\n" % quote(path)) pro.write("INSTALLS += build_system\n") pro.close() else: sipconfig.inform("Creating top level Makefile...") sipconfig.ParentMakefile(configuration=cfg, subdirs=subdirs, installs=installs).generate() if opts.use_qmake: sipconfig.inform("Creating sip code generator .pro file...") pro = open(os.path.join("sipgen", "sipgen.pro"), "w") pro.write("TEMPLATE = app\n") pro.write("TARGET = sip\n") pro.write("CONFIG -= qt app_bundle\n") pro.write("CONFIG += warn_off exceptions_off console %s\n" % (("debug" if opts.debug else "release"))) pro.write("\n") pro.write("# Work around QTBUG-39300.\n") pro.write("CONFIG -= android_install\n") pro.write("\n") pro.write("target.path = %s\n" % os.path.dirname(cfg.sip_bin)) pro.write("INSTALLS += target\n") c_sources = get_sources("sipgen", "*.c") pro.write("\n") pro.write("SOURCES = %s\n" % " ".join(c_sources)) headers = get_sources("sipgen", "*.h") pro.write("\n") pro.write("HEADERS = %s\n" % " ".join(headers)) pro.close() else: sipconfig.inform("Creating sip code generator Makefile...") sipconfig.ProgramMakefile( configuration=cfg, build_file=os.path.join(src_dir, "sipgen", "sipgen.sbf"), dir="sipgen", install_dir=os.path.dirname(cfg.sip_bin), console=1, warnings=0, universal=opts.universal, arch=opts.arch, deployment_target=opts.deployment_target).generate() if opts.use_qmake: sipconfig.inform("Creating sip module .pro file...") pro = open(os.path.join("siplib", "siplib.pro"), "w") pro.write("TEMPLATE = lib\n") pro.write("TARGET = %s\n" % sip_module_base) pro.write("CONFIG -= qt\n") pro.write("CONFIG += warn_on exceptions_off %s %s\n" % (("staticlib" if opts.static else "plugin"), ("debug" if opts.debug else "release"))) pro.write("\n") pro.write("# Work around QTBUG-39300.\n") pro.write("CONFIG -= android_install\n") pro.write("\n") pro.write("INCLUDEPATH += %s\n" % cfg.py_inc_dir) if cfg.py_conf_inc_dir != cfg.py_inc_dir: pro.write("INCLUDEPATH += %s\n" % cfg.py_conf_inc_dir) if not opts.static: # These only need to be correct for Windows. debug_suffix = "_d" if opts.debug else "" link_lib_dir = quote("-L" + cfg.py_lib_dir) pro.write(""" win32 { PY_MODULE = %s%s.pyd target.files = %s%s.pyd LIBS += %s -lpython%d.%d QMAKE_POST_LINK = $(COPY_FILE) $(DESTDIR_TARGET) $$PY_MODULE } else { PY_MODULE = %s.so target.files = %s.so QMAKE_POST_LINK = $(COPY_FILE) $(TARGET) $$PY_MODULE } macx { QMAKE_LFLAGS += "-undefined dynamic_lookup" QMAKE_LFLAGS += "-install_name $$absolute_path($$PY_MODULE, $$target.path)" } """ % (sip_module_base, debug_suffix, sip_module_base, debug_suffix, link_lib_dir, (py_version >> 16), ((py_version >> 8) & 0xff), sip_module_base, sip_module_base)) pro.write("\n") pro.write("target.CONFIG = no_check_exist\n") pro.write("target.path = %s\n" % cfg.sip_mod_dir) pro.write("INSTALLS += target\n") pro.write("\n") pro.write("sip_h.files = sip.h\n") pro.write("sip_h.path = %s\n" % cfg.sip_inc_dir) pro.write("INSTALLS += sip_h\n") c_sources = get_sources("siplib", "*.c") cpp_sources = get_sources("siplib", "*.cpp") pro.write("\n") pro.write("SOURCES = %s\n" % " ".join(c_sources + cpp_sources)) headers = get_sources("siplib", "*.h") pro.write("\n") pro.write("HEADERS = %s\n" % " ".join(headers)) pro.close() else: sipconfig.inform("Creating sip module Makefile...") sipconfig.ModuleMakefile( configuration=cfg, build_file=os.path.join(src_dir, "siplib", "siplib.sbf"), dir="siplib", install_dir=cfg.sip_mod_dir, installs=([os.path.join(src_dir, "siplib", "sip.h")], cfg.sip_inc_dir), console=1, warnings=0, static=opts.static, debug=opts.debug, universal=opts.universal, arch=opts.arch, deployment_target=opts.deployment_target).generate()
def create_makefiles(macros): """Create the Makefiles. macros is the dictionary of platform specific build macros. """ # Bootstrap. Make sure we get the right one. sys.path.insert(0, os.path.curdir) invalidate_caches() import sipconfig cfg = sipconfig.Configuration() cfg.set_build_macros(macros) all_installs = [] top_installs = [] gen_installs = [] subdirs = [] if not opts.no_tools: subdirs.append('sipgen') top_installs.append( (["sipconfig.py", os.path.join(src_dir, "sipdistutils.py")], cfg.sip_root_dir)) gen_installs.append((os.path.join(src_dir, "siplib", "sip.h"), cfg.sip_inc_dir)) if not opts.no_module: subdirs.append('siplib') all_installs.extend(top_installs) all_installs.extend(gen_installs) # The command to run to generate the dist-info directory. mk_distinfo = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'mk_distinfo.py') distinfo_dir = os.path.join( cfg.sip_module_dir, '%s-%s.dist-info' % (sip_module_name.replace('.', '_'), sip_version_str)) if opts.use_qmake: run_mk_distinfo = '%s %s \\\"$(INSTALL_ROOT)\\\" %s installed.txt' % ( sys.executable, mk_distinfo, distinfo_dir) sipconfig.inform("Creating top level .pro file...") pro = open("sip.pro", "w") pro.write("TEMPLATE = subdirs\n") pro.write("SUBDIRS = %s\n" % " ".join(subdirs)) if top_installs: # There will only be one element. files, path = top_installs[0] pro.write("\n") pro.write("build_system.files = %s\n" % " ".join(files)) pro.write("build_system.path = %s\n" % quote(path)) pro.write("INSTALLS += build_system\n") if opts.distinfo: pro.write("\n") pro.write("distinfo.extra = %s\n" % run_mk_distinfo) pro.write("distinfo.path = %s\n" % quote(cfg.sip_module_dir)) pro.write("INSTALLS += distinfo\n") pro.close() else: run_mk_distinfo = '%s %s "$(DESTDIR)" %s installed.txt' % ( sys.executable, mk_distinfo, distinfo_dir) sipconfig.inform("Creating top level Makefile...") # Note that mk_distinfo.py won't exist if we are building from the # repository. if opts.distinfo and os.path.isfile(mk_distinfo): top_installs.append((run_mk_distinfo, None)) sipconfig.ParentMakefile(configuration=cfg, subdirs=subdirs, installs=top_installs).generate() if opts.use_qmake: sipconfig.inform("Creating sip code generator .pro file...") pro = open(os.path.join("sipgen", "sipgen.pro"), "w") pro.write("TEMPLATE = app\n") pro.write("TARGET = sip\n") pro.write("CONFIG -= qt app_bundle\n") pro.write("CONFIG += warn_on exceptions_off console %s\n" % (("debug" if opts.debug else "release"))) pro.write("\n") pro.write("# Work around QTBUG-39300.\n") pro.write("CONFIG -= android_install\n") pro.write("\n") pro.write("target.path = %s\n" % os.path.dirname(cfg.sip_bin)) pro.write("INSTALLS += target\n") c_sources = get_sources("sipgen", "*.c") pro.write("\n") pro.write("SOURCES = %s\n" % " ".join([qmake_quote(s) for s in c_sources])) headers = get_sources("sipgen", "*.h") pro.write("\n") pro.write("HEADERS = %s\n" % " ".join([qmake_quote(h) for h in headers])) if gen_installs: # There will only be one element. files, path = gen_installs[0] pro.write("\n") pro.write("sip_h.files = %s\n" % " ".join(files)) pro.write("sip_h.path = %s\n" % quote(path)) pro.write("INSTALLS += sip_h\n") pro.close() else: sipconfig.inform("Creating sip code generator Makefile...") sipconfig.ProgramMakefile( configuration=cfg, build_file=os.path.join(src_dir, "sipgen", "sipgen.sbf"), dir="sipgen", install_dir=os.path.dirname(cfg.sip_bin), installs=gen_installs, console=1, warnings=1, universal=opts.universal, arch=opts.arch, deployment_target=opts.deployment_target).generate() # The implied code generator installs. if not opts.no_tools: sip_dir, sip_exe = os.path.split(cfg.sip_bin) if sys.platform == 'win32': sip_exe += '.exe' all_installs.append((sip_exe, sip_dir)) # The module installs. module_installs = [] if opts.pyi: module_installs.append((os.path.join(src_dir, 'sip.pyi'), pyi_dir)) all_installs.extend(module_installs) if not opts.no_module: if sys.platform == 'win32': mod = 'sip.lib' if opts.static else 'sip.pyd' else: mod = 'libsip.a' if opts.static else 'sip.so' all_installs.append((mod, sip_module_dest_dir)) if opts.use_qmake: sipconfig.inform("Creating sip module .pro file...") pro = open(os.path.join("siplib", "siplib.pro"), "w") pro.write("TEMPLATE = lib\n") pro.write("TARGET = sip\n") pro.write("CONFIG -= qt\n") pro.write("CONFIG += warn_on exceptions_off %s %s\n" % (("staticlib" if opts.static else "plugin plugin_bundle"), ("debug" if opts.debug else "release"))) pro.write("\n") pro.write("# Work around QTBUG-39300.\n") pro.write("CONFIG -= android_install\n") pro.write("\n") pro.write("INCLUDEPATH += %s\n" % cfg.py_inc_dir) if cfg.py_conf_inc_dir != cfg.py_inc_dir: pro.write("INCLUDEPATH += %s\n" % cfg.py_conf_inc_dir) if sip_module_name != 'sip': pro.write("\n") pro.write('DEFINES += SIP_MODULE_NAME=%s\n' % sip_module_name) base_name = sip_module_name.split('.')[-1] if base_name != 'sip': pro.write('DEFINES += SIP_MODULE_BASENAME=%s\n' % base_name) if not opts.static: # These only need to be correct for Windows. debug_suffix = "_d" if opts.debug else "" link_lib_dir = quote("-L" + cfg.py_lib_dir) pro.write(""" win32 { PY_MODULE = sip%s.pyd PY_MODULE_SRC = $(DESTDIR_TARGET) LIBS += %s } else { PY_MODULE = sip.so macx { PY_MODULE_SRC = $(TARGET).plugin/Contents/MacOS/$(TARGET) QMAKE_LFLAGS += "-undefined dynamic_lookup" } else { PY_MODULE_SRC = $(TARGET) } } QMAKE_POST_LINK = $(COPY_FILE) $$PY_MODULE_SRC $$PY_MODULE target.CONFIG = no_check_exist target.files = $$PY_MODULE """ % (debug_suffix, link_lib_dir)) pro.write("\n") pro.write("target.path = %s\n" % sip_module_dest_dir) pro.write("INSTALLS += target\n") if opts.pyi: pro.write("\n") pro.write("sip_pyi.files = sip.pyi\n") pro.write("sip_pyi.path = %s\n" % pyi_dir) pro.write("INSTALLS += sip_pyi\n") c_sources = get_sources("siplib", "*.c") cpp_sources = get_sources("siplib", "*.cpp") pro.write("\n") pro.write("SOURCES = %s\n" % " ".join([qmake_quote(s) for s in c_sources + cpp_sources])) headers = get_sources("siplib", "*.h") pro.write("\n") pro.write("HEADERS = %s\n" % " ".join([qmake_quote(h) for h in headers])) pro.close() else: sipconfig.inform("Creating sip module Makefile...") build_dir = os.getcwd() makefile = sipconfig.ModuleMakefile( configuration=cfg, build_file=os.path.join(src_dir, "siplib", "siplib.sbf"), dir="siplib", install_dir=sip_module_dest_dir, installs=module_installs, console=1, warnings=1, static=opts.static, debug=opts.debug, universal=opts.universal, arch=opts.arch, deployment_target=opts.deployment_target) if sip_module_name != 'sip': makefile.DEFINES.append('SIP_MODULE_NAME=%s' % sip_module_name) base_name = sip_module_name.split('.')[-1] if base_name != 'sip': makefile.DEFINES.append('SIP_MODULE_BASENAME=%s' % base_name) if src_dir != build_dir: src_siplib_dir = os.path.join(src_dir, "siplib") makefile.extra_include_dirs.append(src_siplib_dir) makefile.extra_source_dirs.append(src_siplib_dir) makefile.generate() # Create the file containing all installed files. if opts.distinfo: installed = open('installed.txt', 'w') for sources, dst in all_installs: if not isinstance(sources, (list, tuple)): sources = [sources] for src in sources: installed.write( os.path.join(dst, os.path.basename(src)) + '\n') installed.close()
build = {} if sys.platform == "win32" and WindowsInterpreter: build["target"] = InterpreterName + "w" build["sources"] = "customw.c" console = False else: build["target"] = InterpreterName build["sources"] = "custom.c" console = True # Assume Qt support is required if Qt support was enabled in the sip module. qt = (cfg.qt_version > 0) # Create the Makefile instance. mf = sipconfig.ProgramMakefile(cfg, build, python=True, console=console, qt=qt) # Modify the Makefile according to the values set above. mf.extra_lib_dirs.extend(ExtraLibraryDirectories) mf.extra_lib_dirs.append(ModuleDirectory) mf.extra_lib_dirs.append(PythonLibraryDirectory) mf.extra_libs.extend(Modules) if sys.platform == "win32": pylib = "python%u%u" else: pylib = "python%u.%u" mf.extra_libs.append(pylib % ((cfg.py_version >> 16), ((cfg.py_version >> 8) & 0xff))) mf.extra_libs.extend(ExtraLibraries)