Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15530237
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类: Python/Ruby

2011-01-27 17:55:01

 makefile.rar  
make from=~/android/bionic
  1. hotcopy-dirs ?= android
  2. hotcopy2-dirs ?= ~/luther.gliethttp
  3. hotcopy-backup-file:=~/.hotcopy-backup-file

  4. ifneq ($(strip $(from)),)
  5. hotcopy-dirs := $(shell readlink -f $(from))
  6. endif

  7. ifneq ($(strip $(to)),)
  8. hotcopy2-dirs := $(shell readlink -f $(to))
  9. endif

  10. $(info copy data "from=$(hotcopy-dirs)" "to=$(hotcopy2-dirs)")

  11. define luther-find-files
  12. $(foreach n,$(1),$(shell find $(n) -type f))
  13. endef

  14. define luther-copy-file
  15. $(shell \
  16.     base_file=`echo $(1) | sed -e "s!^$(hotcopy-dirs)!!"             \
  17.                              -e "s!^/\{1,\}!!"`;                    \
  18.     base_file_abs=$(hotcopy2-dirs)/$$base_file;                        \
  19.     base_file_backup=$$base_file_abs".raw";                            \
  20.     if [ -f $$base_file_abs ]; then                                 \
  21.         [ -f $$base_file_backup ] || {                                \
  22.             cp -a $$base_file_abs $$base_file_backup;                 \
  23.             echo "[ -f $$base_file_backup ] &&
  24.             rename -f 's/.raw//' $$base_file_backup"                 \
  25.             >> $(hotcopy-backup-file);                                \
  26.         };                                                            \
  27.     else                                                            \
  28.         base_dir=`dirname $$base_file_abs`;                            \
  29.         if [ ! -d $$base_dir ]; then                                \
  30.             base_dir_pos=$$base_dir;                                \
  31.             base_dir_top=`dirname $(hotcopy2-dirs)`/`basename $(hotcopy2-dirs)`;\
  32.             while [ "$$base_dir_pos" != "$$base_dir_top" ]; do        \
  33.                 [ -d `dirname $$base_dir_pos` ] && break;            \
  34.                 base_dir_pos=`dirname $$base_dir_pos`;                \
  35.             done;                                                    \
  36.             mkdir -p $$base_dir;                                    \
  37.             echo "[ -d $$base_dir_pos ] &&
  38.             rm -rf $$base_dir_pos"                                    \
  39.             >> $(hotcopy-backup-file);                                \
  40.         fi;                                                         \
  41.         echo "[ -f $$base_file_abs ] &&
  42.         rm -f $$base_file_abs"                                        \
  43.         >> $(hotcopy-backup-file);                                    \
  44.         echo "[ -f $$base_file_backup ] &&
  45.         rm -f $$base_file_backup"                                     \
  46.         >> $(hotcopy-backup-file);                                    \
  47.     fi;                                                             \
  48.     cp -a $(1) $$base_file_abs                                         \
  49. )
  50. endef

  51. define luther-copy-files
  52. $(foreach n,$(1),$(call luther-copy-file, $(n)))
  53. endef

  54. define hot-copy-files
  55. $(call luther-copy-files, $(call luther-find-files, $(hotcopy-dirs)))
  56. endef

  57. # It's slow using this method, so hot-restore-files instead
  58. define hot-restore-files2
  59. $(shell \
  60.     base_file=`echo $(1) | cut -d'/' -f2-`;                            \
  61.     base_file_abs=$(hotcopy2-dirs)/$$base_file;                        \
  62.     base_file_backup=$$base_file_abs".raw";                            \
  63.     base_dir=`dirname $$base_file`;                                    \
  64.     mkdir -p $(hotcopy2-dirs)/$$base_dir;                            \
  65.     echo "[ -f $$base_file_backup ] &&
  66.     rename -f 's/.raw//' $$base_file_backup;"                         \
  67.     >> $(hotcopy-backup-file);                                        \
  68.     if [ -f $$base_file_abs -a ! -f $$base_file_backup ]; then         \
  69.         cp -a $$base_file_abs $$base_file_backup;                     \
  70.     fi;                                                             \
  71.     cp -a $(1) $(hotcopy2-dirs)/$$base_dir/                         \
  72. )
  73. endef

  74. define hot-restore-files
  75. $(shell \
  76.     [ -f $(hotcopy-backup-file) ] && {                                 \
  77.         . $(hotcopy-backup-file);                                     \
  78.         rm -f $(hotcopy-backup-file);                                \
  79.     };                                                                \
  80. )
  81. endef

  82. .PHONY: all clean

  83. all:
  84.     $(hot-copy-files)

  85. clean:
  86.     $(hot-restore-files)

阅读(4384) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~