make/common/ZipArchive.gmk
changeset 27602 236555ddac42
parent 27560 adc258b13e2c
parent 27592 af7df0dd5ff7
child 29312 f3f859137ce6
equal deleted inserted replaced
27581:9fffb959eb41 27602:236555ddac42
       
     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
       
    23 # questions.
       
    24 #
       
    25 
       
    26 ifndef _ZIP_ARCHIVE_GMK
       
    27 _ZIP_ARCHIVE_GMK := 1
       
    28 
       
    29 ifeq (,$(_MAKEBASE_GMK))
       
    30   $(error You must include MakeBase.gmk prior to including ZipArchive.gmk)
       
    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 #   SUFFIXES
       
    46 #   EXTRA_DEPS
       
    47 #   ZIP_OPTIONS extra options to pass to zip
       
    48 define SetupZipArchive
       
    49   $(if $(16),$(error Internal makefile error: Too many arguments to SetupZipArchive, please update ZipArchive.gmk))
       
    50   $(call EvalDebugWrapper,$(strip $1),$(call SetupZipArchiveInner,$(strip $1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)))
       
    51 endef
       
    52 
       
    53 define SetupZipArchiveInner
       
    54   $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $(strip $($i)),$1_$(strip $($i)))$(NEWLINE))
       
    55   $(call LogSetupMacroEntry,SetupZipArchive($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
       
    56   $(if $(16),$(error Internal makefile error: Too many arguments to SetupZipArchive, please update JavaCompilation.gmk))
       
    57 
       
    58   # To avoid running find over too large sets of files, which causes make to crash
       
    59   # on some configurations (cygwin), use INCLUDES and INCLUDE_FILES to build a set
       
    60   # of directories to run find in, if available.
       
    61   ifneq ($$($1_INCLUDES)$$($1_INCLUDE_FILES),)
       
    62     $1_FIND_LIST := $$(wildcard $$(foreach i,$$($1_SRC), \
       
    63         $$(addprefix $$i/,$$($1_INCLUDES) $$($1_INCLUDE_FILES))))
       
    64   else
       
    65     $1_FIND_LIST := $$($1_SRC)
       
    66   endif
       
    67 
       
    68   # Find all files in the source tree.
       
    69   $1_ALL_SRCS := $$(call not-containing,_the.,$$(call CacheFind,$$($1_FIND_LIST)))
       
    70 
       
    71   # Filter on suffixes if set
       
    72   ifneq ($$($1_SUFFIXES),)
       
    73     $1_ALL_SRCS := $$(filter $$(addprefix %, $$($1_SUFFIXES)), $$($1_ALL_SRCS))
       
    74   endif
       
    75 
       
    76   ifneq ($$($1_INCLUDES),)
       
    77     ifneq ($$($1_SUFFIXES),)
       
    78       $1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES), \
       
    79           $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$$s$(DQUOTE),$$($1_INCLUDES))))
       
    80     else
       
    81       $1_ZIP_INCLUDES := $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_INCLUDES)))
       
    82     endif
       
    83   endif
       
    84   ifneq ($$($1_INCLUDE_FILES),)
       
    85     $1_ZIP_INCLUDES += $$(addprefix -i$(SPACE),$$($1_INCLUDE_FILES))
       
    86   endif
       
    87   ifneq ($$($1_EXCLUDES),)
       
    88     $1_ZIP_EXCLUDES := $$(addprefix -x$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_EXCLUDES)))
       
    89     $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
       
    90     $1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_SRCS))
       
    91   endif
       
    92   ifneq ($$($1_EXCLUDE_FILES),)
       
    93     # Cannot precompute ZIP_EXCLUDE_FILES as it is dependent on which src root is being
       
    94     # zipped at the moment.
       
    95     $1_SRC_EXCLUDE_FILES := $$(addprefix %, $$($1_EXCLUDE_FILES)) $$($1_EXCLUDE_FILES)
       
    96     $1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDE_FILES), $$($1_ALL_SRCS))
       
    97   endif
       
    98 
       
    99   # Use a slightly shorter name for logging, but with enough path to identify this zip.
       
   100   $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_ZIP))
       
   101 
       
   102   # Now $1_ALL_SRCS should contain all sources that are going to be put into the zip.
       
   103   # I.e. the zip -i and -x options should match the filtering done in the makefile.
       
   104   # Explicitly excluded files can be given with absolute path. The patsubst solution
       
   105   # isn't perfect but the likelyhood of an absolute path to match something in a src
       
   106   # dir is very small.
       
   107   # If zip has nothing to do, it returns 12 and would fail the build. Check for 12
       
   108   # and only fail if it's not.
       
   109   $$($1_ZIP) : $$($1_ALL_SRCS) $$($1_EXTRA_DEPS)
       
   110 	$(MKDIR) -p $$(@D)
       
   111 	$(ECHO) Updating $$($1_NAME)
       
   112 	$$(foreach i,$$($1_SRC),(cd $$i && $(ZIP) -qru $$($1_ZIP_OPTIONS) $$@ . $$($1_ZIP_INCLUDES) \
       
   113 	    $$($1_ZIP_EXCLUDES) -x \*_the.\* \
       
   114 	    $$(addprefix -x$(SPACE), $$(patsubst $$i/%,%, $$($1_EXCLUDE_FILES))) \
       
   115 	    || test "$$$$?" = "12" )$$(NEWLINE)) true
       
   116 	$(TOUCH) $$@
       
   117 
       
   118   # Add zip to target list
       
   119   $1 += $$($1_ZIP)
       
   120 endef
       
   121 
       
   122 endif # _ZIP_ARCHIVE_GMK