summary refs log tree commit diff
path: root/.config/yamlfs/meson.yml
blob: 378afb11c6afa4a8b96c780d99c0a30ee46d3773 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
meson.build: |-
  project(
      '{% .name %}',
      'c',
      version: '0.0.0+unknown',
      license: 'MIT',
      default_options: [
        'c_std=c99' \
        'warning_level=2' \
        'werror=true' \
      ],
  )

  cc = meson.get_compiler('c')
  add_project_arguments(cc.get_supported_arguments([
    '-D_POSIX_C_SOURCE=200809L',

    '-Wundef',
    '-Wlogical-op',
    '-Wmissing-include-dirs',
    '-Wold-style-definition',
    '-Wpointer-arith',
    '-Winit-self',
    '-Wfloat-equal',
    '-Wstrict-prototypes',
    '-Wredundant-decls',
    '-Wimplicit-fallthrough=2',
    '-Wendif-labels',
    '-Wstrict-aliasing=2',
    '-Woverflow',
    '-Wformat=2',
  
    '-Wno-missing-braces',
    '-Wno-missing-field-initializers',
    '-Wno-unused-parameter',
  ]), language: 'c')

  executable(
    meson.project_name(),
    files(
      'src/main.c',
    ),
    include_directories: include_directories('include'),
    dependencies: [],
    install: true,
  )

  {%- if .doc %}
  scdoc = dependency(
    'scdoc',
    version: '>=1.9.2',
    native: true,
    required: get_option('man-pages'),
  )
  if scdoc.found()
    scdoc_prog = find_program(scdoc.get_pkgconfig_variable('scdoc'), native: true)
    sh = find_program('sh', native: true)
    mandir = get_option('mandir')
    man_files = [
      '{% .name %}.1.scd',
    ]
    foreach fn : man_files
      topic = fn.split('.')[-3].split('/')[-1]
      section = fn.split('.')[-2]
      output = '@0@.@1@'.format(topic, section)

      custom_target(
        output,
        input: fn,
        output: output,
        command: [
          sh, '-c', '@0@ < @INPUT@ > @1@'.format(scdoc_prog.path(), output)
        ],
        install: true,
        install_dir: '@0@/man@1@'.format(mandir, section),
    )
    endforeach
  endif
  {%- end %}

  version = '"@0@ (" __DATE__ ")"'.format(meson.project_version())
  # embed version sourced from git ref
  git = find_program('git', native: true, required: false)
  if git.found()
      git_commit_hash = run_command([
        git, 'describe', '--always', '--tags'
      ])
      git_branch = run_command([
        git, 'rev-parse', '--abbrev-ref', 'HEAD'
      ])
      if git_commit_hash.returncode() == 0 and git_branch.returncode() == 0
        version = '"@0@ (" __DATE__ ", branch \'@1@\')"'.format(
          git_commit_hash.stdout().strip(),
          git_branch.stdout().strip(),
        )
      endif
  endif
  add_project_arguments('-DVERSION=@0@'.format(version), language: 'c')

src:
  main.c: |-
    #define _POSIX_C_SOURCE 200809L
    #include <stdlib.h>
    #include <stdio.h>

    #include "{% .name %}.h"

    int main(int argc, char **argv) {
        printf("%s version %s\n\n", *argv, VERSION);

        printf("args (len: %d)", argc-1);
        for (int i=1; i < argc; ++i) {
            printf(" '%s'", argv[i]);
        }
        printf("\n");

        return 0;
    }

include:
  {% .name | lower %}: |-
    #ifndef {% .name | upper %}_H
    #define {% .name | upper %}_H

    #ifndef VERSION
    #define VERSION "0.0.0+unknown"
    #endif

    /* TODO */

    #endif

.editorconfig: |-
  ; http://editorconfig.org/

  root = true

  [*]
  charset = utf-8
  end_of_line = lf
  indent_style = space

  [*.{c,h,cmake,txt}]
  indent_style = tab
  indent_size = 4

  [*.md]
  trim_trailing_whitespace = false

  [meson.build]
  indent_size = 2

  [Dockerfile]
  indent_size = 4

README.md: |-
  # {% .name %}

  TODO