
MAIN_MAKE=$(MAKE) -C $(ARBHOME)

REV_CHECK=$(ARBHOME)/SOURCE_TOOLS/rev_check.sh

SUCCEEDED_REVISION:=$(shell $(REV_CHECK) last_succeeded)
CURRENT_REVISION:=$(shell $(REV_CHECK) current)

ifeq ($(SUCCEEDED_REVISION),$(CURRENT_REVISION))
UPTODATE=1
else
UPTODATE=0
endif


build_CTARGET:
ifeq ($(CTARGET),)
	@echo "Error: You have to pass CTARGET to Makefile"
	false
else
	@echo "Last success: '$(SUCCEEDED_REVISION)'"
	@echo "Current rev:  '$(CURRENT_REVISION)'"
#	@echo "Uptodate:     '$(UPTODATE)'"
ifeq ($(UPTODATE),0)
	@echo "Need to make '$(CTARGET)'"
	+$(MAIN_MAKE) $(CTARGET)
	$(REV_CHECK) set_succeeded
else
	@echo "Already did a successful '$(CTARGET)' for [$(SUCCEEDED_REVISION)]"
endif
endif

reset:
	$(REV_CHECK) reset
