简体   繁体   English

具有多个目标的 Makefile

[英]Makefile with multiple targets

Hopefully this is a very simple question.希望这是一个非常简单的问题。 I have a makefile pattern rule that looks like this:我有一个看起来像这样的 makefile 模式规则:

%.so : %.f %.pyf
    f2py -c -L${LAPACK_DIR} ${GRASPLIBS} -m $* $^ ${SOURCES} --opt='-02' --f77flags='-fcray-pointer' >> silent.txt

I want the makefile to build a number of .so files, so I tried to get it to build two files (radgrd_py.so and lodiso_py.so) by doing this:我希望 makefile 构建多个 .so 文件,因此我尝试通过执行以下操作使其构建两个文件(radgrd_py.so 和 lodiso_py.so):

radgrd_py.so lodiso_py.so:

%.so : %.f %.pyf
f2py -c -L${LAPACK_DIR} ${GRASPLIBS} -m $* $^ ${SOURCES} --opt='-02' --f77flags='-fcray-pointer' >> silent.txt

and then tried this:然后尝试这个:

radgrd_py.so:

lodiso_py.so:

%.so : %.f %.pyf
f2py -c -L${LAPACK_DIR} ${GRASPLIBS} -m $* $^ ${SOURCES} --opt='-02' --f77flags='-fcray-pointer' >> silent.txt

But in each case, it only builds the first target that I specify.但在每种情况下,它只构建我指定的第一个目标。 If I run 'make radgrd_py.so' it works fine, I'm just not sure how to specify a list of files that need to be built so I can just run 'make'.如果我运行'make radgrd_py.so'它工作正常,我只是不确定如何指定需要构建的文件列表,以便我可以运行'make'。

The usual trick is to add a 'dummy' target as the first that depends on all targets you want to build when running a plain make :通常的技巧是添加一个“虚拟”目标作为第一个,这取决于您在运行普通make时要构建的所有目标:

all: radgrd_py.so lodiso_py.so

It is a convention to call this target 'all' or 'default'.将此目标称为“全部”或“默认”是惯例。 For extra correctness, let make know that this is not a real file by adding this line to your Makefile :为了额外的正确性,通过将这一行添加到你的Makefile来让make知道这不是一个真正的文件:

.PHONY: all

Best way is to add:最好的方法是添加:

.PHONY: all
.DEFAULT: all
all: radgrd_py.so lodiso_py.so

Explanations:说明:

make uses the first target appearing when no .DEFAULT is specified.当没有指定.DEFAULT时, make使用出现的第一个目标。

.PHONY informs make that the targets (a coma-separated list, in fact) don't create any file or folder. .PHONY通知make目标(实际上是一个.PHONY分隔的列表)不创建任何文件或文件夹。

all: as proposed by schot all:正如schot所提议的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM