Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # Python 2.7
- import os
- import errno
- import glob
- # Meta data
- project_name = 'untitled'
- compiler = 'g++'
- compiler_flags = ['-Wall', '-pedantic', '-pedantic-errors', '-Werror', '-Wextra', '-std=c++11']
- include_paths = ['./']
- library_paths = []
- libraries = ['-lsfml-graphics', '-lsfml-window', '-lsfml-system']
- ignored_warnings = ['switch']
- debug = False
- debug_flags = ['-g']
- input_directory = ''
- output_directory = 'bin/'
- # Stored data
- file = open('build.ninja', 'w')
- include_flags = []
- lib_path = []
- # Set up ignored warnings
- for warning in ignored_warnings:
- compiler_flags.append('-Wno-' + warning)
- # Set up include paths
- for path in include_paths:
- include_flags.append(r'-I"' + path + r'"')
- # Set up library paths
- for path in library_paths:
- lib_path.append('-L' + path)
- # Utilities
- def make_path(path):
- if path:
- try:
- os.makedirs(path)
- except OSError as exception:
- if exception.errno != errno.EEXIST:
- raise
- def stringify_list(the_list):
- return ' '.join(map(str, the_list))
- def make_rule(name, type, content):
- result = 'rule ' + name + '\n '
- result = result + type + ' = ' + content + '\n\n'
- return result
- def make_variable(name, string):
- return name + ' = ' + string + '\n\n'
- def make_build(input, output, rule):
- return 'build ' + output + ': ' + rule + ' ' + input + '\n\n'
- # Some preliminary set up
- input_files = glob.glob(input_directory + '*.cpp')
- out_files = []
- make_path(input_directory)
- make_path(output_directory)
- # Start building build.ninja file
- # cxxflags variable
- file.write(make_variable('cxxflags', stringify_list(compiler_flags)))
- # lib variable
- file.write(make_variable('lib', stringify_list(library_paths + libraries)))
- # cxx rule
- file.write(make_rule('cxx', 'command', 'g++ ${cxxflags} ${lib} -c ${in} -o ${out}'))
- # link rule
- file.write(make_rule('link', 'command', 'g++ ${cxxflags} ${lib} ${in} -o ${out}'))
- # Generate build sequences
- for input in input_files:
- output_file = output_directory + input.replace('cpp', 'o')
- file.write(make_build(input, output_file, 'cxx'))
- out_files.append(output_file)
- # Generate link sequence
- file.write(make_build(stringify_list(out_files), output_directory + project_name, 'link'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement