Enable PREFIX for installing on some target types.

pull/15/head
Jussi Pakkanen 12 years ago
parent 127cd43f2a
commit ae23feb36e
  1. 34
      builder_install.py
  2. 21
      generators.py

@ -17,7 +17,8 @@
import sys, pickle, os, shutil, subprocess, gzip
class InstallData():
def __init__(self, depfixer, dep_prefix):
def __init__(self, prefix, depfixer, dep_prefix):
self.prefix = prefix
self.targets = []
self.depfixer = depfixer
self.dep_prefix = dep_prefix
@ -28,6 +29,9 @@ class InstallData():
def do_install(datafilename):
ifile = open(datafilename, 'rb')
d = pickle.load(ifile)
pref_var = 'PREFIX'
if pref_var in os.environ:
d.prefix = os.environ[pref_var]
install_targets(d)
install_headers(d)
install_man(d)
@ -45,21 +49,22 @@ def install_data(d):
def install_man(d):
for m in d.man:
fullfilename = m[0]
outfilename = m[1]
outfileroot = m[1]
outfilename = os.path.join(d.prefix, outfileroot)
full_source_filename = m[0]
outdir = os.path.split(outfilename)[0]
os.makedirs(outdir, exist_ok=True)
print('Installing %s to %s.' % (fullfilename, outdir))
if outfilename.endswith('.gz') and not fullfilename.endswith('.gz'):
open(outfilename, 'wb').write(gzip.compress(open(fullfilename, 'rb').read()))
print('Installing %s to %s.' % (full_source_filename, outdir))
if outfilename.endswith('.gz') and not full_source_filename.endswith('.gz'):
open(outfilename, 'wb').write(gzip.compress(open(full_source_filename, 'rb').read()))
else:
shutil.copyfile(fullfilename, outfilename)
shutil.copystat(fullfilename, outfilename)
shutil.copyfile(full_source_filename, outfilename)
shutil.copystat(full_source_filename, outfilename)
def install_headers(d):
for t in d.headers:
fullfilename = t[0]
outdir = t[1]
outdir = os.path.join(d.prefix, t[1])
fname = os.path.split(fullfilename)[1]
outfilename = os.path.join(outdir, fname)
print('Installing %s to %s' % (fname, outdir))
@ -69,16 +74,15 @@ def install_headers(d):
def install_targets(d):
for t in d.targets:
fullfilename = t[0]
outdir = t[1]
fname = os.path.split(fullfilename)[1]
fname = t[0]
outdir = os.path.join(d.prefix, t[1])
aliases = t[2]
outname = os.path.join(outdir, fname)
should_strip = t[3]
print('Installing %s to %s' % (fname, outdir))
print('Installing %s to %s' % (fname, outname))
os.makedirs(outdir, exist_ok=True)
shutil.copyfile(fullfilename, outname)
shutil.copystat(fullfilename, outname)
shutil.copyfile(fname, outname)
shutil.copystat(fname, outname)
if should_strip:
print('Stripping target')
ps = subprocess.Popen(['strip', outname], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

@ -182,7 +182,7 @@ class NinjaGenerator(Generator):
install_script = os.path.join(script_root, 'builder_install.py')
install_data_file = os.path.join(self.environment.get_scratch_dir(), 'install.dat')
depfixer = os.path.join(self.get_script_root(), 'depfixer.py')
d = InstallData(depfixer, './') # Fixme
d = InstallData(self.environment.get_prefix(), depfixer, './') # Fixme
outfile.write('build install: CUSTOM_COMMAND | all\n')
outfile.write(" COMMAND = '%s' '%s'\n\n" % (ninja_quote(install_script), ninja_quote(install_data_file)))
@ -194,9 +194,8 @@ class NinjaGenerator(Generator):
pickle.dump(d, ofile)
def generate_target_install(self, d):
prefix = self.environment.get_prefix()
libdir = os.path.join(prefix, self.environment.get_libdir())
bindir = os.path.join(prefix, self.environment.get_bindir())
libdir = self.environment.get_libdir()
bindir = self.environment.get_bindir()
should_strip = self.environment.options.strip
for t in self.build.get_targets().values():
@ -205,12 +204,11 @@ class NinjaGenerator(Generator):
outdir = bindir
else:
outdir = libdir
i = [os.path.join(self.environment.get_build_dir(), self.get_target_filename(t)), outdir, t.get_aliaslist(), should_strip]
i = [self.get_target_filename(t), outdir, t.get_aliaslist(), should_strip]
d.targets.append(i)
def generate_header_install(self, d):
prefix = self.environment.get_prefix()
incroot = os.path.join(prefix, self.environment.get_includedir())
incroot = self.environment.get_includedir()
headers = self.build.get_headers()
for h in headers:
@ -221,8 +219,7 @@ class NinjaGenerator(Generator):
d.headers.append(i)
def generate_man_install(self, d):
prefix = self.environment.get_prefix()
manroot = os.path.join(prefix, self.environment.get_mandir())
manroot = self.environment.get_mandir()
man = self.build.get_man()
for m in man:
for f in m.get_sources():
@ -235,15 +232,13 @@ class NinjaGenerator(Generator):
d.man.append(i)
def generate_data_install(self, d):
prefix = self.environment.get_prefix()
dataroot = os.path.join(prefix, self.environment.get_datadir())
dataroot = self.environment.get_datadir()
data = self.build.get_data()
for de in data:
subdir = os.path.join(dataroot, de.get_subdir())
absdir = os.path.join(self.environment.get_prefix(), subdir)
for f in de.get_sources():
srcabs = os.path.join(self.environment.get_source_dir(), f)
dstabs = os.path.join(absdir, f)
dstabs = os.path.join(subdir, f)
i = [srcabs, dstabs]
d.data.append(i)

Loading…
Cancel
Save