Advertisement
Rapptz

bootstrap.py

Aug 31st, 2013
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.32 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # Python 2.7
  3.  
  4. import os
  5. import errno
  6. import glob
  7.  
  8. # Meta data
  9. project_name = 'untitled'
  10. compiler = 'g++'
  11. compiler_flags = ['-Wall', '-pedantic', '-pedantic-errors', '-Werror', '-Wextra', '-std=c++11']
  12. include_paths = ['./']
  13. library_paths = []
  14. libraries = ['-lsfml-graphics', '-lsfml-window', '-lsfml-system']
  15. ignored_warnings = ['switch']
  16. debug = False
  17. debug_flags = ['-g']
  18. input_directory = ''
  19. output_directory = 'bin/'
  20.  
  21. # Stored data
  22. file = open('build.ninja', 'w')
  23. include_flags = []
  24. lib_path = []
  25.  
  26. # Set up ignored warnings
  27. for warning in ignored_warnings:
  28.     compiler_flags.append('-Wno-' + warning)
  29.  
  30. # Set up include paths
  31. for path in include_paths:
  32.     include_flags.append(r'-I"' + path + r'"')
  33.  
  34. # Set up library paths
  35. for path in library_paths:
  36.     lib_path.append('-L' + path)
  37.  
  38. # Utilities
  39.  
  40. def make_path(path):
  41.     if path:
  42.         try:
  43.             os.makedirs(path)
  44.         except OSError as exception:
  45.             if exception.errno != errno.EEXIST:
  46.                 raise
  47.  
  48. def stringify_list(the_list):
  49.     return ' '.join(map(str, the_list))
  50.  
  51. def make_rule(name, type, content):
  52.     result = 'rule ' + name + '\n    '
  53.     result = result + type + ' = ' + content + '\n\n'
  54.     return result
  55.  
  56. def make_variable(name, string):
  57.     return name + ' = ' + string + '\n\n'
  58.  
  59. def make_build(input, output, rule):
  60.     return 'build ' + output + ': ' + rule + ' ' + input + '\n\n'
  61.  
  62. # Some preliminary set up
  63. input_files = glob.glob(input_directory + '*.cpp')
  64. out_files = []
  65. make_path(input_directory)
  66. make_path(output_directory)
  67.  
  68. # Start building build.ninja file
  69.  
  70. # cxxflags variable
  71. file.write(make_variable('cxxflags', stringify_list(compiler_flags)))
  72.  
  73. # lib variable
  74. file.write(make_variable('lib', stringify_list(library_paths + libraries)))
  75.  
  76. # cxx rule
  77. file.write(make_rule('cxx', 'command', 'g++ ${cxxflags} ${lib} -c ${in} -o ${out}'))
  78.  
  79. # link rule
  80. file.write(make_rule('link', 'command', 'g++ ${cxxflags} ${lib} ${in} -o ${out}'))
  81.  
  82. # Generate build sequences
  83. for input in input_files:
  84.     output_file = output_directory + input.replace('cpp', 'o')
  85.     file.write(make_build(input, output_file, 'cxx'))
  86.     out_files.append(output_file)
  87.  
  88. # Generate link sequence
  89. file.write(make_build(stringify_list(out_files), output_directory + project_name, 'link'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement