< prev index next >

make/common/ZipArchive.gmk

Print this page


   1 #
   2 # Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
   3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 #
   5 # This code is free software; you can redistribute it and/or modify it
   6 # under the terms of the GNU General Public License version 2 only, as
   7 # published by the Free Software Foundation.  Oracle designates this
   8 # particular file as subject to the "Classpath" exception as provided
   9 # by Oracle in the LICENSE file that accompanied this code.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any


  31 endif
  32 
  33 # Setup make rules for creating a zip archive.
  34 #
  35 # Parameter 1 is the name of the rule. This name is used as variable prefix,
  36 # and the targets generated are listed in a variable by that name.
  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),)


 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
   1 #
   2 # Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
   3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 #
   5 # This code is free software; you can redistribute it and/or modify it
   6 # under the terms of the GNU General Public License version 2 only, as
   7 # published by the Free Software Foundation.  Oracle designates this
   8 # particular file as subject to the "Classpath" exception as provided
   9 # by Oracle in the LICENSE file that accompanied this code.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any


  31 endif
  32 
  33 # Setup make rules for creating a zip archive.
  34 #
  35 # Parameter 1 is the name of the rule. This name is used as variable prefix,
  36 # and the targets generated are listed in a variable by that name.
  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 #   ZIP_OPTIONS extra options to pass to zip
  52 SetupZipArchive = $(NamedParamsMacroTemplate)
  53 define SetupZipArchiveBody
  54 
  55   # To avoid running find over too large sets of files, which causes make to crash
  56   # on some configurations (cygwin), use INCLUDES and INCLUDE_FILES to build a set
  57   # of directories to run find in, if available.
  58   ifneq ($$($1_INCLUDES)$$($1_INCLUDE_FILES),)
  59     $1_FIND_LIST := $$(wildcard $$(foreach i,$$($1_SRC), \
  60         $$(addprefix $$i/,$$($1_INCLUDES) $$($1_INCLUDE_FILES))))
  61   else
  62     $1_FIND_LIST := $$($1_SRC)
  63   endif
  64 
  65   # Find all files in the source tree.
  66   $1_ALL_SRCS := $$(call not-containing,_the.,$$(call CacheFind,$$($1_FIND_LIST)))






  67 
  68   # Filter on suffixes if set
  69   ifneq ($$($1_SUFFIXES),)
  70     $1_ALL_SRCS := $$(filter $$(addprefix %, $$($1_SUFFIXES)), $$($1_ALL_SRCS))
  71   endif
  72 
  73   ifneq ($$($1_INCLUDES),)
  74     ifneq ($$($1_SUFFIXES),)
  75       $1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES), \
  76           $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$$s$(DQUOTE),$$($1_INCLUDES))))
  77     else
  78       $1_ZIP_INCLUDES := $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_INCLUDES)))
  79     endif
  80   else
  81     ifneq ($$($1_SUFFIXES),)
  82       $1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES), \
  83           $$(addprefix -i$(SPACE)$(DQUOTE),*$$s$(DQUOTE)))
  84     endif
  85   endif
  86   ifneq ($$($1_INCLUDE_FILES),)


 109     $$(if $$($1_EXCLUDE_PATTERNS_$$s), \
 110       $$(eval $1_ZIP_EXCLUDES_$$s += \
 111           $$(addprefix -x$$(SPACE), $$(subst %,\*,$$($1_EXCLUDE_PATTERNS_$$s))) \
 112       ) \
 113     ) \
 114   )
 115 
 116   # Use a slightly shorter name for logging, but with enough path to identify this zip.
 117   $1_NAME:=$$(subst $$(OUTPUTDIR)/,,$$($1_ZIP))
 118 
 119   # Now $1_ALL_SRCS should contain all sources that are going to be put into the zip.
 120   # I.e. the zip -i and -x options should match the filtering done in the makefile.
 121   # Explicitly excluded files can be given with absolute path. The patsubst solution
 122   # isn't perfect but the likelyhood of an absolute path to match something in a src
 123   # dir is very small.
 124   # If zip has nothing to do, it returns 12 and would fail the build. Check for 12
 125   # and only fail if it's not.
 126   $$($1_ZIP) : $$($1_ALL_SRCS) $$($1_EXTRA_DEPS)
 127         $$(call LogWarn, Updating $$($1_NAME))
 128         $$(call MakeTargetDir)
 129         $$(foreach s,$$($1_SRC),(cd $$s && $(ZIPEXE) -qru $$($1_ZIP_OPTIONS) $$@ . \
 130             $$($1_ZIP_INCLUDES) $$($1_ZIP_EXCLUDES) -x \*_the.\* \
 131             $$($1_ZIP_EXCLUDES_$$s) \
 132             || test "$$$$?" = "12" )$$(NEWLINE)) true




 133         $(TOUCH) $$@
 134 
 135   # Add zip to target list
 136   $1 += $$($1_ZIP)
 137 endef
 138 
 139 endif # _ZIP_ARCHIVE_GMK
< prev index next >