10
PROG = "r" + "$Rev: 17 $".strip("$ ").replace("Rev: ", "")
11
PYTHON = os.path.basename(sys.executable)
22
proc = subprocess.Popen(gcc + " -v", stdout=subprocess.PIPE,
23
stderr=subprocess.STDOUT, shell=True)
26
s = proc.stdout.readline()
29
if s.find("gcc version") >= 0:
30
ver = s.split(None, 3)[2]
36
# Get Visual Studio info
43
proc = subprocess.Popen("cl", stdout=subprocess.PIPE,
44
stderr=subprocess.STDOUT)
46
s = proc.stdout.readline()
49
pos = s.find("Version")
53
ver = s.split(None, 1)[0]
80
self.vs_version = "vs" + self.version
81
self.vs_release = "vs" + self.release
93
# Check that EPOCROOT is set
94
if not "EPOCROOT" in os.environ:
95
sys.stderr.write("Error: EPOCROOT environment variable is not set\n")
97
epocroot = os.environ["EPOCROOT"]
98
# EPOCROOT must have trailing backslash
99
if epocroot[-1] != "\\":
100
epocroot = epocroot + "\\"
101
os.environ["EPOCROOT"] = epocroot
102
self.epocroot = epocroot
103
self.sdk = sdk1 = epocroot.split("\\")[-2]
104
self.device = "@" + self.sdk + ":com.nokia.s60"
106
# Check that correct device is set
107
proc = subprocess.Popen("devices", stdout=subprocess.PIPE,
108
stderr=subprocess.STDOUT, shell=True)
111
line = proc.stdout.readline()
112
if line.find("- default") > 0:
113
sdk2 = line.split(":",1)[0]
118
sys.stderr.write("Error: default SDK in device doesn't match EPOCROOT\n")
119
sys.stderr.write("Default device SDK = '" + sdk2 + "'\n")
120
sys.stderr.write("EPOCROOT SDK = '" + sdk1 + "'\n")
123
self.name = sdk2.replace("_", "-")
127
def replace_vars(text):
128
global vs_target, s60_target, build_type, no_test, no_pjsua_test
131
os_info = platform.system() + platform.release() + "-" + platform.machine()
135
if build_type == "s60":
136
s60sdk_var = S60SDK()
137
os_info = s60sdk_var.name
138
elif platform.system().lower() == "windows" or platform.system().lower() == "microsoft":
139
if platform.system().lower() == "microsoft":
140
os_info = platform.release() + "-" + platform.version() + "-" + platform.win32_ver()[2]
141
elif platform.system().lower() == "linux":
142
os_info = "-" + "-".join(platform.linux_distribution()[0:2])
145
if not vs_target and text.find("$(VSTARGET)") >= 0:
146
if build_type != "vs":
147
sys.stderr.write("Warning: $(VSTARGET) only valid for Visual Studio\n")
148
print "Enter Visual Studio vs_target name (e.g. Release, Debug) [Release]: ",
149
vs_target = sys.stdin.readline().replace("\n", "").replace("\r", "")
151
vs_target = "Release"
154
if not s60_target and text.find("$(S60TARGET)") >= 0:
155
if build_type != "s60":
156
sys.stderr.write("Warning: $(S60TARGET) only valid for S60\n")
157
print "Enter S60 target name (e.g. \"gcce urel\") [gcce urel]: ",
158
s60_target = sys.stdin.readline().replace("\n", "").replace("\r", "")
160
s60_target = "gcce urel"
163
if build_type == "vs":
164
suffix = "i386-Win32-vc8-" + vs_target
165
elif build_type == "s60":
166
suffix = s60sdk_var.name + "-" + s60_target.replace(" ", "-")
167
elif build_type == "gnu":
168
proc = subprocess.Popen("sh config.guess", cwd="../..",
169
shell=True, stdout=subprocess.PIPE)
170
suffix = proc.stdout.readline().rstrip(" \r\n")
172
sys.stderr.write("Error: unsupported build type '" + build_type + "'\n")
176
if text.find("$(PJSUA-TESTS)") >= 0:
177
if no_test==False and no_pjsua_test==False:
178
# Determine pjsua exe to use
179
exe = "../../pjsip-apps/bin/pjsua-" + suffix
180
proc = subprocess.Popen(PYTHON + " runall.py --list-xml -e " + exe,
182
shell=True, stdout=subprocess.PIPE)
183
content = proc.stdout.read()
186
text = text.replace("$(PJSUA-TESTS)", content)
187
elif text.find("$(GCC)") >= 0:
188
text = text.replace("$(GCC)", gcc_version("gcc"))
189
elif text.find("$(VS)") >= 0:
191
text = text.replace("$(VS)", VSVersion().vs_release)
192
elif text.find("$(VSTARGET)") >= 0:
193
text = text.replace("$(VSTARGET)", vs_target)
194
elif text.find("$(S60TARGET)") >= 0:
195
text = text.replace("$(S60TARGET)", s60_target)
196
elif text.find("$(S60TARGETNAME)") >= 0:
197
text = text.replace("$(S60TARGETNAME)", s60_target.replace(" ", "-"))
198
elif text.find("$(S60DEVICE)") >= 0:
199
text = text.replace("$(S60DEVICE)", s60sdk_var.device)
200
elif text.find("$(EPOCROOT)") >= 0:
201
text = text.replace("$(EPOCROOT)", s60sdk_var.epocroot)
202
elif text.find("$(DISABLED)") >= 0:
203
text = text.replace("$(DISABLED)", "0")
204
elif text.find("$(IPPROOT)") >= 0:
205
if not os.environ.has_key("IPPROOT"):
206
sys.stderr.write("Error: environment variable IPPROOT is needed but not set\n")
208
text = text.replace("$(IPPROOT)", os.environ["IPPROOT"])
209
elif text.find("$(IPPSAMPLES)") >= 0:
210
if not os.environ.has_key("IPPSAMPLES"):
211
sys.stderr.write("Error: environment variable IPPSAMPLES is needed but not set\n")
213
text = text.replace("$(IPPSAMPLES)", os.environ["IPPSAMPLES"])
214
elif text.find("$(IPPARCH)") >= 0:
215
if not os.environ.has_key("IPPARCH"):
216
text = text.replace("$(IPPARCH)", "")
218
text = text.replace("$(IPPARCH)", os.environ["IPPARCH"])
219
elif text.find("$(OS)") >= 0:
220
text = text.replace("$(OS)", os_info)
221
elif text.find("$(SUFFIX)") >= 0:
222
text = text.replace("$(SUFFIX)", suffix)
223
elif text.find("$(HOSTNAME)") >= 0:
224
text = text.replace("$(HOSTNAME)", socket.gethostname())
225
elif text.find("$(PJDIR)") >= 0:
226
wdir = os.path.join(os.getcwd(), "../..")
227
wdir = os.path.normpath(wdir)
228
text = text.replace("$(PJDIR)", wdir)
229
elif text.find("$(NOP)") >= 0:
230
if platform.system().lower() == "windows" or platform.system().lower() == "microsoft":
231
cmd = "CMD /C echo Success"
234
text = text.replace("$(NOP)", cmd)
235
elif text.find("$(NOTEST)") >= 0:
240
text = text.replace("$(NOTEST)", str)
247
global vs_target, s60_target, build_type, no_test, no_pjsua_test
249
usage = """Usage: configure.py [OPTIONS] scenario_template_file
252
-o FILE Output to file, otherwise to stdout.
253
-t TYPE Specify build type. If not specified, it will be
254
asked if necessary. Values are:
258
-vstarget TARGETNAME Specify Visual Studio target name if build type is set
259
to vs. If not specified then it will be asked.
263
- or any other target in the project file
264
-s60target TARGETNAME Specify S60 target name if build type is set to s60.
265
If not specified then it will be asked. Sample target
269
-notest Disable all tests in the scenario.
270
-nopjsuatest Disable pjsua tests in the scenario.
278
output = open(args[0], "wt")
281
sys.stderr.write("Error: needs value for -o\n")
283
elif args[0]=='-vstarget':
289
sys.stderr.write("Error: needs value for -vstarget\n")
291
elif args[0]=='-s60target':
297
sys.stderr.write("Error: needs value for -s60target\n")
302
build_type = args[0].lower()
305
sys.stderr.write("Error: needs value for -t\n")
307
if not ["vs", "gnu", "s60"].count(build_type):
308
sys.stderr.write("Error: invalid -t argument value\n")
310
elif args[0]=='-notest' or args[0]=='-notests':
313
elif args[0]=='-nopjsuatest' or args[0]=='-nopjsuatests':
320
sys.stderr.write(usage + "\n")
325
if "SHELL" in os.environ:
326
shell = os.environ["SHELL"]
327
if shell.find("sh") > -1:
329
print "Enter the build type (values: vs, gnu, s60) [%s]: " % (defval),
330
build_type = sys.stdin.readline().replace("\n", "").replace("\r", "")
335
tpl_file = args[len(args)-1]
336
if not os.path.isfile(tpl_file):
337
print "Error: unable to find template file '%s'" % (tpl_file)
340
f = open(tpl_file, "r")
344
tpl = replace_vars(tpl)
346
if output != sys.stdout:
351
if __name__ == "__main__":