sb: Add support for building RTEMS 3rd party packages.

Remove the 'opt' from various macros and shell variables.

Add pkgconfig to the checks to make it clear the check is a
pkgconfig check.

Add NTP support as the first package to be built using the RSB.

Split the RTEMS URL's out from the base bset file into a separate
file that be included by other files.

Add an RTEMS BSP configuration file to help abstract the process
of building 3rd party packages.

Clean the cross and canadian cross support up so we can cleanly support
cross and canadian cross building.

Refactor the pkgconfig support and clean up the PC file handling of
loading modules.

Add support for %{?..} to return false if a macro is %{nil}.

Add %{pkgconfig ..} support to allow better control of access RTEMS
pkgconfig files.
This commit is contained in:
Chris Johns
2014-06-15 17:40:34 +12:00
parent 339f92f89f
commit 0ffee19316
24 changed files with 441 additions and 164 deletions

View File

@@ -55,6 +55,13 @@ def _check_bool(value):
istrue = None
return istrue
def _check_nil(value):
if len(value):
istrue = True
else:
istrue = False
return istrue
class package:
def __init__(self, name, arch, config):
@@ -242,10 +249,21 @@ class file:
self.sf = re.compile(r'%\([^\)]+\)')
for arg in self.opts.args:
if arg.startswith('--with-') or arg.startswith('--without-'):
label = arg[2:].lower().replace('-', '_')
self.macros.define(label)
if '=' in arg:
label, value = arg.split('=', 1)
else:
label = arg
value = None
label = label[2:].lower().replace('-', '_')
if value:
self.macros.define(label, value)
else:
self.macros.define(label)
self._includes = []
self.load_depth = 0
self.pkgconfig_prefix = None
self.pkgconfig_crosscompile = False
self.pkgconfig_filter_flags = False
self.load(name)
def __str__(self):
@@ -383,37 +401,97 @@ class file:
def _pkgconfig_check(self, test):
ok = False
if not self._cross_compile():
ts = test.split()
pkg = pkgconfig.package(ts[0], output = log.output)
if len(ts) != 1 and len(ts) != 3:
self._error('malformed check')
else:
op = '>='
ver = '0'
if len(ts) == 3:
op = ts[1]
ver = self.macros.expand(ts[2])
try:
if type(test) == str:
test = test.split()
if not self._cross_compile() or self.pkgconfig_crosscompile:
try:
pkg = pkgconfig.package(test[0],
prefix = self.pkgconfig_prefix,
output = self._output,
src = log.trace)
if len(test) != 1 and len(test) != 3:
self._error('malformed check: %s' % (' '.join(test)))
else:
op = '>='
ver = '0'
if len(test) == 3:
op = test[1]
ver = self.macros.expand(test[2])
ok = pkg.check(op, ver)
except pkgconfig.error, pe:
self._error('check: %s' % (pe))
except:
raise error.interal('pkgconfig failure')
return ok
except pkgconfig.error, pe:
self._error('pkgconfig: check: %s' % (pe))
except:
raise error.internal('pkgconfig failure')
if ok:
return '1'
return '0'
def _pkgconfig_flags(self, package, flags):
pkg_flags = None
if not self._cross_compile():
pkg = pkgconfig.package(package, output = log.output)
if not self._cross_compile() or self.pkgconfig_crosscompile:
try:
pkg = pkgconfig.package(package,
prefix = self.pkgconfig_prefix,
output = self._output,
src = log.trace)
pkg_flags = pkg.get(flags)
if pkg_flags and self.pkgconfig_filter_flags:
fflags = []
for f in pkg_flags.split():
if not f.startswith('-f') and not f.startswith('-W'):
fflags += [f]
pkg_flags = ' '.join(fflags)
log.trace('pkgconfig: %s: %s' % (flags, pkg_flags))
except pkgconfig.error, pe:
self._error('flags:%s: %s' % (flags, pe))
self._error('pkgconfig: %s: %s' % (flags, pe))
except:
raise error.interal('pkgconfig failure')
raise error.internal('pkgconfig failure')
if pkg_flags is None:
pkg_flags = ''
return pkg_flags
def _pkgconfig(self, pcl):
ok = False
ps = ''
if pcl[0] == 'check':
ps = self._pkgconfig_check(pcl[1:])
elif pcl[0] == 'prefix':
if len(pcl) == 2:
self.pkgconfig_prefix = pcl[1]
else:
self._error('prefix error: %s' % (' '.join(pcl)))
elif pcl[0] == 'crosscompile':
ok = True
if len(pcl) == 2:
if pcl[1].lower() == 'yes':
self.pkgconfig_crosscompile = True
elif pcl[1].lower() == 'no':
self.pkgconfig_crosscompile = False
else:
ok = False
else:
ok = False
if not ok:
self._error('crosscompile error: %s' % (' '.join(pcl)))
elif pcl[0] == 'filter-flags':
ok = True
if len(pcl) == 2:
if pcl[1].lower() == 'yes':
self.pkgconfig_filter_flags = True
elif pcl[1].lower() == 'no':
self.pkgconfig_filter_flags = False
else:
ok = False
else:
ok = False
if not ok:
self._error('crosscompile error: %s' % (' '.join(pcl)))
elif pcl[0] in ['ccflags', 'cflags', 'ldflags', 'libs']:
ps = self._pkgconfig_flags(pcl[1], pcl[0])
else:
self._error('pkgconfig error: %s' % (' '.join(pcl)))
return ps
def _expand(self, s):
expand_count = 0
expanded = True
@@ -464,7 +542,7 @@ class file:
mn = None
else:
e = self._expand(m[6:-1].strip())
log.output('%s' % (self._name_line_msg(e)))
log.notice('%s' % (self._name_line_msg(e)))
s = ''
expanded = True
mn = None
@@ -476,44 +554,45 @@ class file:
s = s.replace(m, '0')
expanded = True
mn = None
elif m.startswith('%{check'):
if self._pkgconfig_check(m[7:-1].strip()):
s = s.replace(m, '1')
elif m.startswith('%{path '):
pl = m[7:-1].strip().split()
ok = False
if len(pl) == 2:
ok = True
epl = []
for p in pl[1:]:
epl += [self._expand(p)]
p = ' '.join(epl)
if pl[0].lower() == 'prepend':
if len(self.macros['_pathprepend']):
self.macros['_pathprepend'] = \
'%s:%s' % (p, self.macros['_pathprepend'])
else:
self.macros['_pathprepend'] = p
elif pl[0].lower() == 'postpend':
if len(self.macros['_pathprepend']):
self.macros['_pathprepend'] = \
'%s:%s' % (self.macros['_pathprepend'], p)
else:
self.macros['_pathprepend'] = p
else:
ok = False
if ok:
s = s.replace(m, '')
else:
s = s.replace(m, '0')
expanded = True
self._error('path error: %s' % (' '.join(pl)))
mn = None
elif m.startswith('%{ccflags'):
flags = self._pkgconfig_flags(m[9:-1].strip(), 'ccflags')
if flags:
s = s.replace(m, flags)
elif m.startswith('%{pkgconfig '):
pcl = m[11:-1].strip().split()
if len(pcl):
epcl = []
for pc in pcl:
epcl += [self._expand(pc)]
ps = self._pkgconfig(epcl)
s = s.replace(m, ps)
expanded = True
else:
self._error('ccflags error: %s' % (m[9:-1].strip()))
expanded = True
mn = None
elif m.startswith('%{cflags'):
flags = self._pkgconfig_flags(m[8:-1].strip(), 'cflags')
if flags:
s = s.replace(m, flags)
else:
self._error('cflags error: %s' % (m[8:-1].strip()))
expanded = True
mn = None
elif m.startswith('%{ldflags'):
flags = self._pkgconfig_flags(m[9:-1].strip(), 'ldflags')
if flags:
s = s.replace(m, flags)
else:
self._error('ldflags error: %s' % (m[9:-1].strip()))
expanded = True
mn = None
elif m.startswith('%{libs'):
flags = self._pkgconfig_flags(m[6:-1].strip(), 'libs')
if flags:
s = s.replace(m, flags)
else:
self._error('libs error: %s' % (m[6:-1].strip()))
expanded = True
self._error('pkgconfig error: %s' % (m[11:-1].strip()))
mn = None
elif m.startswith('%{?') or m.startswith('%{!?'):
if m[2] == '!':
@@ -533,10 +612,10 @@ class file:
if m.startswith('%{?'):
istrue = False
if mn in self.macros:
# If defined and 0 then it is false.
# If defined and 0 or '' then it is false.
istrue = _check_bool(self.macros[mn])
if istrue is None:
istrue = True
istrue = _check_nil(self.macros[mn])
if colon >= 0 and istrue:
s = s.replace(m, m[start + colon + 1:-1])
expanded = True

