File: detect.py

package info (click to toggle)
cheesetracker 0.9.9-1sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,564 kB
  • ctags: 6,586
  • sloc: cpp: 43,276; python: 316; makefile: 50; ansic: 6
file content (397 lines) | stat: -rw-r--r-- 9,394 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397

import os;
import string;

class Detect: # an empty object

	def __init__(self):
		self.set_data({})

	def __setattr__(self, n, v):
		self.__dict__['__data'][n] = v

	def __getattr__(self, n):
		return self.__dict__['__data'][n]

	def __str__(self):
		return str(self.__dict__['__data'])

	def set_data(self, data):
		self.__dict__['__data'] = data;

def parse_libs(cmd):

        ret = { 'flags' : [],  'libs' : [] }

        parts = string.split(os.popen(cmd).readlines()[0])
        for part in parts:
                if part[:2] == "-l":
                        ret['libs'].append(part[2:])
                else:
                        ret['flags'].append(part)

        return ret

def check_pkg_config():

	print "Detecting if PKG-CONFIG is installed... ";

	errorval=os.system("pkg-config --version");


	if (errorval):
		print "Error: cant execute pkg-config, please install pkg-config!"
		return 1;
	else:
		print "pkg-config found!";
		return 0;


def check_libdl(libdata):

	print "Checking for libdl...";
	dl_search_dirs=[ \
		"/sw", \
		"/usr", \
		"/usr/local", \
	];

	# search for extra include dirs to add
	for x in dl_search_dirs:
		if (os.path.isfile(x + "/include/dlfcn.h")):
			print "Found dlfcn.h in " + x + "/include";
			libdata.dl_flags=["-I" + x + "/include"];
			break;

	f=open("test.cpp","w");
	f.write("#include <dlfcn.h>\n#include <stdio.h>\nint main() { printf(\"Testing dlfcn.\"); return 0; }\n");
	f.close();

	for x in dl_search_dirs:
		execline="c++ -L" + x + "/lib " + libdata.dl_flags[0] + " test.cpp -o test -ldl 2>>config_errors.log";
		res=os.system(execline);

		if (res == 0):
			libdata.dl_libs=['dl'];
			libdata.dl_link_flags=["-L" + x + "/lib"];
			os.system("rm test.cpp");
			os.system("rm test");
			return 0;
	return 1;

def check_alsa(libdata):

	print "Checking for ALSA...";

	errorval=os.system("pkg-config alsa --atleast-version 0.9");

	if (errorval):
		libdata.has_alsa=0;
		print("Alsa v0.9 or greater not found in pkg-config, disabling support");
		return 1;

	print "ALSA found!";

	res=parse_libs("pkg-config alsa --cflags");
	libdata.alsa_flags=res['flags'];
	res=parse_libs("pkg-config alsa --libs");
	libdata.alsa_link_flags=res['flags'];
	libdata.alsa_libs=res['libs'];
	libdata.has_alsa=1;

	return 0;

def check_jack(libdata):

	print "Checking for JACK...";

	errorval=os.system("pkg-config jack --atleast-version 0.72");

	if (errorval):
		libdata.has_jack=0;
		print("Jack v0.72 or greater not found in pkg-config, disabling support");
		return 1;

	print "JACK found!";

	res=parse_libs("pkg-config jack --cflags");
	libdata.jack_flags=res['flags'];
	res=parse_libs("pkg-config jack --libs");
	libdata.jack_link_flags=res['flags'];
	libdata.jack_libs=res['libs'];
	libdata.has_jack=1;

	return 0;

def check_sigc(libdata):

	print "Checking for libsigc++-1.2...";

	errorval=os.system("pkg-config sigc++-1.2 --modversion");

	if (errorval):
		return 1;

	print "libsigc++-1.2 found!";

	res=parse_libs("pkg-config sigc++-1.2 --cflags");
	libdata.sigc_flags=res['flags'];
	res=parse_libs("pkg-config sigc++-1.2 --libs");
	libdata.sigc_link_flags=res['flags'];
	libdata.sigc_libs=res['libs'];

	return 0;

