尝试使用自动工具构建代码时,我遇到了一个小问题。我的文件结构是:
$ tree
.
|-- configure.ac
|-- Makefile.am
`-- src
|-- constants.f90
|-- environment.f90
|-- init.f90
|-- main.f90
`-- util.f90
(删除了可能不必要的行),我的 Makefile.am 是:
#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
问题是 src/(*.f90) 除了 main.f90 是模块。因此,如果我必须手动编写 makefile,我将拥有:
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
因此,对于 Makefile.am,我必须对 scasr_SOURCES 中的文件进行严格的排序。即来源为:
scasr_SOURCES = \
src/constants.f90 src/environment.f90 src/util.f90 \
src/init.f90 src/main.f90
它编译得很好。但如果我有:
scasr_SOURCES = src/main.f90 \
src/constants.f90 src/environment.f90 src/util.f90 \
src/init.f90
我得到错误:
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
有没有办法让 make/configure 自己检查依赖关系?还是我必须遵守严格的秩序?