Source code for spack_repo.builtin.build_systems.makefile

# Copyright Spack Project Developers. See COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
from typing import List

from spack.package import (
    BuilderWithDefaults,
    PackageBase,
    Prefix,
    Spec,
    apply_macos_rpath_fixups,
    build_system,
    conflicts,
    depends_on,
    execute_install_time_tests,
    register_builder,
    run_after,
    when,
    working_dir,
)

from ._checks import execute_build_time_tests


[docs] class MakefilePackage(PackageBase): """Specialized class for packages built using Makefiles.""" #: This attribute is used in UI queries that need to know the build #: system base class build_system_class = "MakefilePackage" #: Legacy buildsystem attribute used to deserialize and install old specs default_buildsystem = "makefile" build_system("makefile") with when("build_system=makefile"): conflicts("platform=windows") depends_on("gmake", type="build")
[docs] @register_builder("makefile") class MakefileBuilder(BuilderWithDefaults): """The Makefile builder encodes the most common way of building software with Makefiles. It has three phases that can be overridden, if need be: 1. :py:meth:`~.MakefileBuilder.edit` 2. :py:meth:`~.MakefileBuilder.build` 3. :py:meth:`~.MakefileBuilder.install` It is usually necessary to override the :py:meth:`~.MakefileBuilder.edit` phase (which is by default a no-op), while the other two have sensible defaults. For a finer tuning you may override: +-----------------------------------------------+--------------------+ | **Method** | **Purpose** | +===============================================+====================+ | :py:attr:`~.MakefileBuilder.build_targets` | Specify ``make`` | | | targets for the | | | build phase | +-----------------------------------------------+--------------------+ | :py:attr:`~.MakefileBuilder.install_targets` | Specify ``make`` | | | targets for the | | | install phase | +-----------------------------------------------+--------------------+ | :py:meth:`~.MakefileBuilder.build_directory` | Directory where the| | | Makefile is located| +-----------------------------------------------+--------------------+ """ phases = ("edit", "build", "install") #: Names associated with package methods in the old build-system format package_methods = ("check", "installcheck") #: Names associated with package attributes in the old build-system format package_attributes = ( "build_targets", "install_targets", "build_time_test_callbacks", "install_time_test_callbacks", "build_directory", ) #: Targets for ``make`` during the :py:meth:`~.MakefileBuilder.build` phase build_targets: List[str] = [] #: Targets for ``make`` during the :py:meth:`~.MakefileBuilder.install` phase install_targets = ["install"] #: Callback names for build-time test build_time_test_callbacks = ["check"] #: Callback names for install-time test install_time_test_callbacks = ["installcheck"] @property def build_directory(self) -> str: """Return the directory containing the main Makefile.""" return self.pkg.stage.source_path
[docs] def edit(self, pkg: MakefilePackage, spec: Spec, prefix: Prefix) -> None: """Edit the Makefile before calling make. The default is a no-op.""" pass
[docs] def build(self, pkg: MakefilePackage, spec: Spec, prefix: Prefix) -> None: """Run "make" on the build targets specified by the builder.""" with working_dir(self.build_directory): pkg.module.make(*self.build_targets)
[docs] def install(self, pkg: MakefilePackage, spec: Spec, prefix: Prefix) -> None: """Run "make" on the install targets specified by the builder.""" with working_dir(self.build_directory): pkg.module.make(*self.install_targets)
run_after("build")(execute_build_time_tests)
[docs] def check(self) -> None: """Run "make" on the ``test`` and ``check`` targets, if found.""" with working_dir(self.build_directory): self.pkg._if_make_target_execute("test") self.pkg._if_make_target_execute("check")
run_after("install")(execute_install_time_tests)
[docs] def installcheck(self) -> None: """Searches the Makefile for an ``installcheck`` target and runs it if found. """ with working_dir(self.build_directory): self.pkg._if_make_target_execute("installcheck")
# On macOS, force rpaths for shared library IDs and remove duplicate rpaths run_after("install", when="platform=darwin")(apply_macos_rpath_fixups)