.
1 #!/usr/bin/python
2 import subprocess
3 import os
4 import sys
5 import time;
6 from optparse import OptionParser
7 from scripts import version
8 from scripts import configfile
9 import re
10 from scripts.run import run
11
12 VERSION = version.VERSION
13
14 HEADER = '\033[95m'
15 OKBLUE = '\033[94m'
16 OKGREEN = '\033[92m'
17 WARNING = '\033[93m'
18 FAIL = '\033[91m'
19 ENDC = '\033[0m'
20
21 gee = "";
22
23 def test_program_version (program, a, b, c):
24 print ("Checking for %s version >= %s.%s.%s" % (program, a, b, c))
25 process = subprocess.Popen (program + ' --version', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
26 v = process.stdout.readline()
27 process.communicate()[0]
28 if not process.returncode == 0:
29 print (FAIL + "Not found" + ENDC)
30 exit (1)
31 print ("Found " + v)
32
33 o = v.split (" ");
34 for s in o:
35 if re.search( r'[0-9]*\.', s):
36 v = s
37 break
38
39 v = re.sub(r'[a-zA-Z\-].*', '0', v)
40 version = [int(n) for n in v.split (".")]
41 return [a,b,c] <= version
42
43 def test_library_version (lib):
44 print ("Looking for library: " + lib + "\t\t")
45 process = subprocess.Popen ('pkg-config --modversion ' + lib, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
46 process.communicate()[0]
47 return process.returncode == 0
48
49 def has_posixvala ():
50 posixvala = test_library_version ('posixvala')
51 if not posixvala:
52 print (OKGREEN + "Glib will be used instead of Posix (libc)." + ENDC)
53 return "False"
54 else:
55 print (OKGREEN + "Using posix profile." + ENDC)
56 return "True"
57
58 def configure (gtk, libbgee, posixvala):
59 global gee
60
61 if not test_program_version ("valac", 0, 16, 0):
62 print (FAIL + "valac is too old." + ENDC)
63 exit (1)
64
65 if gtk:
66 libs = [
67 'cairo',
68 'gdk-pixbuf-2.0',
69 'gio-2.0',
70 'glib-2.0',
71 'gtk+-3.0',
72 'webkitgtk-3.0',
73 'libsoup-2.4',
74 'libnotify'
75 ]
76 else:
77 libs = [
78 'gdk-pixbuf-2.0',
79 'gio-2.0',
80 'glib-2.0',
81 ]
82
83
84 for lib in libs:
85 if not test_library_version (lib):
86 print (FAIL + "Can not find " + lib + ENDC)
87 exit (1)
88
89 if libbgee == "Any":
90 if test_library_version ('gee-0.8'):
91 gee = "gee-0.8"
92 elif test_library_version ('gee-1.0'):
93 gee = "gee-1.0"
94 else:
95 print (FAIL + "Can not find libgee (version 0.8 or version 1.0)." + ENDC)
96 exit (1)
97 else:
98 if not test_library_version (libbgee):
99 print (FAIL + "Can not find lib gee." + ENDC)
100 exit (1)
101 gee = libbgee;
102
103 run ('mkdir -p build')
104 run ('touch build/configured')
105
106 print ("");
107 print (OKGREEN + "Done" + ENDC);
108
109
110 parser = OptionParser()
111 parser.add_option("-p", "--prefix", dest="prefix", help="Install prefix", metavar="PREFIX")
112 parser.add_option("-d", "--dest", dest="dest", help="Install to this directory", metavar="DEST")
113 parser.add_option("-c", "--cc", dest="cc", help="C compiler", metavar="CC")
114 parser.add_option("-g", "--gtk", dest="gtk", help="Build Gtk version, default is True", metavar="GTK")
115 parser.add_option("-e", "--gee", dest="gee", help="Version of libgee", metavar="GEE")
116 parser.add_option("-x", "--posix", dest="posix", help="Use posixvala", metavar="POSIX")
117
118 (options, args) = parser.parse_args()
119
120 if not options.prefix:
121 options.prefix = "/usr"
122 if not options.dest:
123 options.dest = ""
124 if not options.cc:
125 options.cc = "gcc"
126 if not options.gtk:
127 options.gtk = True
128 if options.gtk == "False":
129 options.gtk = False
130 if not options.gee:
131 options.gee = "Any"
132 if not options.posix:
133 options.posix = has_posixvala ()
134
135 configure (options.gtk, options.gee, options.posix)
136 configfile.write_config (options.prefix)
137 configfile.write_compile_parameters (options.prefix, options.dest, options.cc, gee, options.posix)
138