#list of dirs I can test..

def check_qt(libdata):

	#list of dirs I can test..
	qt_unix_library_dirs = [\
		"",\
		"/usr/lib",\
		"/usr/X11R6/lib",\
		"/usr/lib/qt3/lib",\
		"/usr/local/lib",\
		"/usr/local/lib/qt3/lib",\
		"/opt/qt3/lib"\
	];

	qt_unix_bin_dirs = [\
                "",\
		"/usr/bin",\
		"/usr/X11R6/bin",\
		"/usr/lib/qt3/bin",\
		"/usr/local/bin",\
		"/usr/local/lib/qt3/bin",\
		"/opt/qt3/bin"\
	];

	qt_unix_include_dirs = [\
		"/usr/include",\
		"/usr/include/qt3",\
		"/usr/X11R6/include",\
		"/usr/X11R6/include/qt3",\
		"/usr/lib/qt3/include",\
		"/usr/lib/qt3/include/qt3",\
		"/usr/local/include",\
		"/usr/local/include/qt3",\
		"/usr/local/lib/qt3/include",\
		"/usr/local/lib/qt3/include/qt3",\
		"/opt/qt3/include"\
	];

	print "QT Check:";

	if (os.environ.has_key('QTDIR')):
                qtdir=os.environ['QTDIR'];
		print "$QTDIR exists at, using QTDIR instead of harcdoded pathlist " + qtdir;
		include_qtdir=qtdir+'/include';
		qt_unix_include_dirs=[];
		qt_unix_include_dirs.append(include_qtdir);
		qt_unix_include_dirs.append(include_qtdir + '/qt');
		qt_unix_include_dirs.append(include_qtdir + '/qt3');

		lib_qtdir=qtdir+'/lib';
		qt_unix_library_dirs=[];
		qt_unix_library_dirs.append(lib_qtdir);

		bin_qtdir=qtdir+'/bin';
		qt_unix_bin_dirs=[];
		qt_unix_bin_dirs.append(bin_qtdir);
	else:
		print "$QTDIR not found, you could define this pointing to a proper QT location if not found";
		print "I will try to check if you have Qt in a bunch of paths..";

	print "Looking for QT 3.x Includes:";

        qt_inc_found=0;
        for x in qt_unix_include_dirs:

		file_to_check = "qglobal.h"
		current_file=x + "/" + file_to_check;

		if (os.path.isfile(current_file)):
			print x;
			print "Checking QT version.. \n";
			version=os.popen("cat " + current_file + " | grep \"QT_VERSION_STR \" ").readlines();
			if not len(version):
				print "Cant determine QT version! (qglobal.h not found at " +x+ ")\n";
				continue;

			ver_str=version[0];
			pos=ver_str.find("\"3.");
			if (pos >=0 ): #found QT header
				print ver_str;
				libdata.qt_flags=["-I"+x,"-DQT_NO_EMIT"];
				qt_inc_found=1;
				break;

	print "Looking for QT 3.x Libraries:";

	qt_lib_found=0;

        for x in qt_unix_library_dirs:
		if (not qt_inc_found):
			break;

		test_program="#include <qglobal.h>\n #include<stdio.h>\n int main() { \n printf(\"Testing QT: %s\\n\",QT_VERSION);\n return 0;\n }\n";

		f=open("test.cpp","w");
		f.write(test_program);
                f.close();

		auxlibpath="";
		if (len(x)>0):
			auxlibpath="-L"+x;
		#check if we must use -lqt
		execline="c++ " + auxlibpath + " "+libdata.qt_flags[0]+" test.cpp -o test -lqt  2>> config_errors.log"; # 2>/dev/null";
		res=os.system(execline);

		if (res == 0):
			qt_lib_found=1;
			print "using: -lqt" + auxlibpath;
			libdata.qt_link_flags=[auxlibpath];
			libdata.qt_libs=['qt'];
			os.system("rm test.cpp");
			os.system("rm test");
			break;


		execline="c++ " + auxlibpath + " "+libdata.qt_flags[0]+" test.cpp -o test -lqt-mt 2>> config_errors.log";
		res=os.system(execline);
		os.system("rm test.cpp");
		if (res==0):
			os.system("rm test");
			print "using: -lqt-mt" + auxlibpath;
			qt_lib_found=1;
			libdata.qt_link_flags=[auxlibpath];
			libdata.qt_libs=['qt-mt'];
			break;

	print "Looking for QT 3.x 'moc' Binary:";

	qt_found=0;

        for x in qt_unix_bin_dirs:
		if (not qt_lib_found):
			break;

		command="moc";
		if (len(x)):
			command=x+"/moc";

		res=os.system(command + " -v 2>/dev/null");
		if (res!=256):
                        continue;

       		version=os.popen(command +" -v 2>&1").readlines();
                if (not len(version)):
                        continue;

                pos=version[0].find(" 3.");
                if (pos<0):
                        print("Not version 3:" + command);
                        continue;

       		qt_found=1;
       		print "found moc command: " + command;
       		libdata.moc_bin=command;
		break;


        if (not qt_found):
		print("I Couldnt find QT in your system :(\n");
		print("If you think it is actually installed, you could try the following:\n");
		print("-Define/undefine the $QTDIR env var. Some distros/unixes dont place Qt in standard locations (Like Debian)\n");
		print("-Check if the path where your Qt 3.x stuff is and add it to the list at detect.py!\n");
		print("-I am not a good python coder so detect.py may be buggy, if you fixed it, please send patches to coding@reduz.com.ar :)\n");

		return 1;

	else:
		print("QT was found!\n");
		return 0;



