📄 siputils.py
字号:
Makefile.__init__(self, configuration, console, qt, opengl, 1, threaded, warnings, debug, dir, makefile, installs) self._build = self.parse_build_file(build_file) self._install_dir = install_dir self._dir = dir self.static = static # Don't strip or restrict the exports if this is a debug or static # build. if debug or static: self._strip = 0 self._limit_exports = 0 else: self._strip = strip # The deprecated configuration flag has precedence. if self.config.export_all: self._limit_exports = 0 else: self._limit_exports = not export_all # Save the target name for later. self._target = self._build["target"] if sys.platform != "win32" and static: self._target = "lib" + self._target if sys.platform == "win32" and debug: self._target = self._target + "_d" def finalise(self): """Finalise the macros common to all module Makefiles. """ if self.console: lflags_console = "LFLAGS_CONSOLE" else: lflags_console = "LFLAGS_WINDOWS" if self.static: self.DEFINES.append("SIP_STATIC_MODULE") else: self.CFLAGS.extend(self.optional_list("CFLAGS_SHLIB")) self.CXXFLAGS.extend(self.optional_list("CXXFLAGS_SHLIB")) lflags_dll = self.optional_list("LFLAGS_DLL") if lflags_dll: self.LFLAGS.extend(lflags_dll) elif self.console: lflags_console = "LFLAGS_CONSOLE_DLL" else: lflags_console = "LFLAGS_WINDOWS_DLL" # We use this to explictly create bundles on MacOS. Apple's Python # can handle extension modules that are bundles or dynamic # libraries, but python.org versions need bundles (unless built # with DYNLOADFILE=dynload_shlib.o). if sys.platform == "darwin": lflags_plugin = ["-bundle"] else: lflags_plugin = self.optional_list("LFLAGS_PLUGIN") if not lflags_plugin: lflags_plugin = self.optional_list("LFLAGS_SHLIB") self.LFLAGS.extend(lflags_plugin) self.LFLAGS.extend(self.optional_list(lflags_console)) if sys.platform == "darwin": # We use the -F flag to explictly specify the directory containing # the Python framework rather than rely on the default search path. # This allows Apple's Python to be used even if a later python.org # version is also installed. dl = string.split(sys.exec_prefix, os.sep) dl = dl[:dl.index("Python.framework")] self.LFLAGS.append("-F%s" % string.join(dl, os.sep)) self.LFLAGS.append("-framework Python") Makefile.finalise(self) if not self.static: if self.optional_string("AIX_SHLIB"): # AIX needs a lot of special handling. if self.required_string('LINK') == 'g++': # g++ is used for linking. # For SIP v4 and g++: # 1.) Import the python symbols aix_lflags = ['-Wl,-bI:%s/python.exp' % self.config.py_lib_dir] if self._limit_exports: aix_lflags.append('-Wl,-bnoexpall') aix_lflags.append('-Wl,-bnoentry') aix_lflags.append('-Wl,-bE:%s.exp' % self._target) else: # IBM VisualAge C++ is used for linking. # For SIP v4 and xlC: # 1.) Create a shared object # 2.) Import the python symbols aix_lflags = ['-qmkshrobj', '-bI:%s/python.exp' % self.config.py_lib_dir] if self._limit_exports: aix_lflags.append('-bnoexpall') aix_lflags.append('-bnoentry') aix_lflags.append('-bE:%s.exp' % self._target) self.LFLAGS.extend(aix_lflags) else: if self._limit_exports: if sys.platform[:5] == 'linux': self.LFLAGS.extend(['-Wl,--version-script=%s.exp' % self._target]) elif sys.platform[:5] == 'hp-ux': self.LFLAGS.extend(['-Wl,+e,init%s' % self._target]) elif sys.platform[:5] == 'irix' and self.required_string('LINK') != 'g++': # Doesn't work when g++ is used for linking on IRIX. self.LFLAGS.extend(['-Wl,-exported_symbol,init%s' % self._target]) # Force the shared linker if there is one. link_shlib = self.optional_list("LINK_SHLIB") if link_shlib: self.LINK.set(link_shlib) def module_as_lib(self, mname): """Return the name of a SIP v3.x module when it is used as a library. This will raise an exception when used with SIP v4.x modules. mname is the name of the module. """ raise ValueError, "module_as_lib() can only be used with SIP v3.x" def generate_macros_and_rules(self, mfile): """Generate the macros and rules generation. mfile is the file object. """ if self.static: if sys.platform == "win32": ext = "lib" else: ext = "a" else: if sys.platform == "win32": ext = "pyd" elif sys.platform == "darwin": ext = "so" elif sys.platform == "cygwin": ext = "dll" else: ext = self.optional_string("EXTENSION_PLUGIN") if not ext: ext = self.optional_string("EXTENSION_SHLIB", "so") mfile.write("TARGET = %s\n" % (self._target + "." + ext)) mfile.write("OFILES = %s\n" % self._build["objects"]) mfile.write("HFILES = %s %s\n" % (self._build["headers"], self._build["moc_headers"])) mfile.write("\n") if self.static: if self.generator in ("MSVC", "MSVC.NET", "BMAKE"): mfile.write("LIB = %s\n" % self.required_string("LIB")) else: mfile.write("AR = %s\n" % self.required_string("AR")) self._ranlib = self.optional_string("RANLIB") if self._ranlib: mfile.write("RANLIB = %s\n" % self._ranlib) Makefile.generate_macros_and_rules(self, mfile) def generate_target_default(self, mfile): """Generate the default target. mfile is the file object. """ mfile.write("\n$(TARGET): $(OFILES)\n") if self.generator in ("MSVC", "MSVC.NET"): if self.static: mfile.write("\t$(LIB) /OUT:$(TARGET) @<<\n") mfile.write("\t $(OFILES)\n") mfile.write("<<\n") else: mfile.write("\t$(LINK) $(LFLAGS) /OUT:$(TARGET) @<<\n") mfile.write("\t $(OFILES) $(LIBS)\n") mfile.write("<<\n") elif self.generator == "BMAKE": if self.static: mfile.write("\t-%s $(TARGET)\n" % (self.rm)) mfile.write("\t$(LIB) $(TARGET) @&&|\n") for of in string.split(self._build["objects"]): mfile.write("+%s \\\n" % (of)) mfile.write("|\n") else: mfile.write("\t$(LINK) @&&|\n") mfile.write("\t$(LFLAGS) $(OFILES) ,$(TARGET),,$(LIBS),%s\n" % (self._target)) mfile.write("|\n") # Create the .def file that renames the entry point. defname = self._target + ".def" if self._dir: defname = os.path.join(self._dir, defname) try: dfile = open(defname, "w") except IOError, detail: error("Unable to create \"%s\": %s" % (defname, detail)) dfile.write("EXPORTS\n") dfile.write("init%s=_init%s\n" % (self._target, self._target)) dfile.close() else: if self.static: mfile.write("\t-%s $(TARGET)\n" % self.rm) mfile.write("\t$(AR) $(TARGET) $(OFILES)\n") if self._ranlib: mfile.write("\t$(RANLIB) $(TARGET)\n") else: if self._limit_exports: # Create an export file for AIX and Linux. if sys.platform[:5] == 'linux': mfile.write("\t@echo '{ global: init%s; local: *; };' > %s.exp\n" % (self._target, self._target)) elif sys.platform[:3] == 'aix': mfile.write("\t@echo '#!' >%s.exp" % self._target) mfile.write("; \\\n\t echo 'init%s' >>%s.exp\n" % (self._target, self._target)) mfile.write("\t$(LINK) $(LFLAGS) -o $(TARGET) $(OFILES) $(LIBS)\n") mfile.write("\n$(OFILES): $(HFILES)\n") for mf in string.split(self._build["moc_headers"]): root, discard = os.path.splitext(mf) cpp = "moc_" + root + ".cpp" mfile.write("\n%s: %s\n" % (cpp, mf)) mfile.write("\t$(MOC) -o %s %s\n" % (cpp, mf)) def generate_target_install(self, mfile): """Generate the install target. mfile is the file object. """ if self._install_dir is None: self._install_dir = self.config.default_mod_dir mfile.write("\ninstall: $(TARGET)\n") self.install_file(mfile, "$(TARGET)", self._install_dir, self._strip) def generate_target_clean(self, mfile): """Generate the clean target. mfile is the file object. """ mfile.write("\nclean:\n") self.clean_build_file_objects(mfile, self._build) # Remove any export file on AIX and Linux. if self._limit_exports and (sys.platform[:5] == 'linux' or sys.platform[:3] == 'aix'): mfile.write("\t-%s %s.exp\n" % (self.rm, self._target))class SIPModuleMakefile(ModuleMakefile): """The class that represents a SIP generated module Makefile. """ def finalise(self): """Finalise the macros for a SIP generated module Makefile. """ self.INCDIR.append(self.config.sip_inc_dir) ModuleMakefile.finalise(self)class ProgramMakefile(Makefile): """The class that represents a program Makefile. """ def __init__(self, configuration, build_file=None, install_dir=None, console=0, qt=0, opengl=0, python=0, threaded=0, warnings=1, debug=0, dir=None, makefile="Makefile", installs=None): """Initialise an instance of a program Makefile. build_file is the file containing the target specific information. If it is a dictionary instead then its contents are validated. install_dir is the directory the target will be installed in. """ Makefile.__init__(self, configuration, console, qt, opengl, python, threaded, warnings, debug, dir, makefile, installs) self._install_dir = install_dir if build_file: self._build = self.parse_build_file(build_file) else: self._build = None def build_command(self, source): """Create a command line that will build an executable. Returns a tuple of the name of the executable and the command line. source is the name of the source file. """ self.ready() # The name of the executable. exe, ignore = os.path.splitext(source) if sys.platform in ("win32", "cygwin"): exe = exe + ".exe" # The command line. build = [] build.append(self.required_string("CXX")) for f in self.optional_list("DEFINES"): build.append("-D" + f) for f in self.optional_list("INCDIR"): build.append("-I" + _quote(f)) build.extend(self.optional_list("CXXFLAGS")) # Borland requires all flags to precede all file names. if self.generator != "BMAKE": build.append(source) if self.generator in ("MSVC", "MSVC.NET"): build.append("-Fe") build.append("/link") libdir_prefix = "/LIBPATH:" elif self.generator == "BMAKE": build.append("-e" + exe) libdir_prefix = "-L" else: build.append("-o") build.append(exe) libdir_prefix = "-L" for ld in self.optional_list("LIBDIR"): if sys.platform == "darwin" and self.config.qt_framework: build.append("-F" + _quote(ld)) build.append(libdir_prefix + _quote(ld)) lflags = self.optional_list("LFLAGS") # This is a huge hack demonstrating my lack of understanding of how the # Borland compiler works. if self.generator == "BMAKE": blflags = [] for lf in lflags: for f in string.split(lf): # Tell the compiler to pass the flags to the linker. if f[-1] == "-": f = "-l-" + f[1:-1] elif f[0] == "-": f = "-l" + f[1:] # Remove any explicit object files otherwise the compiler # will complain that they can't be found, but they don't # seem to be needed. if string.lower(f[-4:]) != ".obj": blflags.append(f) lflags = blflags build.extend(lflags) build.extend(self.optional_list("LIBS")) if self.generator == "BMAKE": build.append(source) return (exe, string.join(build)) def finalise(self): """Finalise the macros for a program Makefile. """ if self.generator in ("MSVC", "MSVC.NET"): self.LFLAGS.append("/INCREMENTAL:NO") if self.console: lflags_console = "LFLAGS_CONSOLE" else: lflags_console = "LFLAGS_WINDOWS" self.LFLAGS.extend(self.optional_list(lflags_console)) Makefile.finalise(self) def generate_macros_and_rules(self, mfile): """Generate the macros and rules generation.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -