makefile.rar make from=~/android/bionic
- hotcopy-dirs ?= android
-
hotcopy2-dirs ?= ~/luther.gliethttp
-
hotcopy-backup-file:=~/.hotcopy-backup-file
-
-
ifneq ($(strip $(from)),)
-
hotcopy-dirs := $(shell readlink -f $(from))
-
endif
-
-
ifneq ($(strip $(to)),)
- hotcopy2-dirs
:= $(shell readlink -f $(to))
-
endif
-
-
$(info copy data "from=$(hotcopy-dirs)" "to=$(hotcopy2-dirs)")
-
-
define luther-find-files
-
$(foreach n,$(1),$(shell find $(n) -type f))
-
endef
-
-
define luther-copy-file
-
$(shell \
-
base_file=`echo $(1) | sed -e "s!^$(hotcopy-dirs)!!" \
-
-e "s!^/\{1,\}!!"`; \
-
base_file_abs=$(hotcopy2-dirs)/$$base_file; \
-
base_file_backup=$$base_file_abs".raw"; \
-
if [ -f $$base_file_abs ]; then \
-
[ -f $$base_file_backup ] || { \
-
cp -a $$base_file_abs $$base_file_backup; \
-
echo "[ -f $$base_file_backup ] &&
-
rename -f 's/.raw//' $$base_file_backup" \
-
>> $(hotcopy-backup-file); \
-
}; \
-
else \
-
base_dir=`dirname $$base_file_abs`; \
-
if [ ! -d $$base_dir ]; then \
-
base_dir_pos=$$base_dir; \
-
base_dir_top=`dirname $(hotcopy2-dirs)`/`basename $(hotcopy2-dirs)`;\
-
while [ "$$base_dir_pos" != "$$base_dir_top" ]; do \
-
[ -d `dirname $$base_dir_pos` ] && break; \
-
base_dir_pos=`dirname $$base_dir_pos`; \
-
done; \
-
mkdir -p $$base_dir; \
-
echo "[ -d $$base_dir_pos ] &&
-
rm -rf $$base_dir_pos" \
-
>> $(hotcopy-backup-file); \
-
fi; \
-
echo "[ -f $$base_file_abs ] &&
-
rm -f $$base_file_abs" \
-
>> $(hotcopy-backup-file); \
-
echo "[ -f $$base_file_backup ] &&
-
rm -f $$base_file_backup" \
-
>> $(hotcopy-backup-file); \
-
fi; \
-
cp -a $(1) $$base_file_abs \
-
)
-
endef
-
-
define luther-copy-files
-
$(foreach n,$(1),$(call luther-copy-file, $(n)))
-
endef
-
-
define hot-copy-files
-
$(call luther-copy-files, $(call luther-find-files, $(hotcopy-dirs)))
-
endef
-
-
# It's slow using this method, so hot-restore-files instead
-
define hot-restore-files2
-
$(shell \
-
base_file=`echo $(1) | cut -d'/' -f2-`; \
-
base_file_abs=$(hotcopy2-dirs)/$$base_file; \
-
base_file_backup=$$base_file_abs".raw"; \
-
base_dir=`dirname $$base_file`; \
-
mkdir -p $(hotcopy2-dirs)/$$base_dir; \
-
echo "[ -f $$base_file_backup ] &&
-
rename -f 's/.raw//' $$base_file_backup;" \
-
>> $(hotcopy-backup-file); \
-
if [ -f $$base_file_abs -a ! -f $$base_file_backup ]; then \
-
cp -a $$base_file_abs $$base_file_backup; \
-
fi; \
-
cp -a $(1) $(hotcopy2-dirs)/$$base_dir/ \
-
)
-
endef
-
-
define hot-restore-files
-
$(shell \
-
[ -f $(hotcopy-backup-file) ] && { \
-
. $(hotcopy-backup-file); \
-
rm -f $(hotcopy-backup-file); \
-
}; \
-
)
-
endef
-
-
.PHONY: all clean
-
-
all:
-
$(hot-copy-files)
-
-
clean:
-
$(hot-restore-files)
阅读(4384) | 评论(0) | 转发(0) |