tags:

views:

17

answers:

1

Dear Friends:

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)/*

A: 

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.)

Beta