The Vala compiler, valac, has the --output argument to name the generated binary file. For example:
valac my_source_file.vala --output myprogram
Use valac --help to find more compiler options.
A simple Makefile could be:
sources = $(wildcard src/*.vala)
myprogram:
valac $(sources) --output myprogram
Save this as Makefile in the project directory and issue the command make or make myprogram and you will have the binary file myprogram built. There are a few things to note:
- Tabs are used for indentation, in case that didn't come across from the example
- You will need to delete the output file to rebuild it when you make any changes to the source files
- A wildcard is used to include all Vala source files in the
src directory
Many new Vala projects are using the Meson build system because it is very fast and has a cleaner syntax. With Meson a simple meson.build file could be:
project('myprogram project', 'vala', 'c')
dependencies = [
dependency('glib-2.0'),
dependency('gobject-2.0'),
]
sources = []
subdir('src')
executable('myprogram', sources, dependencies: dependencies)
Save this in the project directory and then in the src directory a meson.build file that explicitly lists the source files:
sources += files(
'a.vala',
'b.vala',
)
Note that subdir() uses the meson.build file in src directory to to append the source files to the sources variable.
To build the project, first set up the build directory. Do this from the project directory:
meson setup builddir
Then build the project:
ninja -C builddir
You may need to use ninja-build for Red Hat based distributions like Fedora. The executable, myprogram, is in the builddir.
If you change a source file then ninja -C builddir will rebuild with no need to delete anything.
As your project grows you will find Meson is far more manageable than using Makefiles.