comparison utils/scons/scons_builders.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
3 #**************************************************************************
4 #project file generators (scon builders)
5 #**************************************************************************
6
7 _sep = os.path.sep
8 msvcbuildpath = os.path.join('build', 'win32', 'build_environments', 'visual_studio_8')
9 msvcbuildpath9 = os.path.join('build', 'win32', 'build_environments', 'visual_studio_9')
10 cbbuildpath_win32 = os.path.join('build', 'win32', 'build_environments', 'code_blocks')
11 cbbuildpath_linux = os.path.join('build', 'linux', 'code_blocks')
12
13
14 def generate_msvc_project(target, source, env):
15 def create_dict_tree(source_dict):
16 for f in source_dict.keys():
17 parts = f.split(os.path.sep, 1)
18 if len(parts) > 1:
19 try:
20 source_dict[parts[0]][parts[1]] = {}
21 except KeyError:
22 source_dict[parts[0]] = {}
23 source_dict[parts[0]][parts[1]] = {}
24 del source_dict[f]
25 for k, d in source_dict.items():
26 create_dict_tree(d)
27 return source_dict
28
29 def get_msvc_repr(d, tabcount=2, curpath=''):
30 retstr = []
31 for k in sorted(d.keys()):
32 newpath = os.path.join(curpath, k)
33 if len(d[k].keys()):
34 retstr.append(tabcount * '\t' + '<Filter Name="%s">' % k)
35 retstr.append(get_msvc_repr(d[k], tabcount+1, newpath))
36 retstr.append(tabcount * '\t' + '</Filter>')
37 else:
38 newpath = os.path.join('..', '..', '..', '..', 'engine', newpath)
39 retstr.append(tabcount * '\t' + '<File RelativePath="%s"></File>' % newpath.replace('/','\\'))
40 return '\n'.join(retstr)
41
42 vcpaths = [os.path.abspath(str(f)).rsplit('%sengine%s' % (_sep, _sep))[-1] for f in source]
43 vcpaths.append(os.path.join('swigwrappers', 'python', 'fife_wrap.cc'))
44 xmlstr = get_msvc_repr(create_dict_tree(dict([[p, {}] for p in vcpaths])))
45 projtxt = open(os.path.join(msvcbuildpath, 'engine_template.xml'), 'r').read()
46 projtxt = projtxt.replace('__FILE_INSERTION_POINT__', xmlstr)
47
48 oldprojtxt = ''
49 try:
50 oldprojtxt = open(str(target[0]), 'r').read()
51 except:
52 pass
53
54 if(oldprojtxt <> projtxt):
55 open(str(target[0]), 'w').write(projtxt)
56 print "FIFE msvc project file succesfully created (%s)" % os.path.abspath(str(target[0]))
57 else:
58 print "FIFE msvc project file already up-to-date (%s)" % os.path.abspath(str(target[0]))
59
60
61 def generate_msvc_project9(target, source, env):
62 def create_dict_tree(source_dict):
63 for f in source_dict.keys():
64 parts = f.split(os.path.sep, 1)
65 if len(parts) > 1:
66 try:
67 source_dict[parts[0]][parts[1]] = {}
68 except KeyError:
69 source_dict[parts[0]] = {}
70 source_dict[parts[0]][parts[1]] = {}
71 del source_dict[f]
72 for k, d in source_dict.items():
73 create_dict_tree(d)
74 return source_dict
75
76 def get_msvc_repr(d, tabcount=2, curpath=''):
77 retstr = []
78 for k in sorted(d.keys()):
79 newpath = os.path.join(curpath, k)
80 if len(d[k].keys()):
81 retstr.append(tabcount * '\t' + '<Filter Name="%s">' % k)
82 retstr.append(get_msvc_repr(d[k], tabcount+1, newpath))
83 retstr.append(tabcount * '\t' + '</Filter>')
84 else:
85 newpath = os.path.join('..', '..', '..', '..', 'engine', newpath)
86 retstr.append(tabcount * '\t' + '<File RelativePath="%s"></File>' % newpath.replace('/','\\'))
87 return '\n'.join(retstr)
88
89 vcpaths = [os.path.abspath(str(f)).rsplit('%sengine%s' % (_sep, _sep))[-1] for f in source]
90 vcpaths.append(os.path.join('swigwrappers', 'python', 'fife_wrap.cc'))
91 xmlstr = get_msvc_repr(create_dict_tree(dict([[p, {}] for p in vcpaths])))
92 projtxt = open(os.path.join(msvcbuildpath9, 'engine_template.xml'), 'r').read()
93 projtxt = projtxt.replace('__FILE_INSERTION_POINT__', xmlstr)
94
95 oldprojtxt = ''
96 try:
97 oldprojtxt = open(str(target[0]), 'r').read()
98 except:
99 pass
100
101 if(oldprojtxt <> projtxt):
102 open(str(target[0]), 'w').write(projtxt)
103 print "FIFE msvc9 project file succesfully created (%s)" % os.path.abspath(str(target[0]))
104 else:
105 print "FIFE msvc9 project file already up-to-date (%s)" % os.path.abspath(str(target[0]))
106
107 def generate_codeblocks_project_win32(target, source, env):
108 codeblocksHeaderDef = \
109 ''' <Unit filename="..\..\..\engine\%s">
110 <Option compilerVar=""/>
111 <Option compile="0"/>
112 <Option link="0"/>
113 <Option target="default"/>
114 </Unit>'''
115
116 codeblocksCppDef = \
117 ''' <Unit filename="..\..\..\..\engine\%s">
118 <Option compilerVar="CPP"/>
119 <Option target="default"/>
120 </Unit>'''
121 xmlstr = []
122 for f in source:
123 newf = os.path.abspath(str(f)).rsplit('%sengine%s' % (_sep, _sep))[-1]
124 newf = newf.replace('/', '\\')
125 if str(f).endswith('.hpp') or str(f).endswith('.h'):
126 xmlstr.append(codeblocksHeaderDef % newf)
127 else:
128 xmlstr.append(codeblocksCppDef % newf)
129
130 xmlstr.append(codeblocksCppDef % os.path.join('swigwrappers', 'python', 'fife_wrap.cc'))
131
132 projtxt = open(os.path.join(cbbuildpath_win32, 'engine_template.xml'), 'r').read()
133 projtxt = projtxt.replace('__FILE_INSERTION_POINT__', '\n'.join(xmlstr))
134 open(str(target[0]), 'w').write(projtxt)
135 print "FIFE code::blocks project file succesfully created (%s)" % os.path.abspath(str(target[0]))
136
137 def generate_codeblocks_project_linux(target, source, env):
138 codeblocksHeaderDef = \
139 ''' <Unit filename="../../../engine/%s">
140 <Option compilerVar=""/>
141 <Option compile="0"/>
142 <Option link="0"/>
143 <Option target="default"/>
144 </Unit>'''
145
146 codeblocksCppDef = \
147 ''' <Unit filename="../../../engine/%s">
148 <Option compilerVar="CPP"/>
149 <Option target="default"/>
150 </Unit>'''
151 xmlstr = []
152 for f in source:
153 newf = os.path.abspath(str(f)).rsplit('%sengine%s' % (_sep, _sep))[-1]
154 newf = newf.replace('/', '\\')
155 if str(f).endswith('.hpp') or str(f).endswith('.h'):
156 xmlstr.append(codeblocksHeaderDef % newf)
157 else:
158 xmlstr.append(codeblocksCppDef % newf)
159
160 xmlstr.append(codeblocksCppDef % os.path.join('swigwrappers', 'python', 'fife_wrap.cc'))
161
162 projtxt = open(os.path.join(cbbuildpath_linux, 'engine_template.xml'), 'r').read()
163 projtxt = projtxt.replace('__FILE_INSERTION_POINT__', '\n'.join(xmlstr))
164 open(str(target[0]), 'w').write(projtxt)
165 print "FIFE code::blocks project file succesfully created (%s)" % os.path.abspath(str(target[0]))
166