View File

@@ -96,14 +96,14 @@ def load():
cxx = '/usr/bin/clang++'
if check.check_exe(cxx, cxx):
raise error.general('no valid c++ not found')
defines['optflags_build'] = '-O2 -pipe -fbracket-depth=1024'
defines['build_cflags'] = '-O2 -pipe -fbracket-depth=1024'
cvs = 'cvs'
if check.check_exe(cvs, cvs):
defines['__cvs'] = cvs
#
# Fix the mess iconv is on FreeBSD 10.0.
#
defines['iconv_optincludes'] = ('none', 'none', '-I/usr/local/include -L/usr/local/lib')
defines['iconv_includes'] = ('none', 'none', '-I/usr/local/include -L/usr/local/lib')
for gv in ['47', '48', '49']:
gcc = '%s-portbld-freebsd%s-gcc%s' % (cpu, version, gv)

View File

@@ -34,6 +34,7 @@
# provided by the full pkg-config so packages can configure and build.
#
import copy
import os
import os.path
import re
@@ -72,6 +73,14 @@ class package(object):
lib_list_splitter = re.compile('[\s,]+')
loaded = {}
@staticmethod
def _copy(src, dst):
dst.name_ = src.name_
dst.file_ = src.file_
dst.defines = copy.copy(src.defines)
dst.fields = copy.copy(src.fields)
dst.nodes = copy.copy(src.nodes)
@staticmethod
def is_version(v):
for n in v.split('.'):
@@ -384,7 +393,9 @@ class package(object):
def load(self, name):
if name in package.loaded:
raise error('package already loaded: %s' % (name))
package._copy(package.loaded[name], self)
return
self._log('loading: %s' % (name))
if self.name_:
self._clean()
self.name_ = name
@@ -392,14 +403,14 @@ class package(object):
if file:
self._log('load: %s (%s)' % (name, file))
if self.src:
self.src.writelines('==%s%s' % ('=' * 80, os.linesep))
self.src.writelines(' %s %s%s' % (file, '=' * (80 - len(file)), os.linesep))
self.src.writelines('==%s%s' % ('=' * 80, os.linesep))
self.src('==%s%s' % ('=' * 80, os.linesep))
self.src(' %s %s%s' % (file, '=' * (80 - len(file)), os.linesep))
self.src('==%s%s' % ('=' * 80, os.linesep))
f = open(file)
tm = False
for l in f.readlines():
if self.src:
self.src.writelines(l)
self.src(l)
l = l[:-1]
hash = l.find('#')
if hash >= 0:
@@ -455,6 +466,7 @@ class package(object):
package.loaded[name] = self
def get(self, label, private = True):
self._log('get: %s (%s)' % (label, ','.join(self.fields)))
if label.lower() not in self.fields:
return None
s = ''
@@ -504,3 +516,46 @@ class package(object):
else:
self._log('check: %s not found' % (self.name_))
return ok
def check_package(libraries, args, output, src):
ec = 1
pkg = None
flags = { 'cflags': '',
'libs': '' }
output('libraries: %s' % (libraries))
libs = package.splitter(libraries)
for lib in libs:
output('pkg: %s' % (lib))
pkg = package(lib[0], prefix = args.prefix, output = output, src = src)
if args.dump:
output(pkg)
if pkg.exists():
if len(lib) == 1:
if args.exact_version:
if pkg.check('=', args.exact_version):
ec = 0
elif args.atleast_version:
if pkg.check('>=', args.atleast_version):
ec = 0
elif args.max_version:
if pkg.check('<=', args.max_version):
ec = 0
else:
ec = 0
else:
if len(lib) != 3:
raise error('invalid package check: %s' % (' '.join(lib)))
if pkg.check(lib[1], lib[2]):
ec = 0
if ec == 0:
cflags = pkg.get('cflags')
if cflags:
flags['cflags'] += cflags
libs = pkg.get('libs', private = False)
if libs:
flags['libs'] += libs
break
if ec > 0:
break
return ec, pkg, flags