fab.tools.linker#

This file contains the base class for any Linker.

Classes

Linker(compiler[, linker, name])

This is the base class for any Linker.

class fab.tools.linker.Linker(compiler, linker=None, name=None)#

This is the base class for any Linker. It takes an existing compiler instance as parameter, and optional another linker. The latter is used to get linker settings - for example, linker-mpif90-gfortran will use mpif90-gfortran as compiler (i.e. to test if it is available and get compilation flags), and linker-gfortran as linker. This way a user only has to specify linker flags in the most basic class (gfortran), all other linker wrapper will inherit the settings.

Parameters:
  • compiler (Compiler) – a compiler instance

  • linker (Optional[Linker]) – an optional linker instance (default: None)

  • name (Optional[str]) – name of the linker (default: None)

Raises:
  • RuntimeError – if both compiler and linker are specified.

  • RuntimeError – if neither compiler nor linker is specified.

check_available()#
Return type:

bool

Returns:

whether this linker is available by asking the wrapped linker or compiler.

property suite: str#
Returns:

the suite this linker belongs to by getting it from the wrapped compiler.

property mpi: bool#
Returns:

whether this linker supports MPI or not by checking with the wrapped compiler.

property openmp: bool#
Returns:

whether this linker supports OpenMP or not by checking with the wrapped compiler.

property output_flag: str#
Returns:

the flag that is used to specify the output name.

define_profile(name, inherit_from=None)#

Defines a new profile name, and allows to specify if this new profile inherit settings from an existing profile.

Parameters:
  • name (str) – Name of the profile to define.

  • inherit_from (Optional[str]) – Optional name of a profile to inherit settings from. (default: None)

get_profile_flags(profile)#
Return type:

List[str]

Returns:

the ProfileFlags for the given profile, combined from the wrapped compiler and this wrapper.

Parameters:

profile (str) – the profile to use.

get_lib_flags(lib)#

Gets the standard flags for a standard library

Parameters:

lib (str) – the library name

Return type:

List[str]

Returns:

a list of flags

Raises:

RuntimeError – if lib is not recognised

add_lib_flags(lib, flags, silent_replace=False)#

Add a set of flags for a standard library

Parameters:
  • lib (str) – the library name

  • flags (List[str]) – the flags to use with the library

  • silent_replace (bool) – if set, no warning will be printed when an existing lib is overwritten. (default: False)

add_pre_lib_flags(flags, profile=None)#

Add a set of flags to use before any library-specific flags

Parameters:

flags (List[str]) – the flags to include

add_post_lib_flags(flags, profile=None)#

Add a set of flags to use after any library-specific flags

Parameters:

flags (List[str]) – the flags to include

Returns the list of pre-link flags. It will concatenate the flags for this instance with all potentially wrapped linkers. This wrapper’s flag will come first - the assumption is that the pre-link flags are likely paths, so we need a wrapper to be able to put a search path before the paths from a wrapped linker.

Return type:

List[str]

Returns:

List of pre-link flags of this linker and all wrapped linkers

get_post_link_flags(config)#

Returns the list of post-link flags. It will concatenate the flags for this instance with all potentially wrapped linkers. This wrapper’s flag will be added to the end.

Return type:

List[str]

Returns:

List of post-link flags of this linker and all wrapped linkers

Executes the linker with the specified input files, creating output_file.

Parameters:
  • input_files (List[Path]) – list of input files to link.

  • output_file (Path) – output file.

  • config (BuildConfig) – The BuildConfig, from which compiler profile and OpenMP status are taken.

  • libs (Optional[List[str]]) – additional libraries to link with. (default: None)

Return type:

str

Returns:

the stdout of the link command