aboutsummaryrefslogtreecommitdiff
path: root/shellgenerator.py
diff options
context:
space:
mode:
Diffstat (limited to 'shellgenerator.py')
-rwxr-xr-xshellgenerator.py63
1 files changed, 47 insertions, 16 deletions
diff --git a/shellgenerator.py b/shellgenerator.py
index e493354..ee2eabd 100755
--- a/shellgenerator.py
+++ b/shellgenerator.py
@@ -27,39 +27,70 @@ class ShellGenerator():
self.environment = build.environment
self.build_filename = 'compile.sh'
self.test_filename = 'run_tests.sh'
+ self.install_filename = 'install.sh'
self.processed_targets = {}
def generate(self):
self.generate_compile_script()
self.generate_test_script()
+ self.generate_install_script()
- def generate_compile_script(self):
- outfilename = os.path.join(self.environment.get_build_dir(), self.build_filename)
+ def create_shfile(self, outfilename, message):
outfile = open(outfilename, 'w')
outfile.write('#!/bin/sh\n\n')
- outfile.write('echo This is an autogenerated shell script build file for project \\"%s\\".\n'
- % self.build.get_project())
- outfile.write('echo This is experimental and most likely will not work!\n')
+ outfile.write(message)
cdcmd = ['cd', self.environment.get_build_dir()]
outfile.write(' '.join(shell_quote(cdcmd)) + '\n')
- self.generate_commands(outfile)
- outfile.close()
os.chmod(outfilename, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC |\
stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
+ return outfile
+
+ def generate_compile_script(self):
+ outfilename = os.path.join(self.environment.get_build_dir(), self.build_filename)
+ message = """echo This is an autogenerated shell script build file for project \\"%s\\"
+echo This is experimental and most likely will not work!
+""" % self.build.get_project()
+ outfile = self.create_shfile(outfilename, message)
+ self.generate_commands(outfile)
+ outfile.close()
def generate_test_script(self):
outfilename = os.path.join(self.environment.get_build_dir(), self.test_filename)
- outfile = open(outfilename, 'w')
- outfile.write('#!/bin/sh\n\n')
- outfile.write('echo This is an autogenerated shell script test file for project \\"%s\\".\n'
- % self.build.get_project())
- outfile.write('echo Run the compile script before this one or bad things will happen!\n')
- cdcmd = ['cd', self.environment.get_build_dir()]
- outfile.write(' '.join(shell_quote(cdcmd)) + '\n')
+ message = """echo This is an autogenerated test script for project \\"%s\\"
+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_tests(outfile)
outfile.close()
- os.chmod(outfilename, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC |\
- stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
+
+ def generate_install_script(self):
+ outfilename = os.path.join(self.environment.get_build_dir(), self.install_filename)
+ message = """echo This is an autogenerated install script for project \\"%s\\"
+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)
+ outfile.close()
+
+ def generate_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)
+ for tmp in self.build.get_targets().items():
+ (name, t) = tmp
+ if t.should_install():
+ if isinstance(t, interpreter.Executable):
+ outdir = bindir
+ 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)
def generate_tests(self, outfile):
for t in self.build.get_tests():