automake with fortran: order of file

こ雲淡風輕ζ 提交于 2019-12-13 15:50:23

问题


I am facing a small problem when trying to build my code with autotools. My file structure is:

$ tree 
.
|-- configure.ac
|-- Makefile.am
`-- src
    |-- constants.f90
    |-- environment.f90
    |-- init.f90
    |-- main.f90
    `-- util.f90

(deleted possibly unnecessary lines) and my Makefile.am is:

#SUBDIRS= help
bin_PROGRAMS = scasr
scasr_SOURCES = \ 
                src/constants.f90  src/environment.f90  src/util.f90 \
                src/init.f90 src/main.f90 
scasr_LDADD = 
EXTRA_DIST= autogen.sh
CLEANFILES =*.mod 

The problem is src/(*.f90)'s except main.f90 are module. Hence, if I have to write the makefile by hand, I will have:

constants.o : constants.f90 
environment.o : environment.f90 
init.o : init.f90 util.o constants.o 
main.o : main.f90 init.o constants.o environment.o 
util.o : util.f90 constants.o 

so, for Makefile.am, I have to make a strict order of files in scasr_SOURCES. i.e. with the sources as :

scasr_SOURCES = \ 
                src/constants.f90  src/environment.f90  src/util.f90 \
                src/init.f90 src/main.f90 

It compiles fine. But if I have as:

scasr_SOURCES = src/main.f90 \ 
                src/constants.f90  src/environment.f90  src/util.f90 \
                src/init.f90  

I get error:

make  all-am
make[1]: Entering directory `/home/rudra/Programs/ScASR/trunk'
gfortran  -g -O2 -c -o src/main.o src/main.f90
src/main.f90:7.4:

use mget_env
    1
Fatal Error: Can't open module file 'mget_env.mod' for reading at (1):
No such file or directory
make[1]: *** [src/main.o] Error 1

Is there any way out so that make/configure will check the dependency by itself? Or I must keep a strict order?


回答1:


(Answers in the comments. See Question with no answers, but issue solved in the comments (or extended in chat) )

@Stefan wrote:

You could enter the dependencies directly to your Makefile.am. So simply put your handwritten Makefile rules (the third code part in your post) in the Makefile.am. Automatic dependency tracking is, as far as I know, not (yet) possible. This could change with the addition of submodules, which are defined in Fortran 2008 but not yet implemented in any popular compiler.

The OP Wrote:

As per @Stefan's comment, I have added the dependencies in make file, and that solved the problem. I have tested that the order of source code is not important anymore. Since, there is not many stuff in internet available, I am putting the complete procedure here:

  1. create a dependency list (makedepf90 is a good option)
$ makedepf90 src/*.f90 src/constants.o : src/constants.f90 src/environment.o : src/environment.f90 src/init.o : src/init.f90 src/util.o src/constants.o src/main.o : src/main.f90 src/init.o src/constants.o src/environment.o src/util.o : src/util.f90 src/constants.o
  1. Just copy-paste the output of step 1 after the scasr_SOURCES:

scasr_SOURCES = src/main.f90\ src/constants.f90 src/environment.f90 rc/util.f90 src/init.f90 src/constants.o : src/constants.f90 src/environment.o : src/environment.f90 src/init.o : src/init.f90 src/util.o src/constants.o src/main.o : src/main.f90 src/init.o src/constants.o src/environment.o src/util.o : src/util.f90 src/constants.o

NB: I have not tested if it will work if you place it some place else in the makefile. But this is working.



来源:https://stackoverflow.com/questions/17864763/automake-with-fortran-order-of-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!