1# used to only create guile docs when possible,
2# otherwise reuse what is already there
3can_make_guile_docs = guile_dep.found () and get_option ('guile_snarf_docs_path') != '' and texi2html.found () and pandoc.found ()
4
5# Create custom targets (each API .rst file) and save
6# them in guile_docs
7guile_docs = []
8if can_make_guile_docs
9  gen_texi_docs_sh = find_program (
10    'guile_gen_texi_docs.sh')
11  format_rst = find_program ('format_rst.sh')
12  foreach snarfable_src : guile_snarfable_srcs
13    split_by_dot = snarfable_src.split('.')
14    without_ext = ''
15    foreach sp : split_by_dot
16      if sp == split_by_dot[split_by_dot.length() - 2]
17        without_ext += sp
18      elif sp != split_by_dot[split_by_dot.length() - 1]
19        without_ext += sp + '.'
20      endif
21    endforeach
22    base_file = ' '.join(without_ext.split (
23      meson_src_root)[1].split('/'))
24    base_file = base_file.split('src guile ')[1]
25    rst_tmp_file = base_file + '.rst.tmp'
26    rst_file = base_file + '.rst'
27    texi_file = '-'.join (base_file.split ('_')) + '.texi'
28    texi_doc = configure_file (
29      output: texi_file,
30      command: [
31        gen_texi_docs_sh,
32        get_option ('guile_snarf_docs_path'),
33        guile_dep.name(), snarfable_src,
34        texi_file, texi_file + '.p',
35        guild.full_path (),
36        '-I' + meson_src_root / 'inc',
37        ],
38      )
39    rst_tmp_doc = configure_file (
40      output: rst_tmp_file,
41      input: texi_doc,
42      command: [
43        # FIXME this should be a shell script, not
44        # guile script
45        guile_gen_docs_scm,
46        guile_dep.name(),
47        meson.current_build_dir () / texi_file,
48        '@OUTPUT@',
49        meson.current_build_dir () / rst_tmp_file + '.p',
50        ],
51      )
52    rst_doc = configure_file (
53      output: rst_file,
54      input: rst_tmp_doc,
55      command: [
56        format_rst,
57        meson.current_build_dir () / rst_tmp_file,
58        '@OUTPUT@',
59        ],
60      )
61    rst_files += rst_doc
62    guile_docs += rst_doc
63  endforeach
64# else if can't make guile docs, copy existing ones
65else
66  c = run_command (['find', '.', '-name', '*.rst'])
67  existing_api_docs = c.stdout().strip().split('\n')
68  foreach existing_api_doc : existing_api_docs
69    rst_files += configure_file (
70      copy: true,
71      input: existing_api_doc,
72      output: '@PLAINNAME@')
73  endforeach
74endif
75
76# copy the Guile API docs to /api in the
77# source code (note: this edits rst source code)
78copy_guile_docs_sh = configure_file (
79  output: 'copy_guile_docs.sh',
80  input: 'copy_guile_docs.sh',
81  configuration: {
82    'BASH': bash.full_path (),
83    'GUILE_DOCS_SRCDIR': meson.current_build_dir (),
84    'GUILE_DOCS_DESTDIR': meson.current_source_dir (),
85    })
86copy_guile_docs_target = custom_target (
87  'guile_localized_docs',
88  output: 'guile_localized_docs',
89  command: copy_guile_docs_sh,
90  depend_files: [
91    guile_docs,
92    ])
93
94copy_files = [
95  'intro.rst',
96  ]
97
98foreach f : copy_files
99  rst_files += configure_file (
100    copy: true,
101    input: f,
102    output: '@PLAINNAME@')
103endforeach
104