📄 gen_win.py
字号:
dblib = None if self.bdb_lib: dblib = self.bdb_lib+(cfg == 'Debug' and 'd.lib' or '.lib') neonlib = self.neon_lib+(cfg == 'Debug' and 'd.lib' or '.lib') zlib = (cfg == 'Debug' and 'zlibstatD.lib' or 'zlibstat.lib') if not isinstance(target, gen_base.TargetLinked): return [] if isinstance(target, gen_base.TargetLib) and target.msvc_static: return [] nondeplibs = target.msvc_libs[:] nondeplibs.append(zlib) if self.enable_nls: if self.libintl_path: nondeplibs.append(self.apath(self.libintl_path, 'lib', 'intl3_svn.lib')) else: nondeplibs.append('intl3_svn.lib') if isinstance(target, gen_base.TargetExe): nondeplibs.append('setargv.obj') if ((isinstance(target, gen_base.TargetSWIG) or isinstance(target, gen_base.TargetSWIGLib)) and target.lang == 'perl'): nondeplibs.append(self.perl_lib) for dep in self.get_win_depends(target, FILTER_LIBS): nondeplibs.extend(dep.msvc_libs) if dep.external_lib == '$(SVN_DB_LIBS)': nondeplibs.append(dblib) if dep.external_lib == '$(NEON_LIBS)': nondeplibs.append(neonlib) return gen_base.unique(nondeplibs) def get_win_sources(self, target, reldir_prefix=''): "Return the list of source files that need to be compliled for target" sources = { } for obj in self.graph.get_sources(gen_base.DT_LINK, target.name): if isinstance(obj, gen_base.Target): continue for src in self.graph.get_sources(gen_base.DT_OBJECT, obj): if isinstance(src, gen_base.SourceFile): if reldir_prefix: if src.reldir: reldir = reldir_prefix + '\\' + src.reldir else: reldir = reldir_prefix else: reldir = src.reldir else: reldir = '' sources[src] = src, obj, reldir return sources.values() def write_file_if_changed(self, fname, new_contents): """Rewrite the file if new_contents are different than its current content. If you have your windows projects open and generate the projects it's not a small thing for windows to re-read all projects so only update those that have changed. """ try: old_contents = open(fname, 'rb').read() except IOError: old_contents = None if old_contents != new_contents: open(fname, 'wb').write(new_contents) print "Wrote:", fname def write_with_template(self, fname, tname, data): fout = StringIO() template = ezt.Template(compress_whitespace = 0) template.parse_file(os.path.join('build', 'generator', tname)) template.generate(fout, data) self.write_file_if_changed(fname, fout.getvalue()) def write_zlib_project_file(self, name): if not self.zlib_path: return zlib_path = os.path.abspath(self.zlib_path) self.move_proj_file(os.path.join('build', 'win32'), name, (('zlib_path', zlib_path), ('zlib_sources', glob.glob(os.path.join(zlib_path, '*.c')) + glob.glob(os.path.join(zlib_path, 'contrib/masmx86/*.c')) + glob.glob(os.path.join(zlib_path, 'contrib/masmx86/*.asm'))), ('zlib_headers', glob.glob(os.path.join(zlib_path, '*.h'))), )) def write_neon_project_file(self, name): neon_path = os.path.abspath(self.neon_path) self.move_proj_file(self.neon_path, name, (('neon_sources', glob.glob(os.path.join(neon_path, 'src', '*.c'))), ('neon_headers', glob.glob(os.path.join(neon_path, 'src', '*.h'))), ('expat_path', os.path.join(os.path.abspath(self.apr_util_path), 'xml', 'expat', 'lib')), ('zlib_path', self.zlib_path and os.path.abspath(self.zlib_path)), ('openssl_path', self.openssl_path and os.path.abspath(self.openssl_path)), )) def write_serf_project_file(self, name): if not self.serf_path: return serf_path = os.path.abspath(self.serf_path) self.move_proj_file(self.serf_path, name, (('serf_sources', glob.glob(os.path.join(serf_path, '*.c')) + glob.glob(os.path.join(serf_path, 'buckets', '*.c'))), ('serf_headers', glob.glob(os.path.join(serf_path, '*.h')) + glob.glob(os.path.join(serf_path, 'buckets', '*.h'))), ('zlib_path', self.zlib_path and os.path.abspath(self.zlib_path)), ('openssl_path', self.openssl_path and os.path.abspath(self.openssl_path)), ('apr_path', os.path.abspath(self.apr_path)), ('apr_util_path', os.path.abspath(self.apr_util_path)), )) def move_proj_file(self, path, name, params=()): ### Move our slightly templatized pre-built project files into place -- ### these projects include apr, zlib, neon, locale, config, etc. dest_file = os.path.join(path, name) source_template = name + '.ezt' data = { 'version' : self.vsnet_proj_ver, } for key, val in params: data[key] = val self.write_with_template(dest_file, source_template, data) def write(self): "Override me when creating a new project type" raise NotImplementedError def _find_bdb(self): "Find the Berkley DB library and version" for lib in ("libdb44", "libdb43", "libdb42", "libdb41", "libdb40"): path = os.path.join(self.bdb_path, "lib") if os.path.exists(os.path.join(path, lib + ".lib")): sys.stderr.write("Found %s.lib in %s\n" % (lib, path)) self.bdb_lib = lib break else: sys.stderr.write("BDB not found, BDB fs will not be built\n") self.bdb_lib = None def _find_perl(self): "Find the right perl library name to link swig bindings with" fp = os.popen('perl -MConfig -e ' + escape_shell_arg( 'print "$Config{PERL_REVISION}$Config{PERL_VERSION}"'), 'r') try: num = fp.readline() if num: msg = 'Found installed perl version number.' self.perl_lib = 'perl' + string.rstrip(num) + '.lib' else: msg = 'Could not detect perl version.' self.perl_lib = 'perl56.lib' sys.stderr.write('%s\n Perl bindings will be linked with %s\n' % (msg, self.perl_lib)) finally: fp.close() def _find_swig(self): # Require 1.3.24. If not found, assume 1.3.25. default_version = '1.3.25' minimum_version = '1.3.24' vernum = 103025 minimum_vernum = 103024 libdir = '' if self.swig_path is not None: self.swig_exe = os.path.join(self.swig_path, 'swig') else: self.swig_exe = 'swig' infp, outfp = os.popen4(self.swig_exe + ' -version') infp.close() try: txt = outfp.read() if txt: vermatch = re.compile(r'^SWIG\ Version\ (\d+)\.(\d+)\.(\d+)$', re.M) \ .search(txt) else: vermatch = None if vermatch: version = (int(vermatch.group(1)), int(vermatch.group(2)), int(vermatch.group(3))) # build/ac-macros/swig.m4 explains the next incantation vernum = int('%d%02d%03d' % version) sys.stderr.write('Found installed SWIG version %d.%d.%d\n' % version) if vernum < minimum_vernum: sys.stderr.write('WARNING: Subversion requires version %s\n' % minimum_version) libdir = self._find_swig_libdir() else: sys.stderr.write('Could not find installed SWIG,' ' assuming version %s\n' % default_version) self.swig_libdir = '' finally: outfp.close() self.swig_vernum = vernum self.swig_libdir = libdir def _find_swig_libdir(self): fp = os.popen(self.swig_exe + ' -swiglib', 'r') try: libdir = string.rstrip(fp.readline()) if libdir: sys.stderr.write('Using SWIG library directory %s\n' % libdir) return libdir else: sys.stderr.write('WARNING: could not find SWIG library directory\n') finally: fp.close() return '' def _find_ml(self): "Check if the ML assembler is in the path" fp = os.popen('ml /help', 'r') try: line = fp.readline() if line: msg = 'Found ML, ZLib build will use ASM sources' self.have_ml = 1 else: msg = 'Could not find ML, ZLib build will not use ASM sources' self.have_ml = 0 sys.stderr.write('%s\n' % (msg,)) finally: fp.close() def _find_neon(self): "Find the neon version" msg = 'WARNING: Unable to determine neon version\n' try: self.neon_lib = "libneon" fp = open(os.path.join(self.neon_path, '.version')) txt = fp.read() vermatch = re.compile(r'(\d+)\.(\d+)\.(\d+)$', re.M) \ .search(txt) if vermatch: version = (int(vermatch.group(1)), int(vermatch.group(2)), int(vermatch.group(3))) # build/ac-macros/swig.m4 explains the next incantation self.neon_ver = int('%d%02d%03d' % version) msg = 'Found neon version %d.%d.%d\n' % version except: msg = 'WARNING: Error while determining neon version\n' sys.stderr.write(msg) def _configure_apr_util(self): if not self.configure_apr_util: return script_path = os.path.join(self.apr_util_path, "build", "w32locatedb.pl") inc_path = os.path.join(self.bdb_path, "include") lib_path = os.path.join(self.bdb_path, "lib") cmdline = "perl %s dll %s %s" % (escape_shell_arg(script_path), escape_shell_arg(inc_path), escape_shell_arg(lib_path)) sys.stderr.write('Configuring apr-util library...\n%s\n' % cmdline) if os.system(cmdline): sys.stderr.write('WARNING: apr-util library was not configured' ' successfully\n')class ProjectItem: "A generic item class for holding sources info, config info, etc for a project" def __init__(self, **kw): vars(self).update(kw)# ============================================================================# This is a cut-down and modified version of code from:# subversion/subversion/bindings/swig/python/svn/core.py#if sys.platform == "win32": _escape_shell_arg_re = re.compile(r'(\\+)(\"|$)') def escape_shell_arg(arg): # The (very strange) parsing rules used by the C runtime library are # described at: # http://msdn.microsoft.com/library/en-us/vclang/html/_pluslang_Parsing_C.2b2b_.Command.2d.Line_Arguments.asp # double up slashes, but only if they are followed by a quote character arg = re.sub(_escape_shell_arg_re, r'\1\1\2', arg) # surround by quotes and escape quotes inside arg = '"' + string.replace(arg, '"', '"^""') + '"' return argelse: def escape_shell_arg(str): return "'" + string.replace(str, "'", "'\\''") + "'"# ============================================================================FILTER_LIBS = 1FILTER_PROJECTS = 2class POFile: "Item class for holding po file info" def __init__(self, base): self.po = base + '.po' self.spo = base + '.spo' self.mo = base + '.mo'# MSVC paths always use backslashes regardless of current platformdef msvc_path(path): """Convert a build path to an msvc path""" return string.replace(path, '/', '\\')def msvc_path_join(*path_parts): """Join path components into an msvc path""" return string.join(path_parts, '\\')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -