.
1 #!/usr/bin/python3
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
11 from scripts.run import run
12
13 TARGETS = ['libbirdfont',
14 'libbirdgems',
15 'birdfont',
16 'birdfont-autotrace',
17 'birdfont-export',
18 'birdfont-import',
19 'birdfont-test']
20
21 VERSION = version.VERSION
22
23 HEADER = '\033[95m'
24 OKBLUE = '\033[94m'
25 OKGREEN = '\033[92m'
26 WARNING = '\033[93m'
27 FAIL = '\033[91m'
28 ENDC = '\033[0m'
29
30 gee = '';
31
32 def test_program_version (program, a, b, c):
33 print ('Checking for %s version >= %s.%s.%s' % (program, a, b, c))
34 process = subprocess.Popen (program + ' --version', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
35 v = process.stdout.readline().decode('utf-8')
36 process.communicate()[0]
37 if not process.returncode == 0:
38 print (FAIL + 'Not found' + ENDC)
39 exit (1)
40 print ('Found ' + v)
41
42 o = v.split (' ');
43 for s in o:
44 if re.search( r'[0-9]*\.', s):
45 v = s
46 break
47
48 v = re.sub(r'[a-zA-Z\-].*', '0', v)
49 version = [int(n) for n in v.split ('.')]
50 return [a,b,c] <= version
51
52 def test_library_version (lib):
53 print ('Looking for library: ' + lib + '\t\t')
54 process = subprocess.Popen ('pkg-config --modversion ' + lib, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
55 process.communicate()[0]
56 return process.returncode == 0
57
58 def has_posixvala ():
59 posixvala = test_library_version ('posixvala')
60 if not posixvala:
61 print (OKGREEN + 'Glib will be used instead of Posix (libc).' + ENDC)
62 return 'False'
63 else:
64 print (OKGREEN + 'Using posix profile.' + ENDC)
65 return 'True'
66
67 def configure(gtk, libbgee):
68 global gee
69
70 if not test_program_version ('valac', 0, 16, 0):
71 print (FAIL + 'valac is too old.' + ENDC)
72 exit (1)
73
74 if gtk:
75 libs = [
76 'cairo',
77 'gdk-pixbuf-2.0',
78 'gio-2.0',
79 'glib-2.0',
80 'gtk+-3.0',
81 'webkitgtk-3.0',
82 'libsoup-2.4',
83 'libnotify',
84 'sqlite3',
85 'xmlbird'
86 ]
87 else:
88 libs = [
89 'gio-2.0',
90 'glib-2.0',
91 'sqlite3',
92 'fontconfig',
93 'xmlbird'
94 ]
95
96 for lib in libs:
97 if not test_library_version (lib):
98 print (FAIL + 'Can not find ' + lib + ENDC)
99 exit (1)
100
101 if libbgee == 'Any':
102 if test_library_version ('gee-0.8'):
103 gee = 'gee-0.8'
104 elif test_library_version ('gee-1.0'):
105 gee = 'gee-1.0'
106 else:
107 print (FAIL + 'Can not find libgee (version 0.8 or version 1.0).' + ENDC)
108 exit (1)
109 else:
110 if not test_library_version (libbgee):
111 print (FAIL + 'Can not find lib gee.' + ENDC)
112 exit (1)
113 gee = libbgee;
114
115 run ('mkdir -p build')
116 run ('touch build/configured')
117
118 print ('');
119 print (OKGREEN + 'Done' + ENDC);
120
121
122 parser = OptionParser()
123 parser.add_option('-p', '--prefix', dest='prefix', help='Install prefix', metavar='PREFIX')
124 parser.add_option('-d', '--dest', dest='dest', help='Install to this directory', metavar='DEST')
125 parser.add_option('-c', '--cc', dest='cc', help='C compiler', metavar='CC')
126 parser.add_option('-g', '--gtk', dest='gtk', help='Build Gtk version, default is True', metavar='GTK')
127 parser.add_option('-e', '--gee', dest='gee', help='Version of libgee', metavar='GEE')
128 parser.add_option('-v', '--valac', dest='valac', help='Vala compiler', metavar='VALAC')
129 parser.add_option('-n', '--nonnull', dest='nonnull', action="store_true", help='Enable compiletime checks for null pointers', metavar='NONNULL')
130
131 parser.add_option('', '--valac-flags', dest='valac_flags', help='Vala compiler flags for all targets', metavar='VALAC_FLAGS', default='')
132 for target in TARGETS:
133 parser.add_option('', '--valac-flags-' + target, dest='valac_flags_' + target, help='Vala compiler flags for ' + target, metavar='VALAC_FLAGS', default='')
134
135 parser.add_option('', '--cflags', dest='cflags', help='C compiler flags for all targets', metavar='CFLAGS', default='')
136 for target in TARGETS:
137 parser.add_option('', '--cflags-' + target, dest='cflags_' + target, help='C compiler flags for ' + target, metavar='CFLAGS', default='')
138
139 parser.add_option('', '--ldflags', dest='ldflags', help='Linker flags for all targets', metavar='LDFLAGS', default='')
140 for target in TARGETS:
141 parser.add_option('', '--ldflags-' + target, dest='ldflags_' + target, help='Linker flags for ' + target, metavar='LDFLAGS', default='')
142
143 (options, args) = parser.parse_args()
144 option_dict = vars(options)
145
146 valacflags = dict()
147 cflags = dict()
148 ldflags = dict()
149
150 for target in TARGETS:
151 cflags[target] = options.cflags
152 cflags[target] = cflags[target] + ' ' + option_dict.get('cflags_' + target, "")
153 cflags[target] = cflags[target].strip()
154
155 ldflags[target] = options.ldflags
156 ldflags[target] = ldflags[target] + ' ' + option_dict.get('ldflags_' + target, "")
157 ldflags[target] = ldflags[target].strip()
158
159 valacflags[target] = options.valac_flags
160 valacflags[target] = valacflags[target] + ' ' + option_dict.get('valac_flags_' + target, "")
161 valacflags[target] = valacflags[target].strip()
162
163 if not options.prefix:
164 if 'bsd' in sys.platform:
165 options.prefix = '${DESTDIR}${PREFIX}'
166 else:
167 options.prefix = '/usr'
168
169 if not options.dest:
170 options.dest = ''
171 if not options.cc:
172 options.cc = 'gcc'
173 if not options.gtk:
174 options.gtk = True
175 if options.gtk == 'False':
176 options.gtk = False
177 if not options.gee:
178 options.gee = 'Any'
179 if not options.valac:
180 options.valac = 'valac'
181 if not options.nonnull:
182 options.nonnull = False
183 else:
184 options.nonnull = True
185
186 configure(options.gtk, options.gee)
187
188 configfile.write_config(options.prefix)
189 configfile.write_compile_parameters(options.prefix,
190 options.dest,
191 options.cc,
192 gee,
193 options.valac,
194 options.nonnull,
195 valacflags,
196 cflags,
197 ldflags,
198 options.gtk)
199