Mercurial > fife-parpg
comparison utils/scons/scons_utils.py @ 378:64738befdf3b
bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author | vtchill@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 11 Jan 2010 23:34:52 +0000 |
parents | |
children | 81641655bc38 |
comparison
equal
deleted
inserted
replaced
377:fe6fb0e0ed23 | 378:64738befdf3b |
---|---|
1 import os, sys | |
2 from string import Template | |
3 | |
4 _sep = os.path.sep | |
5 | |
6 def is_implfile(fname): | |
7 return fname.endswith('.cpp') or fname.endswith('.cxx') or fname.endswith('.m') | |
8 | |
9 def is_headerfile(fname): | |
10 return fname.endswith('.hpp') or fname.endswith('.h') | |
11 | |
12 def is_swigfile(fname): | |
13 return fname.endswith('.i') | |
14 | |
15 #need this function because python 2.5 doesnt support os.path.relpath | |
16 def relpath(longPath, basePath): | |
17 if not longPath.startswith(basePath): | |
18 raise RuntimeError("Unexpected arguments") | |
19 if longPath == basePath: | |
20 return "." | |
21 i = len(basePath) | |
22 if not basePath.endswith(os.path.sep): | |
23 i += len(os.path.sep) | |
24 return longPath[i:] | |
25 | |
26 #This generates the a list of absolute paths with filenames | |
27 def gen_dest_files(dest_path, source_files): | |
28 dest_files = list() | |
29 for f in source_files: | |
30 dest_files.append(os.path.join(dest_path,f)) | |
31 | |
32 return dest_files | |
33 | |
34 def importConfig(config): | |
35 module = __import__(config) | |
36 parts = config.split('.') | |
37 for part in parts[1:]: | |
38 module = getattr(module, part) | |
39 return module | |
40 | |
41 def getPlatformConfig(): | |
42 filename = 'build' + _sep + sys.platform + '-config' | |
43 sconsfilename = 'build.' + sys.platform + '-config' | |
44 if os.path.exists(filename + '.py'): | |
45 return importConfig(sconsfilename) | |
46 else: | |
47 print 'no platform-config found (searched ' + filename + '.py)' | |
48 Exit(1) | |
49 | |
50 def tryConfigCommand(context, cmd): | |
51 ret = context.TryAction(cmd)[0] | |
52 context.Result(ret) | |
53 if ret: | |
54 context.env.ParseConfig(cmd) | |
55 return ret | |
56 | |
57 def checkPKG(context, name): | |
58 context.Message('Checking for %s (using pkg-config)...' %name) | |
59 return tryConfigCommand(context, 'pkg-config --libs --cflags \'%s\'') | |
60 | |
61 def checkConf(context, name): | |
62 binary = '%s-config' % name.lower() | |
63 context.Message('Checking for %s (using %s)... ' % (name, binary)) | |
64 configcall = '%s --libs --cflags' %binary | |
65 return tryConfigCommand(context, configcall) | |
66 | |
67 def filter_by_dir(dirfilters, files): | |
68 result = [] | |
69 for f in files: | |
70 filtered = False | |
71 for p in dirfilters: | |
72 s_files = f.split(_sep) | |
73 for s in s_files: | |
74 if s == p: | |
75 filtered = True | |
76 break | |
77 if not filtered: | |
78 result.append(f) | |
79 return result | |
80 | |
81 def gen_swig_interface(templatefile, source, outdir): | |
82 template = Template(open(templatefile).read()) | |
83 inclusions = sorted([os.path.join('%include engine', str(f)) for f in source]) | |
84 inclusions = '\n'.join(inclusions) | |
85 interfacefile = os.path.join(outdir, 'fife.i') | |
86 open(interfacefile, 'w').write(template.substitute(inclusions=inclusions)) |