spack-Makefile使用手册

原文档链接:https://spack.readthedocs.io/en/latest/spack.build_systems.html#module-spack.build_systems.makefile

spack.build_systems.makefile 模块介绍

使用可编辑 Makefile 构建的包的专用类

这个类提供了三个可以被覆盖的方法:

  1. edit
  2. build
  3. install

通常来说edit方法需要被覆盖,而buildinstall方法并不需要覆盖(bushi)

方法 目的
build_targets 指定build阶段的make目标
install_targets 指定install阶段的make目标
build_directory() Makefile所在的位置(build阶段所在的目录)

常用方法

edit(self, spec, prefix)

主要作用为在执行build之前编辑Makefile,例如修改各类依赖库的位置

经常用到的操作:

需要引用源码中的某些文件,因此要获取安装过程中源码位置

1
pwd = os.getcwd()

需要编辑Makefile的某一项,示例地址:stream

1
2
3
4
5
6
7
8
# 使用FileFilter正则表达式替换
def edit(self, spec, prefix):
makefile = FileFilter('Makefile')

makefile.filter(r'^\s*CC\s*=.*', 'CC = ' + spack_cc)
makefile.filter(r'^\s*CXX\s*=.*', 'CXX = ' + spack_cxx)
makefile.filter(r'^\s*F77\s*=.*', 'F77 = ' + spack_f77)
makefile.filter(r'^\s*FC\s*=.*', 'FC = ' + spack_fc)

或编辑类似make.inc的文件,示例地址:elk

1
2
3
4
5
6
7
8
9
10
11
12
def edit(self, spec, prefix):
config = {
'CC': 'cc',
'MAKE': 'make',
}

if '+blas' in spec:
config['BLAS_LIBS'] = spec['blas'].libs.joined()

with open('make.inc', 'w') as inc:
for key in config:
inc.write('{0} = {1}\n'.format(key, config[key]))

编辑环境变量,示例地址:cebenchesmf(较复杂)

1
2
3
4
5
6
7
8
def edit(self, spec, prefix):
env['PREFIX'] = prefix
env['BLASLIB'] = spec['blas'].libs.ld_flags

# 或是
def setup_build_environment(self, env):
# The location of the PRESTO source tree
env.set('PRESTO', self.stage.source_path)

build(self, spec,prefix)

通过传递的build_targets参数,调用make

常用操作:

修改build目录(更喜欢用with working_dir('src'):)

1
2
build_directory = 'src'
make('target')

setup_build_environment(self, env)

设置build阶段的环境变量,示例如下:

1
2
3
def setup_build_environment(self, env):
env.append_path('LD_LIBRARY_PATH', self.stage.source_path + '/lib')
env.set('PRESTO', self.stage.source_path)

其余方法

build(spec, prefix)[source]
Calls make, passing build_targets as targets.

propertybuild_directory
Returns the directory containing the main Makefile

Returns
build directory

build_system_class= ‘MakefilePackage’
This attribute is used in UI queries that need to know the build system base class

build_targets= []
Targets for make during the build() phase

build_time_test_callbacks= [‘check’]
Callback names for build-time test

check()[source]
Searches the Makefile for targets test and check and runs them if found.

edit(spec, prefix)[source]
Edits the Makefile before calling make. This phase cannot be defaulted.

install(spec, prefix)[source]
Calls make, passing install_targets as targets.

install_targets= [‘install’]
Targets for make during the install() phase

install_time_test_callbacks= [‘installcheck’]
Callback names for install-time test

installcheck()[source]
Searches the Makefile for an installcheck target and runs it if found.

phases= [‘edit’, ‘build’, ‘install’]
Phases of a package that is built with an hand-written Makefile