[英]Specifying input sources (instead of intermediates) as prerequisites to target in Makefile
After reading the first few chapters of Managing Projects with GNU Make , I've come up with my first non-trivial Makefile 在阅读了《 使用GNU Make管理项目》的前几章之后,我想到了我的第一个平凡的Makefile。
all: libTest.a
libTest.a : Test.o MWE.o Test.dlink.o MWE.dlink.o
nvcc -ccbin g++ -m64 -gencode arch=compute_30,code=sm_30 -lib -o $@ $^
%.a : %.dlink.o %.o
nvcc -ccbin g++ -m64 -gencode arch=compute_30,code=sm_30 -lib -o $@ $^
%.dlink.o : %.o
nvcc -ccbin g++ -m64 -gencode arch=compute_30,code=sm_30 -dlink -o $@ $<
%.o: %.cu
nvcc -ccbin g++ -m64 -gencode arch=compute_30,code=sm_30 -dc -o $@ -c $<
clean:
rm -f *.o *.dlink.o
This Makefile works but I really don't like specifying the intermediate files Test.o MWE.o Test.dlink.o MWE.dlink.o
as prerequisites to libTest
. 这个Makefile的作品,但我真的不喜欢指定的中间文件Test.o MWE.o Test.dlink.o MWE.dlink.o
作为先决条件libTest
。 I'd rather specify the input files Test.cu
and MWE.cu
or better still the wildcard %.u
. 我宁愿指定输入文件Test.cu
和MWE.cu
或更好的通配符%.u
。
As long as you can prepare a command (or set of commands) to build libTest.a
from Test.cu
and MWE.cu
, you can have just a rule: 只要你可以准备一个命令(或命令集)来构建libTest.a
从Test.cu
和MWE.cu
,你可以只是一个规则:
libTest.a: Test.cu MWE.cu
list
of
commands
needed
to
build
the
library
but this is hardly a reasonable way of using make
. 但这不是使用make
的合理方法。 What you have shown us in original question is a make
-ish way of doing things. 什么你在原来的问题告诉我们是make
的做事方式-ish。 However if that's your whole Makefile
the rule %.a : %.dlink.o %.o
is superfluous here. 但是,如果这就是您的整个Makefile
则规则%.a : %.dlink.o %.o
在这里是多余的。
What you can do is to generate those prerequisites automatically: 您可以做的是自动生成这些先决条件:
SOURCES=Test.cu MWE.cu
libTest.a: $(SOURCES:%.cu=%.o) $(SOURCES:%.cu=%.dlink.o)
nvcc -ccbin g++ -m64 -gencode arch=compute_30,code=sm_30 -lib -o $@ $^
If you prefer to not add filenames manually to SOURCES
but prefer to use all *.cu
files available in current directory, replace the SOURCES
assignment with: 如果您不希望不手动将文件名添加到SOURCES
而是希望使用当前目录中所有可用的*.cu
文件,请将SOURCES
分配替换为:
SOURCES=$(wildcard *.cu)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.