The Meson Build System
http://mesonbuild.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
4.9 KiB
118 lines
4.9 KiB
12 years ago
|
#!/usr/bin/python3 -tt
|
||
|
|
||
|
# Copyright 2012 Jussi Pakkanen
|
||
|
|
||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
# you may not use this file except in compliance with the License.
|
||
|
# You may obtain a copy of the License at
|
||
|
|
||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||
|
|
||
|
# Unless required by applicable law or agreed to in writing, software
|
||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
# See the License for the specific language governing permissions and
|
||
|
# limitations under the License.
|
||
|
|
||
|
from optparse import OptionParser
|
||
12 years ago
|
import sys, stat
|
||
12 years ago
|
import os.path
|
||
12 years ago
|
import environment, interpreter
|
||
12 years ago
|
import generators, build
|
||
12 years ago
|
|
||
12 years ago
|
version = '0.1-research'
|
||
|
|
||
12 years ago
|
usage_info = '%prog [options] source_dir build_dir'
|
||
|
|
||
12 years ago
|
parser = OptionParser(usage=usage_info, version=version)
|
||
12 years ago
|
|
||
12 years ago
|
build_types = ['plain', 'debug', 'optimized']
|
||
|
buildtype_help = 'build type, one of: %s' % ', '.join(build_types)
|
||
|
buildtype_help += ' (default: %default)'
|
||
|
|
||
12 years ago
|
parser.add_option('--prefix', default='/usr/local', dest='prefix',
|
||
|
help='the installation prefix (default: %default)')
|
||
|
parser.add_option('--libdir', default='lib', dest='libdir',
|
||
|
help='the installation subdir of libraries (default: %default)')
|
||
|
parser.add_option('--bindir', default='bin', dest='bindir',
|
||
|
help='the installation subdir of executables (default: %default)')
|
||
|
parser.add_option('--includedir', default='include', dest='includedir',
|
||
|
help='relative path of installed headers (default: %default)')
|
||
|
parser.add_option('--datadir', default='share', dest='datadir',
|
||
12 years ago
|
help='relative path to the top of data file subdirectory (default: %default)')
|
||
|
parser.add_option('--mandir' , default='share/man', dest='mandir',
|
||
|
help='relatie path of man files (default: %default)')
|
||
12 years ago
|
parser.add_option('-G', '--generator', default='ninja', dest='generator',
|
||
12 years ago
|
help='the backend generator to use (default: %default)')
|
||
12 years ago
|
parser.add_option('--buildtype', default='debug', type='choice', choices=build_types, dest='buildtype',
|
||
|
help=buildtype_help)
|
||
|
parser.add_option('--strip', action='store_true', dest='strip', default=False,\
|
||
|
help='strip targets on install (default: %default)')
|
||
12 years ago
|
|
||
12 years ago
|
class BuilderApp():
|
||
12 years ago
|
|
||
12 years ago
|
def __init__(self, dir1, dir2, script_file, options):
|
||
12 years ago
|
(self.source_dir, self.build_dir) = self.validate_dirs(dir1, dir2)
|
||
12 years ago
|
if options.prefix[0] != '/':
|
||
|
raise RuntimeError('--prefix must be an absolute path.')
|
||
12 years ago
|
self.builder_script_file = script_file
|
||
12 years ago
|
self.options = options
|
||
12 years ago
|
|
||
|
def has_builder_file(self, dirname):
|
||
12 years ago
|
fname = os.path.join(dirname, environment.builder_filename)
|
||
12 years ago
|
try:
|
||
|
ifile = open(fname, 'r')
|
||
12 years ago
|
ifile.close()
|
||
12 years ago
|
return True
|
||
|
except IOError:
|
||
|
return False
|
||
|
|
||
|
def validate_dirs(self, dir1, dir2):
|
||
|
ndir1 = os.path.abspath(dir1)
|
||
|
ndir2 = os.path.abspath(dir2)
|
||
|
if not stat.S_ISDIR(os.stat(ndir1).st_mode):
|
||
|
raise RuntimeError('%s is not a directory' % dir1)
|
||
|
if not stat.S_ISDIR(os.stat(ndir2).st_mode):
|
||
|
raise RuntimeError('%s is not a directory' % dir2)
|
||
|
self.options = options
|
||
12 years ago
|
if os.path.samefile(dir1, dir2):
|
||
12 years ago
|
raise RuntimeError('Source and build directories must not be the same. Create a pristine build directory.')
|
||
|
if self.has_builder_file(ndir1):
|
||
|
if self.has_builder_file(ndir2):
|
||
12 years ago
|
raise RuntimeError('Both directories contain a build file %s.' % environment.builder_filename)
|
||
12 years ago
|
return (ndir1, ndir2)
|
||
|
if self.has_builder_file(ndir2):
|
||
|
return (ndir2, ndir1)
|
||
12 years ago
|
raise RuntimeError('Neither directory contains a build file %s.' % environment.builder_filename)
|
||
12 years ago
|
|
||
|
def generate(self):
|
||
12 years ago
|
env = environment.Environment(self.source_dir, self.build_dir, self.builder_script_file, options)
|
||
12 years ago
|
b = build.Build(env)
|
||
12 years ago
|
intr = interpreter.Interpreter(b)
|
||
12 years ago
|
intr.run()
|
||
12 years ago
|
if options.generator == 'shell':
|
||
|
g = generators.ShellGenerator(b, intr)
|
||
|
elif options.generator == 'ninja':
|
||
|
g = generators.NinjaGenerator(b, intr)
|
||
|
else:
|
||
|
raise RuntimeError('Unknown generator "%s".' % options.generator)
|
||
12 years ago
|
g.generate()
|
||
12 years ago
|
|
||
12 years ago
|
if __name__ == '__main__':
|
||
|
(options, args) = parser.parse_args(sys.argv)
|
||
|
if len(args) == 1 or len(args) > 3:
|
||
12 years ago
|
print('%s <source directory> <build directory>' % sys.argv[0])
|
||
|
print('If you omit either directory, the current directory is substituted.')
|
||
12 years ago
|
sys.exit(1)
|
||
|
dir1 = args[1]
|
||
|
if len(args) > 2:
|
||
|
dir2 = args[2]
|
||
|
else:
|
||
|
dir2 = '.'
|
||
12 years ago
|
this_file = os.path.abspath(__file__)
|
||
|
builder = BuilderApp(dir1, dir2, this_file, options)
|
||
12 years ago
|
print ('Source dir: ' + builder.source_dir)
|
||
|
print ('Build dir: ' + builder.build_dir)
|
||
12 years ago
|
builder.generate()
|
||
|
|