< prev index next >

make/common/ZipArchive.gmk

Print this page




  37 #
  38 # Remaining parameters are named arguments. These include:
  39 #   SRC
  40 #   ZIP
  41 #   INCLUDES
  42 #   INCLUDE_FILES
  43 #   EXCLUDES
  44 #   EXCLUDE_FILES
  45 #   EXCLUDE_PATTERNS - Patterns with at most one % wildcard matching filenames
  46 #                      and not directories.
  47 #   EXCLUDE_PATTERNS_$dir - Exclude patterns just like above but specific to one
  48 #                           src dir
  49 #   SUFFIXES
  50 #   EXTRA_DEPS
  51 #   FOLLOW_SYMLINKS - Set to explicitly follow symlinks. Affects performance of
  52 #                     finding files.
  53 #   ZIP_OPTIONS extra options to pass to zip
  54 SetupZipArchive = $(NamedParamsMacroTemplate)
  55 define SetupZipArchiveBody
  56 
  57   # Create a version $1_SRC with a guaranteed trailing slash
  58   $1_SRC_SLASH := $$(addsuffix /, $$(patsubst %/, %, $$($1_SRC)))
  59 
  60   # To avoid running find over too large sets of files, which causes make to crash
  61   # on some configurations (cygwin), use INCLUDES and INCLUDE_FILES to build a set
  62   # of directories to run find in, if available.
  63   ifneq ($$($1_INCLUDES)$$($1_INCLUDE_FILES),)
  64     $1_FIND_LIST := $$(wildcard $$(foreach s,$$($1_SRC_SLASH), \
  65         $$(addprefix $$s,$$($1_INCLUDES) $$($1_INCLUDE_FILES))))
  66   else
  67     $1_FIND_LIST := $$($1_SRC_SLASH)
  68   endif
  69 
  70   # Find all files in the source tree.
  71   # If asked to, follow symlinks in this find since that is what zip does. To do
  72   # this, we need to call ShellFindFiles directly.
  73   ifeq ($$($1_FOLLOW_SYMLINKS), true)
  74     $1_ALL_SRCS := $$(call not-containing,_the.,$$(call ShellFindFiles,$$($1_FIND_LIST), , -L))
  75   else
  76     $1_ALL_SRCS := $$(call not-containing,_the.,$$(call FindFiles,$$($1_FIND_LIST)))
  77   endif
  78 
  79   # Filter on suffixes if set
  80   ifneq ($$($1_SUFFIXES),)
  81     $1_ALL_SRCS := $$(filter $$(addprefix %, $$($1_SUFFIXES)), $$($1_ALL_SRCS))
  82   endif
  83 
  84   ifneq ($$($1_INCLUDES),)
  85     ifneq ($$($1_SUFFIXES),)
  86       $1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES), \
  87           $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$$s$(DQUOTE),$$($1_INCLUDES))))
  88     else
  89       $1_ZIP_INCLUDES := $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_INCLUDES)))
  90     endif
  91   else
  92     ifneq ($$($1_SUFFIXES),)
  93       $1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES), \
  94           $$(addprefix -i$(SPACE)$(DQUOTE),*$$s$(DQUOTE)))
  95     endif
  96   endif
  97   ifneq ($$($1_INCLUDE_FILES),)
  98     $1_ZIP_INCLUDES += $$(addprefix -i$(SPACE),$$($1_INCLUDE_FILES))
  99   endif
 100   ifneq ($$($1_EXCLUDES),)
 101     $1_ZIP_EXCLUDES := $$(addprefix -x$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_EXCLUDES)))
 102     $1_SRC_EXCLUDES := $$(foreach s,$$($1_SRC_SLASH),$$(addprefix $$s,$$(addsuffix /%,$$($1_EXCLUDES))))
 103     $1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_SRCS))
 104   endif
 105   ifneq ($$($1_EXCLUDE_FILES),)
 106     $1_SRC_EXCLUDE_FILES := $$(addprefix %, $$($1_EXCLUDE_FILES)) $$($1_EXCLUDE_FILES)
 107     $1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDE_FILES), $$($1_ALL_SRCS))
 108     $$(foreach s, $$($1_SRC_SLASH), \
 109       $$(eval $1_ZIP_EXCLUDES_$$s += \
 110           $$(addprefix -x$$(SPACE), $$(patsubst $$s%,%, $$($1_EXCLUDE_FILES))) \
 111       ) \
 112     )
 113   endif
 114   ifneq ($$($1_EXCLUDE_PATTERNS), )
 115     $1_ALL_SRCS := $$(filter-out $$($1_EXCLUDE_PATTERNS), $$($1_ALL_SRCS))
 116     $1_ZIP_EXCLUDES += $$(addprefix -x$(SPACE), $$(subst %,\*,$$($1_EXCLUDE_PATTERNS)))
 117   endif
 118   # Rewrite src dir specific exclude patterns to zip excludes
 119   $$(foreach s, $$($1_SRC_SLASH), \
 120     $$(if $$($1_EXCLUDE_PATTERNS_$$s), \
 121       $$(eval $1_ZIP_EXCLUDES_$$s += \
 122           $$(addprefix -x$$(SPACE), $$(subst %,\*,$$($1_EXCLUDE_PATTERNS_$$s))) \
 123       ) \
 124     ) \
 125   )
 126 
 127   # Use a slightly shorter name for logging, but with enough path to identify this zip.
 128   $1_NAME:=$$(subst $$(OUTPUTDIR)/,,$$($1_ZIP))
 129 
 130   # Now $1_ALL_SRCS should contain all sources that are going to be put into the zip.
 131   # I.e. the zip -i and -x options should match the filtering done in the makefile.
 132   # Explicitly excluded files can be given with absolute path. The patsubst solution
 133   # isn't perfect but the likelyhood of an absolute path to match something in a src
 134   # dir is very small.
 135   # If zip has nothing to do, it returns 12 and would fail the build. Check for 12
 136   # and only fail if it's not.
 137   $$($1_ZIP) : $$($1_ALL_SRCS) $$($1_EXTRA_DEPS)
 138         $$(call LogWarn, Updating $$($1_NAME))
 139         $$(call MakeTargetDir)
 140         # Find duplicate file names in the SRC and generate excludes for all
 141         # instances that should not be included. Run this rather expensive
 142         # calculation as part of the recipe to avoid running it when nothing
 143         # needs to be rebuilt. The drawback is that we cannot exclude these
 144         # files from the make prerequisites list, but the number of files is
 145         # usually small so a very rare unnecessary rebuild is worth it.
 146         # (The inner most foreach here is used instead of eval to declare a
 147         # local variable.)
 148         $$(foreach root, $$($1_SRC_SLASH), \
 149           $$(foreach file, $$(filter $$(root)%, $$($1_ALL_SRCS)), \
 150             $$(foreach relfile, $$(patsubst $$(root)%, %, $$(file)), \
 151               $$(if $$($1_relfiles_$$(call DoubleDollar, $$(relfile))), \
 152                 $$(eval $1_ZIP_EXCLUDES_$$(root) += -x $$(relfile)) \
 153               , \
 154                 $$(eval $1_relfiles_$$(call DoubleDollar, $$(relfile)) := 1) \
 155               ) \
 156             ) \
 157           ) \
 158         )
 159         $$(foreach s,$$($1_SRC_SLASH), $$(call ExecuteWithLog, \
 160             $$(SUPPORT_OUTPUTDIR)/zip/$$(patsubst $$(OUTPUTDIR)/%,%, $$@), \
 161             (cd $$s && $(ZIPEXE) -qru $$($1_ZIP_OPTIONS) $$@ . \
 162                 $$($1_ZIP_INCLUDES) $$($1_ZIP_EXCLUDES) -x \*_the.\* \
 163                 $$($1_ZIP_EXCLUDES_$$s) \
 164                 || test "$$$$?" = "12" \
 165             ))$$(NEWLINE) \
 166         ) true \
 167         $(TOUCH) $$@
 168 
 169   # Add zip to target list
 170   $1 += $$($1_ZIP)
 171 endef
 172 
 173 endif # _ZIP_ARCHIVE_GMK


  37 #
  38 # Remaining parameters are named arguments. These include:
  39 #   SRC
  40 #   ZIP
  41 #   INCLUDES
  42 #   INCLUDE_FILES
  43 #   EXCLUDES
  44 #   EXCLUDE_FILES
  45 #   EXCLUDE_PATTERNS - Patterns with at most one % wildcard matching filenames
  46 #                      and not directories.
  47 #   EXCLUDE_PATTERNS_$dir - Exclude patterns just like above but specific to one
  48 #                           src dir
  49 #   SUFFIXES
  50 #   EXTRA_DEPS
  51 #   FOLLOW_SYMLINKS - Set to explicitly follow symlinks. Affects performance of
  52 #                     finding files.
  53 #   ZIP_OPTIONS extra options to pass to zip
  54 SetupZipArchive = $(NamedParamsMacroTemplate)
  55 define SetupZipArchiveBody
  56 



  57   # To avoid running find over too large sets of files, which causes make to crash
  58   # on some configurations (cygwin), use INCLUDES and INCLUDE_FILES to build a set
  59   # of directories to run find in, if available.
  60   ifneq ($$($1_INCLUDES)$$($1_INCLUDE_FILES),)
  61     $1_FIND_LIST := $$(wildcard $$(foreach i,$$($1_SRC), \
  62         $$(addprefix $$i/,$$($1_INCLUDES) $$($1_INCLUDE_FILES))))
  63   else
  64     $1_FIND_LIST := $$($1_SRC)
  65   endif
  66 
  67   # Find all files in the source tree.
  68   # If asked to, follow symlinks in this find since that is what zip does. To do
  69   # this, we need to call ShellFindFiles directly.
  70   ifeq ($$($1_FOLLOW_SYMLINKS), true)
  71     $1_ALL_SRCS := $$(call not-containing,_the.,$$(call ShellFindFiles,$$($1_FIND_LIST), , -L))
  72   else
  73     $1_ALL_SRCS := $$(call not-containing,_the.,$$(call FindFiles,$$($1_FIND_LIST)))
  74   endif
  75 
  76   # Filter on suffixes if set
  77   ifneq ($$($1_SUFFIXES),)
  78     $1_ALL_SRCS := $$(filter $$(addprefix %, $$($1_SUFFIXES)), $$($1_ALL_SRCS))
  79   endif
  80 
  81   ifneq ($$($1_INCLUDES),)
  82     ifneq ($$($1_SUFFIXES),)
  83       $1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES), \
  84           $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$$s$(DQUOTE),$$($1_INCLUDES))))
  85     else
  86       $1_ZIP_INCLUDES := $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_INCLUDES)))
  87     endif
  88   else
  89     ifneq ($$($1_SUFFIXES),)
  90       $1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES), \
  91           $$(addprefix -i$(SPACE)$(DQUOTE),*$$s$(DQUOTE)))
  92     endif
  93   endif
  94   ifneq ($$($1_INCLUDE_FILES),)
  95     $1_ZIP_INCLUDES += $$(addprefix -i$(SPACE),$$($1_INCLUDE_FILES))
  96   endif
  97   ifneq ($$($1_EXCLUDES),)
  98     $1_ZIP_EXCLUDES := $$(addprefix -x$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_EXCLUDES)))
  99     $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
 100     $1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_SRCS))
 101   endif
 102   ifneq ($$($1_EXCLUDE_FILES),)
 103     $1_SRC_EXCLUDE_FILES := $$(addprefix %, $$($1_EXCLUDE_FILES)) $$($1_EXCLUDE_FILES)
 104     $1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDE_FILES), $$($1_ALL_SRCS))
 105     $$(foreach s, $$($1_SRC), \
 106       $$(eval $1_ZIP_EXCLUDES_$$s += \
 107           $$(addprefix -x$$(SPACE), $$(patsubst $$s/%,%, $$($1_EXCLUDE_FILES))) \
 108       ) \
 109     )
 110   endif
 111   ifneq ($$($1_EXCLUDE_PATTERNS), )
 112     $1_ALL_SRCS := $$(filter-out $$($1_EXCLUDE_PATTERNS), $$($1_ALL_SRCS))
 113     $1_ZIP_EXCLUDES += $$(addprefix -x$(SPACE), $$(subst %,\*,$$($1_EXCLUDE_PATTERNS)))
 114   endif
 115   # Rewrite src dir specific exclude patterns to zip excludes
 116   $$(foreach s, $$($1_SRC), \
 117     $$(if $$($1_EXCLUDE_PATTERNS_$$s), \
 118       $$(eval $1_ZIP_EXCLUDES_$$s += \
 119           $$(addprefix -x$$(SPACE), $$(subst %,\*,$$($1_EXCLUDE_PATTERNS_$$s))) \
 120       ) \
 121     ) \
 122   )
 123 
 124   # Use a slightly shorter name for logging, but with enough path to identify this zip.
 125   $1_NAME:=$$(subst $$(OUTPUTDIR)/,,$$($1_ZIP))
 126 
 127   # Now $1_ALL_SRCS should contain all sources that are going to be put into the zip.
 128   # I.e. the zip -i and -x options should match the filtering done in the makefile.
 129   # Explicitly excluded files can be given with absolute path. The patsubst solution
 130   # isn't perfect but the likelyhood of an absolute path to match something in a src
 131   # dir is very small.
 132   # If zip has nothing to do, it returns 12 and would fail the build. Check for 12
 133   # and only fail if it's not.
 134   $$($1_ZIP) : $$($1_ALL_SRCS) $$($1_EXTRA_DEPS)
 135         $$(call LogWarn, Updating $$($1_NAME))
 136         $$(call MakeTargetDir)
 137         $$(foreach s,$$($1_SRC), $$(call ExecuteWithLog, \



















 138             $$(SUPPORT_OUTPUTDIR)/zip/$$(patsubst $$(OUTPUTDIR)/%,%, $$@), \
 139             (cd $$s && $(ZIPEXE) -qru $$($1_ZIP_OPTIONS) $$@ . \
 140                 $$($1_ZIP_INCLUDES) $$($1_ZIP_EXCLUDES) -x \*_the.\* \
 141                 $$($1_ZIP_EXCLUDES_$$s) \
 142                 || test "$$$$?" = "12" \
 143             ))$$(NEWLINE) \
 144         ) true \
 145         $(TOUCH) $$@
 146 
 147   # Add zip to target list
 148   $1 += $$($1_ZIP)
 149 endef
 150 
 151 endif # _ZIP_ARCHIVE_GMK
< prev index next >