File: build_example.jsonnet

package info (click to toggle)
jsonnet 0.20.0%2Bds-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 16,776 kB
  • sloc: cpp: 23,318; python: 1,788; javascript: 1,003; ansic: 885; sh: 745; makefile: 194; java: 140
file content (28 lines) | stat: -rw-r--r-- 749 bytes parent folder | download | duplicates (3)
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
// Compiler template
local CCompiler = {
  cFlags: [],
  out: 'a.out',
  local flags_str = std.join(' ', self.cFlags),
  local files_str = std.join(' ', self.files),
  cmd: '%s %s %s -o %s' % [self.compiler, flags_str, files_str, self.out],
};

// GCC specialization
local Gcc = CCompiler { compiler: 'gcc' };

// Another specialization
local Clang = CCompiler { compiler: 'clang' };

// Mixins - append flags
local Opt = { cFlags: super.cFlags + ['-O3', '-DNDEBUG'] };
local Dbg = { cFlags: super.cFlags + ['-g'] };

// Output:
{
  targets: [
    Gcc { files: ['a.c', 'b.c'] },
    Clang { files: ['test.c'], out: 'test' },
    Clang + Opt { files: ['test2.c'], out: 'test2' },
    Gcc + Opt + Dbg { files: ['foo.c', 'bar.c'], out: 'baz' },
  ],
}