.
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 'sqlite3'
76 ]
77 else:
78 libs = [
79 'gdk-pixbuf-2.0',
80 'gio-2.0',
81 'glib-2.0',
82 'sqlite3'
83 ]
84
85 for lib in libs:
86 if not test_library_version (lib):
87 print (FAIL + "Can not find " + lib + ENDC)
88 exit (1)
89
90 if libbgee == "Any":
91 if test_library_version ('gee-0.8'):
92 gee = "gee-0.8"
93 elif test_library_version ('gee-1.0'):
94 gee = "gee-1.0"
95 else:
96 print (FAIL + "Can not find libgee (version 0.8 or version 1.0)." + ENDC)
97 exit (1)
98 else:
99 if not test_library_version (libbgee):
100 print (FAIL + "Can not find lib gee." + ENDC)
101 exit (1)
102 gee = libbgee;
103
104 run ('mkdir -p build')
105 run ('touch build/configured')
106
107 print ("");
108 print (OKGREEN + "Done" + ENDC);
109
110
111 parser = OptionParser()
112 parser.add_option("-p", "--prefix", dest="prefix", help="Install prefix", metavar="PREFIX")
113 parser.add_option("-d", "--dest", dest="dest", help="Install to this directory", metavar="DEST")
114 parser.add_option("-c", "--cc", dest="cc", help="C compiler", metavar="CC")
115 parser.add_option("-g", "--gtk", dest="gtk", help="Build Gtk version, default is True", metavar="GTK")
116 parser.add_option("-e", "--gee", dest="gee", help="Version of libgee", metavar="GEE")
117 parser.add_option("-x", "--posix", dest="posix", help="Use posixvala", metavar="POSIX")
118
119 (options, args) = parser.parse_args()
120
121 if not options.prefix:
122 if "bsd" in sys.platform:
123 options.prefix = "${DESTDIR}${PREFIX}"
124 else:
125 options.prefix = "/usr"
126 if not options.dest:
127 options.dest = ""
128 if not options.cc:
129 options.cc = "gcc"
130 if not options.gtk:
131 options.gtk = True
132 if options.gtk == "False":
133 options.gtk = False
134 if not options.gee:
135 options.gee = "Any"
136 if not options.posix:
137 options.posix = has_posixvala ()
138
139 configure (options.gtk, options.gee, options.posix)
140
141 configfile.write_config (options.prefix)
142 configfile.write_compile_parameters (options.prefix, options.dest, options.cc, gee, options.posix)
143