Can install header files.
This commit is contained in:
parent
b6886b2c27
commit
8d038ef09e
4
build.py
4
build.py
|
@ -25,6 +25,7 @@ class Build:
|
|||
self.targets = {}
|
||||
self.compilers = []
|
||||
self.tests = []
|
||||
self.headers = []
|
||||
self.static_linker = self.environment.detect_static_linker()
|
||||
|
||||
def get_project(self):
|
||||
|
@ -35,3 +36,6 @@ class Build:
|
|||
|
||||
def get_tests(self):
|
||||
return self.tests
|
||||
|
||||
def get_headers(self):
|
||||
return self.headers
|
||||
|
|
|
@ -243,6 +243,9 @@ class Environment():
|
|||
def get_bindir(self):
|
||||
return self.options.bindir
|
||||
|
||||
def get_includedir(self):
|
||||
return self.options.includedir
|
||||
|
||||
# This should be an InterpreterObject. Fix it.
|
||||
class PkgConfigDependency():
|
||||
pkgconfig_found = False
|
||||
|
|
|
@ -29,18 +29,41 @@ class InvalidArguments(InterpreterException):
|
|||
|
||||
class InterpreterObject():
|
||||
|
||||
def method_call(self, method_name):
|
||||
raise InvalidCode('Object does not have method %s.' % method_name)
|
||||
def __init__(self):
|
||||
self.methods = {}
|
||||
|
||||
def method_call(self, method_name, args):
|
||||
if method_name in self.methods:
|
||||
return self.methods[method_name](args)
|
||||
raise InvalidCode('Unknown method "%s" in object.' % method_name)
|
||||
|
||||
class Headers(InterpreterObject):
|
||||
|
||||
def __init__(self, sources):
|
||||
InterpreterObject.__init__(self)
|
||||
self.sources = sources
|
||||
self.methods.update({'set_subdir' : self.set_subdir})
|
||||
self.subdir = ''
|
||||
|
||||
def set_subdir(self, args):
|
||||
self.subdir = args[0]
|
||||
|
||||
def get_subdir(self):
|
||||
return self.subdir
|
||||
|
||||
def get_sources(self):
|
||||
return self.sources
|
||||
|
||||
class BuildTarget(InterpreterObject):
|
||||
|
||||
def __init__(self, name, sources):
|
||||
InterpreterObject.__init__(self)
|
||||
self.name = name
|
||||
self.sources = sources
|
||||
self.external_deps = []
|
||||
self.methods = {'add_dep': self.add_dep_method,
|
||||
self.methods.update({'add_dep': self.add_dep_method,
|
||||
'link' : self.link_method,
|
||||
'install': self.install}
|
||||
'install': self.install})
|
||||
self.link_targets = []
|
||||
self.filename = 'no_name'
|
||||
self.need_install = False
|
||||
|
@ -78,11 +101,6 @@ class BuildTarget(InterpreterObject):
|
|||
raise InvalidArguments('Link target is not library.')
|
||||
self.link_targets.append(target)
|
||||
|
||||
def method_call(self, method_name, args):
|
||||
if method_name in self.methods:
|
||||
return self.methods[method_name](args)
|
||||
raise InvalidCode('Unknown method "%s" in BuildTarget.' % method_name)
|
||||
|
||||
def install(self, args):
|
||||
if len(args) != 0:
|
||||
raise InvalidArguments('Install() takes no arguments.')
|
||||
|
@ -142,7 +160,8 @@ class Interpreter():
|
|||
'find_dep' : self.func_find_dep,
|
||||
'static_library' : self.func_static_lib,
|
||||
'shared_library' : self.func_shared_lib,
|
||||
'add_test' : self.func_add_test
|
||||
'add_test' : self.func_add_test,
|
||||
'headers' : self.func_headers
|
||||
}
|
||||
|
||||
def sanity_check_ast(self):
|
||||
|
@ -234,6 +253,14 @@ class Interpreter():
|
|||
self.build.tests.append(t)
|
||||
print('Adding test "%s"' % args[0])
|
||||
|
||||
def func_headers(self, node, args):
|
||||
for a in args:
|
||||
if not isinstance(a, str):
|
||||
raise InvalidArguments('Line %d: Argument %s is not a string.' % (node.lineno(), str(a)))
|
||||
h = Headers(args)
|
||||
self.build.headers.append(h)
|
||||
return h
|
||||
|
||||
def build_target(self, node, args, targetclass):
|
||||
for a in args:
|
||||
if not isinstance(a, str):
|
||||
|
|
|
@ -71,15 +71,40 @@ echo This is experimental and most likely will not work!
|
|||
echo Run compile.sh before this or bad things will happen.
|
||||
""" % self.build.get_project()
|
||||
outfile = self.create_shfile(outfilename, message)
|
||||
self.generate_install(outfile)
|
||||
self.generate_target_install(outfile)
|
||||
self.generate_header_install(outfile)
|
||||
outfile.close()
|
||||
|
||||
def generate_install(self, outfile):
|
||||
def make_subdir(self, outfile, dir):
|
||||
cmdlist = ['mkdir', '-p', dir]
|
||||
outfile.write(' '.join(shell_quote(cmdlist)) + '\n')
|
||||
|
||||
def copy_file(self, outfile, filename, outdir):
|
||||
cpcommand = ['cp', filename, outdir]
|
||||
cpcommand = ' '.join(shell_quote(cpcommand)) + '\n'
|
||||
outfile.write(cpcommand)
|
||||
|
||||
def generate_header_install(self, outfile):
|
||||
prefix = self.environment.get_prefix()
|
||||
incroot = os.path.join(prefix, self.environment.get_includedir())
|
||||
headers = self.build.get_headers()
|
||||
if len(headers) != 0:
|
||||
outfile.write('\necho Installing headers.\n')
|
||||
else:
|
||||
outfile.write('\necho This project has no headers to install.')
|
||||
for h in headers:
|
||||
outdir = os.path.join(incroot, h.get_subdir())
|
||||
self.make_subdir(outfile, outdir)
|
||||
for f in h.get_sources():
|
||||
abspath = os.path.join(self.environment.get_source_dir(), f)
|
||||
self.copy_file(outfile, abspath, outdir)
|
||||
|
||||
def generate_target_install(self, outfile):
|
||||
prefix = self.environment.get_prefix()
|
||||
libdir = os.path.join(prefix, self.environment.get_libdir())
|
||||
bindir = os.path.join(prefix, self.environment.get_bindir())
|
||||
outfile.write("mkdir -p '%s'\n" % libdir)
|
||||
outfile.write("mkdir -p '%s'\n" % bindir)
|
||||
self.make_subdir(outfile, libdir)
|
||||
self.make_subdir(outfile, bindir)
|
||||
for tmp in self.build.get_targets().items():
|
||||
(name, t) = tmp
|
||||
if t.should_install():
|
||||
|
@ -88,9 +113,7 @@ echo Run compile.sh before this or bad things will happen.
|
|||
else:
|
||||
outdir = libdir
|
||||
outfile.write('echo Installing "%s".\n' % name)
|
||||
cpcommand = ['cp', self.get_target_filename(t), outdir]
|
||||
cpcommand = ' '.join(shell_quote(cpcommand)) + '\n'
|
||||
outfile.write(cpcommand)
|
||||
self.copy_file(outfile, self.get_target_filename(t), outdir)
|
||||
|
||||
def generate_tests(self, outfile):
|
||||
for t in self.build.get_tests():
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
project('header install', 'c')
|
||||
|
||||
h1 = headers('rootdir.h')
|
||||
h2 = headers('subdir.h')
|
||||
h2.set_subdir('subdir')
|
|
@ -0,0 +1,3 @@
|
|||
/* This header goes to include dir root. */
|
||||
|
||||
int root_func();
|
|
@ -0,0 +1,3 @@
|
|||
/* This file goes to subdirectory of include root. */
|
||||
|
||||
int subdir_func();
|
Loading…
Reference in New Issue