Makefile 编译所有目标文件而不是最新修改的文件
Makefile compiled all target files instead of the lastest modified file
我已经检查过,但我认为这与我的情况不一样。
我正在使用 f2py 编译我的 fortran 代码,这样我就可以在 python.
中导入这个 fortran 代码
比如我有两个fortran文件:t.f90
和t2.f90
,用这个命令编译:
$ f2py -c t.f90 -m f90t
$ f2py -c t2.f90 -m f90t2
并生成两个.so文件:f90t.cpython-36m-x86_64-linux-gnu.so
和f90t2.cpython-36m-x86_64-linux-gnu.so
。
我想用Makefile来编译这些文件。我的 Makefile 是这样的:
FILES = t.f90 t2.f90
NAMES = $(basename $(FILES))
TARGET = $(addprefix f90, $(NAMES))
all : $(TARGET)
f90% : %.f90
@echo "Compile $< to $@"
f2py -c $< -m $@
.PHONY : clean
clean :
rm f90*.so
Makefile 可以正常工作,但有些地方很奇怪。如果我更改一个fortran文件的内容并执行Makefile,它仍然会“编译”两个fortran文件,但实际上输出文件并没有改变。
像这样:
$ ls # run.py will execute the function of t.f90 and t2.f90
Makefile run.py t.f90 t2.f90
$ make
Compile t.f90 to f90t
....
Compile t2.f90 to f90t2
....
$ python run.py
"This line is printed by t.f90"
"This line is printed by t2.f90"
$ vim t2.f90 # adding some exclamation mark
$ make # I only modified t2.f90, but t.f90 is also compiled
Compile t.f90 to f90t
....
Compile t2.f90 to f90t2
....
$ python run.py # still the old result
"This line is printed by t.f90"
"This line is printed by t2.f90"
$ make clean
$ make
Compile t.f90 to f90t
....
Compile t2.f90 to f90t2
....
$ python run.py # finally ok
"This line is printed by t.f90"
"This line is printed by t2.f90 !!!!!!!!!!!!!!!!"
我不知道为什么会这样。有人可以帮忙吗?
任何建议都不胜感激。谢谢!
您的 makefile 期望构建 f90t
和 f90t2
,但正如您所说
two .so files are generated: f90t.cpython-36m-x86_64-linux-gnu.so
因此,在下一个 运行 上,make 没有找到 f90t
并再次调用该命令。你可以这样做
@touch $@
在规则末尾或重命名目标。
我已经检查过
我正在使用 f2py 编译我的 fortran 代码,这样我就可以在 python.
中导入这个 fortran 代码
比如我有两个fortran文件:t.f90
和t2.f90
,用这个命令编译:
$ f2py -c t.f90 -m f90t
$ f2py -c t2.f90 -m f90t2
并生成两个.so文件:f90t.cpython-36m-x86_64-linux-gnu.so
和f90t2.cpython-36m-x86_64-linux-gnu.so
。
我想用Makefile来编译这些文件。我的 Makefile 是这样的:
FILES = t.f90 t2.f90
NAMES = $(basename $(FILES))
TARGET = $(addprefix f90, $(NAMES))
all : $(TARGET)
f90% : %.f90
@echo "Compile $< to $@"
f2py -c $< -m $@
.PHONY : clean
clean :
rm f90*.so
Makefile 可以正常工作,但有些地方很奇怪。如果我更改一个fortran文件的内容并执行Makefile,它仍然会“编译”两个fortran文件,但实际上输出文件并没有改变。
像这样:
$ ls # run.py will execute the function of t.f90 and t2.f90
Makefile run.py t.f90 t2.f90
$ make
Compile t.f90 to f90t
....
Compile t2.f90 to f90t2
....
$ python run.py
"This line is printed by t.f90"
"This line is printed by t2.f90"
$ vim t2.f90 # adding some exclamation mark
$ make # I only modified t2.f90, but t.f90 is also compiled
Compile t.f90 to f90t
....
Compile t2.f90 to f90t2
....
$ python run.py # still the old result
"This line is printed by t.f90"
"This line is printed by t2.f90"
$ make clean
$ make
Compile t.f90 to f90t
....
Compile t2.f90 to f90t2
....
$ python run.py # finally ok
"This line is printed by t.f90"
"This line is printed by t2.f90 !!!!!!!!!!!!!!!!"
我不知道为什么会这样。有人可以帮忙吗?
任何建议都不胜感激。谢谢!
您的 makefile 期望构建 f90t
和 f90t2
,但正如您所说
two .so files are generated: f90t.cpython-36m-x86_64-linux-gnu.so
因此,在下一个 运行 上,make 没有找到 f90t
并再次调用该命令。你可以这样做
@touch $@
在规则末尾或重命名目标。