1# -*- coding: utf-8 -*- 2# 3# GNAT build configuration file 4 5import sys 6import os 7import time 8import re 9 10sys.path.append('.') 11 12import ada_pygments 13import latex_elements 14 15# Some configuration values for the various documentation handled by 16# this conf.py 17 18DOCS = { 19 'gnat_rm': { 20 'title': u'GNAT Reference Manual'}, 21 'gnat_ugn': { 22 'title': u'GNAT User\'s Guide for Native Platforms'}} 23 24# Then retrieve the source directory 25root_source_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 26gnatvsn_spec = os.path.join(root_source_dir, '..', 'gnatvsn.ads') 27basever = os.path.join(root_source_dir, '..', '..', 'BASE-VER') 28texi_fsf = True # Set to False when FSF doc is switched to sphinx by default 29 30with open(gnatvsn_spec, 'rb') as fd: 31 gnatvsn_content = fd.read() 32 33 34def get_copyright(): 35 return u'2008-%s, Free Software Foundation' % time.strftime('%Y') 36 37 38def get_gnat_version(): 39 m = re.search(r'Gnat_Static_Version_String : ' + 40 r'constant String := "([^\(\)]+)\(.*\)?";', 41 gnatvsn_content) 42 if m: 43 return m.group(1).strip() 44 else: 45 if texi_fsf and os.path.exists(basever): 46 return '' 47 48 try: 49 with open(basever, 'rb') as fd: 50 return fd.read() 51 except: 52 pass 53 54 print 'cannot find GNAT version in gnatvsn.ads or in ' + basever 55 sys.exit(1) 56 57 58def get_gnat_build_type(): 59 m = re.search(r'Build_Type : constant Gnat_Build_Type := (.+);', 60 gnatvsn_content) 61 if m: 62 return {'Gnatpro': 'PRO', 63 'FSF': 'FSF', 64 'GPL': 'GPL'}[m.group(1).strip()] 65 else: 66 print 'cannot compute GNAT build type' 67 sys.exit(1) 68 69 70# First retrieve the name of the documentation we are building 71doc_name = os.environ.get('DOC_NAME', None) 72if doc_name is None: 73 print 'DOC_NAME environment variable should be set' 74 sys.exit(1) 75 76if doc_name not in DOCS: 77 print '%s is not a valid documentation name' % doc_name 78 sys.exit(1) 79 80 81# Exclude sources that are not part of the current documentation 82exclude_patterns = [] 83for d in os.listdir(root_source_dir): 84 if d not in ('share', doc_name, doc_name + '.rst'): 85 exclude_patterns.append(d) 86 print 'ignoring %s' % d 87 88if doc_name == 'gnat_rm': 89 exclude_patterns.append('share/gnat_project_manager.rst') 90 print 'ignoring share/gnat_project_manager.rst' 91 92extensions = [] 93templates_path = ['_templates'] 94source_suffix = '.rst' 95master_doc = doc_name 96 97# General information about the project. 98project = DOCS[doc_name]['title'] 99 100copyright = get_copyright() 101 102version = get_gnat_version() 103release = get_gnat_version() 104 105pygments_style = 'sphinx' 106tags.add(get_gnat_build_type()) 107html_theme = 'sphinxdoc' 108if os.path.isfile('adacore_transparent.png'): 109 html_logo = 'adacore_transparent.png' 110if os.path.isfile('favicon.ico'): 111 html_favicon = 'favicon.ico' 112 113html_static_path = ['_static'] 114 115latex_elements = { 116 'preamble': latex_elements.TOC_DEPTH + 117 latex_elements.PAGE_BLANK + 118 latex_elements.TOC_CMD + 119 latex_elements.LATEX_HYPHEN + 120 latex_elements.doc_settings(DOCS[doc_name]['title'], 121 get_gnat_version()), 122 'tableofcontents': latex_elements.TOC} 123 124latex_documents = [ 125 (master_doc, '%s.tex' % doc_name, project, u'AdaCore', 'manual')] 126 127texinfo_documents = [ 128 (master_doc, doc_name, project, 129 u'AdaCore', doc_name, doc_name, '')] 130 131 132def setup(app): 133 app.add_lexer('ada', ada_pygments.AdaLexer()) 134 app.add_lexer('gpr', ada_pygments.GNATProjectLexer()) 135