I've check this answer but I think it is not the same situation of mine.
I'm using f2py to compile my fortran code, so that I can import this fortran code in python.
For example, I have two fortran files: t.f90
and t2.f90
, and using this command to compile:
$ f2py -c t.f90 -m f90t
$ f2py -c t2.f90 -m f90t2
and two .so files are generated: f90t.cpython-36m-x86_64-linux-gnu.so
and f90t2.cpython-36m-x86_64-linux-gnu.so
.
I want to use Makefile to compile these files. My Makefile is like this:
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
The Makefile can work without error, but something is strange. If I change the content of one fortran file and execute Makefile, it still "compile" two fortran file, but actually the output file is not changed.
Like this:
$ 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 !!!!!!!!!!!!!!!!"
I have no idea why this happened. Can anyone help?
Any suggestion is grateful. Thanks!