比较两个文件夹

发布于 2024-09-26 04:51:36 字数 1193 浏览 3 评论 0原文

我想使用 makefile 来比较两个文件夹。如果两个文件夹相同,我不执行任何操作,但如果它们不同,我想创建一个文件夹。这是我抱怨的 makefile:

#BINDIREXISTS:=T
ifeq "../.build" "../TopicA"
/bin/sh: ifeq: not found
make: *** [checkDest] Error 127

makefile 如下:

PROJNAME=TopicA
TOP=..
SRCDIR=src
BUILDDIR=.build
SRC=TopicA.cpp
EXECUTABLE=TopicA.exe
CC=g++

#################################
#MACROS:
define bindirchk
#BINDIREXISTS:=$(shell if [ -d '$(TOP)/$(1)/$(2)/' ]; then echo "T"; else echo "F"; fi )
    ifeq "$(strip $(TOP)/$(1))" "$(strip $(TOP)/$(2))"
        echo "T"
    else
        echo "F"
    endif   
endef

define mkbuilddirs
    @echo creating build directories $(TOP)/$(1) and $(TOP)/$(1)/$(2)
    $(shell mkdir -p $(TOP)/$(1) $(TOP)/$(1)/$(2))
endef

#################################
#main targets and pre-reqs

all: checkDest 
        #$(CC) $(SRCDIR)/$(SRC) -o $(TOP)/$(BUILDDIR)/$(PROJNAME)/$(EXECUTABLE)


checkDest: 
    $(call bindirchk,$(BUILDDIR),$(PROJNAME))
    echo $(BINDIREXISTS)
    if [ "$(BINDIREXISTS)" "F" ]; then 
    #   echo test found to be true
        $(shell mkdir -p $(TOP)/$(1) $(TOP)/$(1)/$(2))
    fi

clean:
        rm -rf $(TOP)/$(BUILDDIR)/*

I want to use a makefile to compare two folders. If the two folders are equal I don't do anything, but if they are different I want to create a folder. Here is my makefile which is complaining about:

#BINDIREXISTS:=T
ifeq "../.build" "../TopicA"
/bin/sh: ifeq: not found
make: *** [checkDest] Error 127

The makefile is the following:

PROJNAME=TopicA
TOP=..
SRCDIR=src
BUILDDIR=.build
SRC=TopicA.cpp
EXECUTABLE=TopicA.exe
CC=g++

#################################
#MACROS:
define bindirchk
#BINDIREXISTS:=$(shell if [ -d '$(TOP)/$(1)/$(2)/' ]; then echo "T"; else echo "F"; fi )
    ifeq "$(strip $(TOP)/$(1))" "$(strip $(TOP)/$(2))"
        echo "T"
    else
        echo "F"
    endif   
endef

define mkbuilddirs
    @echo creating build directories $(TOP)/$(1) and $(TOP)/$(1)/$(2)
    $(shell mkdir -p $(TOP)/$(1) $(TOP)/$(1)/$(2))
endef

#################################
#main targets and pre-reqs

all: checkDest 
        #$(CC) $(SRCDIR)/$(SRC) -o $(TOP)/$(BUILDDIR)/$(PROJNAME)/$(EXECUTABLE)


checkDest: 
    $(call bindirchk,$(BUILDDIR),$(PROJNAME))
    echo $(BINDIREXISTS)
    if [ "$(BINDIREXISTS)" "F" ]; then 
    #   echo test found to be true
        $(shell mkdir -p $(TOP)/$(1) $(TOP)/$(1)/$(2))
    fi

clean:
        rm -rf $(TOP)/$(BUILDDIR)/*

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

删除→记忆 2024-10-03 04:51:36

Make 没有用于比较两个文件(以及两个目录)是否相等的本机方法。因此,您必须在 Make 将调用的某种脚本中进行相等性检查(也许您已经尝试这样做,但这很难说)。如果您这样做,您也可以在脚本中添加条件和创建新目录的代码;将其放入 makefile 中实际上不会获得任何好处。所以这实际上是一个脚本问题,一旦脚本可以工作,从 makefile 调用它就很简单了。

(我推荐 Perl,但我听说 Python 也很好。)

Make doesn't have a native method for comparing two files for equality (and thereby two directories). So you'll have to do the equality-checking in some kind of script which Make will call (maybe you're trying to do that already, it's hard to tell). And if you do that, you might as well put conditional and the code for making a new directory in the script as well; you really don't gain anything by putting that in the makefile. So this is really a scripting problem, and once you have the script working, calling it from the makefile will be trivial.

(I recommend Perl, but I hear Python is very good too.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文