.
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(pkg_config, lib, required=True, version=None):
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 v = process.stdout.readline().decode('utf-8')
56 process.communicate()[0]
57 return process.returncode == 0
58
59 def has_posixvala ():
60 posixvala = test_library_version ('posixvala')
61 if not posixvala:
62 print (OKGREEN + 'Glib will be used instead of Posix (libc).' + ENDC)
63 return 'False'
64 else:
65 print (OKGREEN + 'Using posix profile.' + ENDC)
66 return 'True'
67
68 def configure(gtk, libbgee, valac, pkg_config):
69 global gee
70
71 if not test_program_version(valac, 0, 16, 0):
72 print (FAIL + 'valac is too old.' + ENDC)
73 exit (1)
74
75 if gtk:
76 libs = [
77 'cairo',
78 'gdk-pixbuf-2.0',
79 'gio-2.0',
80 'glib-2.0',
81 'gtk+-3.0',
82 'webkit2gtk-4.0',
83 'libsoup-2.4',
84 'libnotify',
85 'sqlite3',
86 'xmlbird'
87 ]
88 else:
89 libs = [
90 'gio-2.0',
91 'glib-2.0',
92 'sqlite3',
93 'fontconfig',
94 'xmlbird'
95 ]
96
97 test_library_version(pkg_config, 'xmlbird', True, '1.2.0')
98
99 for lib in libs:
100 test_library_version(pkg_config, lib)
101
102 if libbgee == 'Any':
103 if test_library_version(pkg_config, 'gee-0.8', False):
104 gee = 'gee-0.8'
105 elif test_library_version(pkg_config, 'gee-1.0', False):
106 gee = 'gee-1.0'
107 else:
108 print (FAIL + 'Can not find libgee (version 0.8 or version 1.0).' + ENDC)
109 exit (1)
110 else:
111 if not test_library_version(pkg_config, libbgee):
112 print (FAIL + 'Can not find lib gee.' + ENDC)
113 exit (1)
114 gee = libbgee;
115
116 run ('mkdir -p build')
117 run ('touch build/configured')
118
119 print ('');
120 print (OKGREEN + 'Done' + ENDC);
121
122
123 parser = OptionParser()
124 parser.add_option('-p', '--prefix', dest='prefix', help='Install prefix', metavar='PREFIX')
125 parser.add_option('-d', '--dest', dest='dest', help='Install to this directory', metavar='DEST')
126 parser.add_option('-c', '--cc', dest='cc', help='C compiler', metavar='CC')
127 parser.add_option('-g', '--gtk', dest='gtk', help='Build Gtk version, default is True', metavar='GTK')
128 parser.add_option('-e', '--gee', dest='gee', help='Version of libgee', metavar='GEE')
129 parser.add_option('-v', '--valac', dest='valac', help='Vala compiler', metavar='VALAC')
130 parser.add_option('-P', '--pkg-config', dest='pkg_config', help='Package config tool', metavar='PKG_CONFIG')
131 parser.add_option('-n', '--nonnull', dest='nonnull', action="store_true", help='Enable compiletime checks for null pointers', metavar='NONNULL')
132
133 parser.add_option('', '--valac-flags', dest='valac_flags', help='Vala compiler flags for all targets', metavar='VALAC_FLAGS', default='')
134 for target in TARGETS:
135 parser.add_option('', '--valac-flags-' + target, dest='valac_flags_' + target, help='Vala compiler flags for ' + target, metavar='VALAC_FLAGS', default='')
136
137 parser.add_option('', '--cflags', dest='cflags', help='C compiler flags for all targets', metavar='CFLAGS', default='')
138 for target in TARGETS:
139 parser.add_option('', '--cflags-' + target, dest='cflags_' + target, help='C compiler flags for ' + target, metavar='CFLAGS', default='')
140
141 parser.add_option('', '--ldflags', dest='ldflags', help='Linker flags for all targets', metavar='LDFLAGS', default='')
142 for target in TARGETS:
143 parser.add_option('', '--ldflags-' + target, dest='ldflags_' + target, help='Linker flags for ' + target, metavar='LDFLAGS', default='')
144
145 (options, args) = parser.parse_args()
146 option_dict = vars(options)
147
148 valacflags = dict()
149 cflags = dict()
150 ldflags = dict()
151
152 for target in TARGETS:
153 cflags[target] = options.cflags
154 cflags[target] = cflags[target] + ' ' + option_dict.get('cflags_' + target, "")
155 cflags[target] = cflags[target].strip()
156
157 ldflags[target] = options.ldflags
158 ldflags[target] = ldflags[target] + ' ' + option_dict.get('ldflags_' + target, "")
159 ldflags[target] = ldflags[target].strip()
160
161 valacflags[target] = options.valac_flags
162 valacflags[target] = valacflags[target] + ' ' + option_dict.get('valac_flags_' + target, "")
163 valacflags[target] = valacflags[target].strip()
164
165 if not options.prefix:
166 if 'bsd' in sys.platform:
167 options.prefix = '${DESTDIR}${PREFIX}'
168 else:
169 options.prefix = '/usr'
170
171 if not options.dest:
172 options.dest = ''
173 if not options.cc:
174 options.cc = 'gcc'
175 if not options.gtk:
176 options.gtk = True
177 if options.gtk == 'False':
178 options.gtk = False
179 if not options.gee:
180 options.gee = 'Any'
181 if not options.valac:
182 options.valac = 'valac'
183 if not options.pkg_config:
184 options.pkg_config = 'pkg-config'
185 if not options.nonnull:
186 options.nonnull = False
187 else:
188 options.nonnull = True
189
190 configure(options.gtk, options.gee, options.valac, options.pkg_config)
191
192 configfile.write_config(options.prefix)
193 configfile.write_compile_parameters(options.prefix,
194 options.dest,
195 options.cc,
196 gee,
197 options.valac,
198 options.pkg_config,
199 options.nonnull,
200 valacflags,
201 cflags,
202 ldflags,
203 options.gtk)
204