1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
#!/usr/bin/python3
import subprocess
import os
import sys
import time;
from optparse import OptionParser
from scripts import configfile
import re
import platform
from scripts.run import run
TARGETS = ['xmlbird', 'tests']
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
def test_program_version (program, a, b, c):
print ('Checking for %s version >= %s.%s.%s' % (program, a, b, c))
process = subprocess.Popen (program + ' --version', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
v = process.stdout.readline().decode('utf-8')
process.communicate()[0]
if not process.returncode == 0:
print (FAIL + 'Not found' + ENDC)
exit (1)
print ('Found ' + v)
o = v.split (' ');
for s in o:
if re.search( r'[0-9]*\.', s):
v = s
break
v = re.sub(r'[a-zA-Z\-].*', '0', v)
version = [int(n) for n in v.split ('.')]
return [a,b,c] <= version
def test_library_version (lib):
print ('Looking for library: ' + lib + '\t\t')
process = subprocess.Popen ('pkg-config --modversion ' + lib, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
process.communicate()[0]
return process.returncode == 0
def configure(valac):
if not test_program_version(valac, 0, 16, 0):
print (FAIL + "valac is too old." + ENDC)
exit (1)
def is_debian():
try:
version = platform.version()
print("OS Version: " + version)
if version.find("Ubuntu") > -1:
return True
if version.find("Debian") > -1:
return True
except:
return False
return False
parser = OptionParser()
parser.add_option('-p', '--prefix', dest='prefix', help='Install prefix', metavar='PREFIX')
parser.add_option('-l', '--libdir', dest='libdir', help='path to directory for shared libraries (lib or lib64).', metavar='LIBDIR')
parser.add_option('-d', '--dest', dest='dest', help='Install to this directory', metavar='DEST')
parser.add_option('-c', '--cc', dest='cc', help='C compiler', metavar='CC')
parser.add_option('-v', '--valac', dest='valac', help='Vala compiler', metavar='VALAC')
parser.add_option('-n', '--nonnull', dest='nonnull', action="store_true", help='Enable compiletime checks for null pointers', metavar='NONNULL')
parser.add_option('-t', '--disable-dependency-tracking', dest='deptrack', action="store_true", help='Not in use', metavar='DEPTRACK')
parser.add_option('', '--valac-flags', dest='valac_flags', help='Vala compiler flags for all targets', metavar='VALAC_FLAGS', default='')
for target in TARGETS:
parser.add_option('', '--valac-flags-' + target, dest='valac_flags_' + target, help='Vala compiler flags for ' + target, metavar='VALAC_FLAGS', default='')
parser.add_option('', '--cflags', dest='cflags', help='C compiler flags for all targets', metavar='CFLAGS', default='')
for target in TARGETS:
parser.add_option('', '--cflags-' + target, dest='cflags_' + target, help='C compiler flags for ' + target, metavar='CFLAGS', default='')
parser.add_option('', '--ldflags', dest='ldflags', help='Linker flags for all targets', metavar='LDFLAGS', default='')
for target in TARGETS:
parser.add_option('', '--ldflags-' + target, dest='ldflags_' + target, help='Linker flags for ' + target, metavar='LDFLAGS', default='')
(options, args) = parser.parse_args()
option_dict = vars(options)
valacflags = dict()
cflags = dict()
ldflags = dict()
for target in TARGETS:
cflags[target] = options.cflags
cflags[target] = cflags[target] + ' ' + option_dict.get('cflags_' + target, "")
cflags[target] = cflags[target].strip()
ldflags[target] = options.ldflags
ldflags[target] = ldflags[target] + ' ' + option_dict.get('ldflags_' + target, "")
ldflags[target] = ldflags[target].strip()
valacflags[target] = options.valac_flags
valacflags[target] = valacflags[target] + ' ' + option_dict.get('valac_flags_' + target, "")
valacflags[target] = valacflags[target].strip()
if not options.prefix:
if 'bsd' in sys.platform:
options.prefix = '${DESTDIR}${PREFIX}'
elif sys.platform == 'darwin':
options.prefix = '/usr/local'
else:
options.prefix = '/usr'
if not options.libdir:
if sys.platform == 'darwin':
options.libdir = '/lib'
elif is_debian():
process = subprocess.Popen(['dpkg-architecture', '-qDEB_HOST_MULTIARCH'], stdout=subprocess.PIPE)
out, err = process.communicate()
options.libdir = 'lib/' + out.decode('UTF-8').rstrip('\n')
else:
p = platform.machine()
if p == 'i386' or p == 's390' or p == 'ppc' or p == 'armv7hl':
options.libdir = 'lib'
elif p == 'x86_64' or p == 's390x' or p == 'ppc64':
options.libdir = 'lib64'
else:
options.libdir = 'lib'
options.libdir = '/' + options.libdir.lstrip('/')
if not options.dest:
options.dest = ''
if not options.cc:
options.cc = 'gcc'
if not options.valac:
options.valac = 'valac'
if not options.nonnull:
options.nonnull = False
else:
options.nonnull = True
configure(options.valac)
configfile.write_compile_parameters(options.prefix,
options.libdir,
options.dest,
options.cc,
options.valac,
options.nonnull,
valacflags,
cflags,
ldflags)
|