Debian Codegraph @

subprojects/meson-docs/docs/markdown/Custom-build-targets.md

raw
1 ---
2 short-description: Build targets for custom languages or corner-cases
3 ...
4
5 # Custom build targets
6
7 While Meson tries to support as many languages and tools as possible,
8 there is no possible way for it to cover all corner cases. For these
9 cases it permits you to define custom build targets. Here is how one
10 would use it.
11
12 ```meson
13 comp = find_program('custom_compiler')
14
15 infile = 'source_code.txt'
16 outfile = 'output.bin'
17
18 mytarget = custom_target('targetname',
19 output : outfile,
20 input : infile,
21 command : [comp, '@INPUT@', '@OUTPUT@'],
22 install : true,
23 install_dir : 'subdir')
24 ```
25
26 This would generate the binary `output.bin` and install it to
27 `${prefix}/subdir/output.bin`. Variable substitution works just like
28 it does for source generation.
29
30 See [Generating Sources](Generating-sources.md) for more information on this topic.
31
32 ## Details on command invocation
33
34 Meson only permits you to specify one command to run. This is by
35 design as writing shell pipelines into build definition files leads to
36 code that is very hard to maintain. If your command requires multiple
37 steps you need to write a wrapper script that does all the necessary
38 work.
39
40 When doing this you need to be mindful of the following issues:
41
42 * do not assume that the command is invoked in any specific directory
43 * a target called `target` file `outfile` defined in subdir `subdir`
44 must be written to `build_dir/subdir/foo.dat`
45 * if you need a subdirectory for temporary files, use
46 `build_dir/subdir/target.dir`