比较两个文件夹
我想使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.)