]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - man/meson.build
man/meson: add simple build test for example code
[thirdparty/systemd.git] / man / meson.build
index 488ff7022093e30b076e25427030fc254c033431..22ac236b273d9b8190c2df4236e2d51a10f6889e 100644 (file)
@@ -248,3 +248,87 @@ update_man_rules = custom_target(
                    '@0@/man/*.xml'.format(project_source_root),
                    '@0@/rules/meson.build'.format(meson.current_source_dir())],
         depends : man_page_depends)
+
+############################################################
+
+simple_examples = files(
+        'event-quick-child.c',
+        'hwdb-usb-device.c',
+        'id128-app-specific.c',
+        'inotify-watch-tmp.c',
+        'journal-enumerate-fields.c',
+        'journal-iterate-foreach.c',
+        'journal-iterate-poll.c',
+        'journal-iterate-unique.c',
+        'journal-iterate-wait.c',
+        'journal-stream-fd.c',
+        'logcontrol-example.c',
+        'notify-selfcontained-example.c',
+        'path-documents.c',
+        'print-unit-path-call-method.c',
+        'print-unit-path.c',
+        'sd-bus-container-append.c',
+        'sd-bus-container-read.c',
+        'sd_bus_error-example.c',
+        'sd_bus_service_reconnect.c',
+        'send-unit-files-changed.c',
+        'vtable-example.c',
+)
+
+examples = []
+foreach example : simple_examples
+        examples += [ { 'file' : example } ]
+endforeach
+
+if conf.get('HAVE_GLIB') == 1
+        examples += [
+                {
+                        'file' : files('glib-event-glue.c'),
+                        'opts' : [
+                                '-I', libglib.get_variable('includedir') / 'glib-2.0',
+                                '-I', libglib.get_variable('libdir') / 'glib-2.0/include',
+                        ],
+                },
+        ]
+endif
+
+default_args = [
+        cc.cmd_array(),
+        '-c',
+        '-x', 'c',
+        '-pedantic',
+        '-Wall',
+        '-Werror',
+        '-Wextra',
+        '-Wno-unused-parameter',
+        '-o', '/dev/null',
+        '-I', meson.current_source_dir() / '../src',
+]
+
+std_args_in = [
+        [ '-std=c99', '-D_GNU_SOURCE', ],
+        [ '-std=c11', '-D_GNU_SOURCE', ],
+        [ '-std=c17', '-D_GNU_SOURCE', ],
+        [ '-std=c23', '-D_GNU_SOURCE', ],
+        [ '-std=gnu99', ],
+        [ '-std=gnu11', ],
+        [ '-std=gnu17', ],
+        [ '-std=gnu23', ],
+]
+
+std_args = []
+foreach std : std_args_in
+        if cc.has_argument(std[0])
+                std_args += [std]
+        endif
+endforeach
+
+foreach item : examples
+        foreach std : std_args
+                file = item.get('file')
+                test('cc-' + fs.stem(file) + '-' + std[0].split('=')[1],
+                     env,
+                     suite : 'example',
+                     args : default_args + std + item.get('opts', []) + [file])
+        endforeach
+endforeach