简体   繁体   English

隐式构建规则:GNU使多个Makefile成为多个目录

[英]Implicit Build Rules: GNU Make Multiple Makefiles Multiple Directories

I have the following directory structure: 我有以下目录结构:

.
..
./Graphic/
./Graphic/SymbolXLib

There are several other directories in this project but I won't list them for simplicities sake.I want a main makefile that drives the build of other Makefiles stored in their own directories. 这个项目中还有其他几个目录,但是为了简单起见,我不会列出它们。我想要一个主Makefile,该文件可以驱动其他存储在其自己目录中的Makefile的构建。 There are several project comming together, so I can't just move source around. 有几个项目在一起,所以我不能随便移动源代码。

The main makefile is defined as: 主makefile定义为:

[mehoggan@hogganz400 Core]$ cat ./Makefile 
CORE_LIBS_DIR = libs
OBJS_DIR = obj/symb_obj
include ./Graphic/SymbolXLib/Makefile

The Graphic makefile is defined as: 图形makefile定义为:

#
# make BUILD_MODE={release|debug} OS_ARCH={32|64}
# 
# default is 32-bit release build
#
BUILD_MODE = release

OS_ARCH = 64

OBJS_DIR = $(BUILD_MODE)$(OS_ARCH)

SRC = \
  ./Graphic/SymbolXLib/CartoCursor.cpp \
  ...
  ./Graphic/SymbolXLib/TextureConversion.cpp \
  $(NULL)

CC = gcc -fPIC
OBJS = $(SRC:%.cpp=$(OBJS_DIR)/%.o)

COPTS = -m$(OS_ARCH) -O2

CDEFS = -DLINUXx86 \
        -I../../../SharedArcGIS/Include/GraphicsPipeline/Display/SymbolX/SymbolXLib \
        -I../../../SharedArcGIS/Include/System/Geometry/GeometryXLib \
        -I../../../ArcSDE/pe/include \
        -I../../../ArcSDE/shape/include

CFLAGS = $(COPTS) $(CDEFS) $(CINCS)
TARGET = libSymbolXLib.a

all : $(OBJS_DIR) $(OBJS_DIR)/$(TARGET)

$(OBJS_DIR) : 
        mkdir -p $(OBJS_DIR) 

$(OBJS_DIR)/$(TARGET) : $(OBJS)
        ar qc $@ $^

$(OBJS_DIR)/%.o : %.cpp
        $(CC) -c $(CFLAGS) -o $@ $<

The response at the previous post ( Previous Post ) helped only if I moved alot of things around. 仅当我移动了很多东西时, 上一篇文章( Previous Post )的响应才有所帮助。 I can't do this. 我做不到 So the question still remains, how do I get make to recognize the implicit build in a subdirectory from the main Makefile? 因此问题仍然存在,我如何获得make来识别主Makefile子目录中的隐式构建?

The error I am getting is 我得到的错误是

make: *** No rule to make target `release64/./Graphic/SymbolXLib/CartoCursor.o', needed by `release64/libSymbolXLib.a'.  Stop.

I have to think you'd have far better success if you avoided include and instead use recursive make . 我必须认为,如果避免使用include而是使用递归make那么您将获得更好的成功。 In the top-level Makefile , something like: 在顶级Makefile ,类似:

graphic:
    $(MAKE) -C Graphic

And the Makefile in Graphic/Makefile can have its sub-projects: Makefile中的Graphic/Makefile可以有其子课题:

symbolxlib:
    $(MAKE) -C SymbolXLib

and so on. 等等。 You might need to add each of the targets to a default target or something similar to hang them all together on a single execution. 您可能需要将每个目标添加到默认目标或类似的方法,以将它们全部挂在一起在一次执行中。 You could give each of these targets an actual dependency (they should be .PHONY: if they don't have a dependency...) to rebuild them only when necessary or when commanded to by an upper-level target that touch(1) es "command files". 您可以为每个目标提供实际的依赖关系(它们应该为.PHONY:如果它们没有依赖关系...),则仅在必要时或在上级目标touch(1)发出命令时才重建它们es“命令文件”。

Alternatively, this paper recommends a different approach to avoid recursive make , but I've not yet read it -- and have found recursive make works well enough in projects I've been a part of that I don't mind recommending it. 另外, 本文推荐了不同的方法,以避免重复make ,但我从来没有读过-并发现递归make工程项目不够好,我去过那我不介意建议的一部分。

该gnumake文档是否对您有帮助?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM