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

Revisions

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