以下是我的项目的目录结构:
expt-main
---------
Makefile_main
/ \
subdir-1 subdir-2
-------- --------
Makefile_1 Makefile_2
mod_codeA.f90 mod_code1.f90
mod_codeB.f90 mod_code2.f90
mod_codeC.f90 mod_code3.f90
Makefile_main:
export
SHELL = /bin/sh
F90 = mpxlf95
SRCDIRS = $(subdir-1) $(subdir-2)
all:
@for DIR in ${SRCDIRS} ;
do \
back=`pwd`; \
cd $$DIR ;\
$(MAKE) ; status=$$? ; \
if [ $$status != 0 ] ; then \
echo "Exit status fro make was $$status" ; exit $$status ; \
fi ; \
cd $$back ; \
done
-------------------------------------------------------------------------------
Makefile-1:
%.o: %.f90
$(F90) $(F90FLAGS) -I$(subdir-2) -c $<
mod_codeA.o: mod_codeC.o $(subdir-2)/mod_code2.o
-------------------------------------------------------------------------------
Makefile-2:
PROG = $(exec)
subdir-1_objs = $(subdir-1)/mod_codeA.o mod_codeB.o mod_codeC.o
all: $(PROG)
$(PROG): $(subdir-2_objs) $(subdir-1_objs) -o $@ $(subdir-2_objs) $(subdir-1_objs)
---------------------------------------------------------------------------------
-
我编写了 Makefile_main 以便它首先编译 subdir-1 中的代码(模块),然后编译 subdir-2 中的代码(模块),最后编译为可执行文件。问题:subdir-1 中的模块使用 subdir-2 中的模块,并且以类似的方式,subdir-2 中的模块使用 subdir-1 中的模块。我的制作失败了,因为正在使用的模块在其他目录中。如何编写一个 makefile 来解决这个问题,即在 subdir-1 中编译模块时,每当遇到需要从 subdir-2 获取目标文件时,它应该切换到 subdir-2 编译必要的模块并返回返回 subdir-1 进行进一步操作?