Makefile-来回编译 [英] Makefile - compiling back and forth
问题描述
以下是我的项目的目录结构:
Following is the directory structure of my project:
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:
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中的模块.我的make失败了,因为正在使用的模块在其他目录中.如何编写一个makefile来解决这个问题,即在subdir-1中编译模块时,每当遇到需要从subdir-2获取目标文件时,都应切换到subdir-2编译必要的模块并返回回到subdir-1采取进一步的行动?
I've written the Makefile_main such that it compiles the codes (modules) in subdir-1 first and then the ones in subdir-2 and finally makes the executable. The issue: modules in subdir-1 uses modules from subdir-2 and in similar fashion, modules in subdir-2 uses those in subdir-1. My make is getting failed because the modules being used is in other directory. How to write a makefile which will take care of this issue that is, while compiling modules in subdir-1, whenever it encounters the need for an object file from subdir-2, it should switch to subdir-2 compile the necessary modules and return back to subdir-1 for further action?
推荐答案
如果您说的不同子目录中的模块彼此需要,则这不是递归Make的好用法.
If modules in different subdirectories need each other as you say, then this is not a good use of recursive Make.
放弃Makefile-1
和Makefile-2
,让Makefile_main
完成所有工作. (我无法具体告诉您如何更改Makefile-main
,因为我不执行Fortran,所以我不理解Makefile-2
,并且我看不到subdir-2中的模块对subdir中的模块有任何依赖性. -1).
Do away with Makefile-1
and Makefile-2
, and let Makefile_main
do all the work. (I can't tell you specifically how to change Makefile-main
, since I don't do Fortran, I don't understand Makefile-2
, and I don't see any dependency of modules in subdir-2 upon those in subdir-1).
这篇关于Makefile-来回编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!