From 0717fbeec89643b4c8424e183c669983a4be859c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Mart=C3=ADnez=20de=20Bartolom=C3=A9?= Date: Tue, 29 Jun 2021 13:45:18 +0200 Subject: [PATCH 1/2] Autotools improved --- reference/conanfile/tools/cmake.rst | 1 + reference/conanfile/tools/gnu.rst | 1 - reference/conanfile/tools/gnu/autotools.rst | 46 ++++++++++++++- .../conanfile/tools/gnu/autotoolsdeps.rst | 6 ++ .../conanfile/tools/gnu/autotoolsgen.rst | 58 ------------------- .../tools/gnu/autotoolstoolchain.rst | 58 ++++++++++++++++++- 6 files changed, 107 insertions(+), 63 deletions(-) delete mode 100644 reference/conanfile/tools/gnu/autotoolsgen.rst diff --git a/reference/conanfile/tools/cmake.rst b/reference/conanfile/tools/cmake.rst index 012f94599d7..29fb40379ff 100644 --- a/reference/conanfile/tools/cmake.rst +++ b/reference/conanfile/tools/cmake.rst @@ -10,6 +10,7 @@ conan.tools.cmake .. toctree:: :maxdepth: 2 + cmake/cmakedeps cmake/cmaketoolchain cmake/cmake diff --git a/reference/conanfile/tools/gnu.rst b/reference/conanfile/tools/gnu.rst index e353a27ec43..b009e386a5a 100644 --- a/reference/conanfile/tools/gnu.rst +++ b/reference/conanfile/tools/gnu.rst @@ -9,5 +9,4 @@ conan.tools.gnu gnu/autotoolsdeps gnu/autotoolstoolchain - gnu/autotoolsgen gnu/autotools diff --git a/reference/conanfile/tools/gnu/autotools.rst b/reference/conanfile/tools/gnu/autotools.rst index a46c7698ce6..5133a405d0c 100644 --- a/reference/conanfile/tools/gnu/autotools.rst +++ b/reference/conanfile/tools/gnu/autotools.rst @@ -1,3 +1,5 @@ +.. _conan_tools_gnu_build_helper: + Autotools ========= @@ -24,7 +26,45 @@ The ``Autotools`` helper can be used like: autotools.configure() autotools.make() +It will read the ``conanbuild.json`` file generated by the :ref:`AutotoolsToolchain` +to know read the arguments for calling the configure and make scripts: + +- **configure_args**: Arguments to call the ``configure`` script. +- **make_args**: Arguments to call the ``make`` script. + + +Methods +------- + +configure() ++++++++++++ + +.. code-block:: python + + def configure(self) + +Call the configure script. + + +make() +++++++ + +.. code-block:: python + + def make(self, target=None) + +Call the make program. + +Parameters: + - **target** (Optional, Defaulted to ``None``): Choose which target to build. This allows building of e.g., docs, shared libraries or + install for some AutoTools projects. + + +install() ++++++++++ + +.. code-block:: python + + def install(self) -The current support is limited: -- It does not support cross-building or --target, --host, --build definitions -- It does not handle install functionality \ No newline at end of file +This is just an "alias" of ``self.make(target="install")`` \ No newline at end of file diff --git a/reference/conanfile/tools/gnu/autotoolsdeps.rst b/reference/conanfile/tools/gnu/autotoolsdeps.rst index aa7ad18dd24..51c1fd49675 100644 --- a/reference/conanfile/tools/gnu/autotoolsdeps.rst +++ b/reference/conanfile/tools/gnu/autotoolsdeps.rst @@ -50,3 +50,9 @@ This generator will define aggregated variables ``CPPFLAGS``, ``LIBS``, ``LDFLAG accumulate all dependencies information, including transitive dependencies, with flags like ``-I``, ``-L``, etc. At this moment, only the ``requires`` information is generated, the ``build_requires`` one is not managed by this generator yet. + + +Attributes +++++++++++ + +At this moment, it is pending to expose attributes to let the user modify the behavior before calling ``generate()`` \ No newline at end of file diff --git a/reference/conanfile/tools/gnu/autotoolsgen.rst b/reference/conanfile/tools/gnu/autotoolsgen.rst deleted file mode 100644 index 6f80cd45c27..00000000000 --- a/reference/conanfile/tools/gnu/autotoolsgen.rst +++ /dev/null @@ -1,58 +0,0 @@ -AutotoolsGen -============ - -.. warning:: - - These tools are **experimental** and subject to breaking changes. - - -The ``AutotoolsGen`` is a complete generator for the whole autotools system. It aggregates the -functionality of ``AutotoolsDeps``, ``AutotoolsToolchain`` and ``VirtualEnv`` into a single generator. - -It will generate shell scripts containing environment variable definitions that the autotools build system can understand. - -The ``AutotoolsGen`` generator can be used by name in conanfiles: - -.. code-block:: python - :caption: conanfile.py - - class Pkg(ConanFile): - generators = "AutotoolsGen" - -.. code-block:: text - :caption: conanfile.txt - - [generators] - AutotoolsGen - -And it can also be fully instantiated in the conanfile ``generate()`` method: - -.. code:: python - - from conans import ConanFile - from conan.tools.gnu import AutotoolsGen - - class App(ConanFile): - settings = "os", "arch", "compiler", "build_type" - - def generate(self): - tc = AutotoolsGen(self) - tc.generate() - - -Its implementation is straightforward: - -.. code:: python - - class AutotoolsGen: - def __init__(self, conanfile): - self.toolchain = AutotoolsToolchain(conanfile) - self.deps = AutotoolsDeps(conanfile) - self.env = VirtualEnv(conanfile) - -And it will output the same files as ``VirtualEnv``: - -- *conanbuildenv* .bat or .sh scripts, that are automatically loaded if existing by the ``self.run()`` recipes methods -- *conanrunenv* .bat or .sh scripts, that can be explicitly opted-in in ``self.run()`` recipes methods with ``self.run(..., env=["conanrunenv"])`` - -These files will contain the necessary accumulated information from all the 3 internal generators. diff --git a/reference/conanfile/tools/gnu/autotoolstoolchain.rst b/reference/conanfile/tools/gnu/autotoolstoolchain.rst index a377558c241..d6a4fa56382 100644 --- a/reference/conanfile/tools/gnu/autotoolstoolchain.rst +++ b/reference/conanfile/tools/gnu/autotoolstoolchain.rst @@ -1,3 +1,5 @@ +.. _conan_tools_gnu_autotools_toolchain: + AutotoolsToolchain ================== @@ -9,7 +11,7 @@ AutotoolsToolchain The ``AutotoolsToolchain`` is the toolchain generator for Autotools. It will generate shell scripts containing environment variable definitions that the autotools build system can understand. -The ``AutotooAutotoolsToolchainlsDeps`` generator can be used by name in conanfiles: +The ``AutotooAutotoolsToolchain`` generator can be used by name in conanfiles: .. code-block:: python :caption: conanfile.py @@ -48,3 +50,57 @@ The ``AutotoolsToolchain`` will generate after a ``conan install`` command the * This generator will define aggregated variables ``CPPFLAGS``, ``LDFLAGS``, ``CXXFLAGS``, ``CFLAGS`` that accumulate all dependencies information, including transitive dependencies, with flags like ``-stdlib=libstdc++``, ``-std=gnu14``, architecture flags, etc. + +This generator will also generate a file called ``conanbuild.json`` containing two keys: + +- **configure_args**: Arguments to call the ``configure`` script. +- **make_args**: Arguments to call the ``make`` script. + +The :ref:`Autotools build helper` will use that ``conanbuild.json`` file to seamlessly call +the configure and make script using these precalculated arguments. + +Attributes +++++++++++ + +You can change some attributes before calling the ``generate()`` method if you want to change some of the precalculated +values: + +.. code:: python + + from conans import ConanFile + from conan.tools.gnu import AutotoolsToolchain + + class App(ConanFile): + settings = "os", "arch", "compiler", "build_type" + + def generate(self): + tc = AutotoolsToolchain(self) + tc.configure_args.append("--my_argument") + tc.generate() + + +* **configure_args** (Defaulted to ``[]``): Additional arguments to be passed to the configure script. +* **make_args** (Defaulted to ``[]``): Additional arguments to be passed to he make script. +* **defines** (Defaulted to ``[]``): Additional defines. +* **cxxflags** (Defaulted to ``[]``): Additional cxxflags. +* **cflags** (Defaulted to ``[]``): Additional cflags. +* **ldflags** (Defaulted to ``[]``): Additional ldflags. +* **default_configure_install_args** (Defaulted to ``False``): If True it will pass automatically the following flags to the configure script: + + * ``--prefix``: With the self.package_folder value. + * ``--bindir=${prefix}/bin`` + * ``--sbindir=${prefix}/bin`` + * ``--libdir=${prefix}/lib`` + * ``--includedir=${prefix}/include`` + * ``--oldincludedir=${prefix}/includev`` + * ``--datarootdir=${prefix}/share`` + +* **ndebug**: "NDEBUG" if the ``settings.build_type`` != `Debug`. +* **gcc_cxx11_abi**: "_GLIBCXX_USE_CXX11_ABI" if ``gcc/libstdc++``. +* **libcxx**: Flag calculated from ``settings.compiler.libcxx``. +* **fpic**: True/False from ``options.fpic`` if defined. +* **cppstd**: Flag from ``settings.compiler.cppstd`` +* **arch_flag**: Flag from ``settings.arch`` +* **build_type_flags**: Flags from ``settings.build_type`` +* **apple_arch_flag**: Only when cross-building with Apple systems. Flags from ``settings.arch``. +* **apple_isysroot_flag**: Only when cross-building with Apple systems. Path to the root sdk. \ No newline at end of file From cb1ae6579ee946238d0208a5a05bc439cd3725ca Mon Sep 17 00:00:00 2001 From: Carlos Zoido Date: Tue, 29 Jun 2021 17:55:00 +0200 Subject: [PATCH 2/2] Update reference/conanfile/tools/gnu/autotoolstoolchain.rst Co-authored-by: James --- reference/conanfile/tools/gnu/autotoolstoolchain.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reference/conanfile/tools/gnu/autotoolstoolchain.rst b/reference/conanfile/tools/gnu/autotoolstoolchain.rst index d6a4fa56382..0281ee06d2d 100644 --- a/reference/conanfile/tools/gnu/autotoolstoolchain.rst +++ b/reference/conanfile/tools/gnu/autotoolstoolchain.rst @@ -11,7 +11,7 @@ AutotoolsToolchain The ``AutotoolsToolchain`` is the toolchain generator for Autotools. It will generate shell scripts containing environment variable definitions that the autotools build system can understand. -The ``AutotooAutotoolsToolchain`` generator can be used by name in conanfiles: +The ``AutotoolsToolchain`` generator can be used by name in conanfiles: .. code-block:: python :caption: conanfile.py @@ -103,4 +103,4 @@ values: * **arch_flag**: Flag from ``settings.arch`` * **build_type_flags**: Flags from ``settings.build_type`` * **apple_arch_flag**: Only when cross-building with Apple systems. Flags from ``settings.arch``. -* **apple_isysroot_flag**: Only when cross-building with Apple systems. Path to the root sdk. \ No newline at end of file +* **apple_isysroot_flag**: Only when cross-building with Apple systems. Path to the root sdk.