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.
Cancel save as operation
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(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 libs = [ 76 'cairo', 77 'gdk-pixbuf-2.0', 78 'gio-2.0', 79 'glib-2.0', 80 'gtk+-3.0', 81 'webkit2gtk-4.0', 82 'libsoup-2.4', 83 'libnotify', 84 'sqlite3', 85 'xmlbird' 86 ] 87 88 test_library_version(pkg_config, 'xmlbird', True, '1.2.0') 89 90 for lib in libs: 91 test_library_version(pkg_config, lib) 92 93 if libbgee == 'Any': 94 if test_library_version(pkg_config, 'gee-0.8', False): 95 gee = 'gee-0.8' 96 elif test_library_version(pkg_config, 'gee-1.0', False): 97 gee = 'gee-1.0' 98 else: 99 print (FAIL + 'Can not find libgee (version 0.8 or version 1.0).' + ENDC) 100 exit (1) 101 else: 102 if not test_library_version(pkg_config, libbgee): 103 print (FAIL + 'Can not find lib gee.' + ENDC) 104 exit (1) 105 gee = libbgee; 106 107 run ('mkdir -p build') 108 run ('touch build/configured') 109 110 print (''); 111 print (OKGREEN + 'Done' + ENDC); 112 113 114 parser = OptionParser() 115 parser.add_option('-p', '--prefix', dest='prefix', help='Install prefix', metavar='PREFIX') 116 parser.add_option('-d', '--dest', dest='dest', help='Install to this directory', metavar='DEST') 117 parser.add_option('-c', '--cc', dest='cc', help='C compiler', metavar='CC') 118 parser.add_option('-e', '--gee', dest='gee', help='Version of libgee', metavar='GEE') 119 parser.add_option('-v', '--valac', dest='valac', help='Vala compiler', metavar='VALAC') 120 parser.add_option('-P', '--pkg-config', dest='pkg_config', help='Package config tool', metavar='PKG_CONFIG') 121 parser.add_option('-n', '--nonnull', dest='nonnull', action="store_true", help='Enable compiletime checks for null pointers', metavar='NONNULL') 122 123 parser.add_option('', '--valac-flags', dest='valac_flags', help='Vala compiler flags for all targets', metavar='VALAC_FLAGS', default='') 124 for target in TARGETS: 125 parser.add_option('', '--valac-flags-' + target, dest='valac_flags_' + target, help='Vala compiler flags for ' + target, metavar='VALAC_FLAGS', default='') 126 127 parser.add_option('', '--cflags', dest='cflags', help='C compiler flags for all targets', metavar='CFLAGS', default='') 128 for target in TARGETS: 129 parser.add_option('', '--cflags-' + target, dest='cflags_' + target, help='C compiler flags for ' + target, metavar='CFLAGS', default='') 130 131 parser.add_option('', '--ldflags', dest='ldflags', help='Linker flags for all targets', metavar='LDFLAGS', default='') 132 for target in TARGETS: 133 parser.add_option('', '--ldflags-' + target, dest='ldflags_' + target, help='Linker flags for ' + target, metavar='LDFLAGS', default='') 134 135 (options, args) = parser.parse_args() 136 option_dict = vars(options) 137 138 valacflags = dict() 139 cflags = dict() 140 ldflags = dict() 141 142 for target in TARGETS: 143 cflags[target] = options.cflags 144 cflags[target] = cflags[target] + ' ' + option_dict.get('cflags_' + target, "") 145 cflags[target] = cflags[target].strip() 146 147 ldflags[target] = options.ldflags 148 ldflags[target] = ldflags[target] + ' ' + option_dict.get('ldflags_' + target, "") 149 ldflags[target] = ldflags[target].strip() 150 151 valacflags[target] = options.valac_flags 152 valacflags[target] = valacflags[target] + ' ' + option_dict.get('valac_flags_' + target, "") 153 valacflags[target] = valacflags[target].strip() 154 155 if not options.prefix: 156 if 'bsd' in sys.platform: 157 options.prefix = '${DESTDIR}${PREFIX}' 158 else: 159 options.prefix = '/usr' 160 161 if not options.dest: 162 options.dest = '' 163 if not options.cc: 164 options.cc = 'gcc' 165 if not options.gee: 166 options.gee = 'Any' 167 if not options.valac: 168 options.valac = 'valac' 169 if not options.pkg_config: 170 options.pkg_config = 'pkg-config' 171 if not options.nonnull: 172 options.nonnull = False 173 else: 174 options.nonnull = True 175 176 configure(options.gee, options.valac, options.pkg_config) 177 178 configfile.write_config(options.prefix) 179 configfile.write_compile_parameters(options.prefix, 180 options.dest, 181 options.cc, 182 gee, 183 options.valac, 184 options.pkg_config, 185 options.nonnull, 186 valacflags, 187 cflags, 188 ldflags) 189