[[build]]
=== Upstream build systems

Upstream build systems are designed to go through several steps to install generated binary files to the system from the source distribution.

Three typical build systems are described here.  The situation of other build systems are very similar to these since `debhelper`(7) the does most of the work and helps you build a Debian package.

TIP: Before attempting to make a Debian package, you should become familiar with the upstream build system of the upstream source code and try to build it.

[[autotools]]
==== Autotools

Autotools (*autoconf* + *automake*) has 4 steps.

1. set up the build system (``*vim configure.ac Makefile.am*'' and ``*autoreconf -ivf*'')
2. configure the build system (``*./configure*'')
3. build the source tree (``*make*'')
4. install the binary files (``*make install*'')

The upstream maintainer usually performs step 1 and builds the upstream tarball for distribution using the ``*make dist*'' command.   (The generated tarball contains not only the pristine upstream VCS contents but also other generated files.)

The package maintainer needs to take care of steps 2 to 4 at least.  This is realized by the ``*dh $@ --with autotools-dev*'' command used in the *debian/rules* file.

The package maintainer may wish to take care all steps 1 to 4.  This is realized by the ``*dh $@ --with autoreconf*'' command used in the *debian/rules* file.  This rebuilds all auto-generated files to the latest version and provides better support for porting to the newer architectures.

For *compat* level *10* or newer, the simple ``*dh $@*'' command without ``*--with autoreconf*'' option can take care all steps 1 to 4, too.

If you wish to learn more on Autotools, please see:

* https://www.gnu.org/software/automake/manual/index.html[GNU Automake documentation]
* https://www.gnu.org/software/autoconf/manual/index.html[GNU Autoconf documentation]
* https://www.lrde.epita.fr/~adl/autotools.html[Autotools Tutorial]
* https://www.dwheeler.com/autotools/introduction-autotools.pdf[Introduction to the autotools (autoconf, automake, and libtool)]
* https://autotools.io/index.html[Autotools Mythbuster]

[[cmake]]
==== CMake

CMake has 4 steps.

1. set up the build system (``*vim CMakeLists.txt config.h.in*'')
2. configure the build system (``*cmake*'')
3. build the source tree (``*make*'')
4. install the binary files (``*make install*'')

The upstream tarball contains no auto-generated files and is generated by the *tar* command after step 1.

The package maintainer needs to take care of steps 2 to 4.

If you wish to learn more on the CMake, please see:

* https://cmake.org/[CMake]
* https://cmake.org/cmake-tutorial/[CMake tutorial]

[[meson]]
==== Meson

Meson has 4 steps.

1. set up the *Meson* build system (``*vim meson.build*'')
2. set up the *Ninja* build system and configure it (``*meson setup builddir && cd builddir*'' and ``*meson configure*'')
3. build the source tree (``*meson compile*'')
4. install the binary files (``*meson install*'')

The upstream tarball contains no auto-generated files and is generated by the *tar* command after step 1.

The package maintainer needs to take care of steps 2 to 4.

If you wish to learn more on the Meson, please see:

* https://mesonbuild.com/[The Meson Build system]
* https://ninja-build.org/[Ninja]

[[distutils]]
==== Python distutils

Python distutils has 3 steps.

1. set up and configure the build system (``*vim setup.py*'')
2. build the source tree (``*python3 setup.py build*'')
3. install the binary files (``*python3 setup.py install*'')

The upstream maintainer usually performs step 1 and builds the upstream tarball for distribution using the ``*python3 setup.py sdist*'' command.

The package maintainer needs to take care of step 2.  This is realized simply by the ``*dh $@*'' command used in the *debian/rules* file.

These days, most upstream maintainers of Python packages use setuptools with wheel.  Since setuptools is an extension of distutils, this step 2 works as expected even if `setup.py` doesn't explicitly uses distutils.

If you wish to learn more on Python3, *distutils*, and *setuptools*, please see:

* https://docs.python.org/3/[Python3]
* https://docs.python.org/3.4/library/distutils.html#module-distutils[distutils]
* https://setuptools.readthedocs.io/en/latest/[setuptools]

