
all:	cavacheck sync_master .make_last_install

# Make sure that the CAVA environment is set up.

cavacheck:
        @rc=0 ;                                          \
        if [ "x${CAVA}" = "x" ] ; then                   \
            echo CAVA not set ;                          \
            rc=$$(( $$rc + 1 )) ;                        \
        fi ;                                             \
        if ( echo ${PATH} | grep -vq ${CAVA}/bin) ; then    \
            echo ${CAVA}/bin is not in the PATH ;           \
            rc=$$(( $$rc + 2 )) ;                        \
        fi ;                                             \
        if ( echo ${PATH} | grep -vq ${CAVA}/tools ) ; then \
            echo ${CAVA}/tools is not in the PATH ;         \
            rc=$$(( $$rc + 4 )) ;                        \
        fi ; exit $$rc

# If CAVABUILD has a value, use the new scheme for build directories.
# Otherwise, use the old scheme.

ifeq ($(CAVABUILD),)
  BUILD_DIR = ../../caveat/make	
  BINUTILS_BUILD_DIR = ../../binutils/make
else
  BUILD_DIR = ${CAVABUILD}/caveat
  BINUTILS_BUILD_DIR = ${CAVABUILD}/binutils
endif

$(BUILD_DIR):
	mkdir -p $(BUILD_DIR)


.make_last_install:	.diffcp_last_updated $(BUILD_DIR)

	make -C ${CAVA}/caveat

	touch .make_last_install

rebuild:
	rm -rf $(BUILD_DIR)/*

sync_master:
	diffcp action.h			$(CAVA)/caveat/action.h
	diffcp opcode.c			$(CAVA)/caveat/opcode.c
	diffcp dispatch.h		$(CAVA)/caveat/dispatch.h
	diffcp emulator_extras.h 	$(CAVA)/caveat/emulator_extras.h
	diffcp ../binutils/include/opcode_cava.h $(CAVA)/caveat/opcode_cava.h
