搜索子目录并更新makefile中的路径变量 [英] search subdirectories and update path variables in makefile

查看:465
本文介绍了搜索子目录并更新makefile中的路径变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从Windows环境迁移到Linux,并被要求更新项目-仍在学习,但提示会有所帮助! 我有一个目录结构:

I have just moved from Windows environment to Linux, and have been asked to update a project - still learning but tips would be helpful! I have a directory structure:

RootMakefile.mk
.
.--\GUI1 (Folder)
.......|--config(Folder)
.......|--dataprep(Folder)
...............|---makeVar1.mk
.--\GUI2 (Folder)
.......|--config(Folder)
.......|--dataprep(Folder)
...............|....makeVar2.mk.

makeVar1.mk,makeVar2.mk与之相似,只是变量更改了路径值:

And makeVar1.mk,makeVar2.mk are all similar with just the variables changing the path values:

GUI1_ALL:=GUI1/GUI1_generated.txt

GUI2_ALL:=GUI2/GUI2_generated.txt

我正在尝试仅在根目录创建一个makefile,以便新的GUI文件夹不需要添加新的makefile.

I am trying to make just one makefile at the root so that new GUI folders don't need add new makefiles.

我尝试过的事情: 我将根makefile更改如下:

What I have tried: I changed the root makefile as following:

    TARGET_FILE := GuiDetails.rb
    ACTIVE_GUIS := $(wildcard GUI*/$(TARGET_FILE)))
    GUIS_OF_INTEREST := $(dir $(ACTIVE_GUIS)))
    DATAPREP := dataprep

    GUIS:= $(patsubst %/,%,$(GUIS_OF_INTEREST))
    $(warning The following SMA paths have guis $(GUIS))
    $(foreach GUIS, $(GUIS), $(eval $(call UPDATE_GUI_PATH, $(GUIS), $(DATAPREP))))

$(foreach GUIDEWAYS, $(GUIDEWAYS), $(eval   $(call UPDATE_PATH, $(GUIDEWAYS), $(DATAPREP)))))


define UPDATE_PATH
GUIX_ALL:= $(ROOT)/COMMON/$(1)/$(2)
$(warning GUI1_ALL is set to $(GUIX_ALL))
endef

但是该值未按预期显示,输出为:

But the value do not show up as expected, the output is:

GUIX_ALL is set to 
GUIX_ALL is set to ./COMMON/GUI1/DATAPREP

为什么要转移?

推荐答案

好吧,在定义变量之前(define),尝试使用变量UPDATE_PATH(在foreach循环中);当您在foreach中使用它时,其值为空,因此是空操作.将foreach移到define之后,而不是在它之前.

Well, you try to use the variable UPDATE_PATH (in the foreach loop) before you've defined it (later with define); when you use it in foreach, its value is empty so that is a no-op. Move the foreach so it's after the define, not before it.

第二,您需要转义要推迟到评估之前的变量的值. UPDATE_PATH的值在被传递给eval之前,将通过call函数进行一次扩展.在转义eval之前不需要扩展的内容(例如warning$(GUIX_ALL)引用).

Second, you need to escape the value of the variables you want to defer until the evaluation. The value of UPDATE_PATH will be expanded once by the call function, before it's handed to eval. Things that you don't want expanded until the eval (such as the warning and $(GUIX_ALL) reference) need to be escaped.

我还假设您在foreach的第二个参数中表示的是$(GUIS)而不是$(GUIDEWAYS).

Also I assume you mean $(GUIS) not $(GUIDEWAYS) in the second argument to foreach.

我不知道引用UPDATE_GUI_PATHforeach循环,因为此处未定义.

I don't know about the foreach loop referencing UPDATE_GUI_PATH because that's not defined here.

创建示例时,最好是实际运行它们并确保它们在发布之前达到了您的期望(即使不是您想要的).否则,对于我们来说,很难理解您所面临的真正问题是什么,而不是将您的问题准确地转化为问题.

When creating examples it's best if you actually run them and make sure they do what you expected (even if it's not what you wanted) before posting. Otherwise it's very hard for us to understand what is the real problem you're facing, vs. what's just an inaccurate translation of your problem into the question.

所以,像这样:

define UPDATE_PATH
GUIX_ALL := $(ROOT)/COMMON/$(1)/$(2)
$$(warning GUIX_ALL is set to $$(GUIX_ALL))
endef

$(foreach GUIDEWAYS,$(GUIS),$(eval $(call UPDATE_PATH,$(GUIDEWAYS),$(DATAPREP)))))

但是,我不知道它的作用是什么,因为您只是一遍又一遍地重置相同的变量.最后,变量GUIX_ALL将仅具有最后一个的值.也许您想在这里使用+=而不是:=?

However, I don't know what purpose this serves since you're just resetting the same variable over and over; at the end the variable GUIX_ALL will simply have the value of the last one. Maybe you wanted to use += here not :=?

但是,如果您只需要路径列表,那么为什么要使用calleval的所有复杂性?为什么不设置:

But if all you want is a list of paths, then why are you using all the complexity of call and eval? Why not just set:

GUIX_ALL := $(patsubst %,$(ROOT)/common/%/$(DATAPREP),$(GUIS))

这篇关于搜索子目录并更新makefile中的路径变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