def check_system(libdata):
	f=os.popen("uname");
	sysname=f.readlines()[0];
	libdata.os_is_cygwin=(sysname.find("CYGWIN")>=0);
	libdata.os_is_macosx=(sysname.find("Darwin")>=0);


def check_oss(libdata):

	print "Detecting if OSS exists on the system..";

	test_program="#include <sys/soundcard.h>\n #include <stdio.h>\n int main() { \n printf(\"Testing OSS: \\n\");\n return 0;\n }\n";

	f=open("test.c","w");
	f.write(test_program);
	f.close();

	execline="cc test.c -o test  2>> config_errors.log"; # 2>/dev/null";
	res=os.system(execline);
	libdata.is_oss_installed=(res==0);
	if (libdata.is_oss_installed):
		print("OSS was found.");
	else:
		print("OSS was not detected.");
	os.system("rm test.cpp");


def read_dep_cache(libdata):
	import os
	if not os.path.exists("detect_cache.py"):
		return 0;

	import detect_cache
	osid = os.popen("uname -a").readlines()[0];
	if (not detect_cache.cached_data.has_key('os_id')) or osid != detect_cache.cached_data['os_id']:
		return 0
	libdata.set_data(detect_cache.cached_data)

	return 1

def write_dep_cache(libdata):

	libdata.os_id = os.popen("uname -a").readlines()[0];

	file = open("detect_cache.py",'wt')
	file.write("cached_data = " + str(libdata))
	file.close()

	return 0;

def check_dependences(libdata):

	check_system(libdata);

	if (read_dep_cache(libdata)):
		return 0;

	if ( check_libdl(libdata) ):
		return 1;

	if ( check_pkg_config() ):
		return 1;

	if ( check_sigc(libdata) ):
		return 1;

	if ( check_qt(libdata) ):
		return 1;


	check_jack(libdata)
	check_alsa(libdata)

	check_oss(libdata);
	print "Dependency check successful, writing cache";

	write_dep_cache(libdata);

	return 0;