The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

configure

This file is a part of the Birdfont project.

Contributing

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