
##----------------------------------------------------------##
##                                                          ##
##  Universal Makefile Backup Function                      ##
##                                                          ##
##  Created : Wei Liu 07/06/20                              ##
##  Revision: [Last]Wei Liu 07/07/07                        ##
##                                                          ##
##----------------------------------------------------------##


##--------------------------------------
##
##  Make backup
##
##--------------------------------------
# backup
TIME_STR   = ${shell date +%y%m%d_%H%M%S}
VER_STR    = $(sed -n '/$(MODULE)_VERSION/'p ./src/include/$(MODULE).h | \
               awk -F '[{,}]' $(print $2 $3 $4 ) )
BACK_PATH := ../../../r9_bak
BACK_PATH := $(BACK_PATH)/$(TYPE)/$(MODULE)
BACK_NAME  = $(MODULE)_$(VER_STR)_$(TIME_STR).tgz
LS         = ls -tl

version:
	@echo $(VER_STR)

backfile   ?= *

ifeq "$(backfile)" "*"
	backfile =$(wildcard $(BACK_PATH)/*.tgz)
	CHECK_BACK_FILE =$(backfile)
else
	CHECK_BACK_FILE =$(shell find $(BACK_PATH) -name $(backfile)) 
endif

bk: clean
	@$(MKDIR) -p $(BACK_PATH) --mode=0777 
	@echo Backuping $(MODULE)... $(BACK_PATH)/$(BACK_NAME)
	@tar czvf $(BACK_PATH)/$(BACK_NAME) ./src ./ut  ./doc ./Makefile
	
lsbk:
	@$(LS) $(BACK_PATH)

rmbk:
ifneq "$(CHECK_BACK_FILE)" ""
	@rm -rf $(BACK_PATH)/$(backfile)
	@$(LS) $(BACK_PATH)
endif
	
unzip: 
ifneq "$(CHECK_BACK_FILE)" ""
	@tar czvf $(BACK_PATH)/$(BACK_NAME) ./src ./ut  ./doc ./Makefile
	@tar zxvf $(BACK_PATH)/$(backfile)
	@ls $(BACK_PATH)	
endif

