AutoToolsBuildEnvironment (configure/make)

If you are using configure/make you can use AutoToolsBuildEnvironment helper. This helper sets LIBS, LDFLAGS, CFLAGS, CXXFLAGS and CPPFLAGS environment variables based on your requirements.

from conans import ConanFile, AutoToolsBuildEnvironment

class ExampleConan(ConanFile):
   settings = "os", "compiler", "build_type", "arch"
   requires = "Poco/1.9.0@pocoproject/stable"
   default_options = "Poco:shared=True", "OpenSSL:shared=True"

   def imports(self):
      self.copy("*.dll", dst="bin", src="bin")
      self.copy("*.dylib*", dst="bin", src="lib")

   def build(self):
      autotools = AutoToolsBuildEnvironment(self)
      autotools.configure()
      autotools.make()

It also works using the environment_append context manager applied to your configure and make commands, calling configure and make manually:

from conans import ConanFile, AutoToolsBuildEnvironment

class ExampleConan(ConanFile):
    ...

    def build(self):
        env_build = AutoToolsBuildEnvironment(self)
        with tools.environment_append(env_build.vars):
            self.run("./configure")
            self.run("make")

You can change some variables like fpic, libs, include_paths and defines before accessing the vars to override an automatic value or add new values:

 from conans import ConanFile, AutoToolsBuildEnvironment

 class ExampleConan(ConanFile):
     ...

     def build(self):
         env_build = AutoToolsBuildEnvironment(self)
         env_build.fpic = True
         env_build.libs.append("pthread")
         env_build.defines.append("NEW_DEFINE=23")
         env_build.configure()
         env_build.make()

You can use it also with MSYS2/MinGW subsystems installed by setting the win_bash parameter in the constructor. It will run the the configure and make commands inside a bash that has to be in the path or declared in CONAN_BASH_PATH:

from conans import ConanFile, AutoToolsBuildEnvironment
import platform

class ExampleConan(ConanFile):
   settings = "os", "compiler", "build_type", "arch"

   def imports(self):
     self.copy("*.dll", dst="bin", src="bin")
     self.copy("*.dylib*", dst="bin", src="lib")

   def build(self):
      in_win = platform.system() == "Windows"
      env_build = AutoToolsBuildEnvironment(self, win_bash=in_win)
      env_build.configure()
      env_build.make()

Constructor

class AutoToolsBuildEnvironment(object):

    def __init__(self, conanfile, win_bash=False)
Parameters:
  • conanfile (Required): Conanfile object. Usually self in a conanfile.py

  • win_bash: (Optional, Defaulted to False): When True, it will run the configure/make commands inside a bash.

Attributes

You can adjust the automatically filled values modifying the attributes like this:

 from conans import ConanFile, AutoToolsBuildEnvironment

 class ExampleConan(ConanFile):
     ...

     def build(self):
         autotools = AutoToolsBuildEnvironment(self)
         autotools.fpic = True
         autotools.libs.append("pthread")
         autotools.defines.append("NEW_DEFINE=23")
         autotools.configure()
         autotools.make()

fpic

Defaulted to: None

Set it to True if you want to append the -fPIC flag.

libs

List with library names of the requirements (-l in LIBS).

include_paths

List with the include paths of the requires (-I in CPPFLAGS).

library_paths

List with library paths of the requirements (-L in LDFLAGS).

defines

List with variables that will be defined with -D in CPPFLAGS.

flags

List with compilation flags (CFLAGS and CXXFLAGS).

cxx_flags

List with only C++ compilation flags (CXXFLAGS).

Properties

vars

Environment variables CPPFLAGS, CXXFLAGS, CFLAGS, LDFLAGS, LIBS generated by the build helper to use them in the configure, make and install steps. This variables are generated dynamically with the values of the attributes and can also be modified to be used in the following configure, make or install steps:

def build():
    auotools = AutoToolsBuildEnvironment()
    autotools.fpic = True
    env_build_vars = autotools.vars
    env_build_vars['RCFLAGS'] = '-O COFF'
    autotools.configure(vars=env_build_vars)
    autotools.make(vars=env_build_vars)
    autotools.install(vars=env_build_vars)

vars_dict

Same behavior as vars but this property returns each variable CPPFLAGS, CXXFLAGS, CFLAGS, LDFLAGS, LIBS as dictionaries.

Methods

configure()

def configure(self, configure_dir=None, args=None, build=None, host=None, target=None, pkg_config_paths=None, vars=None)

Configures Autotools project with the given parameters.

Important

This method sets by default the --prefix argument to self.package_folder whenever --prefix is not provided in the args parameter during the configure step.

Parameters:
  • configure_dir (Optional, Defaulted to None): Directory where the configure script is. If None, it will use the current directory.

  • args (Optional, Defaulted to None): A list of additional arguments to be passed to the configure script. Each argument will be escaped according to the current shell. No extra arguments will be added if args=None.

  • build (Optional, Defaulted to None): To specify a value for the parameter --build. If None it will try to detect the value if cross-building is detected according to the settings. If False, it will not use this argument at all.

  • host (Optional, Defaulted to None): To specify a value for the parameter --host. If None it will try to detect the value if cross-building is detected according to the settings. If False, it will not use this argument at all.

  • target (Optional, Defaulted to None): To specify a value for the parameter --target. If None it will try to detect the value if cross-building is detected according to the settings. If False, it will not use this argument at all.

  • pkg_config_paths (Optional, Defaulted to None): To specify folders (in a list) where to find *.pc files (by using the env var PKG_CONFIG_PATH). If None is specified but the conanfile is using the pkg_config generator, the self.build_folder will be added to the PKG_CONFIG_PATH in order to locate the pc files of the requirements of the conanfile.

  • vars (Optional, Defaulted to None): Overrides custom environment variables in the configure step.

make()

def make(self, args="", make_program=None, target=None, vars=None)

Builds Autotools project with the given parameters.

Parameters:
  • args (Optional, Defaulted to ""): A list of additional arguments to be passed to the make command. Each argument will be escaped accordingly to the current shell. No extra arguments will be added if args="".

  • make_program (Optional, Defaulted to None): Allows to specify a different make executable, e.j: mingw32-make. The environment variable CONAN_MAKE_PROGRAM can be used too.

  • 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.

  • vars (Optional, Defaulted to None): Overrides custom environment variables in the make step.

install()

def install(self, args="", make_program=None, vars=None)

Performs the install step of autotools calling make(target="install").

Paramenters:
  • args (Optional, Defaulted to ""): A list of additional arguments to be passed to the make command. Each argument will be escaped accordingly to the current shell. No extra arguments will be added if args="".

  • make_program (Optional, Defaulted to None): Allows to specify a different make executable, e.j: mingw32-make. The environment variable CONAN_MAKE_PROGRAM can be used too.

  • vars (Optional, Defaulted to None): Overrides custom environment variables in the install step.

Environment variables

The following environment variables will also affect the AutoToolsBuildEnvironment helper class.

NAME

DESCRIPTION

LIBS

Library names to link

LDFLAGS

Link flags, (-L, -m64, -m32)

CFLAGS

Options for the C compiler (-g, -s, -m64, -m32, -fPIC)

CXXFLAGS

Options for the C++ compiler (-g, -s, -stdlib, -m64, -m32, -fPIC, -std)

CPPFLAGS

Preprocessor definitions (-D, -I)