2020-08-11 19:34:40 +03:00
|
|
|
==================================
|
|
|
|
The QEMU build system architecture
|
|
|
|
==================================
|
2015-09-24 16:41:38 +03:00
|
|
|
|
|
|
|
This document aims to help developers understand the architecture of the
|
|
|
|
QEMU build system. As with projects using GNU autotools, the QEMU build
|
2022-10-18 10:56:43 +03:00
|
|
|
system has two stages; first the developer runs the "configure" script
|
2015-09-24 16:41:38 +03:00
|
|
|
to determine the local build environment characteristics, then they run
|
2022-10-18 10:56:43 +03:00
|
|
|
"make" to build the project. This is about where the similarities with
|
2015-09-24 16:41:38 +03:00
|
|
|
GNU autotools end, so try to forget what you know about them.
|
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
The two general ways to perform a build are as follows:
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
- build artifacts outside of QEMU source tree entirely::
|
2020-02-04 13:43:54 +03:00
|
|
|
|
|
|
|
cd ../
|
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
../qemu/configure
|
|
|
|
make
|
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
- build artifacts in a subdir of QEMU source tree::
|
2020-02-04 13:43:54 +03:00
|
|
|
|
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
../configure
|
|
|
|
make
|
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
Most of the actual build process uses Meson under the hood, therefore
|
|
|
|
build artifacts cannot be placed in the source tree itself.
|
|
|
|
|
|
|
|
|
|
|
|
Stage 1: configure
|
|
|
|
==================
|
|
|
|
|
|
|
|
The configure script has five tasks:
|
|
|
|
|
|
|
|
- detect the host architecture
|
|
|
|
|
|
|
|
- list the targets for which to build emulators; the list of
|
|
|
|
targets also affects which firmware binaries and tests to build
|
2021-10-07 16:08:29 +03:00
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
- find the compilers (native and cross) used to build executables,
|
|
|
|
firmware and tests. The results are written as either Makefile
|
|
|
|
fragments (``config-host.mak``) or a Meson machine file
|
|
|
|
(``config-meson.cross``)
|
2021-10-07 16:08:29 +03:00
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
- create a virtual environment in which all Python code runs during
|
|
|
|
the build, and possibly install packages into it from PyPI
|
|
|
|
|
|
|
|
- invoke Meson in the virtual environment, to perform the actual
|
|
|
|
configuration step for the emulator build
|
|
|
|
|
|
|
|
The configure script automatically recognizes command line options for
|
|
|
|
which a same-named Meson option exists; dashes in the command line are
|
|
|
|
replaced with underscores.
|
|
|
|
|
|
|
|
Almost all QEMU developers that need to modify the build system will
|
|
|
|
only be concerned with Meson, and therefore can skip the rest of this
|
|
|
|
section.
|
|
|
|
|
|
|
|
|
|
|
|
Modifying ``configure``
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
``configure`` is a shell script; it uses ``#!/bin/sh`` and therefore
|
|
|
|
should be compatible with any POSIX shell. It is important to avoid
|
|
|
|
using bash-isms to avoid breaking development platforms where bash is
|
|
|
|
the primary host.
|
|
|
|
|
|
|
|
The configure script provides a variety of functions to help writing
|
|
|
|
portable shell code and providing consistent behavior across architectures
|
|
|
|
and operating systems:
|
|
|
|
|
|
|
|
``error_exit $MESSAGE $MORE...``
|
|
|
|
Print $MESSAGE to stderr, followed by $MORE... and then exit from the
|
|
|
|
configure script with non-zero status.
|
|
|
|
|
|
|
|
``has $COMMAND``
|
|
|
|
Determine if $COMMAND exists in the current environment, either as a
|
|
|
|
shell builtin, or executable binary, returning 0 on success. The
|
|
|
|
replacement in Meson is ``find_program()``.
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
``probe_target_compiler $TARGET``
|
|
|
|
Detect a cross compiler and cross tools for the QEMU target $TARGET (e.g.,
|
|
|
|
``$CPU-softmmu``, ``$CPU-linux-user``, ``$CPU-bsd-user``). If a working
|
|
|
|
compiler is present, return success and set variables ``$target_cc``,
|
|
|
|
``$target_ar``, etc. to non-empty values.
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
``write_target_makefile``
|
|
|
|
Write a Makefile fragment to stdout, exposing the result of the most
|
|
|
|
``probe_target_compiler`` call as the usual Make variables (``CC``,
|
|
|
|
``AR``, ``LD``, etc.).
|
2015-09-24 16:41:38 +03:00
|
|
|
|
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
Configure does not generally perform tests for compiler options beyond
|
|
|
|
basic checks to detect the host platform and ensure the compiler is
|
|
|
|
functioning. These are performed using a few more helper functions:
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
``compile_object $CFLAGS``
|
2015-09-24 16:41:38 +03:00
|
|
|
Attempt to compile a test program with the system C compiler using
|
|
|
|
$CFLAGS. The test program must have been previously written to a file
|
2022-10-18 10:56:43 +03:00
|
|
|
called $TMPC.
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
``compile_prog $CFLAGS $LDFLAGS``
|
2015-09-24 16:41:38 +03:00
|
|
|
Attempt to compile a test program with the system C compiler using
|
|
|
|
$CFLAGS and link it with the system linker using $LDFLAGS. The test
|
|
|
|
program must have been previously written to a file called $TMPC.
|
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
``check_define $NAME``
|
2022-10-18 10:56:43 +03:00
|
|
|
Determine if the macro $NAME is defined by the system C compiler.
|
|
|
|
|
|
|
|
``do_compiler $CC $ARGS...``
|
|
|
|
Attempt to run the C compiler $CC, passing it $ARGS... This function
|
|
|
|
does not use flags passed via options such as ``--extra-cflags``, and
|
|
|
|
therefore can be used to check for cross compilers. However, most
|
|
|
|
such checks are done at ``make`` time instead (see for example the
|
|
|
|
``cc-option`` macro in ``pc-bios/option-rom/Makefile``).
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
``write_c_skeleton``
|
2015-09-24 16:41:38 +03:00
|
|
|
Write a minimal C program main() function to the temporary file
|
2022-10-18 10:56:43 +03:00
|
|
|
indicated by $TMPC.
|
2015-09-24 16:41:38 +03:00
|
|
|
|
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
Python virtual environments and the QEMU build system
|
|
|
|
-----------------------------------------------------
|
|
|
|
|
|
|
|
TBD
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2020-02-04 13:43:54 +03:00
|
|
|
Stage 2: Meson
|
|
|
|
==============
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
The Meson build system describes the build and install process for:
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2020-02-04 13:43:54 +03:00
|
|
|
1) executables, which include:
|
2020-08-11 19:34:40 +03:00
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
- Tools - ``qemu-img``, ``qemu-nbd``, ``qemu-ga`` (guest agent), etc
|
2020-08-11 19:34:40 +03:00
|
|
|
|
2021-11-18 22:27:44 +03:00
|
|
|
- System emulators - ``qemu-system-$ARCH``
|
2020-08-11 19:34:40 +03:00
|
|
|
|
2021-11-18 22:27:44 +03:00
|
|
|
- Userspace emulators - ``qemu-$ARCH``
|
2020-08-11 19:34:40 +03:00
|
|
|
|
2020-09-07 19:39:13 +03:00
|
|
|
- Unit tests
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2020-02-04 13:43:54 +03:00
|
|
|
2) documentation
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
3) ROMs, whether provided as binary blobs in the QEMU distributions
|
|
|
|
or cross compiled under the direction of the configure script
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2020-02-04 13:43:54 +03:00
|
|
|
4) other data files, such as icons or desktop files
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
All executables are built by default, except for some ``contrib/``
|
2020-09-11 14:12:11 +03:00
|
|
|
binaries that are known to fail to build on some platforms (for example
|
|
|
|
32-bit or big-endian platforms). Tests are also built by default,
|
|
|
|
though that might change in the future.
|
|
|
|
|
2020-10-29 15:06:09 +03:00
|
|
|
The source code is highly modularized, split across many files to
|
|
|
|
facilitate building of all of these components with as little duplicated
|
|
|
|
compilation as possible. Using the Meson "sourceset" functionality,
|
2021-07-26 17:23:29 +03:00
|
|
|
``meson.build`` files group the source files in rules that are
|
2020-10-29 15:06:09 +03:00
|
|
|
enabled according to the available system libraries and to various
|
|
|
|
configuration symbols. Sourcesets belong to one of four groups:
|
|
|
|
|
|
|
|
Subsystem sourcesets:
|
|
|
|
Various subsystems that are common to both tools and emulators have
|
2021-07-26 17:23:29 +03:00
|
|
|
their own sourceset, for example ``block_ss`` for the block device subsystem,
|
|
|
|
``chardev_ss`` for the character device subsystem, etc. These sourcesets
|
2020-10-29 15:06:09 +03:00
|
|
|
are then turned into static libraries as follows::
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2020-02-04 13:43:54 +03:00
|
|
|
libchardev = static_library('chardev', chardev_ss.sources(),
|
|
|
|
name_suffix: 'fa',
|
|
|
|
build_by_default: false)
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2020-02-04 13:43:54 +03:00
|
|
|
chardev = declare_dependency(link_whole: libchardev)
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
As of Meson 0.55.1, the special ``.fa`` suffix should be used for everything
|
|
|
|
that is used with ``link_whole``, to ensure that the link flags are placed
|
2020-10-29 15:06:09 +03:00
|
|
|
correctly in the command line.
|
|
|
|
|
|
|
|
Target-independent emulator sourcesets:
|
|
|
|
Various general purpose helper code is compiled only once and
|
|
|
|
the .o files are linked into all output binaries that need it.
|
|
|
|
This includes error handling infrastructure, standard data structures,
|
|
|
|
platform portability wrapper functions, etc.
|
|
|
|
|
2023-06-13 16:33:47 +03:00
|
|
|
Target-independent code lives in the ``common_ss``, ``system_ss`` and
|
2021-07-26 17:23:29 +03:00
|
|
|
``user_ss`` sourcesets. ``common_ss`` is linked into all emulators,
|
2023-06-13 16:33:47 +03:00
|
|
|
``system_ss`` only in system emulators, ``user_ss`` only in user-mode
|
2020-10-29 15:06:09 +03:00
|
|
|
emulators.
|
|
|
|
|
|
|
|
Target-independent sourcesets must exercise particular care when using
|
2021-07-26 17:23:29 +03:00
|
|
|
``if_false`` rules. The ``if_false`` rule will be used correctly when linking
|
2020-10-29 15:06:09 +03:00
|
|
|
emulator binaries; however, when *compiling* target-independent files
|
2021-07-26 17:23:29 +03:00
|
|
|
into .o files, Meson may need to pick *both* the ``if_true`` and
|
|
|
|
``if_false`` sides to cater for targets that want either side. To
|
2020-10-29 15:06:09 +03:00
|
|
|
achieve that, you can add a special rule using the ``CONFIG_ALL``
|
|
|
|
symbol::
|
|
|
|
|
|
|
|
# Some targets have CONFIG_ACPI, some don't, so this is not enough
|
2023-06-13 16:33:47 +03:00
|
|
|
system_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi.c'),
|
2020-10-29 15:06:09 +03:00
|
|
|
if_false: files('acpi-stub.c'))
|
|
|
|
|
|
|
|
# This is required as well:
|
2023-06-13 16:33:47 +03:00
|
|
|
system_ss.add(when: 'CONFIG_ALL', if_true: files('acpi-stub.c'))
|
2020-10-29 15:06:09 +03:00
|
|
|
|
|
|
|
Target-dependent emulator sourcesets:
|
|
|
|
In the target-dependent set lives CPU emulation, some device emulation and
|
|
|
|
much glue code. This sometimes also has to be compiled multiple times,
|
|
|
|
once for each target being built. Target-dependent files are included
|
2021-07-26 17:23:29 +03:00
|
|
|
in the ``specific_ss`` sourceset.
|
2020-10-29 15:06:09 +03:00
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
Each emulator also includes sources for files in the ``hw/`` and ``target/``
|
2020-10-29 15:06:09 +03:00
|
|
|
subdirectories. The subdirectory used for each emulator comes
|
|
|
|
from the target's definition of ``TARGET_BASE_ARCH`` or (if missing)
|
2021-07-26 17:23:29 +03:00
|
|
|
``TARGET_ARCH``, as found in ``default-configs/targets/*.mak``.
|
2020-10-29 15:06:09 +03:00
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
Each subdirectory in ``hw/`` adds one sourceset to the ``hw_arch`` dictionary,
|
2020-10-29 15:06:09 +03:00
|
|
|
for example::
|
|
|
|
|
|
|
|
arm_ss = ss.source_set()
|
|
|
|
arm_ss.add(files('boot.c'), fdt)
|
|
|
|
...
|
|
|
|
hw_arch += {'arm': arm_ss}
|
|
|
|
|
|
|
|
The sourceset is only used for system emulators.
|
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
Each subdirectory in ``target/`` instead should add one sourceset to each
|
2023-10-04 12:06:27 +03:00
|
|
|
of the ``target_arch`` and ``target_system_arch``, which are used respectively
|
2020-10-29 15:06:09 +03:00
|
|
|
for all emulators and for system emulators only. For example::
|
|
|
|
|
|
|
|
arm_ss = ss.source_set()
|
2023-06-13 16:33:47 +03:00
|
|
|
arm_system_ss = ss.source_set()
|
2020-10-29 15:06:09 +03:00
|
|
|
...
|
|
|
|
target_arch += {'arm': arm_ss}
|
2023-10-04 12:06:27 +03:00
|
|
|
target_system_arch += {'arm': arm_system_ss}
|
2020-10-29 15:06:09 +03:00
|
|
|
|
2021-06-24 13:38:23 +03:00
|
|
|
Module sourcesets:
|
2021-07-26 17:23:29 +03:00
|
|
|
There are two dictionaries for modules: ``modules`` is used for
|
|
|
|
target-independent modules and ``target_modules`` is used for
|
|
|
|
target-dependent modules. When modules are disabled the ``module``
|
2023-06-13 16:33:47 +03:00
|
|
|
source sets are added to ``system_ss`` and the ``target_modules``
|
2021-07-26 17:23:29 +03:00
|
|
|
source sets are added to ``specific_ss``.
|
2021-06-24 13:38:23 +03:00
|
|
|
|
|
|
|
Both dictionaries are nested. One dictionary is created per
|
|
|
|
subdirectory, and these per-subdirectory dictionaries are added to
|
|
|
|
the toplevel dictionaries. For example::
|
|
|
|
|
|
|
|
hw_display_modules = {}
|
|
|
|
qxl_ss = ss.source_set()
|
|
|
|
...
|
|
|
|
hw_display_modules += { 'qxl': qxl_ss }
|
|
|
|
modules += { 'hw-display': hw_display_modules }
|
|
|
|
|
2020-10-29 15:06:09 +03:00
|
|
|
Utility sourcesets:
|
2021-07-26 17:23:29 +03:00
|
|
|
All binaries link with a static library ``libqemuutil.a``. This library
|
2020-10-29 15:06:09 +03:00
|
|
|
is built from several sourcesets; most of them however host generated
|
2021-07-26 17:23:29 +03:00
|
|
|
code, and the only two of general interest are ``util_ss`` and ``stub_ss``.
|
2020-10-29 15:06:09 +03:00
|
|
|
|
|
|
|
The separation between these two is purely for documentation purposes.
|
2021-07-26 17:23:29 +03:00
|
|
|
``util_ss`` contains generic utility files. Even though this code is only
|
2020-10-29 15:06:09 +03:00
|
|
|
linked in some binaries, sometimes it requires hooks only in some of
|
|
|
|
these and depend on other functions that are not fully implemented by
|
2021-07-26 17:23:29 +03:00
|
|
|
all QEMU binaries. ``stub_ss`` links dummy stubs that will only be linked
|
2020-10-29 15:06:09 +03:00
|
|
|
into the binary if the real implementation is not present. In a way,
|
|
|
|
the stubs can be thought of as a portable implementation of the weak
|
|
|
|
symbols concept.
|
|
|
|
|
2017-09-19 17:20:31 +03:00
|
|
|
|
2020-02-04 13:43:54 +03:00
|
|
|
The following files concur in the definition of which files are linked
|
|
|
|
into each emulator:
|
2017-09-19 17:20:31 +03:00
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
``default-configs/devices/*.mak``
|
|
|
|
The files under ``default-configs/devices/`` control the boards and devices
|
2020-10-29 15:06:09 +03:00
|
|
|
that are built into each QEMU system emulation targets. They merely contain
|
|
|
|
a list of config variable definitions such as::
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2020-08-11 19:34:40 +03:00
|
|
|
include arm-softmmu.mak
|
|
|
|
CONFIG_XLNX_ZYNQMP_ARM=y
|
|
|
|
CONFIG_XLNX_VERSAL=y
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
``*/Kconfig``
|
|
|
|
These files are processed together with ``default-configs/devices/*.mak`` and
|
2020-08-11 19:34:40 +03:00
|
|
|
describe the dependencies between various features, subsystems and
|
2020-10-29 15:06:09 +03:00
|
|
|
device models. They are described in :ref:`kconfig`
|
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
``default-configs/targets/*.mak``
|
|
|
|
These files mostly define symbols that appear in the ``*-config-target.h``
|
2020-10-29 15:06:09 +03:00
|
|
|
file for each emulator [#cfgtarget]_. However, the ``TARGET_ARCH``
|
2021-07-26 17:23:29 +03:00
|
|
|
and ``TARGET_BASE_ARCH`` will also be used to select the ``hw/`` and
|
|
|
|
``target/`` subdirectories that are compiled into each target.
|
2020-10-29 15:06:09 +03:00
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
.. [#cfgtarget] This header is included by ``qemu/osdep.h`` when
|
2020-10-29 15:06:09 +03:00
|
|
|
compiling files from the target-specific sourcesets.
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2020-10-29 15:06:09 +03:00
|
|
|
These files rarely need changing unless you are adding a completely
|
|
|
|
new target, or enabling new devices or hardware for a particular
|
|
|
|
system/userspace emulation target
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2020-02-04 13:43:54 +03:00
|
|
|
|
2021-10-07 16:08:29 +03:00
|
|
|
Adding checks
|
|
|
|
-------------
|
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
Compiler checks can be as simple as the following::
|
2021-10-07 16:08:29 +03:00
|
|
|
|
|
|
|
config_host_data.set('HAVE_BTRFS_H', cc.has_header('linux/btrfs.h'))
|
|
|
|
|
|
|
|
A more complex task such as adding a new dependency usually
|
|
|
|
comprises the following tasks:
|
|
|
|
|
|
|
|
- Add a Meson build option to meson_options.txt.
|
|
|
|
|
|
|
|
- Add code to perform the actual feature check.
|
|
|
|
|
2021-10-05 00:52:37 +03:00
|
|
|
- Add code to include the feature status in ``config-host.h``
|
2021-10-07 16:08:29 +03:00
|
|
|
|
|
|
|
- Add code to print out the feature status in the configure summary
|
|
|
|
upon completion.
|
|
|
|
|
|
|
|
Taking the probe for SDL2_Image as an example, we have the following
|
|
|
|
in ``meson_options.txt``::
|
|
|
|
|
|
|
|
option('sdl_image', type : 'feature', value : 'auto',
|
|
|
|
description: 'SDL Image support for icons')
|
|
|
|
|
|
|
|
Unless the option was given a non-``auto`` value (on the configure
|
|
|
|
command line), the detection code must be performed only if the
|
|
|
|
dependency will be used::
|
|
|
|
|
|
|
|
sdl_image = not_found
|
|
|
|
if not get_option('sdl_image').auto() or have_system
|
|
|
|
sdl_image = dependency('SDL2_image', required: get_option('sdl_image'),
|
2022-07-14 15:33:49 +03:00
|
|
|
method: 'pkg-config')
|
2021-10-07 16:08:29 +03:00
|
|
|
endif
|
|
|
|
|
|
|
|
This avoids warnings on static builds of user-mode emulators, for example.
|
|
|
|
Most of the libraries used by system-mode emulators are not available for
|
|
|
|
static linking.
|
|
|
|
|
|
|
|
The other supporting code is generally simple::
|
|
|
|
|
|
|
|
# Create config-host.h (if applicable)
|
|
|
|
config_host_data.set('CONFIG_SDL_IMAGE', sdl_image.found())
|
|
|
|
|
|
|
|
# Summary
|
|
|
|
summary_info += {'SDL image support': sdl_image.found()}
|
|
|
|
|
|
|
|
For the configure script to parse the new option, the
|
|
|
|
``scripts/meson-buildoptions.sh`` file must be up-to-date; ``make
|
2021-10-05 00:52:37 +03:00
|
|
|
update-buildoptions`` (or just ``make``) will take care of updating it.
|
2021-10-07 16:08:29 +03:00
|
|
|
|
|
|
|
|
2020-02-04 13:43:54 +03:00
|
|
|
Support scripts
|
|
|
|
---------------
|
|
|
|
|
|
|
|
Meson has a special convention for invoking Python scripts: if their
|
2021-07-26 17:23:29 +03:00
|
|
|
first line is ``#! /usr/bin/env python3`` and the file is *not* executable,
|
2020-02-04 13:43:54 +03:00
|
|
|
find_program() arranges to invoke the script under the same Python
|
|
|
|
interpreter that was used to invoke Meson. This is the most common
|
|
|
|
and preferred way to invoke support scripts from Meson build files,
|
|
|
|
because it automatically uses the value of configure's --python= option.
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
In case the script is not written in Python, use a ``#! /usr/bin/env ...``
|
2020-02-04 13:43:54 +03:00
|
|
|
line and make the script executable.
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2020-02-04 13:43:54 +03:00
|
|
|
Scripts written in Python, where it is desirable to make the script
|
|
|
|
executable (for example for test scripts that developers may want to
|
|
|
|
invoke from the command line, such as tests/qapi-schema/test-qapi.py),
|
2021-07-26 17:23:29 +03:00
|
|
|
should be invoked through the ``python`` variable in meson.build. For
|
2020-08-11 19:34:40 +03:00
|
|
|
example::
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2020-02-04 13:43:54 +03:00
|
|
|
test('QAPI schema regression tests', python,
|
|
|
|
args: files('test-qapi.py'),
|
|
|
|
env: test_env, suite: ['qapi-schema', 'qapi-frontend'])
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2020-02-04 13:43:54 +03:00
|
|
|
This is needed to obey the --python= option passed to the configure
|
|
|
|
script, which may point to something other than the first python3
|
|
|
|
binary on the path.
|
2015-09-24 16:41:38 +03:00
|
|
|
|
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
Stage 3: Make
|
|
|
|
=============
|
2020-02-04 13:43:54 +03:00
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
The next step in building QEMU is to invoke make. GNU Make is required
|
|
|
|
to build QEMU, and may be installed as ``gmake`` on some hosts.
|
2020-02-04 13:43:54 +03:00
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
The output of Meson is a ``build.ninja`` file, which is used with the
|
|
|
|
Ninja build tool. However, QEMU's build comprises other components than
|
|
|
|
just the emulators (namely firmware and the tests in ``tests/tcg``) which
|
|
|
|
need different cross compilers. The QEMU Makefile wraps both Ninja and
|
|
|
|
the smaller build systems for firmware and tests; it also takes care of
|
|
|
|
running ``configure`` again when the script changes. Apart from invoking
|
|
|
|
these sub-Makefiles, the resulting build is largely non-recursive.
|
2020-02-04 13:43:54 +03:00
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
Tests, whether defined in ``meson.build`` or not, are also ran by the
|
|
|
|
Makefile with the traditional ``make check`` phony target, while benchmarks
|
|
|
|
are run with ``make bench``. Meson test suites such as ``unit`` can be ran
|
|
|
|
with ``make check-unit``, and ``make check-tcg`` builds and runs "non-Meson"
|
|
|
|
tests for all targets.
|
|
|
|
|
|
|
|
If desired, it is also possible to use ``ninja`` and ``meson test``,
|
|
|
|
respectively to build emulators and run tests defined in meson.build.
|
|
|
|
The main difference is that ``make`` needs the ``-jN`` flag in order to
|
|
|
|
enable parallel builds or tests.
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2021-09-07 17:25:50 +03:00
|
|
|
Useful make targets
|
|
|
|
-------------------
|
|
|
|
|
|
|
|
``help``
|
|
|
|
Print a help message for the most common build targets.
|
|
|
|
|
|
|
|
``print-VAR``
|
|
|
|
Print the value of the variable VAR. Useful for debugging the build
|
|
|
|
system.
|
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
|
2020-02-04 13:43:54 +03:00
|
|
|
Important files for the build system
|
|
|
|
====================================
|
|
|
|
|
2015-09-24 16:41:38 +03:00
|
|
|
Statically defined files
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
The following key files are statically defined in the source tree, with
|
|
|
|
the rules needed to build QEMU. Their behaviour is influenced by a
|
|
|
|
number of dynamically created files listed later.
|
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
``Makefile``
|
2020-08-11 19:34:40 +03:00
|
|
|
The main entry point used when invoking make to build all the components
|
|
|
|
of QEMU. The default 'all' target will naturally result in the build of
|
2022-10-18 10:56:43 +03:00
|
|
|
every component.
|
2020-08-11 19:34:40 +03:00
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
``*/meson.build``
|
2020-08-11 19:34:40 +03:00
|
|
|
The meson.build file in the root directory is the main entry point for the
|
|
|
|
Meson build system, and it coordinates the configuration and build of all
|
|
|
|
executables. Build rules for various subdirectories are included in
|
|
|
|
other meson.build files spread throughout the QEMU source tree.
|
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
``tests/Makefile.include``
|
2022-10-18 10:56:43 +03:00
|
|
|
Rules for external test harnesses. These include the TCG tests
|
|
|
|
and the Avocado-based integration tests.
|
2020-08-11 19:34:40 +03:00
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
``tests/docker/Makefile.include``
|
2022-10-18 10:56:43 +03:00
|
|
|
Rules for Docker tests. Like ``tests/Makefile.include``, this file is
|
|
|
|
included directly by the top level Makefile, anything defined in this
|
|
|
|
file will influence the entire build system.
|
2020-08-11 19:34:40 +03:00
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
``tests/vm/Makefile.include``
|
2022-10-18 10:56:43 +03:00
|
|
|
Rules for VM-based tests. Like ``tests/Makefile.include``, this file is
|
|
|
|
included directly by the top level Makefile, anything defined in this
|
|
|
|
file will influence the entire build system.
|
2015-09-24 16:41:38 +03:00
|
|
|
|
|
|
|
Dynamically created files
|
|
|
|
-------------------------
|
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
The following files are generated at run-time in order to control the
|
|
|
|
behaviour of the Makefiles. This avoids the need for QEMU makefiles to
|
|
|
|
go through any pre-processing as seen with autotools, where configure
|
|
|
|
generates ``Makefile`` from ``Makefile.in``.
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2020-02-04 13:43:54 +03:00
|
|
|
Built by configure:
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
``config-host.mak``
|
2020-08-11 19:34:40 +03:00
|
|
|
When configure has determined the characteristics of the build host it
|
2022-02-15 13:37:00 +03:00
|
|
|
will write the paths to various tools to this file, for use in ``Makefile``
|
|
|
|
and to a smaller extent ``meson.build``.
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
``config-host.mak`` is also used as a dependency checking mechanism. If make
|
2020-08-11 19:34:40 +03:00
|
|
|
sees that the modification timestamp on configure is newer than that on
|
2022-10-18 10:56:43 +03:00
|
|
|
``config-host.mak``, then configure will be re-run.
|
|
|
|
|
|
|
|
``config-meson.cross``
|
|
|
|
|
|
|
|
A Meson "cross file" (or native file) used to communicate the paths to
|
|
|
|
the toolchain and other configuration options.
|
|
|
|
|
|
|
|
``config.status``
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
A small shell script that will invoke configure again with the same
|
|
|
|
environment variables that were set during the first run. It's used to
|
|
|
|
rerun configure after changes to the source code, but it can also be
|
|
|
|
inspected manually to check the contents of the environment.
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
``Makefile.prereqs``
|
|
|
|
|
|
|
|
A set of Makefile dependencies that order the build and execution of
|
|
|
|
firmware and tests after the container images and emulators that they
|
|
|
|
need.
|
|
|
|
|
|
|
|
``pc-bios/*/config.mak``, ``tests/tcg/config-host.mak``, ``tests/tcg/*/config-target.mak``
|
|
|
|
|
|
|
|
Configuration variables used to build the firmware and TCG tests,
|
|
|
|
including paths to cross compilation toolchains.
|
|
|
|
|
|
|
|
``pyvenv``
|
|
|
|
|
|
|
|
A Python virtual environment that is used for all Python code running
|
|
|
|
during the build. Using a virtual environment ensures that even code
|
|
|
|
that is run via ``sphinx-build``, ``meson`` etc. uses the same interpreter
|
|
|
|
and packages.
|
2015-09-24 16:41:38 +03:00
|
|
|
|
2020-02-04 13:43:54 +03:00
|
|
|
Built by Meson:
|
|
|
|
|
2022-10-18 10:56:43 +03:00
|
|
|
``config-host.h``
|
|
|
|
Used by C code to determine the properties of the build environment
|
|
|
|
and the set of enabled features for the entire build.
|
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
``${TARGET-NAME}-config-devices.mak``
|
2022-10-18 10:56:43 +03:00
|
|
|
TARGET-NAME is the name of a system emulator. The file is
|
|
|
|
generated by Meson using files under ``configs/devices`` as input.
|
|
|
|
|
|
|
|
``${TARGET-NAME}-config-target.mak``
|
|
|
|
TARGET-NAME is the name of a system or usermode emulator. The file is
|
|
|
|
generated by Meson using files under ``configs/targets`` as input.
|
|
|
|
|
|
|
|
``$TARGET_NAME-config-target.h``, ``$TARGET_NAME-config-devices.h``
|
|
|
|
Used by C code to determine the properties and enabled
|
|
|
|
features for each target. enabled. They are generated from
|
|
|
|
the contents of the corresponding ``*.mak`` files using Meson's
|
|
|
|
``configure_file()`` function; each target can include them using
|
|
|
|
the ``CONFIG_TARGET`` and ``CONFIG_DEVICES`` macro respectively.
|
2020-02-04 13:43:54 +03:00
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
``build.ninja``
|
2020-08-11 19:34:40 +03:00
|
|
|
The build rules.
|
2020-02-04 13:43:54 +03:00
|
|
|
|
|
|
|
|
|
|
|
Built by Makefile:
|
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
``Makefile.ninja``
|
2020-08-13 16:28:11 +03:00
|
|
|
A Makefile include that bridges to ninja for the actual build. The
|
|
|
|
Makefile is mostly a list of targets that Meson included in build.ninja.
|
2020-02-04 13:43:54 +03:00
|
|
|
|
2021-07-26 17:23:29 +03:00
|
|
|
``Makefile.mtest``
|
2020-08-11 19:34:40 +03:00
|
|
|
The Makefile definitions that let "make check" run tests defined in
|
|
|
|
meson.build. The rules are produced from Meson's JSON description of
|
|
|
|
tests (obtained with "meson introspect --tests") through the script
|
|
|
|
scripts/mtest2make.py.
|