| 1 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
|
| 3 |
# This is lame, I know, but meson has no other include mechanism |
| 4 |
subdir('rules') |
| 5 |
|
| 6 |
want_man = get_option('man') |
| 7 |
want_html = get_option('html') |
| 8 |
xsltproc = find_program('xsltproc', |
| 9 |
required : want_man.enabled() or want_html.enabled()) |
| 10 |
want_man = want_man.allowed() and xsltproc.found() |
| 11 |
want_html = want_html.allowed() and xsltproc.found() |
| 12 |
|
| 13 |
xsltproc_flags = [ |
| 14 |
'--nonet', |
| 15 |
'--xinclude', |
| 16 |
'--maxdepth', '9000', |
| 17 |
'--stringparam', 'man.output.quietly', '1', |
| 18 |
'--stringparam', 'funcsynopsis.style', 'ansi', |
| 19 |
'--stringparam', 'man.authors.section.enabled', '0', |
| 20 |
'--stringparam', 'man.copyright.section.enabled', '0', |
| 21 |
'--stringparam', 'systemd.version', '@0@'.format(meson.project_version()), |
| 22 |
'--path', |
| 23 |
'@0@:@1@:@2@:@3@'.format(meson.current_build_dir(), |
| 24 |
meson.current_source_dir(), |
| 25 |
libshared_build_dir, |
| 26 |
libcore_build_dir)] |
| 27 |
|
| 28 |
custom_man_xsl = files('custom-man.xsl') |
| 29 |
custom_html_xsl = files('custom-html.xsl') |
| 30 |
xslt_cmd = [xsltproc, '-o', '@OUTPUT0@'] + xsltproc_flags |
| 31 |
|
| 32 |
custom_entities_ent = custom_target( |
| 33 |
input : 'custom-entities.ent.in', |
| 34 |
output : 'custom-entities.ent', |
| 35 |
command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@']) |
| 36 |
|
| 37 |
man_page_depends += custom_entities_ent |
| 38 |
|
| 39 |
man_pages = [] |
| 40 |
html_pages = [] |
| 41 |
source_xml_files = [] |
| 42 |
dbus_docs = [] |
| 43 |
foreach tuple : manpages |
| 44 |
stem = tuple[0] |
| 45 |
section = tuple[1] |
| 46 |
aliases = tuple[2] |
| 47 |
condition = tuple[3] |
| 48 |
|
| 49 |
xml = stem + '.xml' |
| 50 |
html = stem + '.html' |
| 51 |
man = stem + '.' + section |
| 52 |
|
| 53 |
manaliases = [] |
| 54 |
htmlaliases = [] |
| 55 |
foreach alias : aliases |
| 56 |
manaliases += alias + '.' + section |
| 57 |
htmlaliases += alias + '.html' |
| 58 |
endforeach |
| 59 |
|
| 60 |
mandirn = get_option('mandir') / ('man' + section) |
| 61 |
|
| 62 |
have = true |
| 63 |
foreach word : condition.split() |
| 64 |
if conf.get(word) != 1 |
| 65 |
have = false |
| 66 |
break |
| 67 |
endif |
| 68 |
endforeach |
| 69 |
|
| 70 |
if have |
| 71 |
file = files(tuple[0] + '.xml') |
| 72 |
source_xml_files += file |
| 73 |
if tuple[0].startswith('org.freedesktop.') |
| 74 |
dbus_docs += file |
| 75 |
endif |
| 76 |
|
| 77 |
if xsltproc.found() |
| 78 |
p1 = custom_target( |
| 79 |
input : xml, |
| 80 |
output : [man] + manaliases, |
| 81 |
command : xslt_cmd + [custom_man_xsl, '@INPUT@'], |
| 82 |
depends : man_page_depends, |
| 83 |
install : want_man, |
| 84 |
install_dir : mandirn) |
| 85 |
man_pages += p1 |
| 86 |
|
| 87 |
p2 = [] |
| 88 |
foreach htmlalias : htmlaliases |
| 89 |
link = custom_target( |
| 90 |
output : htmlalias, |
| 91 |
command : [ln, '-fs', html, '@OUTPUT@']) |
| 92 |
if want_html |
| 93 |
install_symlink(htmlalias, |
| 94 |
pointing_to : html, |
| 95 |
install_dir : docdir / 'html') |
| 96 |
p2 += link |
| 97 |
endif |
| 98 |
html_pages += link |
| 99 |
endforeach |
| 100 |
|
| 101 |
p3 = custom_target( |
| 102 |
input : xml, |
| 103 |
output : html, |
| 104 |
command : xslt_cmd + [custom_html_xsl, '@INPUT@'], |
| 105 |
depends : [man_page_depends, p2], |
| 106 |
install : want_html, |
| 107 |
install_dir : docdir / 'html') |
| 108 |
html_pages += p3 |
| 109 |
endif |
| 110 |
else |
| 111 |
message(f'Skipping @stem@.@section@ because @condition@ is false') |
| 112 |
endif |
| 113 |
endforeach |
| 114 |
|
| 115 |
############################################################ |
| 116 |
|
| 117 |
have_lxml = run_command(xml_helper_py, check: false).returncode() == 0 |
| 118 |
if not have_lxml |
| 119 |
message('python-lxml not available, not making man page indices') |
| 120 |
endif |
| 121 |
|
| 122 |
systemd_directives_xml = custom_target( |
| 123 |
input : ['directives-template.xml', source_xml_files], |
| 124 |
output : 'systemd.directives.xml', |
| 125 |
depends : man_page_depends, |
| 126 |
command : [make_directive_index_py, '@OUTPUT@', '@INPUT@']) |
| 127 |
|
| 128 |
nonindex_xml_files = source_xml_files + [systemd_directives_xml] |
| 129 |
systemd_index_xml = custom_target( |
| 130 |
input : nonindex_xml_files, |
| 131 |
output : 'systemd.index.xml', |
| 132 |
command : [make_man_index_py, '@OUTPUT@'] + nonindex_xml_files) |
| 133 |
|
| 134 |
foreach tuple : xsltproc.found() and have_lxml ? [['systemd.directives', '7', systemd_directives_xml], |
| 135 |
['systemd.index', '7', systemd_index_xml]] : [] |
| 136 |
stem = tuple[0] |
| 137 |
section = tuple[1] |
| 138 |
xml = tuple[2] |
| 139 |
|
| 140 |
html = stem + '.html' |
| 141 |
man = stem + '.' + section |
| 142 |
|
| 143 |
mandirn = get_option('mandir') / ('man' + section) |
| 144 |
|
| 145 |
p1 = custom_target( |
| 146 |
input : xml, |
| 147 |
output : man, |
| 148 |
command : xslt_cmd + [custom_man_xsl, '@INPUT@'], |
| 149 |
install : want_man, |
| 150 |
install_dir : mandirn) |
| 151 |
man_pages += p1 |
| 152 |
|
| 153 |
p2 = [] |
| 154 |
if html == 'systemd.index.html' |
| 155 |
htmlalias = 'index.html' |
| 156 |
link = custom_target( |
| 157 |
input : p2, |
| 158 |
output : htmlalias, |
| 159 |
command : [ln, '-fs', html, '@OUTPUT@']) |
| 160 |
if want_html |
| 161 |
install_symlink(htmlalias, |
| 162 |
pointing_to : html, |
| 163 |
install_dir : docdir / 'html') |
| 164 |
p2 += link |
| 165 |
endif |
| 166 |
html_pages += link |
| 167 |
endif |
| 168 |
|
| 169 |
p3 = custom_target( |
| 170 |
input : xml, |
| 171 |
output : html, |
| 172 |
command : xslt_cmd + [custom_html_xsl, '@INPUT@'], |
| 173 |
depends : [man_page_depends, p2], |
| 174 |
install : want_html, |
| 175 |
install_dir : docdir / 'html') |
| 176 |
html_pages += p3 |
| 177 |
endforeach |
| 178 |
|
| 179 |
# Cannot use run_target because those targets are used in depends |
| 180 |
# Also see https://github.com/mesonbuild/meson/issues/368. |
| 181 |
man = custom_target( |
| 182 |
output : 'man', |
| 183 |
depends : man_pages, |
| 184 |
command : [echo]) |
| 185 |
|
| 186 |
html = custom_target( |
| 187 |
output : 'html', |
| 188 |
depends : html_pages, |
| 189 |
command : [echo]) |
| 190 |
|
| 191 |
if rsync.found() |
| 192 |
run_target( |
| 193 |
'doc-sync', |
| 194 |
depends : man_pages + html_pages, |
| 195 |
command : [sync_docs_py, |
| 196 |
'--version', |
| 197 |
'@0@'.format(meson.project_version()), |
| 198 |
meson.current_build_dir(), |
| 199 |
get_option('www-target')]) |
| 200 |
endif |
| 201 |
|
| 202 |
############################################################ |
| 203 |
|
| 204 |
buildroot_substs = configuration_data() |
| 205 |
buildroot_substs.set_quoted('BUILD_ROOT', meson.project_build_root()) |
| 206 |
|
| 207 |
configure_file( |
| 208 |
input : 'man.in', |
| 209 |
output : 'man', |
| 210 |
configuration : buildroot_substs) |
| 211 |
|
| 212 |
configure_file( |
| 213 |
input : 'html.in', |
| 214 |
output : 'html', |
| 215 |
configuration : buildroot_substs) |
| 216 |
|
| 217 |
############################################################ |
| 218 |
|
| 219 |
update_dbus_docs = custom_target( |
| 220 |
output : 'update-dbus-docs', |
| 221 |
command : [update_dbus_docs_py, '--build-dir', meson.project_build_root(), '@INPUT@'], |
| 222 |
input : dbus_docs, |
| 223 |
depends : dbus_programs) |
| 224 |
|
| 225 |
if conf.get('BUILD_MODE_DEVELOPER') == 1 |
| 226 |
test('dbus-docs-fresh', |
| 227 |
update_dbus_docs_py, |
| 228 |
suite : 'dist', |
| 229 |
args : ['--build-dir', meson.project_build_root(), '--test', dbus_docs], |
| 230 |
depends : dbus_programs) |
| 231 |
|
| 232 |
test('check-version-history', |
| 233 |
check_version_history_py, |
| 234 |
suite : 'dist', |
| 235 |
args : source_xml_files) |
| 236 |
endif |
| 237 |
|
| 238 |
update_man_rules = custom_target( |
| 239 |
output : 'update-man-rules', |
| 240 |
command : [update_man_rules_py, |
| 241 |
'@0@/man/*.xml'.format(meson.project_source_root()), |
| 242 |
'@0@/rules/meson.build'.format(meson.current_source_dir())], |
| 243 |
depends : man_page_depends) |
| 244 |
|
| 245 |
############################################################ |
| 246 |
|
| 247 |
simple_examples = files( |
| 248 |
'event-quick-child.c', |
| 249 |
'hwdb-usb-device.c', |
| 250 |
'id128-app-specific.c', |
| 251 |
'inotify-watch-tmp.c', |
| 252 |
'journal-enumerate-fields.c', |
| 253 |
'journal-iterate-foreach.c', |
| 254 |
'journal-iterate-poll.c', |
| 255 |
'journal-iterate-unique.c', |
| 256 |
'journal-iterate-wait.c', |
| 257 |
'journal-stream-fd.c', |
| 258 |
'logcontrol-example.c', |
| 259 |
'notify-selfcontained-example.c', |
| 260 |
'path-documents.c', |
| 261 |
'print-unit-path-call-method.c', |
| 262 |
'print-unit-path.c', |
| 263 |
'sd-bus-container-append.c', |
| 264 |
'sd-bus-container-read.c', |
| 265 |
'sd_bus_error-example.c', |
| 266 |
'sd_bus_service_reconnect.c', |
| 267 |
'sd_device_enumerator_add_match_parent-example.c', |
| 268 |
'sd_device_enumerator_new-example.c', |
| 269 |
'send-unit-files-changed.c', |
| 270 |
'vtable-example.c', |
| 271 |
) |
| 272 |
|
| 273 |
examples = [] |
| 274 |
foreach example : simple_examples |
| 275 |
examples += [ { 'file' : example } ] |
| 276 |
endforeach |
| 277 |
|
| 278 |
if conf.get('HAVE_GLIB') == 1 |
| 279 |
examples += [ |
| 280 |
{ |
| 281 |
'file' : files('glib-event-glue.c'), |
| 282 |
'opts' : [ |
| 283 |
'-I', libglib.get_variable('includedir') / 'glib-2.0', |
| 284 |
'-I', libglib.get_variable('libdir') / 'glib-2.0/include', |
| 285 |
], |
| 286 |
}, |
| 287 |
] |
| 288 |
endif |
| 289 |
|
| 290 |
default_args = [ |
| 291 |
cc.cmd_array(), |
| 292 |
'-c', |
| 293 |
'-x', 'c', |
| 294 |
'-pedantic', |
| 295 |
'-Wall', |
| 296 |
'-Werror', |
| 297 |
'-Wextra', |
| 298 |
'-Wno-unused-parameter', |
| 299 |
'-o', '/dev/null', |
| 300 |
'-I', meson.current_source_dir() / '../src', |
| 301 |
] |
| 302 |
|
| 303 |
std_args_in = [ |
| 304 |
[ '-std=c90', '-Wno-pedantic', '-Wno-variadic-macros', ], |
| 305 |
[ '-std=c99', ], |
| 306 |
[ '-std=c11', ], |
| 307 |
[ '-std=c17', ], |
| 308 |
[ '-std=c23', ], |
| 309 |
[ '-std=gnu90', '-Wno-pedantic', '-Wno-variadic-macros', ], |
| 310 |
[ '-std=gnu99', ], |
| 311 |
[ '-std=gnu11', ], |
| 312 |
[ '-std=gnu17', ], |
| 313 |
[ '-std=gnu23', ], |
| 314 |
] |
| 315 |
|
| 316 |
std_args = [] |
| 317 |
foreach std : std_args_in |
| 318 |
if cc.has_argument(std[0]) |
| 319 |
std_args += [std] |
| 320 |
endif |
| 321 |
endforeach |
| 322 |
|
| 323 |
foreach item : examples |
| 324 |
foreach std : std_args |
| 325 |
file = item.get('file') |
| 326 |
test('cc-' + fs.stem(file) + '-' + std[0].split('=')[1], |
| 327 |
env, |
| 328 |
suite : 'example', |
| 329 |
args : default_args + std + item.get('opts', []) + [file]) |
| 330 |
endforeach |
| 331 |
endforeach |