Can install Man files.

pull/15/head
Jussi Pakkanen 12 years ago
parent 8d038ef09e
commit 5969b1ed33
  1. 4
      build.py
  2. 1
      builder.py
  3. 13
      environment.py
  4. 27
      interpreter.py
  5. 29
      shellgenerator.py
  6. 1
      test cases/10 man install/bar.2
  7. 3
      test cases/10 man install/builder.txt
  8. 1
      test cases/10 man install/foo.1

@ -26,6 +26,7 @@ class Build:
self.compilers = [] self.compilers = []
self.tests = [] self.tests = []
self.headers = [] self.headers = []
self.man = []
self.static_linker = self.environment.detect_static_linker() self.static_linker = self.environment.detect_static_linker()
def get_project(self): def get_project(self):
@ -39,3 +40,6 @@ class Build:
def get_headers(self): def get_headers(self):
return self.headers return self.headers
def get_man(self):
return self.man

@ -27,6 +27,7 @@ parser.add_option('--libdir', default='lib', dest='libdir')
parser.add_option('--bindir', default='bin', dest='bindir') parser.add_option('--bindir', default='bin', dest='bindir')
parser.add_option('--includedir', default='include', dest='includedir') parser.add_option('--includedir', default='include', dest='includedir')
parser.add_option('--datadir', default='share', dest='datadir') parser.add_option('--datadir', default='share', dest='datadir')
parser.add_option('--mandir' , default='share/man', dest='mandir')
class BuilderApp(): class BuilderApp():
builder_filename = 'builder.txt' builder_filename = 'builder.txt'

@ -230,22 +230,25 @@ class Environment():
def get_static_lib_suffix(self): def get_static_lib_suffix(self):
return self.static_lib_suffix return self.static_lib_suffix
def get_object_suffix(self): def get_object_suffix(self):
return self.object_suffix return self.object_suffix
def get_prefix(self): def get_prefix(self):
return self.options.prefix return self.options.prefix
def get_libdir(self): def get_libdir(self):
return self.options.libdir return self.options.libdir
def get_bindir(self): def get_bindir(self):
return self.options.bindir return self.options.bindir
def get_includedir(self): def get_includedir(self):
return self.options.includedir return self.options.includedir
def get_mandir(self):
return self.options.mandir
# This should be an InterpreterObject. Fix it. # This should be an InterpreterObject. Fix it.
class PkgConfigDependency(): class PkgConfigDependency():
pkgconfig_found = False pkgconfig_found = False

@ -53,6 +53,22 @@ class Headers(InterpreterObject):
def get_sources(self): def get_sources(self):
return self.sources return self.sources
class Man(InterpreterObject):
def __init__(self, sources):
InterpreterObject.__init__(self)
self.sources = sources
self.validate_sources()
def validate_sources(self):
for s in self.sources:
num = int(s.split('.')[-1])
if num < 1 or num > 8:
raise InvalidArguments('Man file must have a file extension of a number between 1 and 8')
def get_sources(self):
return self.sources
class BuildTarget(InterpreterObject): class BuildTarget(InterpreterObject):
@ -161,7 +177,8 @@ class Interpreter():
'static_library' : self.func_static_lib, 'static_library' : self.func_static_lib,
'shared_library' : self.func_shared_lib, 'shared_library' : self.func_shared_lib,
'add_test' : self.func_add_test, 'add_test' : self.func_add_test,
'headers' : self.func_headers 'headers' : self.func_headers,
'man' : self.func_man
} }
def sanity_check_ast(self): def sanity_check_ast(self):
@ -260,6 +277,14 @@ class Interpreter():
h = Headers(args) h = Headers(args)
self.build.headers.append(h) self.build.headers.append(h)
return h return h
def func_man(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)))
m = Man(args)
self.build.man.append(m)
return m
def build_target(self, node, args, targetclass): def build_target(self, node, args, targetclass):
for a in args: for a in args:

@ -73,16 +73,37 @@ echo Run compile.sh before this or bad things will happen.
outfile = self.create_shfile(outfilename, message) outfile = self.create_shfile(outfilename, message)
self.generate_target_install(outfile) self.generate_target_install(outfile)
self.generate_header_install(outfile) self.generate_header_install(outfile)
self.generate_man_install(outfile)
outfile.close() outfile.close()
def make_subdir(self, outfile, dir): def make_subdir(self, outfile, dir):
cmdlist = ['mkdir', '-p', dir] cmdlist = ['mkdir', '-p', dir]
outfile.write(' '.join(shell_quote(cmdlist)) + '\n') outfile.write(' '.join(shell_quote(cmdlist)) + ' || exit\n')
def copy_file(self, outfile, filename, outdir): def copy_file(self, outfile, filename, outdir):
cpcommand = ['cp', filename, outdir] cpcommand = ['cp', filename, outdir]
cpcommand = ' '.join(shell_quote(cpcommand)) + '\n' cpcommand = ' '.join(shell_quote(cpcommand)) + ' || exit\n'
outfile.write(cpcommand) outfile.write(cpcommand)
def generate_man_install(self, outfile):
prefix = self.environment.get_prefix()
manroot = os.path.join(prefix, self.environment.get_mandir())
man = self.build.get_man()
if len(man) != 0:
outfile.write('\necho Installing man pages.\n')
else:
outfile.write('\necho This project has no man pages to install.\n')
for m in man:
for f in m.get_sources():
num = f.split('.')[-1]
subdir = 'man' + num
absdir = os.path.join(manroot, subdir)
self.make_subdir(outfile, absdir)
srcabs = os.path.join(self.environment.get_source_dir(), f)
dstabs = os.path.join(manroot,
os.path.join(subdir, f + '.gz'))
cmd = "gzip < '%s' > '%s' || exit\n" % (srcabs, dstabs)
outfile.write(cmd)
def generate_header_install(self, outfile): def generate_header_install(self, outfile):
prefix = self.environment.get_prefix() prefix = self.environment.get_prefix()
@ -91,12 +112,12 @@ echo Run compile.sh before this or bad things will happen.
if len(headers) != 0: if len(headers) != 0:
outfile.write('\necho Installing headers.\n') outfile.write('\necho Installing headers.\n')
else: else:
outfile.write('\necho This project has no headers to install.') outfile.write('\necho This project has no headers to install.\n')
for h in headers: for h in headers:
outdir = os.path.join(incroot, h.get_subdir()) outdir = os.path.join(incroot, h.get_subdir())
self.make_subdir(outfile, outdir) self.make_subdir(outfile, outdir)
for f in h.get_sources(): for f in h.get_sources():
abspath = os.path.join(self.environment.get_source_dir(), f) abspath = os.path.join(self.environment.get_source_dir(), f) # FIXME
self.copy_file(outfile, abspath, outdir) self.copy_file(outfile, abspath, outdir)
def generate_target_install(self, outfile): def generate_target_install(self, outfile):

@ -0,0 +1 @@
this is a man page of bar.2, its contents are irrelevant

@ -0,0 +1,3 @@
project('man install', 'c')
m1 = man('foo.1')
m2 = man('bar.2')

@ -0,0 +1 @@
this is a man page of foo.1 its contents are irrelevant
Loading…
Cancel
Save